From: DeaDDooMER Date: Wed, 13 Nov 2019 12:40:54 +0000 (+0300) Subject: save window options after resizing by user X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=91448a18a3dad8151acb610601f79bf82bca6c91;p=d2df-sdl.git save window options after resizing by user --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 27dcb90..0548792 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -4177,7 +4177,7 @@ end; procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean); begin - sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull); + sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax); end; procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE); diff --git a/src/game/g_main.pas b/src/game/g_main.pas index def9f29..c290df5 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -496,7 +496,7 @@ begin if e_FindResource(ConfigDirs, s) = true then g_Options_Read(s); g_Console_SysInit; - if sys_SetDisplayMode(gScreenWidth, gScreenHeight, gBPP, gFullScreen) = False then + if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then raise Exception.Create('Failed to set videomode on startup.'); e_WriteLog(gLanguage, TMsgType.Notify); diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 078ced2..d523da8 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -174,6 +174,7 @@ begin gRC_Width := gScreenWidth; gRC_Height := gScreenHeight; gRC_FullScreen := gFullScreen; + gRC_Maximized := gWinMaximized; e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight)); g_Console_ResetBinds; end; @@ -191,6 +192,7 @@ begin gRC_Width := gScreenWidth; gRC_Height := gScreenHeight; gRC_FullScreen := gFullScreen; + gRC_Maximized := gWinMaximized; e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight)); g_Console_ResetBinds; end; @@ -648,7 +650,7 @@ begin gRC_Width := Max(1, gRC_Width); gRC_Height := Max(1, gRC_Height); gBPP := Max(1, gBPP); - if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen) = True then + if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then e_LogWriteln('resolution changed') else e_LogWriteln('resolution not changed') diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 0146720..0077089 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -25,7 +25,7 @@ interface (* --- Graphics --- *) function sys_GetDisplayModes (bpp: Integer): SSArray; - function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; procedure sys_EnableVSync (yes: Boolean); procedure sys_Repaint; @@ -76,6 +76,8 @@ implementation gWinSizeY := h; gScreenWidth := w; gScreenHeight := h; + gRC_Width := w; + gRC_Height := h; {$IFDEF ENABLE_HOLMES} fuiScrWdt := w; fuiScrHgt := h; @@ -100,7 +102,7 @@ implementation var flags: Uint32; begin e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]); - result := False; + result := false; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); @@ -120,6 +122,8 @@ implementation nogl_Init; {$ENDIF} SDL_WM_SetCaption(GetTitle(), nil); + gFullScreen := fullscreen; + gRC_FullScreen := fullscreen; UpdateSize(w, h); result := True end @@ -159,7 +163,7 @@ implementation end end; - function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; begin result := InitWindow(w, h, bpp, fullscreen) end; diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 7899e9c..511e062 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -25,7 +25,7 @@ interface (* --- Graphics --- *) function sys_GetDisplayModes (bpp: Integer): SSArray; - function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; procedure sys_EnableVSync (yes: Boolean); procedure sys_Repaint; @@ -79,6 +79,8 @@ implementation gWinSizeY := h; gScreenWidth := w; gScreenHeight := h; + gRC_Width := w; + gRC_Height := h; {$IFDEF ENABLE_HOLMES} fuiScrWdt := w; fuiScrHgt := h; @@ -105,7 +107,7 @@ implementation result := PChar(Format(GameTitle, [info])) end; - function InitWindow (w, h, bpp: Integer; fullScreen: Boolean): Boolean; + function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean; var flags: UInt32; x, y: Integer; begin // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB; @@ -129,6 +131,7 @@ implementation {$ENDIF} flags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE; if fullScreen then flags := flags or SDL_WINDOW_FULLSCREEN; + if maximized then flags := flags or SDL_WINDOW_MAXIMIZED; x := SDL_WINDOWPOS_CENTERED; y := SDL_WINDOWPOS_CENTERED; window := SDL_CreateWindow(GetTitle(), x, y, w, h, flags); @@ -140,6 +143,10 @@ implementation {$IFDEF NOGL_INIT} nogl_Init; {$ENDIF} + gFullScreen := fullscreen; + gWinMaximized := maximized; + gRC_FullScreen := fullscreen; + gRC_Maximized := maximized; UpdateSize(w, h); result := true end @@ -155,9 +162,15 @@ implementation end else begin - if fullScreen then flags := SDL_WINDOW_FULLSCREEN else flags := 0; SDL_SetWindowSize(window, w, h); + if maximized then + SDL_MaximizeWindow(window); + if fullScreen then flags := SDL_WINDOW_FULLSCREEN else flags := 0; SDL_SetWindowFullscreen(window, flags); + gFullScreen := fullscreen; + gWinMaximized := maximized; + gRC_FullScreen := fullscreen; + gRC_Maximized := maximized; UpdateSize(w, h); result := true end @@ -208,9 +221,9 @@ implementation end end; - function sys_SetDisplayMode (w, h, bpp: Integer; fullScreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean; begin - result := InitWindow(w, h, bpp, fullScreen) + result := InitWindow(w, h, bpp, fullScreen, maximized) end; (* --------- Joystick --------- *) @@ -363,6 +376,8 @@ implementation function HandleWindow (var ev: TSDL_WindowEvent): Boolean; begin result := false; + if g_dbg_input then + e_LogWritefln('Window Event: event = %s, data1 = %s, data2 = %s', [ev.event, ev.data1, ev.data2]); case ev.event of SDL_WINDOWEVENT_RESIZED: UpdateSize(ev.data1, ev.data2); SDL_WINDOWEVENT_EXPOSED: sys_Repaint; @@ -378,6 +393,10 @@ implementation end; SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_RESTORED: begin + if ev.event = SDL_WINDOWEVENT_MAXIMIZED then + gRC_Maximized := true + else if ev.event = SDL_WINDOWEVENT_RESTORED then + gRC_Maximized := false; e_MuteChannels(false); {$IFDEF ENABLE_HOLMES} if assigned(winFocusCB) then winFocusCB; diff --git a/src/game/stub/g_system.pas b/src/game/stub/g_system.pas index abae190..c3b4b23 100644 --- a/src/game/stub/g_system.pas +++ b/src/game/stub/g_system.pas @@ -25,7 +25,7 @@ interface (* --- Graphics --- *) function sys_GetDisplayModes (bpp: Integer): SSArray; - function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; procedure sys_EnableVSync (yes: Boolean); procedure sys_Repaint; @@ -68,7 +68,7 @@ implementation result := nil end; - function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen: Boolean): Boolean; + function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; begin result := true end;