Browse Source

window style maintained upon return from fullscreen in directx, Hidden flag added

Upon initialization of the DirectX window, the now (somewhat) customizable style is now saved into the window-specific struct, dx_events. This allows the style to be maintained whenever the window is changed to windowed mode.

The Hidden flag was also added to provide an option for the window's visibility upon initialization. More flags could be provided for consistency in comparison to the SDL implementation, but awaiting further discussion.

As a final minor change, the SDL implementation is no longer forced to use the SDL_WINDOW_SHOWN flag in non-mobile builds.
robbor_io 6 years ago
parent
commit
5946e42aa7
4 changed files with 18 additions and 11 deletions
  1. 3 2
      libs/directx/dx/Window.hx
  2. 11 5
      libs/directx/window.c
  3. 1 1
      libs/sdl/sdl.c
  4. 3 3
      libs/sdl/sdl/Window.hx

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

@@ -18,9 +18,10 @@ class Window {
 
 	static var windows : Array<Window> = [];
 
-	public static inline var CW_USEDEFAULT : Int = 0x80000000;
+	public static inline var CW_USEDEFAULT = 0x80000000;
 
-	public static inline var RESIZABLE : Int = 0x000001;
+	public static inline var HIDDEN    = 0x000001;
+	public static inline var RESIZABLE = 0x000002;
 
 	var win : WinPtr;
 	var savedSize : { x : Int, y : Int, width : Int, height : Int };

+ 11 - 5
libs/directx/window.c

@@ -33,7 +33,8 @@ typedef enum {
 } WindowStateChange;
 
 typedef enum {
-	Resizable = 0x000001
+	Hidden    = 0x000001,
+	Resizable = 0x000002
 } WindowFlags;
 
 typedef struct {
@@ -52,6 +53,7 @@ typedef struct {
 
 typedef struct {
 	dx_event events[MAX_EVENTS];
+	DWORD normal_style;
 	int event_count;
 	int next_event;
 	bool is_over;
@@ -243,8 +245,8 @@ HL_PRIM dx_window *HL_NAME(win_create_ex)( int x, int y, int width, int height,
 
 	RECT r;
 	DWORD style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
-	if( ( windowFlags & Resizable ) == 0 ) {
-		style &= ~(WS_MAXIMIZEBOX | WS_THICKFRAME);
+	if( !(windowFlags & Resizable) ) {
+		style &= ~( WS_MAXIMIZEBOX | WS_THICKFRAME );
 	}
 	r.left = r.top = 0;
 	r.right = width;
@@ -253,8 +255,11 @@ HL_PRIM dx_window *HL_NAME(win_create_ex)( int x, int y, int width, int height,
 	dx_events *event_buffer = (dx_events*)malloc(sizeof(dx_events));
 	memset(event_buffer,0, sizeof(dx_events));
 	dx_window *win = CreateWindowEx(WS_EX_APPWINDOW, USTR("HL_WIN"), USTR(""), style, x, y, r.right - r.left, r.bottom - r.top, NULL, NULL, hinst, event_buffer);
+	event_buffer->normal_style = style;
 	SetTimer(win,0,10,NULL);
-	ShowWindow(win, SW_SHOW);
+	if( !(windowFlags & Hidden) ) {
+		ShowWindow(win, SW_SHOW);
+	}
 	SetCursor(LoadCursor(NULL, IDC_ARROW));
 	SetForegroundWindow(win);
 	SetFocus(win);
@@ -356,7 +361,8 @@ HL_PRIM void HL_NAME(win_set_fullscreen)(dx_window *win, bool fs) {
 		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);
+		dx_events *buf = get_events(win);
+		SetWindowLong(win,GWL_STYLE,buf->normal_style);
 		SetWindowPos(win,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
 	}
 }

+ 1 - 1
libs/sdl/sdl.c

@@ -374,7 +374,7 @@ HL_PRIM SDL_Window *HL_NAME(win_create_ex)(int x, int y, int width, int height,
 	SDL_GetDesktopDisplayMode(0, &displayMode);
 	w = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | sdlFlags);
 #else
-	w = SDL_CreateWindow("", x, y, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | sdlFlags);
+	w = SDL_CreateWindow("", x, y, width, height, SDL_WINDOW_OPENGL | sdlFlags);
 #endif
 #	ifdef HL_WIN
 	// force window to show even if the debugger force process windows to be hidden

+ 3 - 3
libs/sdl/sdl/Window.hx

@@ -18,8 +18,8 @@ class Window {
 
 	static var windows : Array<Window> = [];
 
-	public static inline var SDL_WINDOWPOS_UNDEFINED : Int = 0x1FFF0000;
-	public static inline var SDL_WINDOWPOS_CENTERED : Int = 0x2FFF0000;
+	public static inline var SDL_WINDOWPOS_UNDEFINED = 0x1FFF0000;
+	public static inline var SDL_WINDOWPOS_CENTERED  = 0x2FFF0000;
 
 	public static inline var SDL_WINDOW_FULLSCREEN         = 0x00000001;
 	public static inline var SDL_WINDOW_OPENGL             = 0x00000002;
@@ -55,7 +55,7 @@ class Window {
 	public var displayMode(default, set) : DisplayMode;
 	public var visible(default, set) : Bool = true;
 
-	public function new( title : String, width : Int, height : Int, x : Int = SDL_WINDOWPOS_CENTERED, y : Int = SDL_WINDOWPOS_CENTERED, sdlFlags : Int = SDL_WINDOW_RESIZABLE ) {
+	public function new( title : String, width : Int, height : Int, x : Int = SDL_WINDOWPOS_CENTERED, y : Int = SDL_WINDOWPOS_CENTERED, sdlFlags : Int = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ) {
 		while( true ) {
 			win = winCreateEx(x, y, width, height, sdlFlags);
 			if( win == null ) throw "Failed to create window";