瀏覽代碼

Adds window focus support to hldx/hlsdl (#697)

This adds winRaise to hlSdl and winSetFocus to hldx. These are plumbed through to their respective window classes as well.
Spitko 3 天之前
父節點
當前提交
cb507761c2
共有 4 個文件被更改,包括 26 次插入0 次删除
  1. 8 0
      libs/directx/dx/Window.hx
  2. 5 0
      libs/directx/window.c
  3. 5 0
      libs/sdl/sdl.c
  4. 8 0
      libs/sdl/sdl/Window.hx

+ 8 - 0
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<Int>, y : hl.Ref<Int> ) {
 	}
 
+	@:hlNative("?directx", "win_set_focus")
+	static function winSetFocus( win: WinPtr ) {
+	}
+
 	static function winGetOpacity( win : WinPtr ) : Float {
 		return 0.0;
 	}

+ 5 - 0
libs/directx/window.c

@@ -713,6 +713,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) };
@@ -930,6 +934,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);

+ 5 - 0
libs/sdl/sdl.c

@@ -693,6 +693,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)
@@ -727,6 +731,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));

+ 8 - 0
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;
 	}