aboutsummaryrefslogtreecommitdiff
path: root/src/library_sdl.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r--src/library_sdl.js73
1 files changed, 69 insertions, 4 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 85a04d27..33a33c09 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -28,6 +28,7 @@ var LibrarySDL = {
mouseX: 0,
mouseY: 0,
buttonState: 0,
+ DOMButtons: [0, 0, 0],
DOMEventToSDLEvent: {},
@@ -42,7 +43,7 @@ var LibrarySDL = {
17: 305, // control (right, or left)
18: 308, // alt
- 109: 45, // minus
+ 173: 45, // minus
16: 304, // shift
96: 88 | 1<<10, // keypad 0
@@ -293,7 +294,14 @@ var LibrarySDL = {
pageX: event.pageX,
pageY: event.pageY
};
+ } else if (event.type == 'mousedown') {
+ SDL.DOMButtons[event.button] = 1;
+ } else if (event.type == 'mouseup') {
+ if (!SDL.DOMButtons[event.button]) return false; // ignore extra ups, can happen if we leave the canvas while pressing down, then return,
+ // since we add a mouseup in that case
+ SDL.DOMButtons[event.button] = 0;
}
+
SDL.events.push(event);
if (SDL.events.length >= 10000) {
Module.printErr('SDL event queue full, dropping earliest event');
@@ -305,6 +313,20 @@ var LibrarySDL = {
event.preventDefault();
}
break;
+ case 'mouseout':
+ // Un-press all pressed mouse buttons, because we might miss the release outside of the canvas
+ for (var i = 0; i < 3; i++) {
+ if (SDL.DOMButtons[i]) {
+ SDL.events.push({
+ type: 'mouseup',
+ button: i,
+ pageX: event.pageX,
+ pageY: event.pageY
+ });
+ SDL.DOMButtons[i] = 0;
+ }
+ }
+ break;
}
return false;
},
@@ -382,8 +404,7 @@ var LibrarySDL = {
SDL.mouseY = y;
break;
}
- default:
- throw 'Unhandled SDL event: ' + event.type;
+ default: throw 'Unhandled SDL event: ' + event.type;
}
},
@@ -475,8 +496,39 @@ var LibrarySDL = {
return -1; // -1 == all modes are ok. TODO
},
+ SDL_VideoModeOK: function(width, height, depth, flags) {
+ // SDL_VideoModeOK returns 0 if the requested mode is not supported under any bit depth, or returns the
+ // bits-per-pixel of the closest available mode with the given width, height and requested surface flags
+ return depth; // all modes are ok.
+ },
+
+ SDL_VideoDriverName: function(buf, max_size) {
+ if (SDL.startTime === null) {
+ return 0; //return NULL
+ }
+ //driverName - emscripten_sdl_driver
+ var driverName = [101, 109, 115, 99, 114, 105, 112, 116, 101,
+ 110, 95, 115, 100, 108, 95, 100, 114, 105, 118, 101, 114];
+
+ var index = 0;
+ var size = driverName.length;
+
+ if (max_size <= size) {
+ size = max_size - 1; //-1 cause null-terminator
+ }
+
+ while (index < size) {
+ var value = driverName[index];
+ {{{ makeSetValue('buf', 'index', 'value', 'i8') }}};
+ index++;
+ }
+
+ {{{ makeSetValue('buf', 'index', '0', 'i8') }}};
+ return buf;
+ },
+
SDL_SetVideoMode: function(width, height, depth, flags) {
- ['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll'].forEach(function(event) {
+ ['mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mouseout'].forEach(function(event) {
Module['canvas'].addEventListener(event, SDL.receiveEvent, true);
});
Module['canvas'].width = width;
@@ -484,6 +536,10 @@ var LibrarySDL = {
return SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen');
},
+ SDL_QuitSubSystem: function(flags) {
+ Module.print('SDL_QuitSubSystem called (and ignored)');
+ },
+
SDL_Quit: function() {
for (var i = 0; i < SDL.audios; i++) {
SDL.audios[i].pause();
@@ -597,6 +653,10 @@ var LibrarySDL = {
// We actually do the whole screen in Unlock...
},
+ SDL_UpdateRects: function(surf, numrects, rects) {
+ // We actually do the whole screen in Unlock...
+ },
+
SDL_Delay: function(delay) {
throw 'SDL_Delay called! Potential infinite loop, quitting. ' + new Error().stack;
},
@@ -614,6 +674,11 @@ var LibrarySDL = {
return SDL.keyboardState;
},
+ SDL_GetKeyState__deps: ['SDL_GetKeyboardState'],
+ SDL_GetKeyState: function() {
+ return _SDL_GetKeyboardState();
+ },
+
SDL_GetModState: function() {
// TODO: numlock, capslock, etc.
return (SDL.shiftKey ? 0x0001 & 0x0002 : 0) | // KMOD_LSHIFT & KMOD_RSHIFT