DEADSOFTWARE

menu: allow to build menu without render
[d2df-sdl.git] / src / game / g_gui.pas
index a872643f8852be0abc923c45110279a9e8c2415e..734251a6afce93b4c7a95ed2834cb8dd402104f8 100644 (file)
@@ -539,7 +539,6 @@ uses
   {$ENDIF}
   {$IFDEF ENABLE_RENDER}
     r_gui,
-    r_textures, (* load/free image *)
   {$ENDIF}
   g_sound, SysUtils, e_res,
   g_game, Math, StrUtils, g_player, g_options,
@@ -558,10 +557,16 @@ function GetLines (Text: string; BigFont: Boolean; MaxWidth: Word): SSArray;
   end;
 
   function GetWidth (j, i: Integer): Integer;
-    var w, h: Integer;
+    {$IFDEF ENABLE_RENDER}
+      var w, h: Integer;
+    {$ENDIF}
   begin
-    r_GUI_GetStringSize(BigFont, GetLine(j, i), w, h);
-    result := w
+    {$IFDEF ENABLE_RENDER}
+      r_GUI_GetStringSize(BigFont, GetLine(j, i), w, h);
+      Result := w;
+    {$ELSE}
+      Result := 0;
+    {$ENDIF}
   end;
 
 begin
@@ -947,11 +952,13 @@ end;
 { TGUIMainMenu }
 
 function TGUIMainMenu.AddButton(fProc: Pointer; Caption: string; ShowWindow: string = ''): TGUITextButton;
-var
-  a, _x: Integer;
-  h, hh: Word;
-  lw: Word = 0;
-  lh: Word = 0;
+  var
+    {$IFDEF ENABLE_RENDER}
+      lw: Word = 0;
+    {$ENDIF}
+    a, _x: Integer;
+    h, hh: Word;
+    lh: Word = 0;
 begin
   FIndex := 0;
 
@@ -971,8 +978,10 @@ begin
     if FButtons[a] <> nil then
       _x := Min(_x, (gScreenWidth div 2)-(FButtons[a].GetWidth div 2));
 
-  if FHeader = nil then
-    r_GUI_GetLogoSize(lw, lh);
+  {$IFDEF ENABLE_RENDER}
+    if FHeader = nil then
+      r_GUI_GetLogoSize(lw, lh);
+  {$ENDIF}
   hh := FButtons[High(FButtons)].GetHeight;
 
   if FHeader = nil then h := lh + hh * (1 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1)
@@ -1437,10 +1446,13 @@ begin
 end;
 
 procedure TGUIMenu.ReAlign();
-var
-  a, tx, cx, w, h, fw, fh: Integer;
-  cww: array of Integer; // cached widths
-  maxcww: Integer;
+  var
+    {$IFDEF ENABLE_RENDER}
+      fw, fh: Integer;
+    {$ENDIF}
+    a, tx, cx, w, h: Integer;
+    cww: array of Integer; // cached widths
+    maxcww: Integer;
 begin
   if FItems = nil then Exit;
 
@@ -1508,8 +1520,10 @@ begin
         h := h+(FItems[a].Control as TGUIListBox).GetHeight()
       else
       begin
-        r_GUI_GetMaxFontSize(FBigFont, fw, fh);
-        h := h + fh;
+        {$IFDEF ENABLE_RENDER}
+          r_GUI_GetMaxFontSize(FBigFont, fw, fh);
+          h := h + fh;
+        {$ENDIF}
       end;
     end;
   end;
@@ -1564,8 +1578,12 @@ begin
       else if ControlType = TGUIMemo then Inc(h, (Control as TGUIMemo).GetHeight+MENU_VSPACE)
       else
       begin
-        r_GUI_GetMaxFontSize(FBigFont, fw, fh);
-        h := h + fh + MENU_VSPACE;
+        {$IFDEF ENABLE_RENDER}
+          r_GUI_GetMaxFontSize(FBigFont, fw, fh);
+          h := h + fh + MENU_VSPACE;
+        {$ELSE}
+          h := h + MENU_VSPACE;
+        {$ENDIF}
       end;
     end;
   end;
@@ -2203,7 +2221,9 @@ end;
 { TGUIKeyRead2 }
 
 constructor TGUIKeyRead2.Create(BigFont: Boolean);
-  var a: Byte; w, h: Integer;
+  {$IFDEF ENABLE_RENDER}
+    var a: Byte; w, h: Integer;
+  {$ENDIF}
 begin
   inherited Create();
 
@@ -2216,21 +2236,18 @@ begin
 
   FMaxKeyNameWdt := 0;
 
-  FMaxKeyNameWdt := 0;
-
-  for a := 0 to 255 do
-  begin
-    r_GUI_GetStringSize(BigFont, e_KeyNames[a], w, h);
-    FMaxKeyNameWdt := Max(FMaxKeyNameWdt, w);
-  end;
-
-  FMaxKeyNameWdt := FMaxKeyNameWdt-(FMaxKeyNameWdt div 3);
-
-  r_GUI_GetStringSize(BigFont, KEYREAD_QUERY, w, h);
-  if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w;
-
-  r_GUI_GetStringSize(BigFont, KEYREAD_CLEAR, w, h);
-  if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w;
+  {$IFDEF ENABLE_RENDER}
+    for a := 0 to 255 do
+    begin
+      r_GUI_GetStringSize(BigFont, e_KeyNames[a], w, h);
+      FMaxKeyNameWdt := Max(FMaxKeyNameWdt, w);
+    end;
+    FMaxKeyNameWdt := FMaxKeyNameWdt-(FMaxKeyNameWdt div 3);
+    r_GUI_GetStringSize(BigFont, KEYREAD_QUERY, w, h);
+    if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w;
+    r_GUI_GetStringSize(BigFont, KEYREAD_CLEAR, w, h);
+    if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w;
+  {$ENDIF}
 end;
 
 function TGUIKeyRead2.WantActivationKey (key: LongInt): Boolean;
@@ -3003,9 +3020,6 @@ end;
 
 procedure TGUIimage.ClearImage();
 begin
-  if FImageRes = '' then Exit;
-
-  g_Texture_Delete(FImageRes);
   FImageRes := '';
 end;
 
@@ -3028,9 +3042,7 @@ end;
 
 procedure TGUIimage.SetImage(Res: string);
 begin
-  ClearImage();
-
-  if g_Texture_CreateWADEx(Res, Res) then FImageRes := Res;
+  FImageRes := Res;
 end;
 
 procedure TGUIimage.Update();