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