openMSX
InputEvents.hh
Go to the documentation of this file.
1 #ifndef INPUTEVENTS_HH
2 #define INPUTEVENTS_HH
3 
4 #include "Event.hh"
5 #include "Keys.hh"
6 #include "TclObject.hh"
7 #include <cstdint>
8 #include <memory>
9 #include <vector>
10 
11 namespace openmsx {
12 
13 class TimedEvent : public Event
14 {
15 public:
17  [[nodiscard]] uint64_t getRealTime() const { return realtime; }
18 protected:
19  explicit TimedEvent(EventType type);
20  ~TimedEvent() = default;
21 private:
22  const uint64_t realtime;
23 };
24 
25 
26 class KeyEvent : public TimedEvent
27 {
28 public:
29  [[nodiscard]] Keys::KeyCode getKeyCode() const { return keyCode; }
30  [[nodiscard]] Keys::KeyCode getScanCode() const { return scanCode; }
31  [[nodiscard]] uint32_t getUnicode() const { return unicode; }
32 
33 protected:
34  KeyEvent(EventType type, Keys::KeyCode keyCode, Keys::KeyCode scanCode, uint32_t unicode);
35  ~KeyEvent() = default;
36 
37 private:
38  [[nodiscard]] TclObject toTclList() const override;
39  [[nodiscard]] bool equalImpl(const Event& other) const override;
40  const Keys::KeyCode keyCode;
41  const Keys::KeyCode scanCode; // 2nd class support, see comments in toTclList()
42  const uint32_t unicode;
43 };
44 
45 class KeyUpEvent final : public KeyEvent
46 {
47 public:
48  explicit KeyUpEvent(Keys::KeyCode keyCode_)
49  : KeyUpEvent(keyCode_, keyCode_) {}
50 
51  explicit KeyUpEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
52  : KeyEvent(OPENMSX_KEY_UP_EVENT, keyCode_, scanCode_, 0) {}
53 };
54 
55 class KeyDownEvent final : public KeyEvent
56 {
57 public:
58  explicit KeyDownEvent(Keys::KeyCode keyCode_)
59  : KeyDownEvent(keyCode_, keyCode_, 0) {}
60 
61  explicit KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
62  : KeyDownEvent(keyCode_, scanCode_, 0) {}
63 
64  explicit KeyDownEvent(Keys::KeyCode keyCode_, uint32_t unicode_)
65  : KeyDownEvent(keyCode_, keyCode_, unicode_) {}
66 
67  explicit KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
68  : KeyEvent(OPENMSX_KEY_DOWN_EVENT, keyCode_, scanCode_, unicode_) {}
69 };
70 
71 
73 {
74 public:
75  static constexpr unsigned LEFT = 1;
76  static constexpr unsigned MIDDLE = 2;
77  static constexpr unsigned RIGHT = 3;
78 
79  [[nodiscard]] unsigned getButton() const { return button; }
80 
81 protected:
82  MouseButtonEvent(EventType type, unsigned button_);
83  ~MouseButtonEvent() = default;
84  [[nodiscard]] TclObject toTclHelper(std::string_view direction) const;
85 
86 private:
87  [[nodiscard]] bool equalImpl(const Event& other) const override;
88  const unsigned button;
89 };
90 
92 {
93 public:
94  explicit MouseButtonUpEvent(unsigned button);
95  [[nodiscard]] TclObject toTclList() const override;
96 };
97 
99 {
100 public:
101  explicit MouseButtonDownEvent(unsigned button);
102  [[nodiscard]] TclObject toTclList() const override;
103 };
104 
105 class MouseWheelEvent final : public TimedEvent
106 {
107 public:
108  MouseWheelEvent(int x, int y);
109  [[nodiscard]] int getX() const { return x; }
110  [[nodiscard]] int getY() const { return y; }
111  [[nodiscard]] TclObject toTclList() const override;
112 
113 private:
114  [[nodiscard]] bool equalImpl(const Event& other) const override;
115  const int x;
116  const int y;
117 };
118 
119 class MouseMotionEvent final : public TimedEvent
120 {
121 public:
122  MouseMotionEvent(int xrel, int yrel, int xabs, int yabs);
123  [[nodiscard]] int getX() const { return xrel; }
124  [[nodiscard]] int getY() const { return yrel; }
125  [[nodiscard]] int getAbsX() const { return xabs; }
126  [[nodiscard]] int getAbsY() const { return yabs; }
127  [[nodiscard]] TclObject toTclList() const override;
128 
129 private:
130  [[nodiscard]] bool equalImpl(const Event& other) const override;
131  const int xrel;
132  const int yrel;
133  const int xabs;
134  const int yabs;
135 };
136 
137 class JoystickEvent : public TimedEvent
138 {
139 public:
140  [[nodiscard]] unsigned getJoystick() const { return joystick; }
141 
142 protected:
143  JoystickEvent(EventType type, unsigned joystick);
144  ~JoystickEvent() = default;
145  [[nodiscard]] TclObject toTclHelper() const;
146 
147 private:
148  const unsigned joystick;
149 };
150 
152 {
153 public:
154  [[nodiscard]] unsigned getButton() const { return button; }
155 
156 protected:
157  JoystickButtonEvent(EventType type, unsigned joystick, unsigned button);
158  ~JoystickButtonEvent() = default;
159  [[nodiscard]] TclObject toTclHelper(std::string_view direction) const;
160 
161 private:
162  [[nodiscard]] bool equalImpl(const Event& other) const override;
163  const unsigned button;
164 };
165 
167 {
168 public:
169  JoystickButtonUpEvent(unsigned joystick, unsigned button);
170  [[nodiscard]] TclObject toTclList() const override;
171 };
172 
174 {
175 public:
176  JoystickButtonDownEvent(unsigned joystick, unsigned button);
177  [[nodiscard]] TclObject toTclList() const override;
178 };
179 
181 {
182 public:
183  static constexpr unsigned X_AXIS = 0;
184  static constexpr unsigned Y_AXIS = 1;
185 
186  JoystickAxisMotionEvent(unsigned joystick, unsigned axis, int value);
187  [[nodiscard]] unsigned getAxis() const { return axis; }
188  [[nodiscard]] int getValue() const { return value; }
189  [[nodiscard]] TclObject toTclList() const override;
190 
191 private:
192  [[nodiscard]] bool equalImpl(const Event& other) const override;
193  const unsigned axis;
194  const int value;
195 };
196 
197 class JoystickHatEvent final : public JoystickEvent
198 {
199 public:
200  JoystickHatEvent(unsigned joystick, unsigned hat, unsigned value);
201  [[nodiscard]] unsigned getHat() const { return hat; }
202  [[nodiscard]] unsigned getValue() const { return value; }
203  [[nodiscard]] TclObject toTclList() const override;
204 
205 private:
206  [[nodiscard]] bool equalImpl(const Event& other) const override;
207  const unsigned hat;
208  const unsigned value;
209 };
210 
211 
212 class FocusEvent final : public Event
213 {
214 public:
215  explicit FocusEvent(bool gain);
216  [[nodiscard]] bool getGain() const { return gain; }
217  [[nodiscard]] TclObject toTclList() const override;
218 
219 private:
220  [[nodiscard]] bool equalImpl(const Event& other) const override;
221  const bool gain;
222 };
223 
224 
225 class ResizeEvent final : public Event
226 {
227 public:
228  ResizeEvent(unsigned x, unsigned y);
229  [[nodiscard]] unsigned getX() const { return x; }
230  [[nodiscard]] unsigned getY() const { return y; }
231  [[nodiscard]] TclObject toTclList() const override;
232 
233 private:
234  [[nodiscard]] bool equalImpl(const Event& other) const override;
235  const unsigned x;
236  const unsigned y;
237 };
238 
239 
240 class FileDropEvent final : public Event
241 {
242 public:
243  explicit FileDropEvent(std::string fileName);
244  [[nodiscard]] const std::string& getFileName() const { return fileName; }
245  [[nodiscard]] TclObject toTclList() const override;
246 
247 private:
248  [[nodiscard]] bool equalImpl(const Event& other) const override;
249  const std::string fileName;
250 };
251 
252 
253 class QuitEvent final : public Event
254 {
255 public:
256  QuitEvent();
257  [[nodiscard]] TclObject toTclList() const override;
258 private:
259  [[nodiscard]] bool equalImpl(const Event& other) const override;
260 };
261 
267 {
268 public:
271 
272  [[nodiscard]] unsigned getButton() const { return button; }
273 
285  [[nodiscard]] bool isRepeatStopper(const Event& other) const final;
286 
287 protected:
288  OsdControlEvent(EventType type, unsigned button_,
289  std::shared_ptr<const Event> origEvent);
290  ~OsdControlEvent() = default;
291  [[nodiscard]] TclObject toTclHelper(std::string_view direction) const;
292 
293 private:
294  [[nodiscard]] bool equalImpl(const Event& other) const final;
295  const std::shared_ptr<const Event> origEvent;
296  const unsigned button;
297 };
298 
300 {
301 public:
302  OsdControlReleaseEvent(unsigned button,
303  const std::shared_ptr<const Event>& origEvent);
304  [[nodiscard]] TclObject toTclList() const override;
305 };
306 
308 {
309 public:
310  OsdControlPressEvent(unsigned button,
311  const std::shared_ptr<const Event>& origEvent);
312  [[nodiscard]] TclObject toTclList() const override;
313 };
314 
315 
316 class GroupEvent final : public Event
317 {
318 public:
319  GroupEvent(EventType type, std::vector<EventType> typesToMatch, TclObject tclListComponents);
320  [[nodiscard]] TclObject toTclList() const override;
321 
322 private:
323  [[nodiscard]] bool equalImpl(const Event& other) const override;
324  [[nodiscard]] bool matches(const Event& other) const override;
325  const std::vector<EventType> typesToMatch;
326  const TclObject tclListComponents;
327 };
328 
329 
330 } // namespace openmsx
331 
332 #endif
FileDropEvent(std::string fileName)
Definition: InputEvents.cc:311
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:316
const std::string & getFileName() const
Definition: InputEvents.hh:244
bool getGain() const
Definition: InputEvents.hh:216
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:277
FocusEvent(bool gain)
Definition: InputEvents.cc:272
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:421
GroupEvent(EventType type, std::vector< EventType > typesToMatch, TclObject tclListComponents)
Definition: InputEvents.cc:414
static constexpr unsigned X_AXIS
Definition: InputEvents.hh:183
static constexpr unsigned Y_AXIS
Definition: InputEvents.hh:184
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:219
JoystickAxisMotionEvent(unsigned joystick, unsigned axis, int value)
Definition: InputEvents.cc:212
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:204
JoystickButtonDownEvent(unsigned joystick, unsigned button)
Definition: InputEvents.cc:199
JoystickButtonEvent(EventType type, unsigned joystick, unsigned button)
Definition: InputEvents.cc:163
unsigned getButton() const
Definition: InputEvents.hh:154
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:191
JoystickButtonUpEvent(unsigned joystick, unsigned button)
Definition: InputEvents.cc:186
JoystickEvent(EventType type, unsigned joystick)
Definition: InputEvents.cc:150
TclObject toTclHelper() const
Definition: InputEvents.cc:155
unsigned getJoystick() const
Definition: InputEvents.hh:140
unsigned getValue() const
Definition: InputEvents.hh:202
unsigned getHat() const
Definition: InputEvents.hh:201
JoystickHatEvent(unsigned joystick, unsigned hat, unsigned value)
Definition: InputEvents.cc:236
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:242
KeyDownEvent(Keys::KeyCode keyCode_)
Definition: InputEvents.hh:58
KeyDownEvent(Keys::KeyCode keyCode_, uint32_t unicode_)
Definition: InputEvents.hh:64
KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_, uint32_t unicode_)
Definition: InputEvents.hh:67
KeyDownEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
Definition: InputEvents.hh:61
~KeyEvent()=default
Keys::KeyCode getKeyCode() const
Definition: InputEvents.hh:29
Keys::KeyCode getScanCode() const
Definition: InputEvents.hh:30
uint32_t getUnicode() const
Definition: InputEvents.hh:31
KeyEvent(EventType type, Keys::KeyCode keyCode, Keys::KeyCode scanCode, uint32_t unicode)
Definition: InputEvents.cc:27
KeyUpEvent(Keys::KeyCode keyCode_)
Definition: InputEvents.hh:48
KeyUpEvent(Keys::KeyCode keyCode_, Keys::KeyCode scanCode_)
Definition: InputEvents.hh:51
MouseButtonDownEvent(unsigned button)
Definition: InputEvents.cc:94
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:99
static constexpr unsigned RIGHT
Definition: InputEvents.hh:77
static constexpr unsigned MIDDLE
Definition: InputEvents.hh:76
MouseButtonEvent(EventType type, unsigned button_)
Definition: InputEvents.cc:62
static constexpr unsigned LEFT
Definition: InputEvents.hh:75
unsigned getButton() const
Definition: InputEvents.hh:79
TclObject toTclHelper(std::string_view direction) const
Definition: InputEvents.cc:67
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:86
MouseButtonUpEvent(unsigned button)
Definition: InputEvents.cc:81
MouseMotionEvent(int xrel, int yrel, int xabs, int yabs)
Definition: InputEvents.cc:128
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:135
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:113
MouseWheelEvent(int x, int y)
Definition: InputEvents.cc:107
OSD events are triggered by other events.
Definition: InputEvents.hh:267
TclObject toTclHelper(std::string_view direction) const
Definition: InputEvents.cc:369
bool isRepeatStopper(const Event &other) const final
Get the event that actually triggered the creation of this event.
Definition: InputEvents.cc:353
unsigned getButton() const
Definition: InputEvents.hh:272
OsdControlEvent(EventType type, unsigned button_, std::shared_ptr< const Event > origEvent)
Definition: InputEvents.cc:346
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:406
OsdControlPressEvent(unsigned button, const std::shared_ptr< const Event > &origEvent)
Definition: InputEvents.cc:400
OsdControlReleaseEvent(unsigned button, const std::shared_ptr< const Event > &origEvent)
Definition: InputEvents.cc:386
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:392
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:334
unsigned getY() const
Definition: InputEvents.hh:230
unsigned getX() const
Definition: InputEvents.hh:229
ResizeEvent(unsigned x, unsigned y)
Definition: InputEvents.cc:291
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:296
uint64_t getRealTime() const
Query creation time.
Definition: InputEvents.hh:17
TimedEvent(EventType type)
Definition: InputEvents.cc:18
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
This file implemented 3 utility functions:
Definition: Autofire.cc:9
EventType
Definition: Event.hh:11
@ OPENMSX_KEY_UP_EVENT
Definition: Event.hh:12
@ OPENMSX_KEY_DOWN_EVENT
Definition: Event.hh:13
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:124