10#if __has_include(<SDL2/SDL.h>)
24Result<void> pushEvent(SDL_Event& event) {
25 if (SDL_PushEvent(&event) != 1) {
34 [[nodiscard]] Result<void> injectKey(std::string_view
key,
bool down,
bool repeat)
override {
39 const std::string keyName(
key);
40 const SDL_Keycode keycode = SDL_GetKeyFromName(keyName.c_str());
41 if (keycode == SDLK_UNKNOWN) {
46 event.type = down ? SDL_KEYDOWN : SDL_KEYUP;
47 event.key.type =
event.type;
48 event.key.state = down ? SDL_PRESSED : SDL_RELEASED;
49 event.key.repeat = (down && repeat) ? 1 : 0;
50 event.key.keysym.sym = keycode;
51 event.key.keysym.scancode = SDL_GetScancodeFromKey(keycode);
52 event.key.keysym.mod = KMOD_NONE;
53 return pushEvent(event);
56 [[nodiscard]] Result<void> injectMouseButton(
int button,
bool down,
float x,
float y)
override {
57 if (button < 1 || button > 5) {
62 event.type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
63 event.button.type =
event.type;
64 event.button.button =
static_cast<Uint8
>(
button);
65 event.button.state = down ? SDL_PRESSED : SDL_RELEASED;
66 event.button.clicks = 1;
67 event.button.x =
static_cast<Sint32
>(
x);
68 event.button.y =
static_cast<Sint32
>(
y);
69 return pushEvent(event);
72 [[nodiscard]] Result<void> injectMouseMove(
float x,
float y,
float dx,
float dy)
override {
74 event.type = SDL_MOUSEMOTION;
75 event.motion.type = SDL_MOUSEMOTION;
76 event.motion.x =
static_cast<Sint32
>(
x);
77 event.motion.y =
static_cast<Sint32
>(
y);
78 event.motion.xrel =
static_cast<Sint32
>(
dx);
79 event.motion.yrel =
static_cast<Sint32
>(
dy);
80 return pushEvent(event);
83 [[nodiscard]] Result<void> injectWheel(
float x,
float y)
override {
85 event.type = SDL_MOUSEWHEEL;
86 event.wheel.type = SDL_MOUSEWHEEL;
87 event.wheel.x =
static_cast<Sint32
>(
x);
88 event.wheel.y =
static_cast<Sint32
>(
y);
89 event.wheel.direction = SDL_MOUSEWHEEL_NORMAL;
90#if SDL_VERSION_ATLEAST(2, 0, 18)
91 event.wheel.preciseX =
x;
92 event.wheel.preciseY =
y;
94 return pushEvent(event);
97 [[nodiscard]] Result<void> injectText(std::string_view
text)
override {
103 event.type = SDL_TEXTINPUT;
104 event.text.type = SDL_TEXTINPUT;
105 const std::size_t
n =
106 std::min(
text.size(),
static_cast<std::size_t
>(SDL_TEXTINPUTEVENT_TEXT_SIZE - 1));
107 std::memcpy(event.text.text,
text.data(),
n);
108 event.text.text[
n] =
'\0';
109 return pushEvent(event);
115 static SdlInputInjection injection;
116 eve::cap::provide<eve::IInputInjection>(&injection);
Stable, structured diagnostics shared by engine modules.
Move-only, checked operation results for the common layer.
Structured operation status used by the common Result foundation.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
ControlEdit button(const char *label, float width=0.f, float height=0.f)
Shared immediate renderer for retained and EditorHost buttons.