Skip to content

Commit 3aa3254

Browse files
committed
added touch support
1 parent 7effb96 commit 3aa3254

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

cmake/sokol.cmake

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,14 @@ if(BUILD_SOKOL)
8989
set_target_properties(tic80 PROPERTIES PREFIX "")
9090
elseif(EMSCRIPTEN)
9191
add_executable(tic80 ${TIC80_SRC})
92-
set_target_properties(tic80 PROPERTIES LINK_FLAGS
93-
"-s USE_WEBGPU=1"
94-
"-s ALLOW_MEMORY_GROWTH=1"
95-
"-s FETCH=1"
96-
"-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$dynCall','$writeArrayToMemory']"
97-
"-s EXPORTED_RUNTIME_METHODS=['FS']"
98-
"-s EXPORT_ES6=1"
99-
"-s MODULARIZE=1"
100-
)
92+
set_target_properties(tic80 PROPERTIES LINK_FLAGS "
93+
-s USE_WEBGPU=1
94+
-s ALLOW_MEMORY_GROWTH=1
95+
-s FETCH=1
96+
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$dynCall','$writeArrayToMemory']
97+
-s EXPORTED_RUNTIME_METHODS=['FS']
98+
-s EXPORT_ES6=1
99+
-s MODULARIZE=1")
101100
else()
102101
add_executable(tic80 ${TIC80_SRC})
103102
endif()

src/system/sokol/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,15 @@ static void processMouse(App *app, sapp_mousebutton btn, s32 down)
857857
}
858858
}
859859

860+
static void processTouch(App *app, const sapp_touchpoint *touch)
861+
{
862+
tic80_input* input = &app->input;
863+
864+
Rect r = viewport(app);
865+
app->mouse.x = (touch->pos_x - r.x) * TIC80_FULLWIDTH / r.w;
866+
app->mouse.y = (touch->pos_y - r.y) * TIC80_FULLHEIGHT / r.h;
867+
}
868+
860869
static void event(const sapp_event* event, void *userdata)
861870
{
862871
App *app = userdata;
@@ -901,6 +910,17 @@ static void event(const sapp_event* event, void *userdata)
901910
case SAPP_EVENTTYPE_MOUSE_SCROLL:
902911
input->mouse.scrolly = event->scroll_y > 0 ? 1 : -1;
903912
break;
913+
case SAPP_EVENTTYPE_TOUCHES_BEGAN:
914+
processTouch(app, &event->touches[0]);
915+
processMouse(app, SAPP_MOUSEBUTTON_LEFT, 1);
916+
break;
917+
case SAPP_EVENTTYPE_TOUCHES_ENDED:
918+
processTouch(app, &event->touches[0]);
919+
processMouse(app, SAPP_MOUSEBUTTON_LEFT, 0);
920+
break;
921+
case SAPP_EVENTTYPE_TOUCHES_MOVED:
922+
processTouch(app, &event->touches[0]);
923+
break;
904924
default:
905925
break;
906926
}

0 commit comments

Comments
 (0)