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 "noncopyable.hh"
9 #include "Keys.hh"
10 #include <SDL.h>
11 #include <memory>
12 
13 namespace openmsx {
14 
15 class CommandController;
16 class EventDistributor;
17 class GlobalSettings;
18 
19 class InputEventGenerator final : private Observer<Setting>
20  , private EventListener
21  , private noncopyable
22 {
23 public:
24  InputEventGenerator(CommandController& commandController,
25  EventDistributor& eventDistributor,
26  GlobalSettings& globalSettings);
28 
32  void wait();
33 
37  void setKeyRepeat(bool enable);
38 
44  void reinit();
45 
47  BooleanSetting& getGrabInput() { return grabInput; }
48 
53  static int joystickNumButtons(SDL_Joystick* joystick);
54  static bool joystickGetButton(SDL_Joystick* joystick, int button);
55 
56  void poll();
57 
58 private:
59  using EventPtr = std::shared_ptr<const Event>;
60 
61  void handle(const SDL_Event& event);
62  void setGrabInput(bool grab);
63 
64  // Observer<Setting>
65  void update(const Setting& setting) override;
66 
67  // EventListener
68  int signalEvent(const std::shared_ptr<const Event>& event) override;
69 
70  EventDistributor& eventDistributor;
71  GlobalSettings& globalSettings;
72  BooleanSetting grabInput;
73 
74  struct EscapeGrabCmd final : Command {
75  EscapeGrabCmd(CommandController& commandController);
76  void execute(array_ref<TclObject> tokens, TclObject& result) override;
77  std::string help(const std::vector<std::string>& tokens) const override;
78  } escapeGrabCmd;
79 
80  enum EscapeGrabState {
81  ESCAPE_GRAB_WAIT_CMD,
82  ESCAPE_GRAB_WAIT_LOST,
83  ESCAPE_GRAB_WAIT_GAIN
84  } escapeGrabState;
85 
86  // OsdControl
87  void setNewOsdControlButtonState(
88  unsigned newState, const EventPtr& origEvent);
89  void triggerOsdControlEventsFromJoystickAxisMotion(
90  unsigned axis, short value, const EventPtr& origEvent);
91  void triggerOsdControlEventsFromJoystickHat(
92  int value, const EventPtr& origEvent);
93  void osdControlChangeButton(
94  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
95  void triggerOsdControlEventsFromJoystickButtonEvent(
96  unsigned button, bool up, const EventPtr& origEvent);
97  void triggerOsdControlEventsFromKeyEvent(
98  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
99 
100 
101  bool keyRepeat;
102  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
103 
104  // only for Android
105  static bool androidButtonA;
106  static bool androidButtonB;
107 };
108 
109 } // namespace openmsx
110 
111 #endif
void wait()
Wait for event(s) and handle it.
void reinit()
This functions shouldn't be needed, but in the SDL library input and video or closely coupled (sigh)...
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
InputEventGenerator(CommandController &commandController, EventDistributor &eventDistributor, GlobalSettings &globalSettings)
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
Based on boost::noncopyable, see boost documentation: http://www.boost.org/libs/utility.
Definition: noncopyable.hh:12
This class contains settings that are used by several other class (including some singletons)...