X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_window.pas;h=a40441b492a7d6fee0db0eb2a6c206aafb031e3f;hb=1f93eba25d342649a8eaccdf8f690ff4d8cc0dfc;hp=258b489b1f8f35f335061f207515c48406bab2b0;hpb=6880f8a491a247a34d6afb5508d0a64196a3d26d;p=d2df-sdl.git diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 258b489..a40441b 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,8 +24,6 @@ uses function SDLMain (): Integer; function GetTimer (): Int64; procedure ResetTimer (); -function CreateGLWindow (Title: PChar): Boolean; -procedure KillGLWindow (); procedure PushExitEvent (); function ProcessMessage (): Boolean; procedure ReDrawWindow (); @@ -61,7 +59,7 @@ uses const - ProgressUpdateMSecs = 100; + ProgressUpdateMSecs = 1;//100; var h_Wnd: PSDL_Window = nil; @@ -81,16 +79,13 @@ var {$ENDIF} -procedure KillGLWindow (); +procedure KillGLWindow (preserveGL: Boolean); begin - if (h_Wnd <> nil) then - begin - if assigned(oglDeinitCB) then oglDeinitCB(); - end; + if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end; if (h_Wnd <> nil) then SDL_DestroyWindow(h_Wnd); - if (h_GL <> nil) then SDL_GL_DeleteContext(h_GL); + if (h_GL <> nil) and (not preserveGL) then SDL_GL_DeleteContext(h_GL); h_Wnd := nil; - h_GL := nil; + if (not preserveGL) then h_GL := nil; end; @@ -99,6 +94,7 @@ function g_Window_SetDisplay (preserveGL: Boolean = false): Boolean; var mode, cmode: TSDL_DisplayMode; wFlags: LongWord = 0; + nw, nh: Integer; {$ENDIF} begin {$IF not DEFINED(HEADLESS)} @@ -106,11 +102,9 @@ begin e_WriteLog('Setting display mode...', TMsgType.Notify); - wFlags := SDL_WINDOW_OPENGL or SDL_WINDOW_RESIZABLE; - if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN; - if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED; - - KillGLWindow(); + wFlags := SDL_WINDOW_OPENGL; // or SDL_WINDOW_RESIZABLE; + if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN or SDL_WINDOW_BORDERLESS else wFlags := wFlags or SDL_WINDOW_RESIZABLE; + //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED; if gFullscreen then begin @@ -121,25 +115,44 @@ begin mode.driverdata := nil; if (SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil) then begin + e_WriteLog('SDL: cannot find display mode for '+IntToStr(gScreenWidth), TMsgType.Notify); gScreenWidth := 800; gScreenHeight := 600; end else begin + e_WriteLog('SDL: found display mode for '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight)+': '+IntToStr(cmode.w)+'x'+IntToStr(cmode.h), TMsgType.Notify); gScreenWidth := cmode.w; gScreenHeight := cmode.h; end; end; + KillGLWindow(preserveGL); + h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags); if (h_Wnd = nil) then exit; SDL_GL_MakeCurrent(h_Wnd, h_GL); SDL_ShowCursor(SDL_DISABLE); - if (h_GL <> nil) then + if (gFullscreen) then begin - if assigned(oglInitCB) then oglInitCB(); + nw := 0; + nh := 0; + SDL_GetWindowSize(h_Wnd, @nw, @nh); + if (nw > 128) and (nh > 128) then + begin + e_WriteLog('SDL: fullscreen window got size '+IntToStr(nw)+'x'+IntToStr(nh)+': '+IntToStr(gScreenWidth)+'x'+IntToStr(gScreenHeight), TMsgType.Notify); + gScreenWidth := nw; + gScreenHeight := nh; + end + else + begin + e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify); + end; end; + fuiScrWdt := gScreenWidth; + fuiScrHgt := gScreenHeight; + if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end; {$ENDIF} result := true; @@ -185,6 +198,8 @@ begin gWinSizeX := gScreenWidth; gWinSizeY := gScreenHeight; {$IF not DEFINED(HEADLESS)} + fuiScrWdt := gScreenWidth; + fuiScrHgt := gScreenHeight; e_ResizeWindow(gScreenWidth, gScreenHeight); g_Game_SetupScreenSize(); g_Menu_Reset(); @@ -206,6 +221,7 @@ begin if (gScreenWidth <> w) or (gScreenHeight <> h) then begin result := true; + preserve := true; gScreenWidth := w; gScreenHeight := h; end; @@ -213,6 +229,7 @@ begin if (gFullscreen <> fullscreen) then begin result := true; + preserve := true; gFullscreen := fullscreen; preserve := true; end; @@ -461,15 +478,17 @@ begin if not g_Window_SetDisplay() then begin - KillGLWindow(); + KillGLWindow(false); e_WriteLog('Window creation error (resolution not supported?)', TMsgType.Fatal); exit; end; {$IF not DEFINED(HEADLESS)} - h_Gl := SDL_GL_CreateContext(h_Wnd); - if (h_Gl = nil) then exit; - if assigned(oglInitCB) then oglInitCB(); + h_GL := SDL_GL_CreateContext(h_Wnd); + if (h_GL = nil) then exit; + fuiScrWdt := gScreenWidth; + fuiScrHgt := gScreenHeight; + if (assigned(oglInitCB)) then oglInitCB(); {$ENDIF} e_ResizeWindow(gScreenWidth, gScreenHeight); @@ -577,7 +596,8 @@ begin begin if g_Texture_Get('INTER', ID) then begin - e_DrawSize(ID, 0, 0, 0, false, false, gScreenWidth, gScreenHeight) + e_DrawSize(ID, 0, 0, 0, false, false, gScreenWidth, gScreenHeight); + e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); end else begin @@ -767,9 +787,17 @@ var {$ENDIF} arg: AnsiString; mdfo: TStream; + itmp: Integer; + valres: Word; begin {$IFDEF HEADLESS} e_NoGraphics := true; +{$ELSE} + if (not g_holmes_imfunctional) then + begin + uiInitialize(); + uiContext.font := 'win14'; + end; {$ENDIF} idx := 1; @@ -799,6 +827,7 @@ begin {.$ENDIF} if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end; + if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then begin if (idx <= ParamCount) then @@ -808,6 +837,30 @@ begin end; end; + if (arg = '--holmes-font') or (arg = '-holmes-font') then + begin + if (idx <= ParamCount) then + begin + itmp := 0; + val(ParamStr(idx), itmp, valres); + {$IFNDEF HEADLESS} + if (valres = 0) and (not g_holmes_imfunctional) then + begin + case itmp of + 8: uiContext.font := 'win8'; + 14: uiContext.font := 'win14'; + 16: uiContext.font := 'win16'; + end; + end; + {$ELSE} + // fuck off, fpc! + itmp := itmp; + valres := valres; + {$ENDIF} + Inc(idx); + end; + end; + if (arg = '--game-scale') or (arg = '-game-scale') then begin if (idx <= ParamCount) then @@ -876,7 +929,7 @@ begin while not ProcessMessage() do begin end; Release(); - KillGLWindow(); + KillGLWindow(false); result := 0; end;