DEADSOFTWARE

gl: align hud elements
[d2df-sdl.git] / src / game / renders / opengl / r_draw.pas
index 441ec2d1e4eaf1df55cbf7e57f15b2ed9c92d6b7..0091169d71d2ef99dc51b587961e1c9b810659e8 100644 (file)
@@ -34,6 +34,7 @@ interface
   procedure r_Draw_InvertRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte);
 
   procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont);
+  procedure r_Draw_GetTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer);
 
 implementation
 
@@ -271,4 +272,21 @@ implementation
     end;
   end;
 
+  procedure r_Draw_GetTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer);
+    var i, spc, len: Integer;
+  begin
+    w := 0;
+    h := f.GetMaxHeight();
+    len := Length(text);
+    if len > 0 then
+    begin
+      spc := f.GetSpace();
+      for i := 1 to len - 1 do
+        Inc(w, f.GetWidth(text[i]) + spc);
+      Inc(w, f.GetWidth(text[len]));
+      if spc < 0 then
+        Inc(w, spc)
+    end;
+  end;
+
 end.