| 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 |
|
| 12 |
#include <cstdint> |
| 13 |
#include <optional> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
class CommandController; |
| 18 |
class EventDistributor; |
| 19 |
|
| 20 |
class InputEventGenerator final : private EventListener |
| 21 |
{ |
| 22 |
public: |
| 23 |
InputEventGenerator(CommandController& commandController, |
| 24 |
EventDistributor& eventDistributor); |
| 25 |
InputEventGenerator(const InputEventGenerator&) = delete; |
| 26 |
InputEventGenerator(InputEventGenerator&&) = delete; |
| 27 |
InputEventGenerator& operator=(const InputEventGenerator&) = delete; |
| 28 |
InputEventGenerator& operator=(InputEventGenerator&&) = delete; |
| 29 |
~InputEventGenerator(); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
void wait(); |
| 35 |
|
| 36 |
|
| 37 |
[[nodiscard]] BooleanSetting& getGrabInput() { return grabInput; } |
| 38 |
|
| 39 |
void updateGrab(bool grab); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
void poll(std::optional<int> timeoutMs = {}); |
| 48 |
|
| 49 |
[[nodiscard]] JoystickManager& getJoystickManager() { return joystickManager; } |
| 50 |
|
| 51 |
void initializeGrab() const; |
| 52 |
|
| 53 |
private: |
| 54 |
void handle(SDL_Event& evt); |
| 55 |
void handleKeyDown(const SDL_KeyboardEvent& key, uint32_t unicode); |
| 56 |
void splitText(uint32_t timestamp, const char* utf8); |
| 57 |
void setGrabInput(bool grab) const; |
| 58 |
|
| 59 |
|
| 60 |
bool signalEvent(const Event& event) override; |
| 61 |
|
| 62 |
EventDistributor& eventDistributor; |
| 63 |
JoystickManager joystickManager; |
| 64 |
BooleanSetting grabInput; |
| 65 |
|
| 66 |
struct EscapeGrabCmd final : Command { |
| 67 |
explicit EscapeGrabCmd(CommandController& commandController); |
| 68 |
void execute(std::span<const TclObject> tokens, TclObject& result) override; |
| 69 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 70 |
} escapeGrabCmd; |
| 71 |
|
| 72 |
enum EscapeGrabState : uint8_t { |
| 73 |
ESCAPE_GRAB_WAIT_CMD, |
| 74 |
ESCAPE_GRAB_WAIT_LOST, |
| 75 |
ESCAPE_GRAB_WAIT_GAIN |
| 76 |
} escapeGrabState = ESCAPE_GRAB_WAIT_CMD; |
| 77 |
|
| 78 |
|
| 79 |
void setNewOsdControlButtonState(unsigned newState); |
| 80 |
void triggerOsdControlEventsFromJoystickAxisMotion(unsigned axis, int value); |
| 81 |
void triggerOsdControlEventsFromJoystickHat(int value); |
| 82 |
void osdControlChangeButton(bool down, unsigned changedButtonMask); |
| 83 |
void triggerOsdControlEventsFromJoystickButtonEvent(unsigned button, bool down); |
| 84 |
void triggerOsdControlEventsFromKeyEvent(SDLKey key, bool repeat); |
| 85 |
|
| 86 |
private: |
| 87 |
unsigned osdControlButtonsState = unsigned(~0); |
| 88 |
bool sendQuit = false; |
| 89 |
|
| 90 |
|
| 91 |
static inline bool androidButtonA = false; |
| 92 |
static inline bool androidButtonB = false; |
| 93 |
}; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
#endif |