diff --git a/libs/sdl/sdl.c b/libs/sdl/sdl.c index aa8dd50b2..c19d8ec0a 100644 --- a/libs/sdl/sdl.c +++ b/libs/sdl/sdl.c @@ -91,10 +91,10 @@ typedef struct { int keyCode; int scanCode; bool keyRepeat; - int controller; + int reference; int value; - int fingerId; - int joystick; + int __unused; + int window; vbyte* dropFile; } event_data; @@ -161,6 +161,10 @@ HL_PRIM bool HL_NAME(hint_value)( vbyte* name, vbyte* value) { return SDL_SetHint((char*)name, (char*)value) == SDL_TRUE; } +HL_PRIM int HL_NAME(event_poll)( SDL_Event *e ) { + return SDL_PollEvent(e); +} + HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { while (true) { SDL_Event e; @@ -171,6 +175,7 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { break; case SDL_MOUSEMOTION: event->type = MouseMove; + event->window = e.motion.windowID; event->mouseX = e.motion.x; event->mouseY = e.motion.y; event->mouseXRel = e.motion.xrel; @@ -178,12 +183,14 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { break; case SDL_KEYDOWN: event->type = KeyDown; + event->window = e.key.windowID; event->keyCode = e.key.keysym.sym; event->scanCode = e.key.keysym.scancode; event->keyRepeat = e.key.repeat != 0; break; case SDL_KEYUP: event->type = KeyUp; + event->window = e.key.windowID; event->keyCode = e.key.keysym.sym; event->scanCode = e.key.keysym.scancode; break; @@ -191,36 +198,42 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { continue; case SDL_MOUSEBUTTONDOWN: event->type = MouseDown; + event->window = e.button.windowID; event->button = e.button.button; event->mouseX = e.button.x; event->mouseY = e.motion.y; break; case SDL_MOUSEBUTTONUP: event->type = MouseUp; + event->window = e.button.windowID; event->button = e.button.button; event->mouseX = e.button.x; event->mouseY = e.motion.y; break; case SDL_FINGERDOWN: event->type = TouchDown; + event->window = e.tfinger.windowID; event->mouseX = (int)(e.tfinger.x*10000); event->mouseY = (int)(e.tfinger.y*10000); - event->fingerId = (int)e.tfinger.fingerId; + event->reference = (int)e.tfinger.fingerId; break; case SDL_FINGERMOTION: event->type = TouchMove; + event->window = e.tfinger.windowID; event->mouseX = (int)(e.tfinger.x*10000); event->mouseY = (int)(e.tfinger.y*10000); - event->fingerId = (int)e.tfinger.fingerId; + event->reference = (int)e.tfinger.fingerId; break; case SDL_FINGERUP: event->type = TouchUp; + event->window = e.tfinger.windowID; event->mouseX = (int)(e.tfinger.x*10000); event->mouseY = (int)(e.tfinger.y*10000); - event->fingerId = (int)e.tfinger.fingerId; + event->reference = (int)e.tfinger.fingerId; break; case SDL_MOUSEWHEEL: event->type = MouseWheel; + event->window = e.wheel.windowID; event->wheelDelta = e.wheel.y; # if SDL_VERSION_ATLEAST(2,0,4) if (e.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) event->wheelDelta *= -1; @@ -230,6 +243,7 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { break; case SDL_WINDOWEVENT: event->type = WindowState; + event->window = e.window.windowID; switch (e.window.event) { case SDL_WINDOWEVENT_SHOWN: event->state = Show; @@ -280,82 +294,86 @@ HL_PRIM bool HL_NAME(event_loop)( event_data *event ) { continue; case SDL_TEXTINPUT: event->type = TextInput; + event->window = e.text.windowID; event->keyCode = *(int*)e.text.text; event->keyCode &= e.text.text[0] ? e.text.text[1] ? e.text.text[2] ? e.text.text[3] ? 0xFFFFFFFF : 0xFFFFFF : 0xFFFF : 0xFF : 0; break; case SDL_CONTROLLERDEVICEADDED: event->type = GControllerAdded; - event->controller = e.jdevice.which; + event->reference = e.jdevice.which; break; case SDL_CONTROLLERDEVICEREMOVED: event->type = GControllerRemoved; - event->controller = e.jdevice.which; + event->reference = e.jdevice.which; break; case SDL_CONTROLLERBUTTONDOWN: event->type = GControllerDown; - event->controller = e.cbutton.which; + event->reference = e.cbutton.which; event->button = e.cbutton.button; break; case SDL_CONTROLLERBUTTONUP: event->type = GControllerUp; - event->controller = e.cbutton.which; + event->reference = e.cbutton.which; event->button = e.cbutton.button; break; case SDL_CONTROLLERAXISMOTION: event->type = GControllerAxis; - event->controller = e.caxis.which; + event->reference = e.caxis.which; event->button = e.caxis.axis; event->value = e.caxis.value; break; case SDL_JOYAXISMOTION: event->type = JoystickAxisMotion; - event->joystick = e.jaxis.which; + event->reference = e.jaxis.which; event->button = e.jaxis.axis; event->value = e.jaxis.value; break; case SDL_JOYBALLMOTION: event->type = JoystickBallMotion; - event->joystick = e.jball.which; + event->reference = e.jball.which; event->button = e.jball.ball; event->mouseXRel = e.jball.xrel; event->mouseYRel = e.jball.yrel; break; case SDL_JOYHATMOTION: event->type = JoystickHatMotion; - event->joystick = e.jhat.which; + event->reference = e.jhat.which; event->button = e.jhat.hat; event->value = e.jhat.value; break; case SDL_JOYBUTTONDOWN: event->type = JoystickButtonDown; - event->joystick = e.jbutton.which; + event->reference = e.jbutton.which; event->button = e.jbutton.button; break; case SDL_JOYBUTTONUP: event->type = JoystickButtonUp; - event->joystick = e.jbutton.which; + event->reference = e.jbutton.which; event->button = e.jbutton.button; break; case SDL_JOYDEVICEADDED: event->type = JoystickAdded; - event->joystick = e.jdevice.which; + event->reference = e.jdevice.which; break; case SDL_JOYDEVICEREMOVED: event->type = JoystickRemoved; - event->joystick = e.jdevice.which; + event->reference = e.jdevice.which; break; case SDL_DROPBEGIN: event->type = DropStart; + event->window = e.drop.windowID; break; case SDL_DROPFILE: case SDL_DROPTEXT: { vbyte* bytes = hl_copy_bytes(e.drop.file, (int)strlen(e.drop.file) + 1); SDL_free(e.drop.file); event->type = e.type == SDL_DROPFILE ? DropFile : DropText; event->dropFile = bytes; + event->window = e.drop.windowID; break; } case SDL_DROPCOMPLETE: event->type = DropEnd; + event->window = e.drop.windowID; break; default: //printf("Unknown event type 0x%X\\n", e.type); @@ -475,6 +493,7 @@ HL_PRIM const char *HL_NAME(detect_keyboard_layout)() { DEFINE_PRIM(_BOOL, init_once, _NO_ARG); DEFINE_PRIM(_VOID, gl_options, _I32 _I32 _I32 _I32 _I32 _I32); DEFINE_PRIM(_BOOL, event_loop, _DYN ); +DEFINE_PRIM(_I32, event_poll, _STRUCT ); DEFINE_PRIM(_VOID, quit, _NO_ARG); DEFINE_PRIM(_VOID, delay, _I32); DEFINE_PRIM(_I32, get_screen_width, _NO_ARG); @@ -676,6 +695,10 @@ HL_PRIM void HL_NAME(win_render_to)(SDL_Window *win, SDL_GLContext gl) { SDL_GL_MakeCurrent(win, gl); } +HL_PRIM int HL_NAME(win_get_id)(SDL_Window *window) { + return SDL_GetWindowID(window); +} + HL_PRIM void HL_NAME(win_destroy)(SDL_Window *win, SDL_GLContext gl) { SDL_DestroyWindow(win); SDL_GL_DeleteContext(gl); @@ -703,6 +726,7 @@ DEFINE_PRIM(_BOOL, win_set_opacity, TWIN _F64); DEFINE_PRIM(_VOID, win_swap_window, TWIN); DEFINE_PRIM(_VOID, win_render_to, TWIN TGL); DEFINE_PRIM(_VOID, win_destroy, TWIN TGL); +DEFINE_PRIM(_I32, win_get_id, TWIN); // game controller diff --git a/libs/sdl/sdl/Event.hx b/libs/sdl/sdl/Event.hx index 99506e23f..27de43ec3 100644 --- a/libs/sdl/sdl/Event.hx +++ b/libs/sdl/sdl/Event.hx @@ -12,11 +12,20 @@ package sdl; public var keyCode : Int; public var scanCode : Int; public var keyRepeat : Bool; - public var controller : Int; + public var reference : Int; public var value : Int; - public var fingerId : Int; - public var joystick : Int; + public var __unused : Int; + public var windowId : Int; public var dropFile: hl.Bytes; + + // for compile-time backward compatibility + public var controller(get,never) : Int; + public var joystick(get,never) : Int; + public var fingerId(get,never) : Int; + inline function get_controller() return reference; + inline function get_joystick() return reference; + inline function get_fingerId() return reference; + public function new() { } } diff --git a/libs/sdl/sdl/Window.hx b/libs/sdl/sdl/Window.hx index 0a7516245..ed66f4fbb 100644 --- a/libs/sdl/sdl/Window.hx +++ b/libs/sdl/sdl/Window.hx @@ -49,6 +49,7 @@ class Window { var win : WinPtr; var glctx : GLContext; var lastFrame : Float; + public var id(get,never) : Int; public var title(default, set) : String; public var vsync(default, set) : Bool; public var width(get, never) : Int; @@ -256,6 +257,10 @@ class Window { setWindowGrab(win, v); return v; } + + function get_id() { + return winGetId(win); + } /** Set the current window you will render to (in case of multiple windows) @@ -332,6 +337,11 @@ class Window { return 0; } + @:hlNative("?sdl", "win_get_id") + static function winGetId( win : WinPtr ) : Int { + return 0; + } + static function winSetSize( win : WinPtr, width : Int, height : Int ) { }