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:
23  InputEventGenerator(CommandController& commandController,
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 private:
55  typedef std::shared_ptr<const Event> EventPtr;
56 
57  void poll();
58  void handle(const SDL_Event& event);
59  void setGrabInput(bool grab);
60 
61  // Observer<Setting>
62  virtual void update(const Setting& setting);
63 
64  // EventListener
65  virtual int signalEvent(const std::shared_ptr<const Event>& event);
66 
67  EventDistributor& eventDistributor;
68  const std::unique_ptr<BooleanSetting> grabInput;
69  const std::unique_ptr<EscapeGrabCmd> escapeGrabCmd;
70  friend class EscapeGrabCmd;
71 
72  enum EscapeGrabState {
73  ESCAPE_GRAB_WAIT_CMD,
74  ESCAPE_GRAB_WAIT_LOST,
75  ESCAPE_GRAB_WAIT_GAIN
76  } escapeGrabState;
77 
78  // OsdControl
79  void setNewOsdControlButtonState(
80  unsigned newState, const EventPtr& origEvent);
81  void triggerOsdControlEventsFromJoystickAxisMotion(
82  unsigned axis, short value, const EventPtr& origEvent);
83  void osdControlChangeButton(
84  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
85  void triggerOsdControlEventsFromJoystickButtonEvent(
86  unsigned button, bool up, const EventPtr& origEvent);
87  void triggerOsdControlEventsFromKeyEvent(
88  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
89 
90 
91  bool keyRepeat;
92  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
93 
94  // only for Android
95  static bool androidButtonA;
96  static bool androidButtonB;
97 };
98 
99 } // namespace openmsx
100 
101 #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.
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