12[[nodiscard]]
static Event parseKeyEvent(std::string_view str, uint32_t unicode)
20 evt.key = SDL_KeyboardEvent{};
23 e.timestamp = SDL_GetTicks();
25 e.keysym.unused = unicode;
28 e.state = SDL_PRESSED;
32 e.state = SDL_RELEASED;
39 auto len = str.getListLength(interp);
44 }
else if (len == 2) {
45 auto comp1 = str.getListIndex(interp, 1).getString();
46 return parseKeyEvent(comp1, 0);
47 }
else if (len == 3) {
48 auto comp1 = str.getListIndex(interp, 1).getString();
49 auto comp2 = str.getListIndex(interp, 2).getString();
50 if (comp2.starts_with(
"unicode")) {
51 if (
auto u = StringOp::stringToBase<10, unsigned>(comp2.substr(7))) {
52 return parseKeyEvent(comp1, *u);
59[[nodiscard]]
static bool upDown(std::string_view str)
63 }
else if (str ==
"down") {
67 "Invalid direction (expected 'up' or 'down'): ", str);
72 auto len = str.getListLength(interp);
74 auto comp1 = str.getListIndex(interp, 1).getString();
75 if (comp1 ==
"motion") {
80 }
else if (len ==
one_of(4u, 6u)) {
81 int absX = 0, absY = 0;
83 absX = str.getListIndex(interp, 4).getInt(interp);
84 absY = str.getListIndex(interp, 5).getInt(interp);
90 evt.motion = SDL_MouseMotionEvent{};
93 e.type = SDL_MOUSEMOTION;
94 e.timestamp = SDL_GetTicks();
97 e.xrel = str.getListIndex(interp, 2).getInt(interp);
98 e.yrel = str.getListIndex(interp, 3).getInt(interp);
101 }
else if (comp1.starts_with(
"button")) {
106 }
else if (len == 3) {
107 if (
auto button = StringOp::stringToBase<10, unsigned>(comp1.substr(6))) {
109 evt.button = SDL_MouseButtonEvent{};
110 auto& e = evt.button;
112 e.timestamp = SDL_GetTicks();
113 e.button = narrow<uint8_t>(*button);
114 if (upDown(str.getListIndex(interp, 2).getString())) {
115 e.type = SDL_MOUSEBUTTONUP;
116 e.state = SDL_RELEASED;
119 e.type = SDL_MOUSEBUTTONDOWN;
120 e.state = SDL_PRESSED;
125 }
else if (comp1 ==
"wheel") {
130 }
else if (len == 4) {
132 evt.wheel = SDL_MouseWheelEvent{};
135 e.type = SDL_MOUSEWHEEL;
136 e.timestamp = SDL_GetTicks();
137 e.direction = SDL_MOUSEWHEEL_NORMAL;
138 e.x = str.getListIndex(interp, 2).getInt(interp);
139 e.y = str.getListIndex(interp, 3).getInt(interp);
140 #if (SDL_VERSION_ATLEAST(2, 0, 18))
141 e.preciseX = narrow_cast<float>(e.x);
142 e.preciseY = narrow_cast<float>(e.y);
153 if (str.getListLength(interp) == 3) {
154 auto buttonName = str.getListIndex(interp, 1).getString();
157 if (buttonName ==
"LEFT") {
159 }
else if (buttonName ==
"RIGHT") {
161 }
else if (buttonName ==
"UP") {
163 }
else if (buttonName ==
"DOWN") {
165 }
else if (buttonName ==
"A") {
167 }
else if (buttonName ==
"B") {
171 "Invalid OSDcontrol event, invalid button name: ",
175 auto buttonAction = str.getListIndex(interp, 2).getString();
176 if (buttonAction ==
"RELEASE") {
178 }
else if (buttonAction ==
"PRESS") {
187 auto len = str.getListLength(interp);
189 auto comp0 = str.getListIndex(interp, 0).getString();
190 auto comp1 = str.getListIndex(interp, 1).getString();
194 if (comp1.starts_with(
"button")) {
198 }
else if (comp1.starts_with(
"axis")) {
202 }
else if (comp1.starts_with(
"hat")) {
204 std::initializer_list<EventType>{
JOY_HAT},
207 }
else if (len == 3) {
208 auto comp2 = str.getListIndex(interp, 2);
209 if (
auto j = StringOp::stringToBase<10, unsigned>(comp0.substr(3))) {
210 unsigned joystick = *j - 1;
211 if (comp1.starts_with(
"button")) {
212 if (
auto button = StringOp::stringToBase<10, unsigned>(comp1.substr(6))) {
214 evt.jbutton = SDL_JoyButtonEvent{};
215 auto& e = evt.jbutton;
217 e.timestamp = SDL_GetTicks();
219 e.button = narrow_cast<uint8_t>(*button);
220 if (upDown(comp2.getString())) {
221 e.type = SDL_JOYBUTTONUP;
222 e.state = SDL_RELEASED;
225 e.type = SDL_JOYBUTTONDOWN;
226 e.state = SDL_PRESSED;
230 }
else if (comp1.starts_with(
"axis")) {
231 if (
auto axis = StringOp::stringToBase<10, unsigned>(comp1.substr(4))) {
233 evt.jaxis = SDL_JoyAxisEvent{};
236 e.type = SDL_JOYAXISMOTION;
237 e.timestamp = SDL_GetTicks();
239 e.axis = narrow_cast<uint8_t>(*axis);
240 e.value = narrow_cast<int16_t>(str.getListIndex(interp, 2).getInt(interp));
243 }
else if (comp1.starts_with(
"hat")) {
244 if (
auto hat = StringOp::stringToBase<10, unsigned>(comp1.substr(3))) {
245 auto valueStr = str.getListIndex(interp, 2).getString();
247 if (valueStr ==
"up")
return SDL_HAT_UP;
248 else if (valueStr ==
"right")
return SDL_HAT_RIGHT;
249 else if (valueStr ==
"down")
return SDL_HAT_DOWN;
250 else if (valueStr ==
"left")
return SDL_HAT_LEFT;
251 else if (valueStr ==
"rightup")
return SDL_HAT_RIGHTUP;
252 else if (valueStr ==
"rightdown")
return SDL_HAT_RIGHTDOWN;
253 else if (valueStr ==
"leftup")
return SDL_HAT_LEFTUP;
254 else if (valueStr ==
"leftdown")
return SDL_HAT_LEFTDOWN;
255 else if (valueStr ==
"center")
return SDL_HAT_CENTERED;
261 evt.jhat = SDL_JoyHatEvent{};
264 e.type = SDL_JOYHATMOTION;
265 e.timestamp = SDL_GetTicks();
267 e.hat = narrow_cast<uint8_t>(*hat);
268 e.value = narrow_cast<uint8_t>(value);
280 if (str.getListLength(interp) != 2) {
283 bool gained = str.getListIndex(interp, 1).getBoolean(interp);
286 evt.window = SDL_WindowEvent{};
287 auto& e = evt.window;
289 e.type = SDL_WINDOWEVENT;
290 e.timestamp = SDL_GetTicks();
292 e.event = gained ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST;
298 if (str.getListLength(interp) != 1) {
308 if (str.getListLength(interp) != 1) {
320 if (type ==
"keyb") {
321 return parseKeyEvent(str, interp);
322 }
else if (type ==
"mouse") {
323 return parseMouseEvent(str, interp);
324 }
else if (type.starts_with(
"joy")) {
325 return parseJoystickEvent(str, interp);
326 }
else if (type ==
"focus") {
327 return parseFocusEvent(str, interp);
328 }
else if (type ==
"filedrop") {
329 return parseFileDropEvent(str, interp);
330 }
else if (type ==
"quit") {
331 return parseQuitEvent(str, interp);
332 }
else if (type ==
"command") {
334 evt.key = SDL_KeyboardEvent{};
335 evt.key.type = SDL_KEYUP;
336 evt.key.state = SDL_RELEASED;
339 }
else if (type ==
"OSDcontrol") {
340 return parseOsdControlEvent(str, interp);
343 return parseKeyEvent(str.
getString(), 0);
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