openMSX
InputEventGenerator.hh
Go to the documentation of this file.
1 #ifndef INPUTEVENTGENERATOR_HH
2 #define INPUTEVENTGENERATOR_HH
3 
4 #include "Observer.hh"
5 #include "BooleanSetting.hh"
6 #include "EventListener.hh"
7 #include "Command.hh"
8 #include "Keys.hh"
9 #include <SDL.h>
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class CommandController;
15 class EventDistributor;
16 class GlobalSettings;
17 
18 class InputEventGenerator final : private Observer<Setting>
19  , private EventListener
20 {
21 public:
24 
25  InputEventGenerator(CommandController& commandController,
26  EventDistributor& eventDistributor,
27  GlobalSettings& globalSettings);
29 
33  void wait();
34 
38  void setKeyRepeat(bool enable);
39 
45  void reinit();
46 
48  BooleanSetting& getGrabInput() { return grabInput; }
49 
54  static int joystickNumButtons(SDL_Joystick* joystick);
55  static bool joystickGetButton(SDL_Joystick* joystick, int button);
56 
57  void poll();
58 
59 private:
60  using EventPtr = std::shared_ptr<const Event>;
61 
62  void handle(const SDL_Event& event);
63  void setGrabInput(bool grab);
64 
65  // Observer<Setting>
66  void update(const Setting& setting) override;
67 
68  // EventListener
69  int signalEvent(const std::shared_ptr<const Event>& event) override;
70 
71  EventDistributor& eventDistributor;
72  GlobalSettings& globalSettings;
73  BooleanSetting grabInput;
74 
75  struct EscapeGrabCmd final : Command {
76  explicit EscapeGrabCmd(CommandController& commandController);
77  void execute(array_ref<TclObject> tokens, TclObject& result) override;
78  std::string help(const std::vector<std::string>& tokens) const override;
79  } escapeGrabCmd;
80 
81  enum EscapeGrabState {
82  ESCAPE_GRAB_WAIT_CMD,
83  ESCAPE_GRAB_WAIT_LOST,
84  ESCAPE_GRAB_WAIT_GAIN
85  } escapeGrabState;
86 
87  // OsdControl
88  void setNewOsdControlButtonState(
89  unsigned newState, const EventPtr& origEvent);
90  void triggerOsdControlEventsFromJoystickAxisMotion(
91  unsigned axis, int value, const EventPtr& origEvent);
92  void triggerOsdControlEventsFromJoystickHat(
93  int value, const EventPtr& origEvent);
94  void osdControlChangeButton(
95  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
96  void triggerOsdControlEventsFromJoystickButtonEvent(
97  unsigned button, bool up, const EventPtr& origEvent);
98  void triggerOsdControlEventsFromKeyEvent(
99  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
100 
101 
102  bool keyRepeat;
103  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
104 
105  // only for Android
106  static bool androidButtonA;
107  static bool androidButtonB;
108 };
109 
110 } // namespace openmsx
111 
112 #endif
void wait()
Wait for event(s) and handle it.
void reinit()
This functions shouldn&#39;t be needed, but in the SDL library input and video or closely coupled (sigh)...
InputEventGenerator & operator=(const InputEventGenerator &)=delete
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
static int joystickNumButtons(SDL_Joystick *joystick)
Normally the following two functions simply delegate to SDL_JoystickNumButtons() and SDL_JoystickGetB...
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void setKeyRepeat(bool enable)
Enable or disable keyboard event repeats.
BooleanSetting & getGrabInput()
Input Grab on or off.
static bool joystickGetButton(SDL_Joystick *joystick, int button)
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
This class contains settings that are used by several other class (including some singletons)...
InputEventGenerator(const InputEventGenerator &)=delete