aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/click_detector.hpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-05-24 01:40:02 +0800
committercrupest <crupest@outlook.com>2020-05-24 01:40:02 +0800
commitd86a71f79afe0e4dac768f61d6bff690567aca5b (patch)
tree4957e9a64c77680deb07201fbd879bf036616dae /include/cru/ui/click_detector.hpp
parentf3a8fd608a9776ef0a5f547da918a32cf6074060 (diff)
downloadcru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.gz
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.tar.bz2
cru-d86a71f79afe0e4dac768f61d6bff690567aca5b.zip
...
Diffstat (limited to 'include/cru/ui/click_detector.hpp')
-rw-r--r--include/cru/ui/click_detector.hpp86
1 files changed, 0 insertions, 86 deletions
diff --git a/include/cru/ui/click_detector.hpp b/include/cru/ui/click_detector.hpp
deleted file mode 100644
index 6c4761e7..00000000
--- a/include/cru/ui/click_detector.hpp
+++ /dev/null
@@ -1,86 +0,0 @@
-#pragma once
-#include "control.hpp"
-
-
-namespace cru::ui {
-class ClickEventArgs : Object {
- public:
- ClickEventArgs(Control* sender, const Point& down_point,
- const Point& up_point, MouseButton button)
- : sender_(sender),
- down_point_(down_point),
- up_point_(up_point),
- button_(button) {}
-
- CRU_DEFAULT_COPY(ClickEventArgs)
- CRU_DEFAULT_MOVE(ClickEventArgs)
-
- ~ClickEventArgs() override = default;
-
- Control* GetSender() const { return sender_; }
- Point GetDownPoint() const { return down_point_; }
- Point GetUpPoint() const { return up_point_; }
- MouseButton GetButton() const { return button_; }
-
- private:
- Control* sender_;
- Point down_point_;
- Point up_point_;
- MouseButton button_;
-};
-
-enum class ClickState {
- None, // Mouse is outside the control.
- Hover, // Mouse hovers on the control but not pressed
- Press, // Mouse is pressed and if released click is done.
- PressInactive // Mouse is pressed but if released click is canceled.
-};
-
-class ClickDetector : public Object {
- public:
- explicit ClickDetector(Control* control);
-
- CRU_DELETE_COPY(ClickDetector)
- CRU_DELETE_MOVE(ClickDetector)
-
- ~ClickDetector() override = default;
-
- Control* GetControl() const { return control_; }
-
- ClickState GetState() const { return state_; }
-
- // Default is enable.
- bool IsEnabled() const { return enable_; }
- // If disable when user is pressing, the pressing is deactivated.
- void SetEnabled(bool enable);
-
- // Default is left and right.
- MouseButton GetTriggerButton() const { return trigger_button_; }
- // If unset the trigger button when user is pressing, the pressing is
- // deactivated.
- void SetTriggerButton(MouseButton trigger_button);
-
- IEvent<ClickEventArgs>* ClickEvent() { return &event_; }
-
- IEvent<ClickState>* StateChangeEvent() { return &state_change_event_; }
-
- private:
- void SetState(ClickState state);
-
- private:
- Control* control_;
-
- ClickState state_;
-
- bool enable_ = true;
- MouseButton trigger_button_ = mouse_buttons::left | mouse_buttons::right;
-
- Event<ClickEventArgs> event_;
- Event<ClickState> state_change_event_;
-
- std::vector<EventRevokerGuard> event_rovoker_guards_;
-
- Point down_point_;
- MouseButton button_;
-};
-} // namespace cru::ui