Skip to content

Commit

Permalink
Emscripten: Fixed touch coordinates not being normalized.
Browse files Browse the repository at this point in the history
  • Loading branch information
philippwiesemann committed May 6, 2015
1 parent 5715097 commit 3f51758
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -371,7 +371,7 @@ Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, vo
EM_BOOL
Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{
/*SDL_WindowData *window_data = userData;*/
SDL_WindowData *window_data = userData;
int i;

SDL_TouchID deviceId = 0;
Expand All @@ -382,14 +382,15 @@ Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, vo
}

for (i = 0; i < touchEvent->numTouches; i++) {
long x, y, id;
SDL_FingerID id;
float x, y;

if (!touchEvent->touches[i].isChanged)
continue;

id = touchEvent->touches[i].identifier;
x = touchEvent->touches[i].canvasX;
y = touchEvent->touches[i].canvasY;
x = touchEvent->touches[i].canvasX / (float)window_data->windowed_width;
y = touchEvent->touches[i].canvasY / (float)window_data->windowed_height;

if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
Expand Down

0 comments on commit 3f51758

Please sign in to comment.