From 57eea56cadbee2ab1e505f50144d1e1671deaa30 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 31 Jan 2022 20:15:35 +0300 Subject: [PATCH] render: draw menu via render --- src/game/Doom2DF.lpr | 2 +- src/game/g_gui.pas | 701 +++++------------------------------ src/game/g_menu.pas | 93 ++--- src/game/opengl/r_game.pas | 6 +- src/game/opengl/r_gui.pas | 607 ++++++++++++++++++++++++++++++ src/game/opengl/r_render.pas | 9 + 6 files changed, 738 insertions(+), 680 deletions(-) create mode 100644 src/game/opengl/r_gui.pas diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 63c895f..0a361e6 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -187,6 +187,7 @@ uses {$IFDEF ENABLE_MENU} g_gui in 'g_gui.pas', g_menu in 'g_menu.pas', + r_gui in 'opengl/r_gui.pas', {$ENDIF} {$ENDIF} @@ -992,7 +993,6 @@ end; g_Game_Init; {$IFDEF ENABLE_MENU} g_Menu_Init; - g_GUI_Init; {$ENDIF} g_Game_Process_Params; // TODO reload GAME textures diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 26a9ee5..832e737 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -19,7 +19,7 @@ interface uses {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} - g_base, r_graphics, e_input, e_log, g_playermodel, g_basic, MAPDEF, utils; + g_base, e_input, e_log, g_playermodel, g_basic, MAPDEF, utils; const MAINMENU_HEADER_COLOR: TRGB = (R:255; G:255; B:255); @@ -57,15 +57,6 @@ const KEYREAD_TIMEOUT = 24; MAPPREVIEW_WIDTH = 8; MAPPREVIEW_HEIGHT = 8; - BOX1 = 'BOX1'; - BOX2 = 'BOX2'; - BOX3 = 'BOX3'; - BOX4 = 'BOX4'; - BOX5 = 'BOX5'; - BOX6 = 'BOX6'; - BOX7 = 'BOX7'; - BOX8 = 'BOX8'; - BOX9 = 'BOX9'; BSCROLL_UPA = 'BSCROLL_UP_A'; BSCROLL_UPU = 'BSCROLL_UP_U'; BSCROLL_DOWNA = 'BSCROLL_DOWN_A'; @@ -88,7 +79,7 @@ type TFont = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private - ID: DWORD; + FID: DWORD; FScale: Single; FFontType: TFontType; public @@ -97,6 +88,7 @@ type procedure Draw(X, Y: Integer; Text: string; R, G, B: Byte); procedure GetTextSize(Text: string; var w, h: Word); property Scale: Single read FScale write FScale; + property ID: DWORD read FID; end; TGUIControl = class; @@ -123,7 +115,6 @@ type constructor Create; procedure OnMessage(var Msg: TMessage); virtual; procedure Update; virtual; - procedure Draw; virtual; function GetWidth(): Integer; virtual; function GetHeight(): Integer; virtual; function WantActivationKey (key: LongInt): Boolean; virtual; @@ -133,6 +124,9 @@ type property Name: string read FName write FName; property UserData: Pointer read FUserData write FUserData; property RightAlign: Boolean read FRightAlign write FRightAlign; // for menu + property CMaxWidth: Integer read FMaxWidth; + + property Window: TGUIWindow read FWindow; end; TGUIWindow = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} @@ -155,7 +149,6 @@ type function AddChild(Child: TGUIControl): TGUIControl; procedure OnMessage(var Msg: TMessage); procedure Update; - procedure Draw; procedure SetActive(Control: TGUIControl); function GetControl(Name: string): TGUIControl; property OnKeyDown: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown; @@ -167,6 +160,8 @@ type property BackTexture: string read FBackTexture write FBackTexture; property MainWindow: Boolean read FMainWindow write FMainWindow; property UserData: Pointer read FUserData write FUserData; + + property ActiveControl: TGUIControl read FActiveControl; end; TGUITextButton = class(TGUIControl) @@ -183,9 +178,6 @@ type destructor Destroy(); override; procedure OnMessage(var Msg: TMessage); override; procedure Update(); override; - procedure Draw(); override; - function GetWidth(): Integer; override; - function GetHeight(): Integer; override; procedure Click(Silent: Boolean = False); property Caption: string read FText write FText; property Color: TRGB read FColor write FColor; @@ -203,9 +195,6 @@ type public constructor Create(Text: string; FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; - function GetWidth: Integer; override; - function GetHeight: Integer; override; property OnClick: TOnClickEvent read FOnClickEvent write FOnClickEvent; property FixedLength: Word read FFixedLen write FFixedLen; property Text: string read FText write FText; @@ -217,27 +206,23 @@ type private FValue: Integer; FMax: Word; - FLeftID: DWORD; - FRightID: DWORD; - FMiddleID: DWORD; - FMarkerID: DWORD; FOnChangeEvent: TOnChangeEvent; procedure FSetValue(a: Integer); public constructor Create(); procedure OnMessage(var Msg: TMessage); override; procedure Update; override; - procedure Draw; override; - function GetWidth(): Integer; override; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; property Max: Word read FMax write FMax; property Value: Integer read FValue write FSetValue; - end; + end; + + TGUIItemsList = array of string; TGUISwitch = class(TGUIControl) private FFont: TFont; - FItems: array of string; + FItems: TGUIItemsList; FIndex: Integer; FColor: TRGB; FOnChangeEvent: TOnChangeEvent; @@ -246,13 +231,12 @@ type procedure OnMessage(var Msg: TMessage); override; procedure AddItem(Item: string); procedure Update; override; - procedure Draw; override; - function GetWidth(): Integer; override; function GetText: string; property ItemIndex: Integer read FIndex write FIndex; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; + property Items: TGUIItemsList read FItems; end; TGUIEdit = class(TGUIControl) @@ -264,9 +248,6 @@ type FText: string; FColor: TRGB; FOnlyDigits: Boolean; - FLeftID: DWORD; - FRightID: DWORD; - FMiddleID: DWORD; FOnChangeEvent: TOnChangeEvent; FOnEnterEvent: TOnEnterEvent; FInvalid: Boolean; @@ -275,8 +256,6 @@ type constructor Create(FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; procedure Update; override; - procedure Draw; override; - function GetWidth(): Integer; override; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; property OnEnter: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent; property Width: Word read FWidth write FWidth; @@ -286,6 +265,8 @@ type property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; property Invalid: Boolean read FInvalid write FInvalid; + + property CaretPos: Integer read FCaretPos; end; TGUIKeyRead = class(TGUIControl) @@ -297,12 +278,12 @@ type public constructor Create(FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; - function GetWidth(): Integer; override; function WantActivationKey (key: LongInt): Boolean; override; property Key: Word read FKey write FKey; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + + property IsQuery: Boolean read FIsQuery; end; // can hold two keys @@ -318,13 +299,15 @@ type public constructor Create(FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; - function GetWidth(): Integer; override; function WantActivationKey (key: LongInt): Boolean; override; property Key0: Word read FKey0 write FKey0; property Key1: Word read FKey1 write FKey1; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + + property IsQuery: Boolean read FIsQuery; + property MaxKeyNameWdt: Integer read FMaxKeyNameWdt; + property KeyIdx: Integer read FKeyIdx; end; TGUIModelView = class(TGUIControl) @@ -340,7 +323,6 @@ type procedure NextAnim(); procedure NextWeapon(); procedure Update; override; - procedure Draw; override; property Model: TPlayerModel read FModel; end; @@ -349,9 +331,11 @@ type PanelType: Word; end; + TPreviewPanelArray = array of TPreviewPanel; + TGUIMapPreview = class(TGUIControl) private - FMapData: array of TPreviewPanel; + FMapData: TPreviewPanelArray; FMapSize: TDFPoint; FScale: Single; public @@ -361,8 +345,11 @@ type procedure SetMap(Res: string); procedure ClearMap(); procedure Update(); override; - procedure Draw(); override; function GetScaleStr: String; + + property MapData: TPreviewPanelArray read FMapData; + property MapSize: TDFPoint read FMapSize; + property Scale: Single read FScale; end; TGUIImage = class(TGUIControl) @@ -376,8 +363,9 @@ type procedure SetImage(Res: string); procedure ClearImage(); procedure Update(); override; - procedure Draw(); override; + property DefaultRes: string read FDefaultRes write FDefaultRes; + property ImageRes: string read FImageRes; end; TGUIListBox = class(TGUIControl) @@ -401,13 +389,10 @@ type public constructor Create(FontID: DWORD; Width, Height: Word); procedure OnMessage(var Msg: TMessage); override; - procedure Draw(); override; procedure AddItem(Item: String); function ItemExists (item: String): Boolean; procedure SelectItem(Item: String); procedure Clear(); - function GetWidth(): Integer; override; - function GetHeight(): Integer; override; function SelectedItem(): String; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; @@ -419,6 +404,10 @@ type property ActiveColor: TRGB read FActiveColor write FActiveColor; property UnActiveColor: TRGB read FUnActiveColor write FUnActiveColor; property Font: TFont read FFont write FFont; + + property Width: Word read FWidth; + property Height: Word read FHeight; + property StartLine: Integer read FStartLine; end; TGUIFileListBox = class(TGUIListBox) @@ -453,29 +442,30 @@ type public constructor Create(FontID: DWORD; Width, Height: Word); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; procedure Clear; - function GetWidth(): Integer; override; - function GetHeight(): Integer; override; procedure SetText(Text: string); property DrawBack: Boolean read FDrawBack write FDrawBack; property DrawScrollBar: Boolean read FDrawScroll write FDrawScroll; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + + property Width: Word read FWidth; + property Height: Word read FHeight; + property StartLine: Integer read FStartLine; + property Lines: SSArray read FLines; end; + TGUITextButtonList = array of TGUITextButton; + TGUIMainMenu = class(TGUIControl) private - FButtons: array of TGUITextButton; + FButtons: TGUITextButtonList; FHeader: TGUILabel; - FLogo: DWord; FIndex: Integer; FFontID: DWORD; - FCounter: Byte; - FMarkerID1: DWORD; - FMarkerID2: DWORD; + FCounter: Byte; // !!! update it within render public - constructor Create(FontID: DWORD; Logo, Header: string); + constructor Create(FontID: DWORD; Header: string); destructor Destroy; override; procedure OnMessage(var Msg: TMessage); override; function AddButton(fProc: Pointer; Caption: string; ShowWindow: string = ''): TGUITextButton; @@ -483,7 +473,11 @@ type procedure EnableButton(aName: string; e: Boolean); procedure AddSpace(); procedure Update; override; - procedure Draw; override; + + property Header: TGUILabel read FHeader; + property Buttons: TGUITextButtonList read FButtons; + property Index: Integer read FIndex; + property Counter: Byte read FCounter; end; TControlType = class of TGUIControl; @@ -494,10 +488,11 @@ type ControlType: TControlType; Control: TGUIControl; end; + TMenuItemList = array of TMenuItem; TGUIMenu = class(TGUIControl) private - FItems: array of TMenuItem; + FItems: TMenuItemList; FHeader: TGUILabel; FIndex: Integer; FFontID: DWORD; @@ -526,12 +521,17 @@ type procedure ReAlign(); function GetControl(aName: string): TGUIControl; function GetControlsText(aName: string): TGUILabel; - procedure Draw; override; procedure Update; override; procedure UpdateIndex(); property Align: Boolean read FAlign write FAlign; property Left: Integer read FLeft write FLeft; property YesNo: Boolean read FYesNo write FYesNo; + + property Header: TGUILabel read FHeader; + property Counter: Byte read FCounter; + property Index: Integer read FIndex; + property Items: TMenuItemList read FItems; + property FontID: DWORD read FFontID; end; var @@ -539,7 +539,6 @@ var g_ActiveWindow: TGUIWindow = nil; g_GUIGrabInput: Boolean = False; -procedure g_GUI_Init(); function g_GUI_AddWindow(Window: TGUIWindow): TGUIWindow; function g_GUI_GetWindow(Name: string): TGUIWindow; procedure g_GUI_ShowWindow(Name: string); @@ -555,13 +554,15 @@ uses {$IFDEF ENABLE_TOUCH} g_system, {$ENDIF} - g_sound, SysUtils, e_res, r_textures, - g_game, Math, StrUtils, g_player, g_options, r_playermodel, + {$IFDEF ENABLE_RENDER} + r_gui, r_textures, r_graphics, + {$ENDIF} + g_sound, SysUtils, e_res, + g_game, Math, StrUtils, g_player, g_options, g_map, g_weapons, xdynrec, wadreader; var - Box: Array [0..8] of DWORD; Saved_Windows: SSArray; function GetLines (Text: string; FontID: DWORD; MaxWidth: Word): SSArray; @@ -618,19 +619,6 @@ begin end; end; -procedure g_GUI_Init(); -begin - g_Texture_Get(BOX1, Box[0]); - g_Texture_Get(BOX2, Box[1]); - g_Texture_Get(BOX3, Box[2]); - g_Texture_Get(BOX4, Box[3]); - g_Texture_Get(BOX5, Box[4]); - g_Texture_Get(BOX6, Box[5]); - g_Texture_Get(BOX7, Box[6]); - g_Texture_Get(BOX8, Box[7]); - g_Texture_Get(BOX9, Box[8]); -end; - function g_GUI_Destroy(): Boolean; var i: Integer; @@ -790,41 +778,6 @@ begin end; end; -procedure DrawBox(X, Y: Integer; Width, Height: Word); -begin - e_Draw(Box[0], X, Y, 0, False, False); - e_DrawFill(Box[1], X+4, Y, Width*4, 1, 0, False, False); - e_Draw(Box[2], X+4+Width*16, Y, 0, False, False); - e_DrawFill(Box[3], X, Y+4, 1, Height*4, 0, False, False); - e_DrawFill(Box[4], X+4, Y+4, Width, Height, 0, False, False); - e_DrawFill(Box[5], X+4+Width*16, Y+4, 1, Height*4, 0, False, False); - e_Draw(Box[6], X, Y+4+Height*16, 0, False, False); - e_DrawFill(Box[7], X+4, Y+4+Height*16, Width*4, 1, 0, False, False); - e_Draw(Box[8], X+4+Width*16, Y+4+Height*16, 0, False, False); -end; - -procedure DrawScroll(X, Y: Integer; Height: Word; Up, Down: Boolean); -var - ID: DWORD; -begin - if Height < 3 then Exit; - - if Up then - g_Texture_Get(BSCROLL_UPA, ID) - else - g_Texture_Get(BSCROLL_UPU, ID); - e_Draw(ID, X, Y, 0, False, False); - - if Down then - g_Texture_Get(BSCROLL_DOWNA, ID) - else - g_Texture_Get(BSCROLL_DOWNU, ID); - e_Draw(ID, X, Y+(Height-1)*16, 0, False, False); - - g_Texture_Get(BSCROLL_MIDDLE, ID); - e_DrawFill(ID, X, Y+16, 1, Height-2, 0, False, False); -end; - { TGUIWindow } constructor TGUIWindow.Create(Name: string); @@ -867,34 +820,6 @@ begin if Childs[i] <> nil then Childs[i].Update; end; -procedure TGUIWindow.Draw; -var - i: Integer; - ID: DWORD; - tw, th: Word; -begin - if FBackTexture <> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground() - if g_Texture_Get(FBackTexture, ID) then - begin - e_Clear(0, 0, 0); - e_GetTextureSize(ID, @tw, @th); - if tw = th then - tw := round(tw * 1.333 * (gScreenHeight / th)) - else - tw := trunc(tw * (gScreenHeight / th)); - e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight); - end - else - e_Clear(0.5, 0.5, 0.5); - - // small hack here - if FName = 'AuthorsMenu' then - e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); - - for i := 0 to High(Childs) do - if Childs[i] <> nil then Childs[i].Draw; -end; - procedure TGUIWindow.OnMessage(var Msg: TMessage); begin if FActiveControl <> nil then FActiveControl.OnMessage(Msg); @@ -958,24 +883,34 @@ procedure TGUIControl.Update(); begin end; -procedure TGUIControl.Draw(); -begin -end; - function TGUIControl.WantActivationKey (key: LongInt): Boolean; begin result := false; end; -function TGUIControl.GetWidth(): Integer; -begin - result := 0; -end; + function TGUIControl.GetWidth (): Integer; + {$IFDEF ENABLE_RENDER} + var h: Integer; + {$ENDIF} + begin + {$IFDEF ENABLE_RENDER} + r_GUI_GetSize(Self, Result, h); + {$ELSE} + Result := 0; + {$ENDIF} + end; -function TGUIControl.GetHeight(): Integer; -begin - result := 0; -end; + function TGUIControl.GetHeight (): Integer; + {$IFDEF ENABLE_RENDER} + var w: Integer; + {$ENDIF} + begin + {$IFDEF ENABLE_RENDER} + r_GUI_GetSize(Self, w, Result); + {$ELSE} + Result := 0; + {$ENDIF} + end; { TGUITextButton } @@ -1007,27 +942,6 @@ begin inherited; end; -procedure TGUITextButton.Draw; -begin - FFont.Draw(FX, FY, FText, FColor.R, FColor.G, FColor.B) -end; - -function TGUITextButton.GetHeight: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := h; -end; - -function TGUITextButton.GetWidth: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := w; -end; - procedure TGUITextButton.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -1051,8 +965,7 @@ end; constructor TFont.Create(FontID: DWORD; FontType: TFontType); begin - ID := FontID; - + FID := FontID; FScale := 1; FFontType := FontType; end; @@ -1091,6 +1004,7 @@ function TGUIMainMenu.AddButton(fProc: Pointer; Caption: string; ShowWindow: str var a, _x: Integer; h, hh: Word; + lw: Word = 0; lh: Word = 0; begin FIndex := 0; @@ -1111,10 +1025,11 @@ begin if FButtons[a] <> nil then _x := Min(_x, (gScreenWidth div 2)-(FButtons[a].GetWidth div 2)); - if FLogo <> 0 then e_GetTextureSize(FLogo, nil, @lh); + if FHeader = nil then + r_GUI_GetLogoSize(lw, lh); hh := FButtons[High(FButtons)].GetHeight; - if FLogo <> 0 then h := lh + hh * (1 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1) + if FHeader = nil then h := lh + hh * (1 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1) else h := hh * (2 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1); h := (gScreenHeight div 2) - (h div 2); @@ -1124,7 +1039,7 @@ begin FY := h; end; - if FLogo <> 0 then Inc(h, lh) + if FHeader = nil then Inc(h, lh) else Inc(h, hh*2); for a := 0 to High(FButtons) do @@ -1148,7 +1063,7 @@ begin FButtons[High(FButtons)] := nil; end; -constructor TGUIMainMenu.Create(FontID: DWORD; Logo, Header: string); +constructor TGUIMainMenu.Create(FontID: DWORD; Header: string); begin inherited Create(); @@ -1156,10 +1071,7 @@ begin FFontID := FontID; FCounter := MAINMENU_MARKERDELAY; - g_Texture_Get(MAINMENU_MARKER1, FMarkerID1); - g_Texture_Get(MAINMENU_MARKER2, FMarkerID2); - - if not g_Texture_Get(Logo, FLogo) then + if Header <> '' then begin FHeader := TGUILabel.Create(Header, FFontID); with FHeader do @@ -1184,30 +1096,6 @@ begin inherited; end; -procedure TGUIMainMenu.Draw; -var - a: Integer; - w, h: Word; - -begin - inherited; - - if FHeader <> nil then FHeader.Draw - else begin - e_GetTextureSize(FLogo, @w, @h); - e_Draw(FLogo, ((gScreenWidth div 2) - (w div 2)), FButtons[0].FY - FButtons[0].GetHeight - h, 0, True, False); - end; - - if FButtons <> nil then - begin - for a := 0 to High(FButtons) do - if FButtons[a] <> nil then FButtons[a].Draw; - - if FIndex <> -1 then - e_Draw(FMarkerID1, FButtons[FIndex].FX-48, FButtons[FIndex].FY, 0, True, False); - end; -end; - procedure TGUIMainMenu.EnableButton(aName: string; e: Boolean); var a: Integer; @@ -1288,19 +1176,9 @@ begin end; procedure TGUIMainMenu.Update; -var - t: DWORD; begin inherited; - - if FCounter = 0 then - begin - t := FMarkerID1; - FMarkerID1 := FMarkerID2; - FMarkerID2 := t; - - FCounter := MAINMENU_MARKERDELAY; - end else Dec(FCounter); + FCounter := (FCounter + 1) MOD (2 * MAINMENU_MARKERDELAY) end; { TGUILabel } @@ -1316,40 +1194,6 @@ begin FOnClickEvent := nil; end; -procedure TGUILabel.Draw; -var - w, h: Word; -begin - if RightAlign then - begin - FFont.GetTextSize(FText, w, h); - FFont.Draw(FX+FMaxWidth-w, FY, FText, FColor.R, FColor.G, FColor.B); - end - else - begin - FFont.Draw(FX, FY, FText, FColor.R, FColor.G, FColor.B); - end; -end; - -function TGUILabel.GetHeight: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := h; -end; - -function TGUILabel.GetWidth: Integer; -var - w, h: Word; -begin - if FFixedLen = 0 then - FFont.GetTextSize(FText, w, h) - else - w := e_CharFont_GetMaxWidth(FFont.ID)*FFixedLen; - Result := w; -end; - procedure TGUILabel.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -1494,48 +1338,6 @@ begin inherited; end; -procedure TGUIMenu.Draw; -var - a, locx, locy: Integer; -begin - inherited; - - if FHeader <> nil then FHeader.Draw; - - if FItems <> nil then - for a := 0 to High(FItems) do - begin - if FItems[a].Text <> nil then FItems[a].Text.Draw; - if FItems[a].Control <> nil then FItems[a].Control.Draw; - end; - - if (FIndex <> -1) and (FCounter > MENU_MARKERDELAY div 2) then - begin - locx := 0; - locy := 0; - - if FItems[FIndex].Text <> nil then - begin - locx := FItems[FIndex].Text.FX; - locy := FItems[FIndex].Text.FY; - //HACK! - if FItems[FIndex].Text.RightAlign then - begin - locx := locx+FItems[FIndex].Text.FMaxWidth-FItems[FIndex].Text.GetWidth; - end; - end - else if FItems[FIndex].Control <> nil then - begin - locx := FItems[FIndex].Control.FX; - locy := FItems[FIndex].Control.FY; - end; - - locx := locx-e_CharFont_GetMaxWidth(FFontID); - - e_CharFont_PrintEx(FFontID, locx, locy, #16, _RGB(255, 0, 0)); - end; -end; - function TGUIMenu.GetControl(aName: String): TGUIControl; var a: Integer; @@ -2148,26 +1950,6 @@ begin FMax := 0; FOnChangeEvent := nil; - - g_Texture_Get(SCROLL_LEFT, FLeftID); - g_Texture_Get(SCROLL_RIGHT, FRightID); - g_Texture_Get(SCROLL_MIDDLE, FMiddleID); - g_Texture_Get(SCROLL_MARKER, FMarkerID); -end; - -procedure TGUIScroll.Draw; -var - a: Integer; -begin - inherited; - - e_Draw(FLeftID, FX, FY, 0, True, False); - e_Draw(FRightID, FX+8+(FMax+1)*8, FY, 0, True, False); - - for a := 0 to FMax do - e_Draw(FMiddleID, FX+8+a*8, FY, 0, True, False); - - e_Draw(FMarkerID, FX+8+FValue*8, FY, 0, True, False); end; procedure TGUIScroll.FSetValue(a: Integer); @@ -2175,11 +1957,6 @@ begin if a > FMax then FValue := FMax else FValue := a; end; -function TGUIScroll.GetWidth: Integer; -begin - Result := 16+(FMax+1)*8; -end; - procedure TGUIScroll.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -2234,35 +2011,12 @@ begin FFont := TFont.Create(FontID, TFontType.Character); end; -procedure TGUISwitch.Draw; -begin - inherited; - - FFont.Draw(FX, FY, FItems[FIndex], FColor.R, FColor.G, FColor.B); -end; - function TGUISwitch.GetText: string; begin if FIndex <> -1 then Result := FItems[FIndex] else Result := ''; end; -function TGUISwitch.GetWidth: Integer; -var - a: Integer; - w, h: Word; -begin - Result := 0; - - if FItems = nil then Exit; - - for a := 0 to High(FItems) do - begin - FFont.GetTextSize(FItems[a], w, h); - if w > Result then Result := w; - end; -end; - procedure TGUISwitch.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -2323,43 +2077,6 @@ begin FMaxLength := 0; FWidth := 0; FInvalid := false; - - g_Texture_Get(EDIT_LEFT, FLeftID); - g_Texture_Get(EDIT_RIGHT, FRightID); - g_Texture_Get(EDIT_MIDDLE, FMiddleID); -end; - -procedure TGUIEdit.Draw; -var - c, w, h: Word; - r, g, b: Byte; -begin - inherited; - - e_Draw(FLeftID, FX, FY, 0, True, False); - e_Draw(FRightID, FX+8+FWidth*16, FY, 0, True, False); - - for c := 0 to FWidth-1 do - e_Draw(FMiddleID, FX+8+c*16, FY, 0, True, False); - - r := FColor.R; - g := FColor.G; - b := FColor.B; - if FInvalid and (FWindow.FActiveControl <> self) then begin r := 128; g := 128; b := 128; end; - FFont.Draw(FX+8, FY, FText, r, g, b); - - if (FWindow.FActiveControl = self) then - begin - FFont.GetTextSize(Copy(FText, 1, FCaretPos), w, h); - h := e_CharFont_GetMaxHeight(FFont.ID); - e_DrawLine(2, FX+8+w, FY+h-3, FX+8+w+EDIT_CURSORLEN, FY+h-3, - EDIT_CURSORCOLOR.R, EDIT_CURSORCOLOR.G, EDIT_CURSORCOLOR.B); - end; -end; - -function TGUIEdit.GetWidth: Integer; -begin - Result := 16+FWidth*16; end; procedure TGUIEdit.OnMessage(var Msg: TMessage); @@ -2449,34 +2166,6 @@ begin FFont := TFont.Create(FontID, TFontType.Character); end; -procedure TGUIKeyRead.Draw; -begin - inherited; - - FFont.Draw(FX, FY, IfThen(FIsQuery, KEYREAD_QUERY, IfThen(FKey <> 0, e_KeyNames[FKey], KEYREAD_CLEAR)), - FColor.R, FColor.G, FColor.B); -end; - -function TGUIKeyRead.GetWidth: Integer; -var - a: Byte; - w, h: Word; -begin - Result := 0; - - for a := 0 to 255 do - begin - FFont.GetTextSize(e_KeyNames[a], w, h); - Result := Max(Result, w); - end; - - FFont.GetTextSize(KEYREAD_QUERY, w, h); - if w > Result then Result := w; - - FFont.GetTextSize(KEYREAD_CLEAR, w, h); - if w > Result then Result := w; -end; - function TGUIKeyRead.WantActivationKey (key: LongInt): Boolean; begin result := @@ -2594,40 +2283,6 @@ begin if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w; end; -procedure TGUIKeyRead2.Draw; - procedure drawText (idx: Integer); - var - x, y: Integer; - r, g, b: Byte; - kk: DWORD; - begin - if idx = 0 then kk := FKey0 else kk := FKey1; - y := FY; - if idx = 0 then x := FX+8 else x := FX+8+FMaxKeyNameWdt+16; - r := 255; - g := 0; - b := 0; - if FKeyIdx = idx then begin r := 255; g := 255; b := 255; end; - if FIsQuery and (FKeyIdx = idx) then - FFont.Draw(x, y, KEYREAD_QUERY, r, g, b) - else - FFont.Draw(x, y, IfThen(kk <> 0, e_KeyNames[kk], KEYREAD_CLEAR), r, g, b); - end; - -begin - inherited; - - //FFont.Draw(FX+8, FY, IfThen(FIsQuery and (FKeyIdx = 0), KEYREAD_QUERY, IfThen(FKey0 <> 0, e_KeyNames[FKey0], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B); - //FFont.Draw(FX+8+FMaxKeyNameWdt+16, FY, IfThen(FIsQuery and (FKeyIdx = 1), KEYREAD_QUERY, IfThen(FKey1 <> 0, e_KeyNames[FKey1], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B); - drawText(0); - drawText(1); -end; - -function TGUIKeyRead2.GetWidth: Integer; -begin - Result := FMaxKeyNameWdt*2+8+8+16; -end; - function TGUIKeyRead2.WantActivationKey (key: LongInt): Boolean; begin case key of @@ -2748,16 +2403,6 @@ begin inherited; end; -procedure TGUIModelView.Draw; -begin - inherited; - - DrawBox(FX, FY, 4, 4); - - if FModel <> nil then - r_PlayerModel_Draw(FModel, FX+4, FY+4); -end; - procedure TGUIModelView.NextAnim(); begin if FModel = nil then @@ -2822,84 +2467,6 @@ begin inherited; end; -procedure TGUIMapPreview.Draw(); -var - a: Integer; - r, g, b: Byte; -begin - inherited; - - DrawBox(FX, FY, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT); - - if (FMapSize.X <= 0) or (FMapSize.Y <= 0) then - Exit; - - e_DrawFillQuad(FX+4, FY+4, - FX+4 + Trunc(FMapSize.X / FScale) - 1, - FY+4 + Trunc(FMapSize.Y / FScale) - 1, - 32, 32, 32, 0); - - if FMapData <> nil then - for a := 0 to High(FMapData) do - with FMapData[a] do - begin - if X1 > MAPPREVIEW_WIDTH*16 then Continue; - if Y1 > MAPPREVIEW_HEIGHT*16 then Continue; - - if X2 < 0 then Continue; - if Y2 < 0 then Continue; - - if X2 > MAPPREVIEW_WIDTH*16 then X2 := MAPPREVIEW_WIDTH*16; - if Y2 > MAPPREVIEW_HEIGHT*16 then Y2 := MAPPREVIEW_HEIGHT*16; - - if X1 < 0 then X1 := 0; - if Y1 < 0 then Y1 := 0; - - case PanelType of - PANEL_WALL: - begin - r := 255; - g := 255; - b := 255; - end; - PANEL_CLOSEDOOR: - begin - r := 255; - g := 255; - b := 0; - end; - PANEL_WATER: - begin - r := 0; - g := 0; - b := 192; - end; - PANEL_ACID1: - begin - r := 0; - g := 176; - b := 0; - end; - PANEL_ACID2: - begin - r := 176; - g := 0; - b := 0; - end; - else - begin - r := 128; - g := 128; - b := 128; - end; - end; - - if ((X2-X1) > 0) and ((Y2-Y1) > 0) then - e_DrawFillQuad(FX+4 + X1, FY+4 + Y1, - FX+4 + X2 - 1, FY+4 + Y2 - 1, r, g, b, 0); - end; -end; - procedure TGUIMapPreview.OnMessage(var Msg: TMessage); begin inherited; @@ -3078,48 +2645,6 @@ begin FDrawScroll := True; end; -procedure TGUIListBox.Draw; -var - w2, h2: Word; - a: Integer; - s: string; -begin - inherited; - - if FDrawBack then DrawBox(FX, FY, FWidth+1, FHeight); - if FDrawScroll then - DrawScroll(FX+4+FWidth*16, FY+4, FHeight, (FStartLine > 0) and (FItems <> nil), - (FStartLine+FHeight-1 < High(FItems)) and (FItems <> nil)); - - if FItems <> nil then - for a := FStartLine to Min(High(FItems), FStartLine+FHeight-1) do - begin - s := Items[a]; - - FFont.GetTextSize(s, w2, h2); - while (Length(s) > 0) and (w2 > FWidth*16) do - begin - SetLength(s, Length(s)-1); - FFont.GetTextSize(s, w2, h2); - end; - - if a = FIndex then - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, s, FActiveColor.R, FActiveColor.G, FActiveColor.B) - else - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, s, FUnActiveColor.R, FUnActiveColor.G, FUnActiveColor.B); - end; -end; - -function TGUIListBox.GetHeight: Integer; -begin - Result := 8+FHeight*16; -end; - -function TGUIListBox.GetWidth: Integer; -begin - Result := 8+(FWidth+1)*16; -end; - procedure TGUIListBox.OnMessage(var Msg: TMessage); var a: Integer; @@ -3486,32 +3011,6 @@ begin FDrawScroll := True; end; -procedure TGUIMemo.Draw; -var - a: Integer; -begin - inherited; - - if FDrawBack then DrawBox(FX, FY, FWidth+1, FHeight); - if FDrawScroll then - DrawScroll(FX+4+FWidth*16, FY+4, FHeight, (FStartLine > 0) and (FLines <> nil), - (FStartLine+FHeight-1 < High(FLines)) and (FLines <> nil)); - - if FLines <> nil then - for a := FStartLine to Min(High(FLines), FStartLine+FHeight-1) do - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, FLines[a], FColor.R, FColor.G, FColor.B); -end; - -function TGUIMemo.GetHeight: Integer; -begin - Result := 8+FHeight*16; -end; - -function TGUIMemo.GetWidth: Integer; -begin - Result := 8+(FWidth+1)*16; -end; - procedure TGUIMemo.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -3574,20 +3073,6 @@ begin inherited; end; -procedure TGUIimage.Draw(); -var - ID: DWORD; -begin - inherited; - - if FImageRes = '' then - begin - if g_Texture_Get(FDefaultRes, ID) then e_Draw(ID, FX, FY, 0, True, False); - end - else - if g_Texture_Get(FImageRes, ID) then e_Draw(ID, FX, FY, 0, True, False); -end; - procedure TGUIimage.OnMessage(var Msg: TMessage); begin inherited; diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 33a2477..f80e7cb 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -51,13 +51,19 @@ uses {$IFDEF ENABLE_CORPSES} g_corpses, {$ENDIF} - g_gui, r_textures, r_graphics, g_game, g_map, + {$IFDEF ENABLE_RENDER} + r_render, r_game, + {$ENDIF} + {$IFDEF ENABLE_SYSTEM} + g_system, + {$ENDIF} + g_gui, g_game, g_map, g_base, g_basic, g_console, g_sound, g_player, g_options, g_weapons, e_log, SysUtils, CONFIG, g_playermodel, DateUtils, MAPDEF, Math, g_saveload, g_language, e_res, g_net, g_netmsg, g_netmaster, g_items, e_input, - utils, wadreader, g_system, r_render, r_game; + utils, wadreader; type TYNCallback = procedure (yes:Boolean); @@ -810,8 +816,12 @@ begin slWaitStr := _lc[I_NET_SLIST_WAIT]; - r_Render_Draw; - sys_Repaint; + {$IFDEF ENABLE_RENDER} + r_Render_Draw; + {$ENDIF} + {$IFDEF ENABLE_SYSTEM} + sys_Repaint; + {$ENDIF} slReturnPressed := True; if g_Net_Slist_Fetch(slCurrent) then @@ -987,32 +997,6 @@ procedure MenuLoadData(); begin e_WriteLog('Loading menu data...', TMsgType.Notify); - g_Texture_CreateWADEx('MAINMENU_LOGO', GameWAD+':TEXTURES\MAINLOGO'); - g_Texture_CreateWADEx('MAINMENU_MARKER1', GameWAD+':TEXTURES\MARKER1'); - g_Texture_CreateWADEx('MAINMENU_MARKER2', GameWAD+':TEXTURES\MARKER2'); - g_Texture_CreateWADEx('SCROLL_LEFT', GameWAD+':TEXTURES\SLEFT'); - g_Texture_CreateWADEx('SCROLL_RIGHT', GameWAD+':TEXTURES\SRIGHT'); - g_Texture_CreateWADEx('SCROLL_MIDDLE', GameWAD+':TEXTURES\SMIDDLE'); - g_Texture_CreateWADEx('SCROLL_MARKER', GameWAD+':TEXTURES\SMARKER'); - g_Texture_CreateWADEx('EDIT_LEFT', GameWAD+':TEXTURES\ELEFT'); - g_Texture_CreateWADEx('EDIT_RIGHT', GameWAD+':TEXTURES\ERIGHT'); - g_Texture_CreateWADEx('EDIT_MIDDLE', GameWAD+':TEXTURES\EMIDDLE'); - g_Texture_CreateWADEx('BOX1', GameWAD+':TEXTURES\BOX1'); - g_Texture_CreateWADEx('BOX2', GameWAD+':TEXTURES\BOX2'); - g_Texture_CreateWADEx('BOX3', GameWAD+':TEXTURES\BOX3'); - g_Texture_CreateWADEx('BOX4', GameWAD+':TEXTURES\BOX4'); - g_Texture_CreateWADEx('BOX5', GameWAD+':TEXTURES\BOX5'); - g_Texture_CreateWADEx('BOX6', GameWAD+':TEXTURES\BOX6'); - g_Texture_CreateWADEx('BOX7', GameWAD+':TEXTURES\BOX7'); - g_Texture_CreateWADEx('BOX8', GameWAD+':TEXTURES\BOX8'); - g_Texture_CreateWADEx('BOX9', GameWAD+':TEXTURES\BOX9'); - g_Texture_CreateWADEx('BSCROLL_UP_A', GameWAD+':TEXTURES\SCROLLUPA'); - g_Texture_CreateWADEx('BSCROLL_UP_U', GameWAD+':TEXTURES\SCROLLUPU'); - g_Texture_CreateWADEx('BSCROLL_DOWN_A', GameWAD+':TEXTURES\SCROLLDOWNA'); - g_Texture_CreateWADEx('BSCROLL_DOWN_U', GameWAD+':TEXTURES\SCROLLDOWNU'); - g_Texture_CreateWADEx('BSCROLL_MIDDLE', GameWAD+':TEXTURES\SCROLLMIDDLE'); - g_Texture_CreateWADEx('NOPIC', GameWAD+':TEXTURES\NOPIC'); - g_Sound_CreateWADEx('MENU_SELECT', GameWAD+':SOUNDS\MENUSELECT'); g_Sound_CreateWADEx('MENU_OPEN', GameWAD+':SOUNDS\MENUOPEN'); g_Sound_CreateWADEx('MENU_CLOSE', GameWAD+':SOUNDS\MENUCLOSE'); @@ -1024,35 +1008,6 @@ end; procedure MenuFreeData(); begin - e_CharFont_Remove(gMenuFont); - e_CharFont_Remove(gMenuSmallFont); - - g_Texture_Delete('MAINMENU_LOGO'); - g_Texture_Delete('MAINMENU_MARKER1'); - g_Texture_Delete('MAINMENU_MARKER2'); - g_Texture_Delete('SCROLL_LEFT'); - g_Texture_Delete('SCROLL_RIGHT'); - g_Texture_Delete('SCROLL_MIDDLE'); - g_Texture_Delete('SCROLL_MARKER'); - g_Texture_Delete('EDIT_LEFT'); - g_Texture_Delete('EDIT_RIGHT'); - g_Texture_Delete('EDIT_MIDDLE'); - g_Texture_Delete('BOX1'); - g_Texture_Delete('BOX2'); - g_Texture_Delete('BOX3'); - g_Texture_Delete('BOX4'); - g_Texture_Delete('BOX5'); - g_Texture_Delete('BOX6'); - g_Texture_Delete('BOX7'); - g_Texture_Delete('BOX8'); - g_Texture_Delete('BOX9'); - g_Texture_Delete('BSCROLL_UP_A'); - g_Texture_Delete('BSCROLL_UP_U'); - g_Texture_Delete('BSCROLL_DOWN_A'); - g_Texture_Delete('BSCROLL_DOWN_U'); - g_Texture_Delete('BSCROLL_MIDDLE'); - g_Texture_Delete('NOPIC'); - g_Sound_Delete('MENU_SELECT'); g_Sound_Delete('MENU_OPEN'); g_Sound_Delete('MENU_CLOSE'); @@ -1899,7 +1854,7 @@ var begin Menu := TGUIWindow.Create('FirstLanguageMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', ' '))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, ' '))) do // space to prevent show logo begin Name := 'mmFirstLanguageMenu'; AddButton(@ProcSetFirstRussianLanguage, 'Ðóññêèé', ''); @@ -1992,7 +1947,7 @@ var //list: SSArray; begin Menu := TGUIWindow.Create('MainMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, 'MAINMENU_LOGO', _lc[I_MENU_MAIN_MENU]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '' (*_lc[I_MENU_MAIN_MENU]*) ))) do begin Name := 'mmMainMenu'; AddButton(nil, _lc[I_MENU_NEW_GAME], 'NewGameMenu'); @@ -2013,7 +1968,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('NewGameMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_NEW_GAME]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_NEW_GAME]))) do begin Name := 'mmNewGameMenu'; AddButton(@ProcSingle1Player, _lc[I_MENU_1_PLAYER]); @@ -2025,7 +1980,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('NetGameMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_MULTIPLAYER]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_MULTIPLAYER]))) do begin Name := 'mmNetGameMenu'; AddButton(@ProcRecallAddress, _lc[I_MENU_START_CLIENT], 'NetClientMenu'); @@ -2602,7 +2557,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('OptionsMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_OPTIONS]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_OPTIONS]))) do begin Name := 'mmOptionsMenu'; AddButton(nil, _lc[I_MENU_VIDEO_OPTIONS], 'OptionsVideoMenu'); @@ -3192,7 +3147,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('GameSingleMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_MAIN_MENU]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_MAIN_MENU]))) do begin Name := 'mmGameSingleMenu'; AddButton(nil, _lc[I_MENU_LOAD_GAME], 'LoadMenu'); @@ -3217,7 +3172,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('GameCustomMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_MAIN_MENU]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_MAIN_MENU]))) do begin Name := 'mmGameCustomMenu'; AddButton(nil, _lc[I_MENU_CHANGE_PLAYERS], 'TeamMenu'); @@ -3235,7 +3190,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('GameServerMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_MAIN_MENU]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_MAIN_MENU]))) do begin Name := 'mmGameServerMenu'; AddButton(nil, _lc[I_MENU_CHANGE_PLAYERS], 'TeamMenu'); @@ -3251,7 +3206,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('GameClientMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_MAIN_MENU]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_MAIN_MENU]))) do begin Name := 'mmGameClientMenu'; AddButton(nil, _lc[I_MENU_CHANGE_PLAYERS], 'TeamMenu'); @@ -3346,7 +3301,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('TeamMenu'); - with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, '', _lc[I_MENU_CHANGE_PLAYERS]))) do + with TGUIMainMenu(Menu.AddChild(TGUIMainMenu.Create(gMenuFont, _lc[I_MENU_CHANGE_PLAYERS]))) do begin Name := 'mmTeamMenu'; AddButton(@ProcJoinRed, _lc[I_MENU_JOIN_RED], '').Name := 'tmJoinRed'; diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index 6b25a4f..daa4ca7 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -42,7 +42,7 @@ implementation g_holmes, {$ENDIF} {$IFDEF ENABLE_MENU} - g_gui, g_menu, + g_gui, g_menu, r_gui, {$ENDIF} {$IFDEF ENABLE_GFX} g_gfx, r_gfx, @@ -212,6 +212,8 @@ end; procedure r_Game_Free; begin + e_CharFont_Remove(gMenuFont); + e_CharFont_Remove(gMenuSmallFont); g_Texture_Delete('NOTEXTURE'); g_Texture_Delete('TEXTURE_PLAYER_HUD'); g_Texture_Delete('TEXTURE_PLAYER_HUDBG'); @@ -2164,7 +2166,7 @@ begin //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180); e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); end; - g_ActiveWindow.Draw(); + r_GUI_Draw_Window(g_ActiveWindow); end; {$ENDIF} diff --git a/src/game/opengl/r_gui.pas b/src/game/opengl/r_gui.pas new file mode 100644 index 0000000..039af75 --- /dev/null +++ b/src/game/opengl/r_gui.pas @@ -0,0 +1,607 @@ +(* 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 + * the Free Software Foundation, version 3 of the License ONLY. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) +{$INCLUDE ../../shared/a_modes.inc} +unit r_gui; + +interface + + uses g_gui; + + procedure r_GUI_Load; + procedure r_GUI_Free; + + procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer); + procedure r_GUI_GetLogoSize (out w, h: WORD); + procedure r_GUI_Draw_Window (win: TGUIWindow); + +implementation + + uses + Classes, Math, + MAPDEF, utils, + g_basic, g_base, e_input, g_options, + r_graphics, r_textures, r_playermodel, r_game, + g_game, g_menu + ; + + const + BOX1 = 'BOX1'; + BOX2 = 'BOX2'; + BOX3 = 'BOX3'; + BOX4 = 'BOX4'; + BOX5 = 'BOX5'; + BOX6 = 'BOX6'; + BOX7 = 'BOX7'; + BOX8 = 'BOX8'; + BOX9 = 'BOX9'; + + var + Box: Array [0..8] of DWORD; + MarkerID: array [Boolean] of DWORD; + ScrollLeft, ScrollRight, ScrollMiddle, ScrollMarker: DWORD; + EditLeft, EditRight, EditMiddle: DWORD; + + Font: array [boolean] of TFont; (* Small[FALSE] / Big[TRUE] *) + LogoTex: DWORD; + + procedure r_GUI_GetLogoSize (out w, h: WORD); + begin + w := 0; + h := 0; + if LogoTex <> 0 then + e_GetTextureSize(LogoTex, @w, @h); + end; + + procedure r_GUI_Load; + begin + g_Texture_CreateWADEx('MAINMENU_LOGO', GameWAD + ':TEXTURES\MAINLOGO'); + g_Texture_CreateWADEx('MAINMENU_MARKER1', GameWAD + ':TEXTURES\MARKER1'); + g_Texture_CreateWADEx('MAINMENU_MARKER2', GameWAD + ':TEXTURES\MARKER2'); + g_Texture_CreateWADEx('SCROLL_LEFT', GameWAD + ':TEXTURES\SLEFT'); + g_Texture_CreateWADEx('SCROLL_RIGHT', GameWAD + ':TEXTURES\SRIGHT'); + g_Texture_CreateWADEx('SCROLL_MIDDLE', GameWAD + ':TEXTURES\SMIDDLE'); + g_Texture_CreateWADEx('SCROLL_MARKER', GameWAD + ':TEXTURES\SMARKER'); + g_Texture_CreateWADEx('EDIT_LEFT', GameWAD + ':TEXTURES\ELEFT'); + g_Texture_CreateWADEx('EDIT_RIGHT', GameWAD + ':TEXTURES\ERIGHT'); + g_Texture_CreateWADEx('EDIT_MIDDLE', GameWAD + ':TEXTURES\EMIDDLE'); + g_Texture_CreateWADEx('BOX1', GameWAD + ':TEXTURES\BOX1'); + g_Texture_CreateWADEx('BOX2', GameWAD + ':TEXTURES\BOX2'); + g_Texture_CreateWADEx('BOX3', GameWAD + ':TEXTURES\BOX3'); + g_Texture_CreateWADEx('BOX4', GameWAD + ':TEXTURES\BOX4'); + g_Texture_CreateWADEx('BOX5', GameWAD + ':TEXTURES\BOX5'); + g_Texture_CreateWADEx('BOX6', GameWAD + ':TEXTURES\BOX6'); + g_Texture_CreateWADEx('BOX7', GameWAD + ':TEXTURES\BOX7'); + g_Texture_CreateWADEx('BOX8', GameWAD + ':TEXTURES\BOX8'); + g_Texture_CreateWADEx('BOX9', GameWAD + ':TEXTURES\BOX9'); + g_Texture_CreateWADEx('BSCROLL_UP_A', GameWAD + ':TEXTURES\SCROLLUPA'); + g_Texture_CreateWADEx('BSCROLL_UP_U', GameWAD + ':TEXTURES\SCROLLUPU'); + g_Texture_CreateWADEx('BSCROLL_DOWN_A', GameWAD + ':TEXTURES\SCROLLDOWNA'); + g_Texture_CreateWADEx('BSCROLL_DOWN_U', GameWAD + ':TEXTURES\SCROLLDOWNU'); + g_Texture_CreateWADEx('BSCROLL_MIDDLE', GameWAD + ':TEXTURES\SCROLLMIDDLE'); + g_Texture_CreateWADEx('NOPIC', GameWAD + ':TEXTURES\NOPIC'); + + g_Texture_Get(MAINMENU_MARKER1, MarkerID[FALSE]); + g_Texture_Get(MAINMENU_MARKER2, MarkerID[TRUE]); + + g_Texture_Get(BOX1, Box[0]); + g_Texture_Get(BOX2, Box[1]); + g_Texture_Get(BOX3, Box[2]); + g_Texture_Get(BOX4, Box[3]); + g_Texture_Get(BOX5, Box[4]); + g_Texture_Get(BOX6, Box[5]); + g_Texture_Get(BOX7, Box[6]); + g_Texture_Get(BOX8, Box[7]); + g_Texture_Get(BOX9, Box[8]); + + g_Texture_Get(SCROLL_LEFT, ScrollLeft); + g_Texture_Get(SCROLL_RIGHT, ScrollRight); + g_Texture_Get(SCROLL_MIDDLE, ScrollMiddle); + g_Texture_Get(SCROLL_MARKER, ScrollMarker); + + g_Texture_Get(EDIT_LEFT, EditLeft); + g_Texture_Get(EDIT_RIGHT, EditRight); + g_Texture_Get(EDIT_MIDDLE, EditMiddle); + + Font[FALSE] := TFont.Create(gMenuSmallFont, TFontType.Character); + Font[TRUE] := TFont.Create(gMenuFont, TFontType.Character); + + g_Texture_Get('MAINMENU_LOGO', LogoTex) + end; + + procedure r_GUI_Free; + begin + g_Texture_Delete('MAINMENU_LOGO'); + g_Texture_Delete('MAINMENU_MARKER1'); + g_Texture_Delete('MAINMENU_MARKER2'); + g_Texture_Delete('SCROLL_LEFT'); + g_Texture_Delete('SCROLL_RIGHT'); + g_Texture_Delete('SCROLL_MIDDLE'); + g_Texture_Delete('SCROLL_MARKER'); + g_Texture_Delete('EDIT_LEFT'); + g_Texture_Delete('EDIT_RIGHT'); + g_Texture_Delete('EDIT_MIDDLE'); + g_Texture_Delete('BOX1'); + g_Texture_Delete('BOX2'); + g_Texture_Delete('BOX3'); + g_Texture_Delete('BOX4'); + g_Texture_Delete('BOX5'); + g_Texture_Delete('BOX6'); + g_Texture_Delete('BOX7'); + g_Texture_Delete('BOX8'); + g_Texture_Delete('BOX9'); + g_Texture_Delete('BSCROLL_UP_A'); + g_Texture_Delete('BSCROLL_UP_U'); + g_Texture_Delete('BSCROLL_DOWN_A'); + g_Texture_Delete('BSCROLL_DOWN_U'); + g_Texture_Delete('BSCROLL_MIDDLE'); + g_Texture_Delete('NOPIC'); + end; + + procedure r_GUI_GetSize_TextButton (ctrl: TGUITextButton; out w, h: Integer); + var ww, hh: WORD; + begin + ctrl.Font.GetTextSize(ctrl.Caption, ww, hh); + w := ww; + h := hh; + end; + + procedure r_GUI_GetSize_Label (ctrl: TGUILabel; out w, h: Integer); + var ww, hh: WORD; + begin + ctrl.Font.GetTextSize(ctrl.Text, ww, hh); + h := hh; + if ctrl.FixedLength = 0 then + w := ww + else + w := e_CharFont_GetMaxWidth(ctrl.Font.ID) * ctrl.FixedLength + end; + + procedure r_GUI_GetSize_Switch (ctrl: TGUISwitch; out w, h: Integer); + var i: Integer; ww, hh: WORD; + begin + w := 0; + h := 0; + if ctrl.Items <> nil then + begin + for i := 0 to High(ctrl.Items) do + begin + ctrl.Font.GetTextSize(ctrl.Items[i], ww, hh); + if ww > w then + w := ww; + end; + end; + end; + + procedure r_GUI_GetSize_KeyRead (ctrl: TGUIKeyRead; out w, h: Integer); + var i: Integer; ww, hh: WORD; + begin + w := 0; + h := 0; // ??? always 0 + for i := 0 to 255 do + begin + ctrl.Font.GetTextSize(e_KeyNames[i], ww, hh); + w := MAX(w, ww); + end; + ctrl.Font.GetTextSize(KEYREAD_QUERY, ww, hh); + if ww > w then w := ww; + ctrl.Font.GetTextSize(KEYREAD_CLEAR, ww, hh); + if ww > w then w := ww; + end; + + procedure r_GUI_GetSize (ctrl: TGUIControl; out w, h: Integer); + begin + w := 0; + h := 0; + if ctrl is TGUITextButton then + r_GUI_GetSize_TextButton(ctrl as TGUITextButton, w, h) + else if ctrl is TGUILabel then + r_GUI_GetSize_Label(ctrl as TGUILabel, w, h) + else if ctrl is TGUIScroll then + w := 16 + ((ctrl as TGUIScroll).Max + 1) * 8 // ??? but h = 0 + else if ctrl is TGUISwitch then + r_GUI_GetSize_Switch(ctrl as TGUISwitch, w, h) + else if ctrl is TGUIEdit then + w := 16 + (ctrl as TGUIEdit).Width * 16 // ??? but h = 0 + else if ctrl is TGUIKeyRead then + r_GUI_GetSize_KeyRead(ctrl as TGUIKeyRead, w, h) + else if ctrl is TGUIKeyRead2 then + w := (ctrl as TGUIKeyRead2).MaxKeyNameWdt * 2 + 8 + 8 + 16 // ??? but h = 0 + else if ctrl is TGUIListBox then + begin + w := 8 + ((ctrl as TGUIListBox).Width + 1) * 16; // recheck w & h + h := 8 + (ctrl as TGUIListBox).Height * 16; + end + else if ctrl is TGUIMemo then + begin + w := 8 + ((ctrl as TGUIMemo).Width + 1) * 16; + h := 8 + (ctrl as TGUIMemo).Height * 16; + end + else + begin + w := ctrl.GetWidth(); + h := ctrl.GetHeight(); + end; + end; + + procedure r_GUI_Draw_Control (ctrl: TGUIControl); forward; + + procedure r_GUI_Draw_TextButton (ctrl: TGUITextButton); + begin + ctrl.Font.Draw(ctrl.X, ctrl.Y, ctrl.Caption, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B) + end; + + procedure r_GUI_Draw_Label (ctrl: TGUILabel); + var w, h: Word; + begin + if ctrl.RightAlign then + begin + ctrl.Font.GetTextSize(ctrl.Text, w, h); + ctrl.Font.Draw(ctrl.X + ctrl.CMaxWidth - w, ctrl.Y, ctrl.Text, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B); + end + else + ctrl.Font.Draw(ctrl.X, ctrl.Y, ctrl.Text, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B); + end; + + procedure r_GUI_Draw_Scroll (ctrl: TGUIScroll); + var a: Integer; + begin + e_Draw(ScrollLeft, ctrl.X, ctrl.Y, 0, True, False); + e_Draw(ScrollRight, ctrl.X + 8 + (ctrl.Max + 1) * 8, ctrl.Y, 0, True, False); + for a := 0 to ctrl.Max do + e_Draw(ScrollMiddle, ctrl.X + 8 + a * 8, ctrl.Y, 0, True, False); + e_Draw(ScrollMarker, ctrl.X + 8 + ctrl.Value * 8, ctrl.Y, 0, True, False); + end; + + procedure r_GUI_Draw_Switch (ctrl: TGUISwitch); + begin + ctrl.Font.Draw(ctrl.X, ctrl.Y, ctrl.Items[ctrl.ItemIndex], ctrl.Color.R, ctrl.Color.G, ctrl.Color.B); + end; + + procedure r_GUI_Draw_Edit (ctrl: TGUIEdit); + var c, w, h: Word; r, g, b: Byte; + begin + e_Draw(EditLeft, ctrl.X, ctrl.Y, 0, True, False); + e_Draw(EditRight, ctrl.X + 8 + ctrl.Width * 16, ctrl.Y, 0, True, False); + for c := 0 to ctrl.Width - 1 do + e_Draw(EditMiddle, ctrl.X + 8 + c * 16, ctrl.Y, 0, True, False); + r := ctrl.Color.R; + g := ctrl.Color.G; + b := ctrl.Color.B; + if ctrl.Invalid and (ctrl.Window.ActiveControl <> ctrl) then + begin + r := 128; + g := 128; + b := 128; + end; + ctrl.Font.Draw(ctrl.X + 8, ctrl.Y, ctrl.Text, r, g, b); + if ctrl.Window.ActiveControl = ctrl then + begin + ctrl.Font.GetTextSize(Copy(ctrl.Text, 1, ctrl.CaretPos), w, h); + h := e_CharFont_GetMaxHeight(ctrl.Font.ID); + e_DrawLine(2, ctrl.X + 8 + w, ctrl.Y + h - 3, ctrl.X + 8 + w + EDIT_CURSORLEN, ctrl.Y + h - 3, EDIT_CURSORCOLOR.R, EDIT_CURSORCOLOR.G, EDIT_CURSORCOLOR.B); + end; + end; + + procedure r_GUI_Draw_KeyRead (ctrl: TGUIKeyRead); + var k: AnsiString; + begin + if ctrl.IsQuery then + k := KEYREAD_QUERY + else if ctrl.Key <> 0 then + k := e_KeyNames[ctrl.Key] + else + k := KEYREAD_CLEAR; + ctrl.Font.Draw(ctrl.X, ctrl.Y, k, ctrl.Color.R, ctrl.Color.G, ctrl.Color.B); + end; + + procedure r_GUI_Draw_KeyRead2 (ctrl: TGUIKeyRead2); + + procedure drawText (idx: Integer); + var x, y: Integer; r, g, b: Byte; kk: DWORD; str: AnsiString; + begin + if idx = 0 then kk := ctrl.Key0 else kk := ctrl.Key1; + y := ctrl.Y; + if idx = 0 then x := ctrl.X + 8 else x := ctrl.X + 8 + ctrl.MaxKeyNameWdt + 16; + r := 255; + g := 0; + b := 0; + if ctrl.KeyIdx = idx then + begin + r := 255; g := 255; b := 255; + end; + if ctrl.IsQuery and (ctrl.KeyIdx = idx) then + begin + ctrl.Font.Draw(x, y, KEYREAD_QUERY, r, g, b) + end + else + begin + if kk <> 0 then + str := e_KeyNames[kk] + else + str := KEYREAD_CLEAR; + ctrl.Font.Draw(x, y, str, r, g, b); + end + end; + + begin + drawText(0); + drawText(1); + end; + + procedure DrawBox(X, Y: Integer; Width, Height: Word); + begin + e_Draw(Box[0], X, Y, 0, False, False); + e_DrawFill(Box[1], X + 4, Y, Width * 4, 1, 0, False, False); + e_Draw(Box[2], X + 4 + Width * 16, Y, 0, False, False); + e_DrawFill(Box[3], X, Y + 4, 1, Height * 4, 0, False, False); + e_DrawFill(Box[4], X + 4, Y + 4, Width, Height, 0, False, False); + e_DrawFill(Box[5], X + 4 + Width * 16, Y + 4, 1, Height * 4, 0, False, False); + e_Draw(Box[6], X, Y + 4 + Height * 16, 0, False, False); + e_DrawFill(Box[7], X + 4, Y + 4 + Height * 16, Width * 4, 1, 0, False, False); + e_Draw(Box[8], X + 4 + Width * 16, Y + 4 + Height * 16, 0, False, False); + end; + + procedure r_GUI_Draw_ModelView (ctrl: TGUIModelView); + begin + DrawBox(ctrl.X, ctrl.Y, 4, 4); + if ctrl.Model <> nil then + r_PlayerModel_Draw(ctrl.Model, ctrl.X + 4, ctrl.Y + 4); + end; + + procedure r_GUI_Draw_MapPreview (ctrl: TGUIMapPreview); + var a: Integer; r, g, b: Byte; + begin + DrawBox(ctrl.X, ctrl.Y, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT); + if (ctrl.MapSize.X <= 0) or (ctrl.MapSize.Y <= 0) then + Exit; + e_DrawFillQuad(ctrl.X + 4, ctrl.Y + 4, ctrl.X + 4 + Trunc(ctrl.MapSize.X / ctrl.Scale) - 1, ctrl.Y + 4 + Trunc(ctrl.MapSize.Y / ctrl.Scale) - 1, 32, 32, 32, 0); + if ctrl.MapData <> nil then + for a := 0 to High(ctrl.MapData) do + with ctrl.MapData[a] do + begin + if X1 > MAPPREVIEW_WIDTH * 16 then Continue; + if Y1 > MAPPREVIEW_HEIGHT * 16 then Continue; + if X2 < 0 then Continue; + if Y2 < 0 then Continue; + if X2 > MAPPREVIEW_WIDTH * 16 then X2 := MAPPREVIEW_WIDTH * 16; + if Y2 > MAPPREVIEW_HEIGHT * 16 then Y2 := MAPPREVIEW_HEIGHT * 16; + if X1 < 0 then X1 := 0; + if Y1 < 0 then Y1 := 0; + case PanelType of + PANEL_WALL: + begin + r := 255; g := 255; b := 255; + end; + PANEL_CLOSEDOOR: + begin + r := 255; g := 255; b := 0; + end; + PANEL_WATER: + begin + r := 0; g := 0; b := 192; + end; + PANEL_ACID1: + begin + r := 0; g := 176; b := 0; + end; + PANEL_ACID2: + begin + r := 176; g := 0; b := 0; + end; + else + r := 128; g := 128; b := 128; + end; + if ((X2 - X1) > 0) and ((Y2 - Y1) > 0) then + e_DrawFillQuad(ctrl.X + 4 + X1, ctrl.Y + 4 + Y1, ctrl.X + 4 + X2 - 1, ctrl.Y + 4 + Y2 - 1, r, g, b, 0); + end; + end; + + procedure r_GUI_Draw_Image (ctrl: TGUIImage); + var ID: DWORD; + begin + if ctrl.ImageRes = '' then + begin + if g_Texture_Get(ctrl.DefaultRes, ID) then + e_Draw(ID, ctrl.X, ctrl.Y, 0, True, False); + end + else + begin + if g_Texture_Get(ctrl.ImageRes, ID) then + e_Draw(ID, ctrl.X, ctrl.Y, 0, True, False); + end; + end; + + procedure DrawScroll(X, Y: Integer; Height: Word; Up, Down: Boolean); + var ID: DWORD; + begin + if Height < 3 then + Exit; + if Up then + g_Texture_Get(BSCROLL_UPA, ID) + else + g_Texture_Get(BSCROLL_UPU, ID); + e_Draw(ID, X, Y, 0, False, False); + if Down then + g_Texture_Get(BSCROLL_DOWNA, ID) + else + g_Texture_Get(BSCROLL_DOWNU, ID); + e_Draw(ID, X, Y + (Height - 1) * 16, 0, False, False); + g_Texture_Get(BSCROLL_MIDDLE, ID); + e_DrawFill(ID, X, Y + 16, 1, Height - 2, 0, False, False); + end; + + procedure r_GUI_Draw_ListBox (ctrl: TGUIListBox); // + TGUIFileListBox + var w2, h2: Word; a: Integer; s: string; + begin + if ctrl.DrawBack then + DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height); + if ctrl.DrawScrollBar then + DrawScroll(ctrl.X + 4 + ctrl.Width * 16, ctrl.Y + 4, ctrl.Height, (ctrl.StartLine > 0) and (ctrl.Items <> nil), (ctrl.StartLine + ctrl.Height - 1 < High(ctrl.Items)) and (ctrl.Items <> nil)); + if ctrl.Items <> nil then + begin + for a := ctrl.StartLine to Min(High(ctrl.Items), ctrl.StartLine + ctrl.Height - 1) do + begin + s := ctrl.Items[a]; + ctrl.Font.GetTextSize(s, w2, h2); + while (Length(s) > 0) and (w2 > ctrl.Width * 16) do + begin + SetLength(s, Length(s) - 1); + ctrl.Font.GetTextSize(s, w2, h2); + end; + if a = ctrl.ItemIndex then + ctrl.Font.Draw(ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, s, ctrl.ActiveColor.R, ctrl.ActiveColor.G, ctrl.ActiveColor.B) + else + ctrl.Font.Draw(ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, s, ctrl.UnActiveColor.R, ctrl.UnActiveColor.G, ctrl.UnActiveColor.B); + end; + end; + end; + + procedure r_GUI_Draw_Memo (ctrl: TGUIMemo); + var a: Integer; + begin + if ctrl.DrawBack then + DrawBox(ctrl.X, ctrl.Y, ctrl.Width + 1, ctrl.Height); + if ctrl.DrawScrollBar then + DrawScroll(ctrl.X + 4 + ctrl.Width * 16, ctrl.Y + 4, ctrl.Height, (ctrl.StartLine > 0) and (ctrl.Lines <> nil), (ctrl.StartLine + ctrl.Height - 1 < High(ctrl.Lines)) and (ctrl.Lines <> nil)); + if ctrl.Lines <> nil then + for a := ctrl.StartLine to Min(High(ctrl.Lines), ctrl.StartLine + ctrl.Height - 1) do + ctrl.Font.Draw(ctrl.X + 4, ctrl.Y + 4 + (a - ctrl.StartLine) * 16, ctrl.Lines[a], ctrl.Color.R, ctrl.Color.G, ctrl.Color.B); + end; + + procedure r_GUI_Draw_MainMenu (ctrl: TGUIMainMenu); + var a: Integer; w, h: Word; ID: DWORD; + begin + if ctrl.Header <> nil then + begin + r_GUI_Draw_Label(ctrl.Header) + end + else if LogoTex <> 0 then + begin + e_GetTextureSize(LogoTex, @w, @h); + e_Draw(LogoTex, ((gScreenWidth div 2) - (w div 2)), ctrl.Buttons[0].Y - ctrl.Buttons[0].GetHeight - h, 0, True, False); + end; + if ctrl.Buttons <> nil then + begin + for a := 0 to High(ctrl.Buttons) do + if ctrl.Buttons[a] <> nil then + r_GUI_Draw_TextButton(ctrl.Buttons[a]); + if ctrl.Index <> -1 then + begin + ID := MarkerID[ctrl.Counter DIV MAINMENU_MARKERDELAY MOD 2 <> 0]; + e_Draw(ID, ctrl.Buttons[ctrl.Index].X - 48, ctrl.Buttons[ctrl.Index].Y, 0, True, False); + end + end; + end; + + procedure r_GUI_Draw_Menu (ctrl: TGUIMenu); + var a, locx, locy: Integer; + begin + if ctrl.Header <> nil then + r_GUI_Draw_Label(ctrl.Header); + if ctrl.Items <> nil then + begin + for a := 0 to High(ctrl.Items) do + begin + if ctrl.Items[a].Text <> nil then + r_GUI_Draw_Control(ctrl.Items[a].Text); + if ctrl.Items[a].Control <> nil then + r_GUI_Draw_Control(ctrl.Items[a].Control); + end; + end; + if (ctrl.Index <> -1) and (ctrl.Counter > MENU_MARKERDELAY div 2) then + begin + locx := 0; + locy := 0; + if ctrl.Items[ctrl.Index].Text <> nil then + begin + locx := ctrl.Items[ctrl.Index].Text.X; + locy := ctrl.Items[ctrl.Index].Text.Y; + //HACK! + if ctrl.Items[ctrl.Index].Text.RightAlign then + begin + locx := locx + ctrl.Items[ctrl.Index].Text.CMaxWidth - ctrl.Items[ctrl.Index].Text.GetWidth; + end; + end + else if ctrl.Items[ctrl.Index].Control <> nil then + begin + locx := ctrl.Items[ctrl.Index].Control.X; + locy := ctrl.Items[ctrl.Index].Control.Y; + end; + locx := locx - e_CharFont_GetMaxWidth(ctrl.FontID); + e_CharFont_PrintEx(ctrl.FontID, locx, locy, #16, _RGB(255, 0, 0)); + end; + end; + + procedure r_GUI_Draw_Control (ctrl: TGUIControl); + begin + if ctrl is TGUITextButton then + r_GUI_Draw_TextButton(TGUITextButton(ctrl)) + else if ctrl is TGUILabel then + r_GUI_Draw_Label(TGUILabel(ctrl)) + else if ctrl is TGUIScroll then + r_GUI_Draw_Scroll(TGUIScroll(ctrl)) + else if ctrl is TGUISwitch then + r_GUI_Draw_Switch(TGUISwitch(ctrl)) + else if ctrl is TGUIEdit then + r_GUI_Draw_Edit(TGUIEdit(ctrl)) + else if ctrl is TGUIKeyRead then + r_GUI_Draw_KeyRead(TGUIKeyRead(ctrl)) + else if ctrl is TGUIKeyRead2 then + r_GUI_Draw_KeyRead2(TGUIKeyRead2(ctrl)) + else if ctrl is TGUIModelView then + r_GUI_Draw_ModelView(TGUIModelView(ctrl)) + else if ctrl is TGUIMapPreview then + r_GUI_Draw_MapPreview(TGUIMapPreview(ctrl)) + else if ctrl is TGUIImage then + r_GUI_Draw_Image(TGUIImage(ctrl)) + else if ctrl is TGUIListBox then + r_GUI_Draw_ListBox(TGUIListBox(ctrl)) // + TGUIFileListBox + else if ctrl is TGUIMemo then + r_GUI_Draw_Memo(TGUIMemo(ctrl)) + else if ctrl is TGUIMainMenu then + r_GUI_Draw_MainMenu(TGUIMainMenu(ctrl)) + else if ctrl is TGUIMenu then + r_GUI_Draw_Menu(TGUIMenu(ctrl)) + else + Assert(False) + end; + + procedure r_GUI_Draw_Window (win: TGUIWindow); + var i: Integer; ID: DWORD; tw, th: Word; + begin + // Here goes code duplication from g_game.pas:DrawMenuBackground() + if win.BackTexture <> '' then + if g_Texture_Get(win.BackTexture, ID) then + begin + e_Clear(0, 0, 0); + e_GetTextureSize(ID, @tw, @th); + if tw = th then + tw := round(tw * 1.333 * (gScreenHeight / th)) + else + tw := trunc(tw * (gScreenHeight / th)); + e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight); + end + else + e_Clear(0.5, 0.5, 0.5); + + // small hack here + if win.Name = 'AuthorsMenu' then + e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150); + for i := 0 to High(win.Childs) do + if win.Childs[i] <> nil then + r_GUI_Draw_Control(win.Childs[i]); + end; + +end. diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index 2a4c3e7..869b27f 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -64,6 +64,9 @@ implementation {$IFDEF ENABLE_SYSTEM} g_system, {$ENDIF} + {$IFDEF ENABLE_MENU} + r_gui, + {$ENDIF} SysUtils, Classes, Math, e_log, utils, g_game, g_options, g_console, @@ -220,10 +223,16 @@ implementation {$IFDEF ENABLE_GFX} r_GFX_Load; {$ENDIF} + {$IFDEF ENABLE_MENU} + r_GUI_Load; + {$ENDIF} end; procedure r_Render_Free; begin + {$IFDEF ENABLE_MENU} + r_GUI_Free; + {$ENDIF} {$IFDEF ENABLE_GFX} r_GFX_Free; {$ENDIF} -- 2.29.2