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 Setting;
17 class EscapeGrabCmd;
18 
19 class InputEventGenerator final : private Observer<Setting>
20  , private EventListener
21  , private noncopyable
22 {
23 public:
25  EventDistributor& eventDistributor);
27 
31  void wait();
32 
36  void setKeyRepeat(bool enable);
37 
43  void reinit();
44 
46  BooleanSetting& getGrabInput() const { return *grabInput; }
47 
52  static int joystickNumButtons(SDL_Joystick* joystick);
53  static bool joystickGetButton(SDL_Joystick* joystick, int button);
54 
55  void poll();
56 
57 private:
58  typedef std::shared_ptr<const Event> EventPtr;
59 
60  void handle(const SDL_Event& event);
61  void setGrabInput(bool grab);
62 
63  // Observer<Setting>
64  void update(const Setting& setting) override;
65 
66  // EventListener
67  int signalEvent(const std::shared_ptr<const Event>& event) override;
68 
69  EventDistributor& eventDistributor;
70  const std::unique_ptr<BooleanSetting> grabInput;
71  const std::unique_ptr<EscapeGrabCmd> escapeGrabCmd;
72  friend class EscapeGrabCmd;
73 
74  enum EscapeGrabState {
75  ESCAPE_GRAB_WAIT_CMD,
76  ESCAPE_GRAB_WAIT_LOST,
77  ESCAPE_GRAB_WAIT_GAIN
78  } escapeGrabState;
79 
80  // OsdControl
81  void setNewOsdControlButtonState(
82  unsigned newState, const EventPtr& origEvent);
83  void triggerOsdControlEventsFromJoystickAxisMotion(
84  unsigned axis, short value, const EventPtr& origEvent);
85  void triggerOsdControlEventsFromJoystickHat(
86  int value, const EventPtr& origEvent);
87  void osdControlChangeButton(
88  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
89  void triggerOsdControlEventsFromJoystickButtonEvent(
90  unsigned button, bool up, const EventPtr& origEvent);
91  void triggerOsdControlEventsFromKeyEvent(
92  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
93 
94 
95  bool keyRepeat;
96  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
97 
98  // only for Android
99  static bool androidButtonA;
100  static bool androidButtonB;
101 };
102 
103 } // namespace openmsx
104 
105 #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
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)
InputEventGenerator(CommandController &commandController, EventDistributor &eventDistributor)
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