From 61f7c9a8dce8421494a01ec17bfc15de19b1b37e Mon Sep 17 00:00:00 2001 From: jonas echterhoff Date: Thu, 8 May 2014 15:03:15 +0200 Subject: Make scroll wheel work with SDL --- src/library_sdl.js | 28 +++++++++++++--------------- src/struct_info.json | 8 ++++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/library_sdl.js b/src/library_sdl.js index 077f72eb..429c3afa 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -541,21 +541,12 @@ var LibrarySDL = { event.preventDefault(); } - if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') { - var button = Browser.getMouseWheelDelta(event) > 0 ? 4 : 3; - var event2 = { - type: 'mousedown', - button: button, - pageX: event.pageX, - pageY: event.pageY - }; - SDL.events.push(event2); - event = { - type: 'mouseup', - button: button, - pageX: event.pageX, - pageY: event.pageY - }; + if (event.type == 'DOMMouseScroll') { + SDL.events.push({ + type: 'mousewheel', + wheelDelta: -event.detail, + }); + break; } else if (event.type == 'mousedown') { SDL.DOMButtons[event.button] = 1; SDL.events.push({ @@ -787,6 +778,12 @@ var LibrarySDL = { } break; } + case 'mousewheel': { + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.type, 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}}; + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.x, '0', 'i32') }}}; + {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.y, 'Browser.getMouseWheelDelta(event)', 'i32') }}}; + break; + } case 'touchstart': case 'touchend': case 'touchmove': { var touch = event.touch; var w = Module['canvas'].width; @@ -1064,6 +1061,7 @@ var LibrarySDL = { SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */; SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */; SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */; + SDL.DOMEventToSDLEvent['mousewheel'] = 0x403 /* SDL_MOUSEWHEEL */; SDL.DOMEventToSDLEvent['touchstart'] = 0x700 /* SDL_FINGERDOWN */; SDL.DOMEventToSDLEvent['touchend'] = 0x701 /* SDL_FINGERUP */; SDL.DOMEventToSDLEvent['touchmove'] = 0x702 /* SDL_FINGERMOTION */; 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", -- cgit v1.2.3-18-g5258 From 524e0b0f4f8836f77e789832a7dacb8f339c88d2 Mon Sep 17 00:00:00 2001 From: jonas echterhoff Date: Fri, 9 May 2014 09:40:08 +0200 Subject: Bring back old style SDL scroll events represented as mouse buttons; Support newer 'wheel' event to support Chrome; Support vertical as well as horizontal deltas. --- src/library_browser.js | 17 ++++++++++++++++- src/library_sdl.js | 52 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/library_browser.js b/src/library_browser.js index 44e8c473..4593f203 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -478,7 +478,22 @@ 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 429c3afa..b630ca5c 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,12 +541,40 @@ var LibrarySDL = { event.preventDefault(); } - if (event.type == 'DOMMouseScroll') { - SDL.events.push({ - type: 'mousewheel', - wheelDelta: -event.detail, - }); - break; + 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 event1 = { + type: 'mousedown', + button: button, + pageX: event.pageX, + pageY: event.pageY + }; + 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({ @@ -778,10 +806,10 @@ var LibrarySDL = { } break; } - case 'mousewheel': { + case 'wheel': { {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.type, 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}}; - {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.x, '0', 'i32') }}}; - {{{ makeSetValue('ptr', C_STRUCTS.SDL_MouseWheelEvent.y, 'Browser.getMouseWheelDelta(event)', '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': { @@ -1061,7 +1089,7 @@ var LibrarySDL = { SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */; SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */; SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */; - SDL.DOMEventToSDLEvent['mousewheel'] = 0x403 /* SDL_MOUSEWHEEL */; + SDL.DOMEventToSDLEvent['wheel'] = 0x403 /* SDL_MOUSEWHEEL */; SDL.DOMEventToSDLEvent['touchstart'] = 0x700 /* SDL_FINGERDOWN */; SDL.DOMEventToSDLEvent['touchend'] = 0x701 /* SDL_FINGERUP */; SDL.DOMEventToSDLEvent['touchmove'] = 0x702 /* SDL_FINGERMOTION */; @@ -1136,7 +1164,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); }); -- cgit v1.2.3-18-g5258 From 87134a2855cb62d2fb5e189ea82be9eb0815cd9e Mon Sep 17 00:00:00 2001 From: jonas echterhoff Date: Sun, 11 May 2014 20:57:42 +0200 Subject: Code conventions and sign fix according to pull request feedback --- src/library_browser.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/library_browser.js b/src/library_browser.js index 4593f203..2317ca47 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -479,13 +479,12 @@ mergeInto(LibraryManager.library, { getMouseWheelDelta: function(event) { var delta = 0; - switch (event.type) - { + switch (event.type) { case 'DOMMouseScroll': delta = event.detail; break; case 'mousewheel': - delta = event.wheelDelta; + delta = -event.wheelDelta; break; case 'wheel': delta = event.deltaY; -- cgit v1.2.3-18-g5258 From 366d0ec788a0847e2513c74c3c35e1f3807741c4 Mon Sep 17 00:00:00 2001 From: jonas echterhoff Date: Sun, 11 May 2014 20:58:42 +0200 Subject: Bump version --- emscripten-version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emscripten-version.txt b/emscripten-version.txt index f9505a5c..2ef35729 100644 --- a/emscripten-version.txt +++ b/emscripten-version.txt @@ -1,2 +1,2 @@ -1.17.0 +1.17.1 -- cgit v1.2.3-18-g5258