From 7ad0293db6adf437a78210a1db58d5ff3b19abc7 Mon Sep 17 00:00:00 2001 From: Spitko Date: Fri, 12 Jul 2024 19:31:43 -0700 Subject: [PATCH] Adds window focus support to hldx/hlsdl This adds winRaise to hlSdl and winSetFocus to hldx. These are plumbed through to their respective window classes as well. --- libs/directx/dx/Window.hx | 8 ++++++++ libs/directx/window.c | 5 +++++ libs/sdl/sdl.c | 5 +++++ libs/sdl/sdl/Window.hx | 8 ++++++++ 4 files changed, 26 insertions(+) diff --git a/libs/directx/dx/Window.hx b/libs/directx/dx/Window.hx index b3e5689ff..54351e42d 100644 --- a/libs/directx/dx/Window.hx +++ b/libs/directx/dx/Window.hx @@ -145,6 +145,10 @@ class Window { winResize(win, 2); } + public function focus() { + winSetFocus(win); + } + public function getNextEvent( e : Event ) : Bool { return winGetNextEvent(win, e); } @@ -322,6 +326,10 @@ class Window { static function winGetPosition( win : WinPtr, x : hl.Ref, y : hl.Ref ) { } + @:hlNative("?directx", "win_set_focus") + static function winSetFocus( win: WinPtr ) { + } + static function winGetOpacity( win : WinPtr ) : Float { return 0.0; } diff --git a/libs/directx/window.c b/libs/directx/window.c index e229864e5..70b5330d8 100644 --- a/libs/directx/window.c +++ b/libs/directx/window.c @@ -699,6 +699,10 @@ HL_PRIM void HL_NAME(win_resize)(dx_window *win, int mode) { } } +HL_PRIM void HL_NAME(win_set_focus)(dx_window* win) { + SetFocus(win); +} + HL_PRIM void HL_NAME(win_set_fullscreen)(dx_window *win, bool fs) { if( fs ) { MONITORINFO mi = { sizeof(mi) }; @@ -916,6 +920,7 @@ DEFINE_PRIM(TWIN, win_create_ex, _I32 _I32 _I32 _I32 _I32); DEFINE_PRIM(TWIN, win_create, _I32 _I32); DEFINE_PRIM(_VOID, win_set_fullscreen, TWIN _BOOL); DEFINE_PRIM(_VOID, win_resize, TWIN _I32); +DEFINE_PRIM(_VOID, win_set_focus, TWIN); DEFINE_PRIM(_VOID, win_set_title, TWIN _BYTES); DEFINE_PRIM(_VOID, win_set_size, TWIN _I32 _I32); DEFINE_PRIM(_VOID, win_set_min_size, TWIN _I32 _I32); diff --git a/libs/sdl/sdl.c b/libs/sdl/sdl.c index 183c49987..596ca2680 100644 --- a/libs/sdl/sdl.c +++ b/libs/sdl/sdl.c @@ -689,6 +689,10 @@ HL_PRIM void HL_NAME(win_resize)(SDL_Window *win, int mode) { } } +HL_PRIM void HL_NAME(win_raise)(SDL_Window *win) { + SDL_RaiseWindow(win); +} + HL_PRIM void HL_NAME(win_swap_window)(SDL_Window *win) { #if defined(HL_IOS) || defined(HL_TVOS) @@ -723,6 +727,7 @@ DEFINE_PRIM(_BOOL, win_set_fullscreen, TWIN _I32); DEFINE_PRIM(_BOOL, win_set_display_mode, TWIN _I32 _I32 _I32); DEFINE_PRIM(_I32, win_display_handle, TWIN); DEFINE_PRIM(_VOID, win_resize, TWIN _I32); +DEFINE_PRIM(_VOID, win_raise, TWIN); DEFINE_PRIM(_VOID, win_set_title, TWIN _BYTES); DEFINE_PRIM(_VOID, win_set_position, TWIN _I32 _I32); DEFINE_PRIM(_VOID, win_get_position, TWIN _REF(_I32) _REF(_I32)); diff --git a/libs/sdl/sdl/Window.hx b/libs/sdl/sdl/Window.hx index d5dd1a133..aac77be21 100644 --- a/libs/sdl/sdl/Window.hx +++ b/libs/sdl/sdl/Window.hx @@ -180,6 +180,10 @@ class Window { setPosition(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); } + public function raise() { + winRaise( win ); + } + public function warpMouse( x : Int, y : Int ) { warpMouseInWindow(win, x, y); } @@ -369,6 +373,10 @@ class Window { return 0.0; } + @:hlNative("?sdl", "win_raise") + static function winRaise( win : WinPtr ) { + } + static function winSetOpacity( win : WinPtr, opacity : Float ) : Bool { return false; }