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 const unsigned LEFT = 1;
63  static const unsigned MIDDLE = 2;
64  static const 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(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(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 const unsigned X_AXIS = 0;
173  static const 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:
245  enum { LEFT_BUTTON, RIGHT_BUTTON, UP_BUTTON, DOWN_BUTTON,
246  A_BUTTON, B_BUTTON };
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(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
unsigned getButton() const
Definition: InputEvents.hh:66
unsigned getButton() const
Definition: InputEvents.hh:143
TimedEvent(EventType type)
Definition: InputEvents.cc:19
bool getGain() const
Definition: InputEvents.hh:205
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
unsigned getHat() const
Definition: InputEvents.hh:190
OSD events are triggered by other events.
Definition: InputEvents.hh:242
virtual TclObject toTclList() const =0
Similar to toString(), but retains the structure of the event.
unsigned getJoystick() const
Definition: InputEvents.hh:127
uint32_t getUnicode() const
Definition: InputEvents.hh:30
virtual bool isRepeatStopper(const Event &) const
Should &#39;bind -repeat&#39; be stopped by &#39;other&#39; event.
Definition: Event.hh:105
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
EventType
Definition: Event.hh:10
KeyDownEvent(Keys::KeyCode keyCode_)
Definition: InputEvents.hh:52
Keys::KeyCode getKeyCode() const
Definition: InputEvents.hh:29
unsigned getButton() const
Definition: InputEvents.hh:248
unsigned getX() const
Definition: InputEvents.hh:218
virtual bool matches(const Event &other) const
Does this event &#39;match&#39; the given event.
Definition: Event.hh:112
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
uint64_t getRealTime() const
Query creation time.
Definition: InputEvents.hh:17
unsigned getY() const
Definition: InputEvents.hh:219
unsigned getValue() const
Definition: InputEvents.hh:191