ReXGlue SDK
Toggle main menu visibility
Loading...
Searching...
No Matches
ui_event.h
Go to the documentation of this file.
1
12
13
#pragma once
14
15
#include <climits>
16
#include <filesystem>
17
18
#include <
rex/input_keys.h
>
19
#include <
rex/types.h
>
20
21
namespace
rex::ui {
22
24
class
UIEvent {
25
public
:
26
enum class
Type
: u8 {
27
kOpened,
28
kDPIChanged,
29
kMonitorUpdate,
30
kMinimized,
31
kRestored,
32
kClosing,
33
kFileDrop,
34
kResize,
35
kClose,
36
kFocus,
37
kTouch,
38
};
39
40
explicit
UIEvent
(
Type
type) : type_(type) {}
41
42
virtual
~UIEvent() =
default
;
43
44
Type
GetType()
const
{
return
type_; }
45
51
template
<
typename
T>
52
const
T*
As
()
const
{
53
return
T::Carries(type_) ?
static_cast<
const
T*
>
(
this
) :
nullptr
;
54
}
55
56
private
:
57
Type
type_;
58
};
59
61
class
UISetupEvent
:
public
UIEvent {
62
public
:
69
UISetupEvent
(
Type
type,
bool
is_initial_setup =
false
)
70
: UIEvent(type), is_initial_setup_(is_initial_setup) {}
71
77
static
constexpr
bool
Carries
(
Type
type) {
78
return
type ==
Type::kOpened
|| type ==
Type::kDPIChanged
|| type ==
Type::kResize
||
79
type ==
Type::kFocus
|| type ==
Type::kMonitorUpdate
;
80
}
81
82
bool
IsInitialSetup()
const
{
return
is_initial_setup_; }
83
84
private
:
85
bool
is_initial_setup_;
86
};
87
88
class
MonitorUpdateEvent
:
public
UISetupEvent
{
89
public
:
96
MonitorUpdateEvent
(
bool
old_monitor_potentially_disconnected,
bool
is_initial_setup =
false
)
97
:
UISetupEvent
(
Type
::kMonitorUpdate, is_initial_setup),
98
old_monitor_potentially_disconnected_(old_monitor_potentially_disconnected) {}
99
105
static
constexpr
bool
Carries
(
Type
type) {
return
type ==
Type::kMonitorUpdate
; }
106
107
bool
IsOldMonitorPotentiallyDisconnected()
const
{
return
old_monitor_potentially_disconnected_; }
108
109
private
:
110
bool
old_monitor_potentially_disconnected_;
111
};
112
113
class
FileDropEvent
:
public
UIEvent {
114
public
:
116
FileDropEvent
(std::filesystem::path filename)
117
: UIEvent(
Type
::kFileDrop), filename_(std::move(filename)) {}
118
124
static
constexpr
bool
Carries
(
Type
type) {
return
type ==
Type::kFileDrop
; }
125
127
const
std::filesystem::path&
GetFilename
()
const
{
return
filename_; }
128
129
private
:
130
const
std::filesystem::path filename_;
131
};
132
133
class
TouchEvent
:
public
UIEvent {
134
public
:
135
enum class
Action
: u8 {
136
kDown,
137
kUp,
138
kCancel
,
139
kMove,
140
};
141
143
static
constexpr
u32
kPointerIDNone
= UINT32_MAX;
144
151
TouchEvent
(
Type
type, u32 pointer_id,
Action
action, f32 x, f32 y)
152
: UIEvent(type), pointer_id_(pointer_id), action_(action), x_(x), y_(y) {}
153
155
static
constexpr
bool
Carries
(
Type
type) {
return
type ==
Type::kTouch
; }
156
158
bool
IsHandled
()
const
{
return
handled_; }
159
165
void
SetHandled
(
bool
value) { handled_ = value; }
166
167
u32 GetPointerID()
const
{
return
pointer_id_; }
168
169
Action
GetAction()
const
{
return
action_; }
170
171
f32 GetX()
const
{
return
x_; }
172
173
f32 GetY()
const
{
return
y_; }
174
175
private
:
176
bool
handled_ =
false
;
177
u32 pointer_id_;
178
Action
action_;
179
f32 x_;
180
f32 y_;
181
};
182
184
class
IUIEventListener
{
185
public
:
186
virtual
~IUIEventListener
() =
default
;
187
193
virtual
void
OnUIEvent
(
const
ui::UIEvent
& event) = 0;
194
201
virtual
void
OnInputEvent
(
InputEvent
& event) = 0;
202
};
203
204
}
// namespace rex::ui
rex::ui::FileDropEvent::FileDropEvent
FileDropEvent(std::filesystem::path filename)
Definition
ui_event.h:116
rex::ui::FileDropEvent::GetFilename
const std::filesystem::path & GetFilename() const
Definition
ui_event.h:127
rex::ui::FileDropEvent::Carries
static constexpr bool Carries(Type type)
Definition
ui_event.h:124
rex::ui::IUIEventListener
Definition
ui_event.h:184
rex::ui::IUIEventListener::OnUIEvent
virtual void OnUIEvent(const ui::UIEvent &event)=0
rex::ui::IUIEventListener::OnInputEvent
virtual void OnInputEvent(InputEvent &event)=0
rex::ui::MonitorUpdateEvent::Carries
static constexpr bool Carries(Type type)
Definition
ui_event.h:105
rex::ui::MonitorUpdateEvent::MonitorUpdateEvent
MonitorUpdateEvent(bool old_monitor_potentially_disconnected, bool is_initial_setup=false)
Definition
ui_event.h:96
rex::ui::TouchEvent::TouchEvent
TouchEvent(Type type, u32 pointer_id, Action action, f32 x, f32 y)
Definition
ui_event.h:151
rex::ui::TouchEvent::Carries
static constexpr bool Carries(Type type)
Definition
ui_event.h:155
rex::ui::TouchEvent::kPointerIDNone
static constexpr u32 kPointerIDNone
Definition
ui_event.h:143
rex::ui::TouchEvent::Action
Action
Definition
ui_event.h:135
rex::ui::TouchEvent::SetHandled
void SetHandled(bool value)
Definition
ui_event.h:165
rex::ui::TouchEvent::IsHandled
bool IsHandled() const
Definition
ui_event.h:158
rex::ui::UIEvent
Definition
ui_event.h:24
rex::ui::UIEvent::Type
Type
Definition
ui_event.h:26
rex::ui::UIEvent::Type::kDPIChanged
@ kDPIChanged
Definition
ui_event.h:28
rex::ui::UIEvent::Type::kFileDrop
@ kFileDrop
Definition
ui_event.h:33
rex::ui::UIEvent::Type::kOpened
@ kOpened
Definition
ui_event.h:27
rex::ui::UIEvent::Type::kMonitorUpdate
@ kMonitorUpdate
Definition
ui_event.h:29
rex::ui::UIEvent::Type::kFocus
@ kFocus
Definition
ui_event.h:36
rex::ui::UIEvent::Type::kTouch
@ kTouch
Definition
ui_event.h:37
rex::ui::UIEvent::Type::kResize
@ kResize
Definition
ui_event.h:34
rex::ui::UIEvent::As
const T * As() const
Definition
ui_event.h:52
rex::ui::UISetupEvent::Carries
static constexpr bool Carries(Type type)
Definition
ui_event.h:77
rex::ui::UISetupEvent::UISetupEvent
UISetupEvent(Type type, bool is_initial_setup=false)
Definition
ui_event.h:69
input_keys.h
rex::VirtualKey::kCancel
@ kCancel
Definition
input_keys.h:40
rex::InputEvent
Definition
input_keys.h:417
types.h
Integer types, byte order wrappers and size literals.
rex
ui
ui_event.h
Generated by
1.18.0