Skip to content

Commit

Permalink
Merge pull request #2596 from pavelmachek/m_2_sdl
Browse files Browse the repository at this point in the history
sdl: Add support for input
  • Loading branch information
gfwilliams authored Jan 16, 2025
2 parents f3a0b2f + 19d632e commit 7345ea6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 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 @@ -91,13 +93,49 @@ void lcdInit_SDL(JsGraphics *gfx) {
SDL_Quit();
exit(1);
}
SDL_WM_SetCaption("Espruino", NULL);
}

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

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

if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
nativeQuit();
break;
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);
}
}
}

void lcdSetCallbacks_SDL(JsGraphics *gfx) {
Expand Down

0 comments on commit 7345ea6

Please sign in to comment.