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 #include <memory>
10 
11 namespace openmsx {
12 
13 class CommandController;
14 class EventDistributor;
15 class GlobalSettings;
16 
17 class InputEventGenerator final : private EventListener
18 {
19 public:
22 
23  InputEventGenerator(CommandController& commandController,
24  EventDistributor& eventDistributor,
25  GlobalSettings& globalSettings);
27 
31  void wait();
32 
34  BooleanSetting& getGrabInput() { return grabInput; }
36  void updateGrab(bool grab);
37 
42  [[nodiscard]] static int joystickNumButtons(SDL_Joystick* joystick);
43  [[nodiscard]] static bool joystickGetButton(SDL_Joystick* joystick, int button);
44 
45  void poll();
46 
47 private:
48  using EventPtr = std::shared_ptr<const Event>;
49 
50  void handle(const SDL_Event& evt);
51  void handleKeyDown(const SDL_KeyboardEvent& key, uint32_t unicode);
52  void handleText(const char* utf8);
53  void setGrabInput(bool grab);
54 
55  // EventListener
56  int signalEvent(const std::shared_ptr<const Event>& event) noexcept override;
57 
58  EventDistributor& eventDistributor;
59  GlobalSettings& globalSettings;
60  BooleanSetting grabInput;
61 
62  struct EscapeGrabCmd final : Command {
63  explicit EscapeGrabCmd(CommandController& commandController);
64  void execute(span<const TclObject> tokens, TclObject& result) override;
65  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
66  } escapeGrabCmd;
67 
68  enum EscapeGrabState {
69  ESCAPE_GRAB_WAIT_CMD,
70  ESCAPE_GRAB_WAIT_LOST,
71  ESCAPE_GRAB_WAIT_GAIN
72  } escapeGrabState;
73 
74  // OsdControl
75  void setNewOsdControlButtonState(
76  unsigned newState, const EventPtr& origEvent);
77  void triggerOsdControlEventsFromJoystickAxisMotion(
78  unsigned axis, int value, const EventPtr& origEvent);
79  void triggerOsdControlEventsFromJoystickHat(
80  int value, const EventPtr& origEvent);
81  void osdControlChangeButton(
82  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
83  void triggerOsdControlEventsFromJoystickButtonEvent(
84  unsigned button, bool up, const EventPtr& origEvent);
85  void triggerOsdControlEventsFromKeyEvent(
86  Keys::KeyCode keyCode, bool up, bool repeat, const EventPtr& origEvent);
87 
88 
89  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
90 
91  // only for Android
92  static inline bool androidButtonA = false;
93  static inline bool androidButtonB = false;
94 };
95 
96 } // namespace openmsx
97 
98 #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