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  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  Keys::KeyCode getKeyCode() const { return keyCode; }
30  uint32_t getUnicode() const { return unicode; }
31 
32 protected:
33  KeyEvent(EventType type, Keys::KeyCode keyCode, uint32_t unicode);
34  ~KeyEvent() = default;
35 
36 private:
37  TclObject toTclList() const override;
38  bool lessImpl(const Event& other) const override;
39  const Keys::KeyCode keyCode;
40  const uint32_t unicode;
41 };
42 
43 class KeyUpEvent final : public KeyEvent
44 {
45 public:
46  explicit KeyUpEvent(Keys::KeyCode keyCode);
47 };
48 
49 class KeyDownEvent final : public KeyEvent
50 {
51 public:
52  explicit KeyDownEvent(Keys::KeyCode keyCode_)
53  : KeyDownEvent(keyCode_, 0) {}
54 
55  explicit KeyDownEvent(Keys::KeyCode keyCode, uint32_t unicode);
56 };
57 
58 
60 {
61 public:
62  static constexpr unsigned LEFT = 1;
63  static constexpr unsigned MIDDLE = 2;
64  static constexpr unsigned RIGHT = 3;
65 
66  unsigned getButton() const { return button; }
67 
68 protected:
69  MouseButtonEvent(EventType type, unsigned button_);
70  ~MouseButtonEvent() = default;
71  TclObject toTclHelper(std::string_view direction) const;
72 
73 private:
74  bool lessImpl(const Event& other) const override;
75  const unsigned button;
76 };
77 
79 {
80 public:
81  explicit MouseButtonUpEvent(unsigned button);
82  TclObject toTclList() const override;
83 };
84 
86 {
87 public:
88  explicit MouseButtonDownEvent(unsigned button);
89  TclObject toTclList() const override;
90 };
91 
92 class MouseWheelEvent final : public TimedEvent
93 {
94 public:
95  MouseWheelEvent(int x, int y);
96  int getX() const { return x; }
97  int getY() const { return y; }
98  TclObject toTclList() const override;
99 
100 private:
101  bool lessImpl(const Event& other) const override;
102  const int x;
103  const int y;
104 };
105 
106 class MouseMotionEvent final : public TimedEvent
107 {
108 public:
109  MouseMotionEvent(int xrel, int yrel, int xabs, int yabs);
110  int getX() const { return xrel; }
111  int getY() const { return yrel; }
112  int getAbsX() const { return xabs; }
113  int getAbsY() const { return yabs; }
114  TclObject toTclList() const override;
115 
116 private:
117  bool lessImpl(const Event& other) const override;
118  const int xrel;
119  const int yrel;
120  const int xabs;
121  const int yabs;
122 };
123 
124 class JoystickEvent : public TimedEvent
125 {
126 public:
127  unsigned getJoystick() const { return joystick; }
128 
129 protected:
130  JoystickEvent(EventType type, unsigned joystick);
131  ~JoystickEvent() = default;
132  TclObject toTclHelper() const;
133 
134 private:
135  bool lessImpl(const Event& other) const override;
136  virtual bool lessImpl(const JoystickEvent& other) const = 0;
137  const unsigned joystick;
138 };
139 
141 {
142 public:
143  unsigned getButton() const { return button; }
144 
145 protected:
146  JoystickButtonEvent(EventType type, unsigned joystick, unsigned button);
147  ~JoystickButtonEvent() = default;
148  TclObject toTclHelper(std::string_view direction) const;
149 
150 private:
151  bool lessImpl(const JoystickEvent& other) const override;
152  const unsigned button;
153 };
154 
156 {
157 public:
158  JoystickButtonUpEvent(unsigned joystick, unsigned button);
159  TclObject toTclList() const override;
160 };
161 
163 {
164 public:
165  JoystickButtonDownEvent(unsigned joystick, unsigned button);
166  TclObject toTclList() const override;
167 };
168 
170 {
171 public:
172  static constexpr unsigned X_AXIS = 0;
173  static constexpr unsigned Y_AXIS = 1;
174 
175  JoystickAxisMotionEvent(unsigned joystick, unsigned axis, int value);
176  unsigned getAxis() const { return axis; }
177  int getValue() const { return value; }
178  TclObject toTclList() const override;
179 
180 private:
181  bool lessImpl(const JoystickEvent& other) const override;
182  const unsigned axis;
183  const int value;
184 };
185 
186 class JoystickHatEvent final : public JoystickEvent
187 {
188 public:
189  JoystickHatEvent(unsigned joystick, unsigned hat, unsigned value);
190  unsigned getHat() const { return hat; }
191  unsigned getValue() const { return value; }
192  TclObject toTclList() const override;
193 
194 private:
195  bool lessImpl(const JoystickEvent& other) const override;
196  const unsigned hat;
197  const unsigned value;
198 };
199 
200 
201 class FocusEvent final : public Event
202 {
203 public:
204  explicit FocusEvent(bool gain);
205  bool getGain() const { return gain; }
206  TclObject toTclList() const override;
207 
208 private:
209  bool lessImpl(const Event& other) const override;
210  const bool gain;
211 };
212 
213 
214 class ResizeEvent final : public Event
215 {
216 public:
217  ResizeEvent(unsigned x, unsigned y);
218  unsigned getX() const { return x; }
219  unsigned getY() const { return y; }
220  TclObject toTclList() const override;
221 
222 private:
223  bool lessImpl(const Event& other) const override;
224  const unsigned x;
225  const unsigned y;
226 };
227 
228 
229 class QuitEvent final : public Event
230 {
231 public:
232  QuitEvent();
233  TclObject toTclList() const override;
234 private:
235  bool lessImpl(const Event& other) const override;
236 };
237 
243 {
244 public:
247 
248  unsigned getButton() const { return button; }
249 
261  bool isRepeatStopper(const Event& other) const final override;
262 
263 protected:
264  OsdControlEvent(EventType type, unsigned button_,
265  std::shared_ptr<const Event> origEvent);
266  ~OsdControlEvent() = default;
267  TclObject toTclHelper(std::string_view direction) const;
268 
269 private:
270  bool lessImpl(const Event& other) const final override;
271  const std::shared_ptr<const Event> origEvent;
272  const unsigned button;
273 };
274 
276 {
277 public:
278  OsdControlReleaseEvent(unsigned button,
279  const std::shared_ptr<const Event>& origEvent);
280  TclObject toTclList() const override;
281 };
282 
284 {
285 public:
286  OsdControlPressEvent(unsigned button,
287  const std::shared_ptr<const Event>& origEvent);
288  TclObject toTclList() const override;
289 };
290 
291 
292 class GroupEvent final : public Event
293 {
294 public:
295  GroupEvent(EventType type, std::vector<EventType> typesToMatch, const TclObject& tclListComponents);
296  TclObject toTclList() const override;
297 
298 private:
299  bool lessImpl(const Event& other) const override;
300  bool matches(const Event& other) const override;
301  const std::vector<EventType> typesToMatch;
302  const TclObject tclListComponents;
303 };
304 
305 
306 } // namespace openmsx
307 
308 #endif
openmsx::KeyEvent
Definition: InputEvents.hh:26
openmsx::JoystickButtonUpEvent::JoystickButtonUpEvent
JoystickButtonUpEvent(unsigned joystick, unsigned button)
Definition: InputEvents.cc:198
openmsx::OsdControlEvent::DOWN_BUTTON
Definition: InputEvents.hh:245
openmsx::OsdControlEvent::RIGHT_BUTTON
Definition: InputEvents.hh:245
openmsx::ResizeEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:307
openmsx::KeyEvent::KeyEvent
KeyEvent(EventType type, Keys::KeyCode keyCode, uint32_t unicode)
Definition: InputEvents.cc:27
openmsx::MouseButtonEvent::MouseButtonEvent
MouseButtonEvent(EventType type, unsigned button_)
Definition: InputEvents.cc:67
openmsx::OsdControlReleaseEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:384
openmsx::Event
Definition: Event.hh:81
openmsx::JoystickHatEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:254
openmsx::KeyUpEvent
Definition: InputEvents.hh:43
TclObject.hh
openmsx::MouseButtonEvent::RIGHT
static constexpr unsigned RIGHT
Definition: InputEvents.hh:64
openmsx::MouseMotionEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:140
openmsx::JoystickButtonUpEvent
Definition: InputEvents.hh:155
openmsx::MouseButtonDownEvent
Definition: InputEvents.hh:85
openmsx::MouseButtonEvent::toTclHelper
TclObject toTclHelper(std::string_view direction) const
Definition: InputEvents.cc:72
openmsx::OsdControlPressEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:398
openmsx::JoystickButtonEvent
Definition: InputEvents.hh:140
openmsx::TimedEvent::~TimedEvent
~TimedEvent()=default
openmsx::OsdControlReleaseEvent
Definition: InputEvents.hh:275
openmsx::MouseButtonEvent::getButton
unsigned getButton() const
Definition: InputEvents.hh:66
openmsx::KeyEvent::getUnicode
uint32_t getUnicode() const
Definition: InputEvents.hh:30
openmsx::OsdControlEvent::toTclHelper
TclObject toTclHelper(std::string_view direction) const
Definition: InputEvents.cc:361
openmsx::TimedEvent
Definition: InputEvents.hh:13
openmsx::JoystickButtonDownEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:216
openmsx::JoystickEvent::getJoystick
unsigned getJoystick() const
Definition: InputEvents.hh:127
openmsx::MouseButtonDownEvent::MouseButtonDownEvent
MouseButtonDownEvent(unsigned button)
Definition: InputEvents.cc:99
openmsx::OsdControlEvent::getButton
unsigned getButton() const
Definition: InputEvents.hh:248
openmsx::JoystickButtonEvent::~JoystickButtonEvent
~JoystickButtonEvent()=default
openmsx::ResizeEvent::getY
unsigned getY() const
Definition: InputEvents.hh:219
openmsx::JoystickAxisMotionEvent::JoystickAxisMotionEvent
JoystickAxisMotionEvent(unsigned joystick, unsigned axis, int value)
Definition: InputEvents.cc:224
openmsx::MouseWheelEvent::MouseWheelEvent
MouseWheelEvent(int x, int y)
Definition: InputEvents.cc:112
openmsx::ResizeEvent::getX
unsigned getX() const
Definition: InputEvents.hh:218
openmsx::JoystickAxisMotionEvent::getValue
int getValue() const
Definition: InputEvents.hh:177
openmsx::JoystickButtonDownEvent
Definition: InputEvents.hh:162
openmsx::JoystickAxisMotionEvent::getAxis
unsigned getAxis() const
Definition: InputEvents.hh:176
openmsx::FocusEvent
Definition: InputEvents.hh:201
openmsx::OsdControlEvent::isRepeatStopper
bool isRepeatStopper(const Event &other) const final override
Get the event that actually triggered the creation of this event.
Definition: InputEvents.cc:345
openmsx::JoystickAxisMotionEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:231
openmsx::ResizeEvent::ResizeEvent
ResizeEvent(unsigned x, unsigned y)
Definition: InputEvents.cc:302
openmsx::MouseMotionEvent::MouseMotionEvent
MouseMotionEvent(int xrel, int yrel, int xabs, int yabs)
Definition: InputEvents.cc:133
openmsx::MouseWheelEvent::getX
int getX() const
Definition: InputEvents.hh:96
openmsx::FocusEvent::getGain
bool getGain() const
Definition: InputEvents.hh:205
openmsx::KeyUpEvent::KeyUpEvent
KeyUpEvent(Keys::KeyCode keyCode)
Definition: InputEvents.cc:51
openmsx::OsdControlPressEvent::OsdControlPressEvent
OsdControlPressEvent(unsigned button, const std::shared_ptr< const Event > &origEvent)
Definition: InputEvents.cc:392
openmsx::JoystickEvent::JoystickEvent
JoystickEvent(EventType type, unsigned joystick)
Definition: InputEvents.cc:155
openmsx::JoystickHatEvent::getValue
unsigned getValue() const
Definition: InputEvents.hh:191
openmsx::JoystickHatEvent::JoystickHatEvent
JoystickHatEvent(unsigned joystick, unsigned hat, unsigned value)
Definition: InputEvents.cc:248
openmsx::MouseMotionEvent::getY
int getY() const
Definition: InputEvents.hh:111
openmsx::JoystickButtonEvent::getButton
unsigned getButton() const
Definition: InputEvents.hh:143
openmsx::MouseButtonUpEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:91
openmsx::GroupEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:413
Keys.hh
openmsx::JoystickButtonUpEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:203
openmsx::JoystickHatEvent
Definition: InputEvents.hh:186
openmsx::JoystickEvent
Definition: InputEvents.hh:124
openmsx::GroupEvent
Definition: InputEvents.hh:292
openmsx::MouseWheelEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:118
openmsx::MouseButtonEvent::MIDDLE
static constexpr unsigned MIDDLE
Definition: InputEvents.hh:63
openmsx::OsdControlReleaseEvent::OsdControlReleaseEvent
OsdControlReleaseEvent(unsigned button, const std::shared_ptr< const Event > &origEvent)
Definition: InputEvents.cc:378
openmsx::x
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:1377
openmsx::MouseMotionEvent::getX
int getX() const
Definition: InputEvents.hh:110
openmsx::TimedEvent::TimedEvent
TimedEvent(EventType type)
Definition: InputEvents.cc:18
openmsx::QuitEvent
Definition: InputEvents.hh:229
openmsx::MouseMotionEvent::getAbsX
int getAbsX() const
Definition: InputEvents.hh:112
openmsx::MouseButtonUpEvent::MouseButtonUpEvent
MouseButtonUpEvent(unsigned button)
Definition: InputEvents.cc:86
openmsx::OsdControlEvent::UP_BUTTON
Definition: InputEvents.hh:245
openmsx::TimedEvent::getRealTime
uint64_t getRealTime() const
Query creation time.
Definition: InputEvents.hh:17
openmsx::JoystickEvent::toTclHelper
TclObject toTclHelper() const
Definition: InputEvents.cc:160
openmsx::JoystickAxisMotionEvent::Y_AXIS
static constexpr unsigned Y_AXIS
Definition: InputEvents.hh:173
openmsx::OsdControlEvent::LEFT_BUTTON
Definition: InputEvents.hh:245
openmsx::FocusEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:288
openmsx::MouseButtonUpEvent
Definition: InputEvents.hh:78
openmsx::EventType
EventType
Definition: Event.hh:10
openmsx::QuitEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:326
Event.hh
openmsx::MouseMotionEvent::getAbsY
int getAbsY() const
Definition: InputEvents.hh:113
openmsx::OsdControlEvent::~OsdControlEvent
~OsdControlEvent()=default
openmsx::MouseButtonEvent::~MouseButtonEvent
~MouseButtonEvent()=default
openmsx::MouseMotionEvent
Definition: InputEvents.hh:106
openmsx::OsdControlEvent::A_BUTTON
Definition: InputEvents.hh:246
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::GroupEvent::GroupEvent
GroupEvent(EventType type, std::vector< EventType > typesToMatch, const TclObject &tclListComponents)
Definition: InputEvents.cc:406
openmsx::OsdControlEvent::B_BUTTON
Definition: InputEvents.hh:246
openmsx::Keys::KeyCode
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:25
openmsx::JoystickAxisMotionEvent::X_AXIS
static constexpr unsigned X_AXIS
Definition: InputEvents.hh:172
openmsx::MouseButtonEvent::LEFT
static constexpr unsigned LEFT
Definition: InputEvents.hh:62
openmsx::JoystickAxisMotionEvent
Definition: InputEvents.hh:169
openmsx::MouseButtonDownEvent::toTclList
TclObject toTclList() const override
Similar to toString(), but retains the structure of the event.
Definition: InputEvents.cc:104
openmsx::ResizeEvent
Definition: InputEvents.hh:214
openmsx::OsdControlEvent
OSD events are triggered by other events.
Definition: InputEvents.hh:242
openmsx::OsdControlPressEvent
Definition: InputEvents.hh:283
openmsx::KeyDownEvent
Definition: InputEvents.hh:49
openmsx::KeyEvent::getKeyCode
Keys::KeyCode getKeyCode() const
Definition: InputEvents.hh:29
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::KeyDownEvent::KeyDownEvent
KeyDownEvent(Keys::KeyCode keyCode_)
Definition: InputEvents.hh:52
openmsx::KeyEvent::~KeyEvent
~KeyEvent()=default
openmsx::MouseWheelEvent
Definition: InputEvents.hh:92
openmsx::JoystickButtonDownEvent::JoystickButtonDownEvent
JoystickButtonDownEvent(unsigned joystick, unsigned button)
Definition: InputEvents.cc:211
openmsx::FocusEvent::FocusEvent
FocusEvent(bool gain)
Definition: InputEvents.cc:283
openmsx::QuitEvent::QuitEvent
QuitEvent()
Definition: InputEvents.cc:322
openmsx::JoystickHatEvent::getHat
unsigned getHat() const
Definition: InputEvents.hh:190
openmsx::OsdControlEvent::OsdControlEvent
OsdControlEvent(EventType type, unsigned button_, std::shared_ptr< const Event > origEvent)
Definition: InputEvents.cc:338
openmsx::MouseWheelEvent::getY
int getY() const
Definition: InputEvents.hh:97
openmsx::MouseButtonEvent
Definition: InputEvents.hh:59
openmsx::JoystickEvent::~JoystickEvent
~JoystickEvent()=default
openmsx::JoystickButtonEvent::JoystickButtonEvent
JoystickButtonEvent(EventType type, unsigned joystick, unsigned button)
Definition: InputEvents.cc:176