diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-10 21:44:51 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-10 21:44:51 -0700 |
commit | 9f9af4cefb142960cad37b3f43f4777e4334f2f2 (patch) | |
tree | 8f1765a7a077dba9e441b1edd80f6380cecc588a /src | |
parent | f6cbc9e6a01f777d179d31f45b3453808cd59e33 (diff) | |
parent | fe247614cd79a135d3145fb5e66e152b620c9025 (diff) |
Merge pull request #1363 from dtc/sdl-touch
Add basic touch support that translates to mouse events.
Diffstat (limited to 'src')
-rw-r--r-- | src/library_sdl.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 646aa54c..b64a34ef 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -361,8 +361,48 @@ var LibrarySDL = { SDL.surfaces[surf] = null; }, + touchX:0, touchY: 0, + receiveEvent: function(event) { switch(event.type) { + case 'touchstart': + event.preventDefault(); + var touch = event.touches[0]; + touchX = touch.pageX; + touchY = touch.pageY; + var event = { + type: 'mousedown', + button: 0, + pageX: touchX, + pageY: touchY + }; + SDL.DOMButtons[0] = 1; + SDL.events.push(event); + break; + case 'touchmove': + event.preventDefault(); + var touch = event.touches[0]; + touchX = touch.pageX; + touchY = touch.pageY; + event = { + type: 'mousemove', + button: 0, + pageX: touchX, + pageY: touchY + }; + SDL.events.push(event); + break; + case 'touchend': + event.preventDefault(); + event = { + type: 'mouseup', + button: 0, + pageX: touchX, + pageY: touchY + }; + SDL.DOMButtons[0] = 0; + SDL.events.push(event); + break; case 'mousemove': if (Browser.pointerLock) { // workaround for firefox bug 750111 |