ttx 0.1.0
Loading...
Searching...
No Matches
mouse_event.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/reflect/enumerator.h"
4#include "di/reflect/field.h"
5#include "di/reflect/prelude.h"
6#include "dius/tty.h"
7#include "ttx/modifiers.h"
8#include "ttx/mouse.h"
9
10namespace ttx {
11enum class MouseEventType {
12 Press = 1,
13 Move = 2,
15};
16
17constexpr auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseEventType>) {
18 using enum MouseEventType;
19 return di::make_enumerators<"KeyEventType">(di::enumerator<"Press", Press>, di::enumerator<"Move", Move>,
20 di::enumerator<"Release", Release>);
21}
22
24public:
29
32 : m_type(type), m_button(button), m_position(position), m_modifiers(modifiers) {}
33
34 constexpr auto type() const -> MouseEventType { return m_type; }
35 constexpr auto button() const -> MouseButton { return m_button; }
36 constexpr auto position() const -> MousePosition const& { return m_position; }
37 constexpr auto modifiers() const -> Modifiers { return m_modifiers; }
38
39 constexpr auto is_vertical_scroll() const -> bool { return !!(button() & MouseButton::VerticalScrollButtons); }
40
41 constexpr auto translate(MouseCoordinate offset_in_cells, dius::tty::WindowSize const& size) const -> MouseEvent {
42 return { type(), button(), position().translate(offset_in_cells, size), modifiers() };
43 }
44
45 auto operator==(MouseEvent const&) const -> bool = default;
46
47private:
48 constexpr friend auto tag_invoke(di::Tag<di::reflect>, di::InPlaceType<MouseEvent>) {
49 return di::make_fields<"MouseEvent">(
50 di::field<"type", &MouseEvent::m_type>, di::field<"button", &MouseEvent::m_button>,
51 di::field<"position", &MouseEvent::m_position>, di::field<"modifers", &MouseEvent::m_modifiers>);
52 }
53
55 MouseButton m_button { MouseButton::None };
56 MousePosition m_position;
57 Modifiers m_modifiers { Modifiers::None };
58};
59}
Definition mouse.h:39
Definition mouse_event.h:23
constexpr MouseEvent(MouseEventType type, MouseButton button, MousePosition const &position={}, Modifiers modifiers=Modifiers::None)
Definition mouse_event.h:30
constexpr auto type() const -> MouseEventType
Definition mouse_event.h:34
constexpr auto is_vertical_scroll() const -> bool
Definition mouse_event.h:39
static constexpr auto press(MouseButton button, MousePosition const &position={}, Modifiers modifiers=Modifiers::None) -> MouseEvent
Definition mouse_event.h:25
constexpr friend auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< MouseEvent >)
Definition mouse_event.h:48
auto operator==(MouseEvent const &) const -> bool=default
constexpr auto position() const -> MousePosition const &
Definition mouse_event.h:36
constexpr auto modifiers() const -> Modifiers
Definition mouse_event.h:37
constexpr auto button() const -> MouseButton
Definition mouse_event.h:35
constexpr auto translate(MouseCoordinate offset_in_cells, dius::tty::WindowSize const &size) const -> MouseEvent
Definition mouse_event.h:41
Definition mouse.h:59
Definition cursor_style.h:5
MouseButton
Definition mouse.h:10
@ VerticalScrollButtons
Definition mouse.h:24
@ None
Definition mouse.h:11
Modifiers
Definition modifiers.h:9
@ None
Definition modifiers.h:10
@ Press
Definition key_event.h:13
@ Release
Definition key_event.h:15
constexpr auto tag_invoke(di::Tag< di::reflect >, di::InPlaceType< CursorStyle >)
Definition cursor_style.h:16
MouseEventType
Definition mouse_event.h:11
@ Press
Definition mouse_event.h:12
@ Move
Definition mouse_event.h:13