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  typedef std::shared_ptr<const Event> EventPtr;
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  class EscapeGrabCmd final : public Command {
75  public:
76  EscapeGrabCmd(CommandController& commandController,
77  InputEventGenerator& inputEventGenerator);
78  void execute(array_ref<TclObject> tokens, TclObject& result) override;
79  std::string help(const std::vector<std::string>& tokens) const override;
80  private:
81  InputEventGenerator& inputEventGenerator;
82  } escapeGrabCmd;
83 
84  enum EscapeGrabState {
85  ESCAPE_GRAB_WAIT_CMD,
86  ESCAPE_GRAB_WAIT_LOST,
87  ESCAPE_GRAB_WAIT_GAIN
88  } escapeGrabState;
89 
90  // OsdControl
91  void setNewOsdControlButtonState(
92  unsigned newState, const EventPtr& origEvent);
93  void triggerOsdControlEventsFromJoystickAxisMotion(
94  unsigned axis, short value, const EventPtr& origEvent);
95  void triggerOsdControlEventsFromJoystickHat(
96  int value, const EventPtr& origEvent);
97  void osdControlChangeButton(
98  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
99  void triggerOsdControlEventsFromJoystickButtonEvent(
100  unsigned button, bool up, const EventPtr& origEvent);
101  void triggerOsdControlEventsFromKeyEvent(
102  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
103 
104 
105  bool keyRepeat;
106  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
107 
108  // only for Android
109  static bool androidButtonA;
110  static bool androidButtonB;
111 };
112 
113 } // namespace openmsx
114 
115 #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)...