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 "Command.hh"
6#include "EventListener.hh"
7#include "JoystickManager.hh"
8
9#include "SDLKey.hh"
10#include <SDL.h>
11
12namespace openmsx {
13
14class CommandController;
15class EventDistributor;
16class GlobalSettings;
17
19{
20public:
21 InputEventGenerator(CommandController& commandController,
22 EventDistributor& eventDistributor,
23 GlobalSettings& globalSettings);
29
33 void wait();
34
36 [[nodiscard]] BooleanSetting& getGrabInput() { return grabInput; }
38 void updateGrab(bool grab);
39
40 void poll();
41
42 [[nodiscard]] JoystickManager& getJoystickManager() { return joystickManager; }
43
44private:
45 void handle(const SDL_Event& evt);
46 void handleKeyDown(const SDL_KeyboardEvent& key, uint32_t unicode);
47 void splitText(uint32_t timestamp, const char* utf8);
48 void setGrabInput(bool grab) const;
49
50 // EventListener
51 bool signalEvent(const Event& event) override;
52
53 EventDistributor& eventDistributor;
54 GlobalSettings& globalSettings;
55 JoystickManager joystickManager;
56 BooleanSetting grabInput;
57
58 struct EscapeGrabCmd final : Command {
59 explicit EscapeGrabCmd(CommandController& commandController);
60 void execute(std::span<const TclObject> tokens, TclObject& result) override;
61 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
62 } escapeGrabCmd;
63
64 enum EscapeGrabState {
65 ESCAPE_GRAB_WAIT_CMD,
66 ESCAPE_GRAB_WAIT_LOST,
67 ESCAPE_GRAB_WAIT_GAIN
68 } escapeGrabState = ESCAPE_GRAB_WAIT_CMD;
69
70 // OsdControl
71 void setNewOsdControlButtonState(unsigned newState);
72 void triggerOsdControlEventsFromJoystickAxisMotion(unsigned axis, int value);
73 void triggerOsdControlEventsFromJoystickHat(int value);
74 void osdControlChangeButton(bool down, unsigned changedButtonMask);
75 void triggerOsdControlEventsFromJoystickButtonEvent(unsigned button, bool down);
76 void triggerOsdControlEventsFromKeyEvent(SDLKey key, bool repeat);
77
78private:
79 unsigned osdControlButtonsState = unsigned(~0); // 0 is pressed, 1 is released
80
81 // only for Android
82 static inline bool androidButtonA = false;
83 static inline bool androidButtonB = false;
84};
85
86} // namespace openmsx
87
88#endif
This class contains settings that are used by several other class (including some singletons).
InputEventGenerator(const InputEventGenerator &)=delete
InputEventGenerator(InputEventGenerator &&)=delete
BooleanSetting & getGrabInput()
Input Grab on or off.
JoystickManager & getJoystickManager()
void updateGrab(bool grab)
Must be called when 'grabinput' or 'fullscreen' setting changes.
InputEventGenerator & operator=(InputEventGenerator &&)=delete
void wait()
Wait for event(s) and handle it.
InputEventGenerator & operator=(const InputEventGenerator &)=delete
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:445
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.
Definition xrange.hh:147