openMSX
InputEventGenerator.hh
Go to the documentation of this file.
1 #ifndef INPUTEVENTGENERATOR_HH
2 #define INPUTEVENTGENERATOR_HH
3 
4 #include "BooleanSetting.hh"
5 #include "EventListener.hh"
6 #include "Command.hh"
7 #include "Keys.hh"
8 #include <SDL.h>
9 
10 namespace openmsx {
11 
12 class CommandController;
13 class EventDistributor;
14 class GlobalSettings;
15 
16 class InputEventGenerator final : private EventListener
17 {
18 public:
21 
22  InputEventGenerator(CommandController& commandController,
23  EventDistributor& eventDistributor,
24  GlobalSettings& globalSettings);
26 
30  void wait();
31 
33  BooleanSetting& getGrabInput() { return grabInput; }
35  void updateGrab(bool grab);
36 
41  [[nodiscard]] static int joystickNumButtons(SDL_Joystick* joystick);
42  [[nodiscard]] static bool joystickGetButton(SDL_Joystick* joystick, int button);
43 
44  void poll();
45 
46 private:
47  void handle(const SDL_Event& evt);
48  void handleKeyDown(const SDL_KeyboardEvent& key, uint32_t unicode);
49  void handleText(const char* utf8);
50  void setGrabInput(bool grab);
51 
52  // EventListener
53  int signalEvent(const Event& event) noexcept override;
54 
55  EventDistributor& eventDistributor;
56  GlobalSettings& globalSettings;
57  BooleanSetting grabInput;
58 
59  struct EscapeGrabCmd final : Command {
60  explicit EscapeGrabCmd(CommandController& commandController);
61  void execute(span<const TclObject> tokens, TclObject& result) override;
62  [[nodiscard]] std::string help(span<const TclObject> tokens) const override;
63  } escapeGrabCmd;
64 
65  enum EscapeGrabState {
66  ESCAPE_GRAB_WAIT_CMD,
67  ESCAPE_GRAB_WAIT_LOST,
68  ESCAPE_GRAB_WAIT_GAIN
69  } escapeGrabState;
70 
71  // OsdControl
72  void setNewOsdControlButtonState(
73  unsigned newState, const Event& origEvent);
74  void triggerOsdControlEventsFromJoystickAxisMotion(
75  unsigned axis, int value, const Event& origEvent);
76  void triggerOsdControlEventsFromJoystickHat(
77  int value, const Event& origEvent);
78  void osdControlChangeButton(
79  bool up, unsigned changedButtonMask, const Event& origEvent);
80  void triggerOsdControlEventsFromJoystickButtonEvent(
81  unsigned button, bool up, const Event& origEvent);
82  void triggerOsdControlEventsFromKeyEvent(
83  Keys::KeyCode keyCode, bool up, bool repeat, const Event& origEvent);
84 
85 
86  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
87 
88  // only for Android
89  static inline bool androidButtonA = false;
90  static inline bool androidButtonB = false;
91 };
92 
93 } // namespace openmsx
94 
95 #endif
This class contains settings that are used by several other class (including some singletons).
static int joystickNumButtons(SDL_Joystick *joystick)
Normally the following two functions simply delegate to SDL_JoystickNumButtons() and SDL_JoystickGetB...
InputEventGenerator(const InputEventGenerator &)=delete
static bool joystickGetButton(SDL_Joystick *joystick, int button)
InputEventGenerator & operator=(const InputEventGenerator &)=delete
void updateGrab(bool grab)
Must be called when 'grabinput' or 'fullscreen' setting changes.
BooleanSetting & getGrabInput()
Input Grab on or off.
void wait()
Wait for event(s) and handle it.
Definition: span.hh:126
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.
Definition: xrange.hh:170