openMSX
InputEventGenerator.hh
Go to the documentation of this file.
1 #ifndef INPUTEVENTGENERATOR_HH
2 #define INPUTEVENTGENERATOR_HH
3 
4 #include "BooleanSetting.hh"
5 #include "EventListener.hh"
6 #include "Command.hh"
7 #include "Keys.hh"
8 #include <SDL.h>
9 #include <memory>
10 
11 namespace openmsx {
12 
13 class CommandController;
14 class EventDistributor;
15 class GlobalSettings;
16 
17 class InputEventGenerator final : private EventListener
18 {
19 public:
22 
23  InputEventGenerator(CommandController& commandController,
24  EventDistributor& eventDistributor,
25  GlobalSettings& globalSettings);
27 
31  void wait();
32 
34  BooleanSetting& getGrabInput() { return grabInput; }
36  void updateGrab(bool grab);
37 
42  static int joystickNumButtons(SDL_Joystick* joystick);
43  static bool joystickGetButton(SDL_Joystick* joystick, int button);
44 
45  void poll();
46 
47 private:
48  using EventPtr = std::shared_ptr<const Event>;
49 
50  void handle(const SDL_Event& evt);
51  void handleKeyDown(const SDL_KeyboardEvent& key, uint32_t unicode);
52  void handleText(const char* utf8);
53  void setGrabInput(bool grab);
54 
55  // EventListener
56  int signalEvent(const std::shared_ptr<const Event>& event) override;
57 
58  EventDistributor& eventDistributor;
59  GlobalSettings& globalSettings;
60  BooleanSetting grabInput;
61 
62  struct EscapeGrabCmd final : Command {
63  explicit EscapeGrabCmd(CommandController& commandController);
64  void execute(span<const TclObject> tokens, TclObject& result) override;
65  std::string help(const std::vector<std::string>& tokens) const override;
66  } escapeGrabCmd;
67 
68  enum EscapeGrabState {
69  ESCAPE_GRAB_WAIT_CMD,
70  ESCAPE_GRAB_WAIT_LOST,
71  ESCAPE_GRAB_WAIT_GAIN
72  } escapeGrabState;
73 
74  // OsdControl
75  void setNewOsdControlButtonState(
76  unsigned newState, const EventPtr& origEvent);
77  void triggerOsdControlEventsFromJoystickAxisMotion(
78  unsigned axis, int value, const EventPtr& origEvent);
79  void triggerOsdControlEventsFromJoystickHat(
80  int value, const EventPtr& origEvent);
81  void osdControlChangeButton(
82  bool up, unsigned changedButtonMask, const EventPtr& origEvent);
83  void triggerOsdControlEventsFromJoystickButtonEvent(
84  unsigned button, bool up, const EventPtr& origEvent);
85  void triggerOsdControlEventsFromKeyEvent(
86  Keys::KeyCode keyCode, bool up, bool repeat, const EventPtr& origEvent);
87 
88 
89  unsigned osdControlButtonsState; // 0 is pressed, 1 is released
90 
91  // only for Android
92  static inline bool androidButtonA = false;
93  static inline bool androidButtonB = false;
94 };
95 
96 } // namespace openmsx
97 
98 #endif
openmsx::InputEventGenerator::poll
void poll()
Definition: InputEventGenerator.cc:62
utf8
Definition: utf8_checked.hh:36
openmsx::CommandController
Definition: CommandController.hh:18
openmsx::InputEventGenerator::joystickGetButton
static bool joystickGetButton(SDL_Joystick *joystick, int button)
Definition: InputEventGenerator.cc:475
openmsx::InputEventGenerator
Definition: InputEventGenerator.hh:18
openmsx::InputEventGenerator::getGrabInput
BooleanSetting & getGrabInput()
Input Grab on or off.
Definition: InputEventGenerator.hh:34
EventListener.hh
openmsx::EventDistributor
Definition: EventDistributor.hh:17
BooleanSetting.hh
span
Definition: span.hh:126
openmsx::InputEventGenerator::InputEventGenerator
InputEventGenerator(const InputEventGenerator &)=delete
openmsx::InputEventGenerator::wait
void wait()
Wait for event(s) and handle it.
Definition: InputEventGenerator.cc:50
openmsx::InputEventGenerator::joystickNumButtons
static int joystickNumButtons(SDL_Joystick *joystick)
Normally the following two functions simply delegate to SDL_JoystickNumButtons() and SDL_JoystickGetB...
Definition: InputEventGenerator.cc:467
openmsx::InputEventGenerator::~InputEventGenerator
~InputEventGenerator()
Definition: InputEventGenerator.cc:45
Keys.hh
openmsx::EventListener
Definition: EventListener.hh:11
openmsx::GlobalSettings
This class contains settings that are used by several other class (including some singletons).
Definition: GlobalSettings.hh:25
openmsx::BooleanSetting
Definition: BooleanSetting.hh:9
Command.hh
openmsx::InputEventGenerator::operator=
InputEventGenerator & operator=(const InputEventGenerator &)=delete
openmsx::Command
Definition: Command.hh:41
openmsx::InputEventGenerator::updateGrab
void updateGrab(bool grab)
Must be called when 'grabinput' or 'fullscreen' setting changes.
Definition: InputEventGenerator.cc:422
openmsx::TclObject
Definition: TclObject.hh:22
openmsx::Keys::KeyCode
KeyCode
Constants that identify keys and key modifiers.
Definition: Keys.hh:26
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5