diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-03-24 16:25:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-03-24 16:25:06 -0700 |
commit | 1fec3101dd42c568e17b9d8d3a32228f514625d4 (patch) | |
tree | aa7ac7eb892dff62922ac37dcff91624662a891b | |
parent | eb3f5116a5006d03c9e0f94f797b9dfd9dee3aee (diff) |
properly match SDL mousebuttons to DOM buttons
-rw-r--r-- | src/library_sdl.js | 2 | ||||
-rwxr-xr-x | tests/runner.py | 2 | ||||
-rw-r--r-- | tests/sdl_mouse.c | 8 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 63d6c9da..9ba78ae2 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -311,7 +311,7 @@ mergeInto(LibraryManager.library, { if (event.type != 'mousemove') { var down = event.type === 'mousedown'; {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.type', 'down ? 0x401 : 0x402', 'i32') }}}; - {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.button', 'event.button', 'i8') }}}; + {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.button', 'event.button+1', 'i8') }}}; // DOM buttons are 0-2, SDL 1-3 {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.state', 'down ? 1 : 0', 'i8') }}}; {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.x', 'x', 'i32') }}}; {{{ makeSetValue('ptr', 'SDL.structs.MouseButtonEvent.y', 'y', 'i32') }}}; diff --git a/tests/runner.py b/tests/runner.py index 0106df5d..e6a792eb 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6413,7 +6413,7 @@ f.close() open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' function simulateMouseEvent(x, y, button) { var event = document.createEvent("MouseEvents"); - if (button) { + if (button >= 0) { var event1 = document.createEvent("MouseEvents"); event1.initMouseEvent('mousedown', true, true, window, 1, Module['canvas'].offsetLeft + x, Module['canvas'].offsetTop + y, Module['canvas'].offsetLeft + x, Module['canvas'].offsetTop + y, diff --git a/tests/sdl_mouse.c b/tests/sdl_mouse.c index eb731186..a0520839 100644 --- a/tests/sdl_mouse.c +++ b/tests/sdl_mouse.c @@ -46,10 +46,10 @@ int main() { SDL_Rect rect = { 0, 0, 600, 450 }; SDL_FillRect(screen, &rect, 0x2244ff00); - emscripten_run_script("simulateMouseEvent(10, 20, 0)"); // move from 0,0 to 10,20 - emscripten_run_script("simulateMouseEvent(10, 20, 1)"); // click - emscripten_run_script("simulateMouseEvent(30, 77, 0)"); // move some more - emscripten_run_script("simulateMouseEvent(30, 77, 2)"); // trigger the end + emscripten_run_script("simulateMouseEvent(10, 20, -1)"); // move from 0,0 to 10,20 + emscripten_run_script("simulateMouseEvent(10, 20, 0)"); // click + emscripten_run_script("simulateMouseEvent(30, 77, -1)"); // move some more + emscripten_run_script("simulateMouseEvent(30, 77, 1)"); // trigger the end emscripten_set_main_loop(one, 0); |