From: DeaDDooMER Date: Thu, 14 Nov 2019 10:32:19 +0000 (+0300) Subject: save window position X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=5301ecea6db1b7e6e3de991b8a8d420e53ee220f;p=d2df-sdl.git save window position --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 0548792..ca8ee63 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -287,8 +287,6 @@ var gTempDelete: Boolean = False; gLastMap: Boolean = False; gWinSizeX, gWinSizeY: Integer; - gWinFrameX, gWinFrameY, gWinCaption: Integer; - gWinActive: Boolean = True; // by default window is active, lol gResolutionChange: Boolean = False; gRC_Width, gRC_Height: Integer; gRC_FullScreen, gRC_Maximized: Boolean; @@ -5850,7 +5848,6 @@ begin begin g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight])); g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY])); - g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption])); end else if cmd = 'd_sounds' then begin diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 511e062..bfb76fb 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -40,7 +40,7 @@ interface implementation uses - SysUtils, SDL2, Math, + SysUtils, SDL2, Math, ctypes, e_log, e_graphics, e_input, e_sound, {$INCLUDE ../nogl/noGLuses.inc} {$IFDEF ENABLE_HOLMES} @@ -54,7 +54,8 @@ implementation var window: PSDL_Window; context: TSDL_GLContext; - display: Integer; + display, wx, wy: Integer; + wc: Boolean; JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick; JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean; JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer; @@ -108,7 +109,7 @@ implementation end; function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean; - var flags: UInt32; x, y: Integer; + var flags: UInt32; x, y: cint; begin // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB; e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]); @@ -132,8 +133,16 @@ implementation 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; + if wc then + begin + x := SDL_WINDOWPOS_CENTERED; + y := SDL_WINDOWPOS_CENTERED + end + else + begin + x := wx; + y := wy + end; window := SDL_CreateWindow(GetTitle(), x, y, w, h, flags); if window <> nil then begin @@ -143,6 +152,11 @@ implementation {$IFDEF NOGL_INIT} nogl_Init; {$ENDIF} + if (fullscreen = false) and (maximized = false) and (wc = false) then + begin + SDL_GetWindowPosition(window, @x, @y); + wx := x; wy := y + end; gFullScreen := fullscreen; gWinMaximized := maximized; gRC_FullScreen := fullscreen; @@ -152,6 +166,7 @@ implementation end else begin + // SDL_DestroyWindow(window); e_LogWritefln('SDL: unable to create OpenGL context: %s', [SDL_GetError]) end end @@ -163,6 +178,22 @@ implementation else begin SDL_SetWindowSize(window, w, h); + if wc then + begin + x := SDL_WINDOWPOS_CENTERED; + y := SDL_WINDOWPOS_CENTERED + end + else + begin + x := wx; + y := wy + end; + SDL_SetWindowPosition(window, x, y); + if (fullscreen = false) and (maximized = false) and (wc = false) then + begin + SDL_GetWindowPosition(window, @x, @y); + wx := x; wy := y + end; if maximized then SDL_MaximizeWindow(window); if fullScreen then flags := SDL_WINDOW_FULLSCREEN else flags := 0; @@ -382,6 +413,11 @@ implementation SDL_WINDOWEVENT_RESIZED: UpdateSize(ev.data1, ev.data2); SDL_WINDOWEVENT_EXPOSED: sys_Repaint; SDL_WINDOWEVENT_CLOSE: result := true; + SDL_WINDOWEVENT_MOVED: + begin + wx := ev.data1; + wy := ev.data2 + end; SDL_WINDOWEVENT_FOCUS_LOST, SDL_WINDOWEVENT_MINIMIZED: begin e_UnpressAllKeys; @@ -394,9 +430,15 @@ implementation SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_MAXIMIZED, SDL_WINDOWEVENT_RESTORED: begin if ev.event = SDL_WINDOWEVENT_MAXIMIZED then + begin + gWinMaximized := true; gRC_Maximized := true + end else if ev.event = SDL_WINDOWEVENT_RESTORED then - gRC_Maximized := false; + begin + gWinMaximized := false; + gRC_Maximized := false + end; e_MuteChannels(false); {$IFDEF ENABLE_HOLMES} if assigned(winFocusCB) then winFocusCB; @@ -518,4 +560,11 @@ implementation initialization conRegVar('sdl2_display_index', @display, 'use display index as base', ''); + conRegVar('sdl2_window_x', @wx, 'window position x', ''); + conRegVar('sdl2_window_y', @wy, 'window position y', ''); + conRegVar('sdl2_window_center', @wc, 'force window creation at center', ''); + display := 0; + wx := SDL_WINDOWPOS_CENTERED; + wy := SDL_WINDOWPOS_CENTERED; + wc := false end.