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 "EventListener.hh"
6 #include "noncopyable.hh"
7 #include "Keys.hh"
8 #include <SDL.h>
9 #include <memory>
10 
11 namespace openmsx {
12 
13 class CommandController;
14 class BooleanSetting;
15 class EventDistributor;
16 class GlobalSettings;
17 class Setting;
18 class EscapeGrabCmd;
19 
20 class InputEventGenerator final : private Observer<Setting>
21  , private EventListener
22  , private noncopyable
23 {
24 public:
26  EventDistributor& eventDistributor,
27  GlobalSettings& globalSettings);
29 
33  void wait();
34 
38  void setKeyRepeat(bool enable);
39 
45  void reinit();
46 
48  BooleanSetting& getGrabInput() const { 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  typedef std::shared_ptr<const Event> EventPtr;
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  const std::unique_ptr<BooleanSetting> grabInput;
74  const std::unique_ptr<EscapeGrabCmd> escapeGrabCmd;
75  friend class EscapeGrabCmd;
76 
77  enum EscapeGrabState {
78  ESCAPE_GRAB_WAIT_CMD,
79  ESCAPE_GRAB_WAIT_LOST,
80  ESCAPE_GRAB_WAIT_GAIN
81  } escapeGrabState;
82 
83  // OsdControl
84  void setNewOsdControlButtonState(
85  unsigned newState, const EventPtr& origEvent);
86  void triggerOsdControlEventsFromJoystickAxisMotion(
87  unsigned axis, short value, const EventPtr& origEvent);
88  void triggerOsdControlEventsFromJoystickHat(
89  int value, const EventPtr& origEvent);
90  void osdControlChangeButton(
91  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
92  void triggerOsdControlEventsFromJoystickButtonEvent(
93  unsigned button, bool up, const EventPtr& origEvent);
94  void triggerOsdControlEventsFromKeyEvent(
95  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
96 
97 
98  bool keyRepeat;
99  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
100 
101  // only for Android
102  static bool androidButtonA;
103  static bool androidButtonB;
104 };
105 
106 } // namespace openmsx
107 
108 #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)...
std::shared_ptr< const Event > EventPtr
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
InputEventGenerator(CommandController &commandController, EventDistributor &eventDistributor, GlobalSettings &globalSettings)
BooleanSetting & getGrabInput() const
Input Grab on or off.
static int joystickNumButtons(SDL_Joystick *joystick)
Normally the following two functions simply delegate to SDL_JoystickNumButtons() and SDL_JoystickGetB...
void setKeyRepeat(bool enable)
Enable or disable keyboard event repeats.
commandController(commandController_)
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)...