Skip to content

Commit

Permalink
[sdl, web] fix #3 - explicitly check for mouse buttons and properly m…
Browse files Browse the repository at this point in the history
…ap them
  • Loading branch information
asiekierka committed Aug 25, 2020
1 parent e2cb9b5 commit f7b96c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/sdl/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,23 @@ int main(int argc, char **argv) {
SDL_SetRelativeMouseMode(1);
}
} else {
zzt_mouse_set(event.button.button);
if (event.button.button == SDL_BUTTON_LEFT) {
zzt_mouse_set(0);
} else if (event.button.button == SDL_BUTTON_RIGHT) {
zzt_mouse_set(1);
} else if (event.button.button == SDL_BUTTON_MIDDLE) {
zzt_mouse_set(2);
}
}
break;
case SDL_MOUSEBUTTONUP:
zzt_mouse_clear(event.button.button);
if (event.button.button == SDL_BUTTON_LEFT) {
zzt_mouse_clear(0);
} else if (event.button.button == SDL_BUTTON_RIGHT) {
zzt_mouse_clear(1);
} else if (event.button.button == SDL_BUTTON_MIDDLE) {
zzt_mouse_clear(2);
}
break;
case SDL_MOUSEMOTION:
if (SDL_GetRelativeMouseMode() != 0) {
Expand Down
8 changes: 6 additions & 2 deletions web/src/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ class Emulator {
element.requestPointerLock();

if (emu == undefined) return;
emu._zzt_mouse_set(e.button);
if (e.button == 0) emu._zzt_mouse_set(0);
else if (e.button == 2) emu._zzt_mouse_set(1);
else if (e.button == 1) emu._zzt_mouse_set(2);
});

this.element.addEventListener("mouseup", function(e) {
if (emu == undefined) return;
emu._zzt_mouse_clear(e.button);
if (e.button == 0) emu._zzt_mouse_clear(0);
else if (e.button == 2) emu._zzt_mouse_clear(1);
else if (e.button == 1) emu._zzt_mouse_clear(2);
});
}

Expand Down

0 comments on commit f7b96c5

Please sign in to comment.