Skip to content

Commit

Permalink
sdl: Add SDL input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelmachek committed Jan 15, 2025
1 parent f4f0372 commit b764e40
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions libs/graphics/lcd_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "platform_config.h"
#include "jsutils.h"
#include "jsparse.h"
#include "jsinteractive.h"
#include "lcd_sdl.h"
#include <SDL/SDL.h>

Expand Down Expand Up @@ -95,10 +97,42 @@ void lcdInit_SDL(JsGraphics *gfx) {
}

void lcdIdle_SDL() {
SDL_Event event;
bool sendEvent = false;
static bool down;

if (needsFlip) {
needsFlip = false;
SDL_Flip(screen);
}

if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEMOTION:
if (down) {
sendEvent = true;
}
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
down = event.type == SDL_MOUSEBUTTONDOWN;
sendEvent = true;
break;
}
}

if (sendEvent) {
JsVar *E = jsvObjectGetChildIfExists(execInfo.root, "E");
if (E) {
JsVar *o = jsvNewObject();
jsvObjectSetChildAndUnLock(o,"x", jsvNewFromInteger(event.button.x));
jsvObjectSetChildAndUnLock(o,"y", jsvNewFromInteger(event.button.y));
jsvObjectSetChildAndUnLock(o,"b", jsvNewFromInteger(down?1:0));
jsiQueueObjectCallbacks(E, JS_EVENT_PREFIX"touch", &o, 1);
jsvUnLock2(E,o);
}
}
fflush(stdout);
}

void lcdSetCallbacks_SDL(JsGraphics *gfx) {
Expand Down

0 comments on commit b764e40

Please sign in to comment.