diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 11:39:17 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-12 11:39:17 -0700 |
commit | 0edf2a8c95724ffcb89f01fb65c2331eea8b9248 (patch) | |
tree | e16e0d219844ec04fcfd267e15048cec38c492a3 | |
parent | d3e3d803adce646cf169bdb361bb366c0712f598 (diff) | |
parent | 366d0ec788a0847e2513c74c3c35e1f3807741c4 (diff) |
Merge branch 'sdl_mouse_wheel' of github.com:jechter/emscripten into incoming1.18.1
Conflicts:
emscripten-version.txt
-rw-r--r-- | emscripten-version.txt | 2 | ||||
-rw-r--r-- | src/library_browser.js | 16 | ||||
-rw-r--r-- | src/library_sdl.js | 38 | ||||
-rw-r--r-- | src/struct_info.json | 8 |
4 files changed, 56 insertions, 8 deletions
diff --git a/emscripten-version.txt b/emscripten-version.txt index a36c9a1e..6cee04e0 100644 --- a/emscripten-version.txt +++ b/emscripten-version.txt @@ -1,2 +1,2 @@ -1.18.0 +1.18.1 diff --git a/src/library_browser.js b/src/library_browser.js index 57fe1f9f..fce7bdd5 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -478,7 +478,21 @@ mergeInto(LibraryManager.library, { }, getMouseWheelDelta: function(event) { - return Math.max(-1, Math.min(1, event.type === 'DOMMouseScroll' ? event.detail : -event.wheelDelta)); + var delta = 0; + switch (event.type) { + case 'DOMMouseScroll': + delta = event.detail; + break; + case 'mousewheel': + delta = -event.wheelDelta; + break; + case 'wheel': + delta = event.deltaY; + break; + default: + throw 'unrecognized mouse wheel event: ' + event.type; + } + return Math.max(-1, Math.min(1, delta)); }, mouseX: 0, diff --git a/src/library_sdl.js b/src/library_sdl.js index d5b2b354..ae384d22 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -532,7 +532,7 @@ var LibrarySDL = { } } // fall through - case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel': + case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel': case 'wheel': // If we preventDefault on keydown events, the subsequent keypress events // won't fire. However, it's fine (and in some cases necessary) to // preventDefault for keys that don't generate a character. Otherwise, @@ -541,21 +541,40 @@ var LibrarySDL = { event.preventDefault(); } - if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') { + if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel' || event.type == 'wheel') { + // Simulate old-style SDL events representing mouse wheel input as buttons var button = Browser.getMouseWheelDelta(event) > 0 ? 4 : 3; - var event2 = { + var event1 = { type: 'mousedown', button: button, pageX: event.pageX, pageY: event.pageY }; - SDL.events.push(event2); - event = { + SDL.events.push(event1); + var event2 = { type: 'mouseup', button: button, pageX: event.pageX, pageY: event.pageY }; + SDL.events.push(event2); + + // Convert DOMMouseScroll events to wheel events for new style SDL events. + if (event.type == 'DOMMouseScroll') { + SDL.events.push({ + type: 'wheel', + deltaX: 0, + deltaY: -event.detail, + }); + break; + } else if (event.type == 'mousewheel') { + SDL.events.push({ + type: 'wheel', + deltaX: 0, + deltaY: event.wheelDelta, + }); + break; + } } else if (event.type == 'mousedown') { SDL.DOMButtons[event.button] = 1; SDL.events.push({ @@ -787,6 +806,12 @@ var LibrarySDL = { } break; } + case 'wheel': { + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.type, 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}}; + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.x, 'event.deltaX', 'i32') }}}; + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.y, 'event.deltaY', 'i32') }}}; + break; + } case 'touchstart': case 'touchend': case 'touchmove': { var touch = event.touch; if (!Browser.touches[touch.identifier]) break; @@ -1065,6 +1090,7 @@ var LibrarySDL = { SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */; SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */; SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */; + SDL.DOMEventToSDLEvent['wheel'] = 0x403 /* SDL_MOUSEWHEEL */; SDL.DOMEventToSDLEvent['touchstart'] = 0x700 /* SDL_FINGERDOWN */; SDL.DOMEventToSDLEvent['touchend'] = 0x701 /* SDL_FINGERUP */; SDL.DOMEventToSDLEvent['touchmove'] = 0x702 /* SDL_FINGERMOTION */; @@ -1139,7 +1165,7 @@ var LibrarySDL = { }, SDL_SetVideoMode: function(width, height, depth, flags) { - ['touchstart', 'touchend', 'touchmove', 'mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach(function(event) { + ['touchstart', 'touchend', 'touchmove', 'mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'wheel', 'mouseout'].forEach(function(event) { Module['canvas'].addEventListener(event, SDL.receiveEvent, true); }); diff --git a/src/struct_info.json b/src/struct_info.json index f762bf2b..9aeeb283 100644 --- a/src/struct_info.json +++ b/src/struct_info.json @@ -969,6 +969,14 @@ "x", "y" ], + "SDL_MouseWheelEvent": [ + "type", + "timestamp", + "windowID", + "which", + "x", + "y" + ], "SDL_JoyAxisEvent": [ "type", "which", |