Prechádzať zdrojové kódy

fixed fullscreen functionality

Nicolas Cannasse 8 rokov pred
rodič
commit
32ebbb793d
2 zmenil súbory, kde vykonal 46 pridanie a 6 odobranie
  1. 27 2
      libs/directx/dx/Window.hx
  2. 19 4
      libs/directx/window.c

+ 27 - 2
libs/directx/dx/Window.hx

@@ -19,10 +19,12 @@ class Window {
 	static var windows : Array<Window> = [];
 
 	var win : WinPtr;
-	var savedSize : { width : Int, height : Int };
+	var savedSize : { x : Int, y : Int, width : Int, height : Int };
 	public var title(default, set) : String;
 	public var width(get, never) : Int;
 	public var height(get, never) : Int;
+	public var x(get, never) : Int;
+	public var y(get, never) : Int;
 	public var displayMode(default, set) : DisplayMode;
 	public var vsync : Bool;
 
@@ -45,12 +47,13 @@ class Window {
 		var fs = mode != Windowed;
 		if( savedSize == null ) {
 			if( !fs ) return mode;
-			savedSize = { width : width, height : height };
+			savedSize = { x : x, y : y, width : width, height : height };
 			winSetFullscreen(win,true);
 		} else {
 			if( fs ) return mode;
 			winSetFullscreen(win, false);
 			resize(savedSize.width, savedSize.height);
+			setPosition(savedSize.x, savedSize.y);
 			savedSize = null;
 		}
 		return mode;
@@ -60,6 +63,10 @@ class Window {
 		winSetSize(win, width, height);
 	}
 
+	public function setPosition( x : Int, y : Int ) {
+		winSetPosition(win, x, y);
+	}
+
 	function get_width() {
 		var w = 0;
 		winGetSize(win, w, null);
@@ -72,6 +79,18 @@ class Window {
 		return h;
 	}
 
+	function get_x() {
+		var x = 0;
+		winGetPosition(win, x, null);
+		return x;
+	}
+
+	function get_y() {
+		var y = 0;
+		winGetPosition(win, null, y);
+		return y;
+	}
+
 	public function destroy() {
 		winDestroy(win);
 		win = null;
@@ -107,12 +126,18 @@ class Window {
 	static function winSetSize( win : WinPtr, width : Int, height : Int ) {
 	}
 
+	static function winSetPosition( win : WinPtr, x : Int, y : Int ) {
+	}
+
 	static function winResize( win : WinPtr, mode : Int ) {
 	}
 
 	static function winGetSize( win : WinPtr, width : hl.Ref<Int>, height : hl.Ref<Int> ) {
 	}
 
+	static function winGetPosition( win : WinPtr, x : hl.Ref<Int>, y : hl.Ref<Int> ) {
+	}
+
 	static function winDestroy( win : WinPtr ) {
 	}
 

+ 19 - 4
libs/directx/window.c

@@ -190,6 +190,17 @@ HL_PRIM void HL_NAME(win_get_size)(dx_window *win, int *width, int *height) {
 	if( height ) *height = r.bottom;
 }
 
+HL_PRIM void HL_NAME(win_get_position)(dx_window *win, int *x, int *y) {
+	RECT r;
+	GetWindowRect(win,&r);
+	if( x ) *x = r.left;
+	if( y ) *y = r.top;
+}
+
+HL_PRIM void HL_NAME(win_set_position)(dx_window *win, int x, int y) {
+	SetWindowPos(win,NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER);
+}
+
 HL_PRIM void HL_NAME(win_resize)(dx_window *win, int mode) {
 	switch( mode ) {
 	case 0:
@@ -206,13 +217,15 @@ HL_PRIM void HL_NAME(win_resize)(dx_window *win, int mode) {
 	}
 }
 
-
 HL_PRIM void HL_NAME(win_set_fullscreen)(dx_window *win, bool fs) {
 	if( fs ) {
-		SetWindowLong(win,GWL_STYLE,WS_POPUPWINDOW);
-		SetWindowPos(win,NULL,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),SWP_NOOWNERZORDER);
+		MONITORINFO mi = { sizeof(mi) };
+        GetMonitorInfo(MonitorFromWindow(win,MONITOR_DEFAULTTOPRIMARY), &mi);
+		SetWindowLong(win,GWL_STYLE,WS_POPUP | WS_VISIBLE);
+		SetWindowPos(win,NULL,mi.rcMonitor.left,mi.rcMonitor.top,mi.rcMonitor.right - mi.rcMonitor.left,mi.rcMonitor.bottom - mi.rcMonitor.top,SWP_NOOWNERZORDER|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
 	} else {
 		SetWindowLong(win,GWL_STYLE,WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+		SetWindowPos(win,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
 	}
 }
 
@@ -254,7 +267,9 @@ DEFINE_PRIM(_VOID, win_set_fullscreen, TWIN _BOOL);
 DEFINE_PRIM(_VOID, win_resize, TWIN _I32);
 DEFINE_PRIM(_VOID, win_set_title, TWIN _BYTES);
 DEFINE_PRIM(_VOID, win_set_size, TWIN _I32 _I32);
+DEFINE_PRIM(_VOID, win_set_position, TWIN _I32 _I32);
 DEFINE_PRIM(_VOID, win_get_size, TWIN _REF(_I32) _REF(_I32));
+DEFINE_PRIM(_VOID, win_get_position, TWIN _REF(_I32) _REF(_I32));
 DEFINE_PRIM(_VOID, win_destroy, TWIN);
 DEFINE_PRIM(_BOOL, win_get_next_event, TWIN _DYN);
 
@@ -294,7 +309,7 @@ HL_PRIM dx_cursor HL_NAME(create_cursor)( int width, int height, vbyte *data, in
 	if( maskbits == NULL )
 		return NULL;
 	memset(maskbits,0xFF,maskbitslen);
-  
+
 	memset(&ii,0,sizeof(ii));
     ii.fIcon = FALSE;
     ii.xHotspot = (DWORD)hotX;