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 "build-info.hh"
8 #include "Keys.hh"
9 #include <SDL.h>
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class CommandController;
15 class BooleanSetting;
16 class EventDistributor;
17 class Setting;
18 class EscapeGrabCmd;
19 
20 class InputEventGenerator : private Observer<Setting>, private EventListener,
21  private noncopyable
22 {
23 public:
24  InputEventGenerator(CommandController& commandController,
25  EventDistributor& eventDistributor);
26  virtual ~InputEventGenerator();
27 
31  void wait();
32 
36  void setKeyRepeat(bool enable);
37 
43  void reinit();
44 
46  BooleanSetting& getGrabInput() const { return *grabInput; }
47 
48 private:
49  typedef std::shared_ptr<const Event> EventPtr;
50 
51  void poll();
52  void handle(const SDL_Event& event);
53  void setGrabInput(bool grab);
54 
55  // Observer<Setting>
56  virtual void update(const Setting& setting);
57 
58  // EventListener
59  virtual int signalEvent(const std::shared_ptr<const Event>& event);
60 
61  EventDistributor& eventDistributor;
62  const std::unique_ptr<BooleanSetting> grabInput;
63  const std::unique_ptr<EscapeGrabCmd> escapeGrabCmd;
64  friend class EscapeGrabCmd;
65 
66  enum EscapeGrabState {
67  ESCAPE_GRAB_WAIT_CMD,
68  ESCAPE_GRAB_WAIT_LOST,
69  ESCAPE_GRAB_WAIT_GAIN
70  } escapeGrabState;
71 
72  // OsdControl
73  void setNewOsdControlButtonState(
74  unsigned newState, const EventPtr& origEvent);
75  void triggerOsdControlEventsFromJoystickAxisMotion(
76  unsigned axis, short value, const EventPtr& origEvent);
77  void osdControlChangeButton(
78  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
79  void triggerOsdControlEventsFromJoystickButtonEvent(
80  unsigned button, bool up, const EventPtr& origEvent);
81  void triggerOsdControlEventsFromKeyEvent(
82  Keys::KeyCode keyCode, bool up, const EventPtr& origEvent);
83 
84 
85 #if PLATFORM_GP2X
86  int stat8; // last joystick status (8 input switches)
87 #endif
88  bool keyRepeat;
89 
90  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
91 };
92 
93 } // namespace openmsx
94 
95 #endif