-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathevent.h
294 lines (248 loc) · 5.42 KB
/
event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#pragma once
#include <Tempest/Size>
#include <cstdint>
namespace Tempest {
class PaintDevice;
class TextureAtlas;
class Painter;
class Event {
public:
Event()=default;
virtual ~Event(){}
void accept(){ accepted = true; }
void ignore(){ accepted = false; }
bool isAccepted() const {
return accepted;
}
enum Type : uint16_t {
NoEvent = 0,
MouseDown,
MouseUp,
MouseMove,
MouseDrag,
MouseWheel,
MouseEnter,
MouseLeave,
KeyDown,
KeyRepeat,
KeyUp,
Focus,
Resize,
Shortcut,
Paint,
Close,
Polish,
Gesture,
Custom = 512
};
enum MouseButton : uint8_t {
ButtonNone = 0,
ButtonLeft,
ButtonRight,
ButtonMid,
ButtonBack,
ButtonForward
};
enum KeyType : uint8_t {
K_NoKey = 0,
K_ESCAPE,
K_RControl,
K_LControl,
K_RCommand, // APPLE command key
K_LCommand,
K_RShift,
K_LShift,
K_LAlt,
K_RAlt,
K_Left,
K_Up,
K_Right,
K_Down,
K_Back,
K_Tab,
K_Delete,
K_Insert,
K_Return,
K_Home,
K_End,
K_Pause,
K_Space,
K_CapsLock,
K_F1,
K_F2,
K_F3,
K_F4,
K_F5,
K_F6,
K_F7,
K_F8,
K_F9,
K_F10,
K_F11,
K_F12,
K_F13,
K_F14,
K_F15,
K_F16,
K_F17,
K_F18,
K_F19,
K_F20,
K_F21,
K_F22,
K_F23,
K_F24,
K_A,
K_B,
K_C,
K_D,
K_E,
K_F,
K_G,
K_H,
K_I,
K_J,
K_K,
K_L,
K_M,
K_N,
K_O,
K_P,
K_Q,
K_R,
K_S,
K_T,
K_U,
K_V,
K_W,
K_X,
K_Y,
K_Z,
K_0,
K_1,
K_2,
K_3,
K_4,
K_5,
K_6,
K_7,
K_8,
K_9,
K_Last
};
enum Modifier : uint8_t {
M_NoModifier = 0,
M_Shift = 1<<0,
M_Alt = 1<<1,
M_Ctrl = 1<<2,
M_Command = 1<<3, // APPLE command key
};
enum FocusReason : uint8_t {
TabReason,
ClickReason,
WheelReason,
UnknownReason
};
Type type () const{ return etype; }
protected:
void setType( Type t ){ etype = t; }
private:
bool accepted=true;
Type etype =NoEvent;
};
class PaintEvent: public Event {
public:
PaintEvent(PaintDevice & p,TextureAtlas& ta,uint32_t w,uint32_t h)
: PaintEvent(p,ta,int(w),int(h)) {
}
PaintEvent(PaintDevice & p,TextureAtlas& ta,int32_t w,int32_t h)
: dev(p),ta(ta),outW(uint32_t(w)),outH(uint32_t(h)),
vp(0,0,w,h) {
setType( Paint );
}
PaintEvent(PaintEvent& parent,int32_t dx,int32_t dy,int32_t x,int32_t y,int32_t w,int32_t h)
: dev(parent.dev),ta(parent.ta),outW(parent.outW),outH(parent.outH),
dp(parent.dp.x+dx,parent.dp.y+dy),vp(x,y,w,h){
setType( Paint );
}
PaintDevice& device() { return dev; }
uint32_t w() const { return outW; }
uint32_t h() const { return outH; }
const Point& orign() const { return dp; }
const Rect& viewPort() const { return vp; }
private:
PaintDevice& dev;
TextureAtlas& ta;
uint32_t outW=0;
uint32_t outH=0;
Point dp;
Rect vp;
using Event::accept;
friend class Painter;
};
/*!
* \brief The SizeEvent class contains event parameters for resize events.
*/
class SizeEvent : public Event {
public:
SizeEvent(int w,int h): w(uint32_t(std::max(w,0))), h(uint32_t(std::max(h,0))) {
setType( Resize );
}
SizeEvent(uint32_t w,uint32_t h): w(w), h(h) {
setType( Resize );
}
const uint32_t w, h;
Tempest::Size size() const { return Size(int(w),int(h)); }
};
/*!
* \brief The MouseEvent class contains event parameters for mouse and touch events.
*/
class MouseEvent : public Event {
public:
MouseEvent( int mx = -1, int my = -1,
MouseButton b = ButtonNone,
Modifier m = M_NoModifier,
int mdelta = 0,
int mouseID = 0,
Type t = MouseMove )
:x(mx), y(my), delta(mdelta), button(b), modifier(m), mouseID(mouseID){
setType( t );
}
const int x, y, delta;
const MouseButton button;
const Modifier modifier = M_NoModifier;
const int mouseID;
Point pos() const { return Point(x,y); }
};
class KeyEvent: public Event {
public:
KeyEvent(KeyType k = K_NoKey, Modifier m = M_NoModifier, Type t = KeyDown):key(k),modifier(m){
setType( t );
}
KeyEvent(uint32_t k, Modifier m = M_NoModifier, Type t = KeyDown ):key(K_NoKey), code(k), modifier(m){
setType( t );
}
KeyEvent(KeyType k, uint32_t k1, Modifier m = M_NoModifier, Type t = KeyDown):key(k), code(k1), modifier(m){
setType( t );
}
const KeyType key = K_NoKey;
const uint32_t code = 0;
const Modifier modifier = M_NoModifier;
};
class FocusEvent: public Event {
public:
FocusEvent( bool in, FocusReason reason ): in(in), reason(reason) {
setType( Focus );
}
const bool in;
const FocusReason reason;
};
class CloseEvent: public Event {
public:
CloseEvent() { setType(Close); }
};
class PolishEvent: public Event {
public:
PolishEvent() { setType(Polish); }
};
}