Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,16 @@ var LibrarySDL = {
receiveEvent(event) {
function unpressAllPressedKeys() {
// Un-press all pressed keys: TODO
for (var code in SDL.keyboardMap) {
for (var keyCode of SDL.keyboardMap) {
SDL.events.push({
type: 'keyup',
keyCode: SDL.keyboardMap[code]
keyCode,
});
}
};
switch (event.type) {
case 'touchstart': case 'touchmove': {
case 'touchstart':
case 'touchmove': {
event.preventDefault();

var touches = [];
Expand Down Expand Up @@ -637,7 +638,9 @@ var LibrarySDL = {
};
break;
}
case 'DOMMouseScroll': case 'mousewheel': case 'wheel':
case 'DOMMouseScroll':
case 'mousewheel':
case 'wheel':
// Flip the wheel direction to translate from browser wheel direction
// (+:down) to SDL direction (+:up)
var delta = -Browser.getMouseWheelDelta(event);
Expand Down Expand Up @@ -684,7 +687,11 @@ var LibrarySDL = {
}
}
// fall through
case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup':
case 'keydown':
case 'keyup':
case 'keypress':
case 'mousedown':
case 'mouseup':
// 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,
Expand Down Expand Up @@ -834,11 +841,14 @@ var LibrarySDL = {
event.handled = true;

switch (event.type) {
case 'touchstart': case 'touchend': case 'touchmove': {
case 'touchstart':
case 'touchend':
case 'touchmove': {
Browser.calculateMouseEvent(event);
break;
}
case 'keydown': case 'keyup': {
case 'keydown':
case 'keyup': {
var down = event.type === 'keydown';
var code = SDL.lookupKeyCodeForEvent(event);
#if !SAFE_HEAP
Expand All @@ -863,7 +873,8 @@ var LibrarySDL = {

break;
}
case 'mousedown': case 'mouseup':
case 'mousedown':
case 'mouseup':
if (event.type == 'mousedown') {
// SDL_BUTTON(x) is defined as (1 << ((x)-1)). SDL buttons are 1-3,
// and DOM buttons are 0-2, so this means that the below formula is
Expand Down Expand Up @@ -1478,11 +1489,7 @@ var LibrarySDL = {
SDL.addedResizeListener = true;
Browser.resizeListeners.push((w, h) => {
if (!SDL.settingVideoMode) {
SDL.receiveEvent({
type: 'resize',
w,
h
});
SDL.receiveEvent({ type: 'resize', w, h });
}
});
}
Expand Down
Loading