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