7#include "mouse_buttons.hpp"
8#include "../geometry/point.hpp"
9#include "../geometry/vector.hpp"
10#include "../geometry/transform.hpp"
13namespace hi::inline v1 {
16 enum class Type { None, Entered, Exited, Move, Drag, ButtonDown, ButtonUp, Wheel };
20 std::chrono::utc_time<std::chrono::nanoseconds> timePoint;
40 mouse_event() noexcept : type(Type::None), position(), cause(), down(), clickCount(0) {}
42 [[nodiscard]]
bool empty() const noexcept
44 return type == Type::None;
47 operator bool() const noexcept
52 static mouse_event entered(point2 position = {})
noexcept
55 event.position = position;
56 event.type = mouse_event::Type::Entered;
60 static mouse_event exited() noexcept
67 event.position = point2{far_, far_};
68 event.type = mouse_event::Type::Exited;
76 return type == Type::ButtonUp and cause.leftButton and active_area.contains(position);
83 return type == Type::Drag ? position - downPosition :
vector2{};
89 r.position =
point2{transform * rhs.position};
90 r.downPosition = point2{transform * rhs.downPosition};
91 r.wheelDelta = vector2{
transform * rhs.wheelDelta};
99 using enum mouse_event::Type;
100 case None: type_s =
"none";
break;
101 case Entered: type_s =
"entered";
break;
102 case Exited: type_s =
"exited";
break;
103 case Move: type_s =
"move";
break;
104 case Drag: type_s =
"drag";
break;
105 case ButtonDown: type_s =
"down";
break;
106 case ButtonUp: type_s =
"up";
break;
107 case Wheel: type_s =
"wheel";
break;
108 default: hi_no_default();
111 return std::format(
"<mouse {} {}>", type_s, rhs.position);
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Definition mouse_buttons.hpp:11
Definition mouse_event.hpp:15
mouse_buttons cause
Buttons which has caused this event.
Definition mouse_event.hpp:32
vector2 wheelDelta
Change in wheel rotation, in pixels.
Definition mouse_event.hpp:29
bool is_left_button_up(aarectangle active_area) const noexcept
Check if this event is for a left-button-up event while the mouse pointer is in the given area.
Definition mouse_event.hpp:74
int clickCount
Number of clicks from the last button clicked.
Definition mouse_event.hpp:38
point2 position
The current position of the mouse pointer.
Definition mouse_event.hpp:23
point2 downPosition
The position the last time a button was pressed.
Definition mouse_event.hpp:26
mouse_buttons down
Buttons that are pressed/held down.
Definition mouse_event.hpp:35
vector2 delta() const noexcept
Get the location of the mouse relative to the start of a drag.
Definition mouse_event.hpp:81
Definition transform.hpp:82