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.js41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 4ad7a9a9..96ae6fa2 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -44,6 +44,8 @@ var LibrarySDL = {
ctrlKey: false,
altKey: false,
+ textInput: false,
+
startTime: null,
mouseX: 0,
mouseY: 0,
@@ -173,6 +175,11 @@ var LibrarySDL = {
['i16', 'mod'],
['i32', 'unicode']
]),
+ TextInputEvent: Runtime.generateStructInfo([
+ ['i32', 'type'],
+ ['i32', 'windowID'],
+ ['b256', 'text'],
+ ]),
MouseMotionEvent: Runtime.generateStructInfo([
['i32', 'type'],
['i32', 'windowID'],
@@ -373,7 +380,7 @@ var LibrarySDL = {
}
}
// fall through
- case 'keydown': case 'keyup': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
+ case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') {
var button = (event.type == 'DOMMouseScroll' ? event.detail : -event.wheelDelta) > 0 ? 4 : 3;
var event2 = {
@@ -397,6 +404,10 @@ var LibrarySDL = {
SDL.DOMButtons[event.button] = 0;
}
+ if (event.type == 'keypress' && !SDL.textInput) {
+ break;
+ }
+
SDL.events.push(event);
if (SDL.events.length >= 10000) {
Module.printErr('SDL event queue full, dropping earliest event');
@@ -476,6 +487,15 @@ var LibrarySDL = {
break;
}
+ case 'keypress': {
+ {{{ makeSetValue('ptr', 'SDL.structs.TextInputEvent.type', 'SDL.DOMEventToSDLEvent[event.type]', 'i32') }}}
+ // Not filling in windowID for now
+ var cStr = intArrayFromString(String.fromCharCode(event.charCode));
+ for (var i = 0; i < cStr.length; ++i) {
+ {{{ makeSetValue('ptr', 'SDL.structs.TextInputEvent.text + i', 'cStr[i]', 'i8') }}};
+ }
+ break;
+ }
case 'mousedown': case 'mouseup':
if (event.type == 'mousedown') {
// SDL_BUTTON(x) is defined as (1 << ((x)-1)). SDL buttons are 1-3,
@@ -618,6 +638,7 @@ var LibrarySDL = {
// Initialize this structure carefully for closure
SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */;
SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */;
+ SDL.DOMEventToSDLEvent['keypress'] = 0x303 /* SDL_TEXTINPUT */;
SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */;
SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */;
SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */;
@@ -1079,7 +1100,9 @@ var LibrarySDL = {
}
var surf = SDL.makeSurface(raw.width, raw.height, 0, false, 'load:' + filename);
var surfData = SDL.surfaces[surf];
+ surfData.ctx.globalCompositeOperation = "copy";
surfData.ctx.drawImage(raw, 0, 0, raw.width, raw.height, 0, 0, raw.width, raw.height);
+ surfData.ctx.globalCompositeOperation = "source-over";
// XXX SDL does not specify that loaded images must have available pixel data, in fact
// there are cases where you just want to blit them, so you just need the hardware
// accelerated version. However, code everywhere seems to assume that the pixels
@@ -1173,11 +1196,21 @@ var LibrarySDL = {
SDL_CondWait: function() {},
SDL_DestroyCond: function() {},
- SDL_StartTextInput: function() {}, // TODO
- SDL_StopTextInput: function() {}, // TODO
+ SDL_StartTextInput: function() {
+ SDL.textInput = true;
+ },
+ SDL_StopTextInput: function() {
+ SDL.textInput = false;
+ },
// SDL Mixer
+ Mix_Init: function(flags) {
+ if (!flags) return 0;
+ return 8; /* MIX_INIT_OGG */
+ },
+ Mix_Quit: function(){},
+
Mix_OpenAudio: function(frequency, format, channels, chunksize) {
SDL.allocateChannels(32);
// Just record the values for a later call to Mix_QuickLoad_RAW
@@ -1282,6 +1315,8 @@ var LibrarySDL = {
// the browser has already preloaded the audio file.
var channelInfo = SDL.channels[channel];
channelInfo.audio = audio = audio.cloneNode(true);
+ audio.numChannels = info.audio.numChannels;
+ audio.frequency = info.audio.frequency;
if (SDL.channelFinished) {
audio['onended'] = function() { // TODO: cache these
Runtime.getFuncWrapper(SDL.channelFinished, 'vi')(channel);