X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Frenders%2Fopengl%2Fr_draw.pas;h=fbdae7e4ee8e09cdfd307dc29365d7b322f88149;hb=38f37ffd695612d219b1dbd7bf3165880a012502;hp=5f01c5b4c10947afc90195ae181816ce3c7dfe68;hpb=86639e1fae2121ee4e86727933dfa1f06983b67c;p=d2df-sdl.git diff --git a/src/game/renders/opengl/r_draw.pas b/src/game/renders/opengl/r_draw.pas index 5f01c5b..fbdae7e 100644 --- a/src/game/renders/opengl/r_draw.pas +++ b/src/game/renders/opengl/r_draw.pas @@ -18,7 +18,7 @@ unit r_draw; interface uses - g_textures, + g_animations, r_textures ; @@ -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 @@ -149,8 +150,8 @@ implementation if img = nil then r_Draw_Texture(nil, x, y, w, h, flip, NTR, NTG, NTB, NTB, blend) else - for j := 0 to h div img.height - 1 do - for i := 0 to w div img.width - 1 do + for j := 0 to (h - 1) div img.height do + for i := 0 to (w - 1) div img.width do r_Draw_Texture(img, x + i * img.width, y + j * img.height, img.width, img.height, flip, r, g, b, a, blend); end; @@ -258,16 +259,31 @@ implementation end; procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont); - var i, xoff: Integer; t: TGLTexture; ch: AnsiChar; + var i, xoff, spc: Integer; t: TGLTexture; ch: AnsiChar; begin - xoff := x; + xoff := x; spc := MAX(0, f.GetSpace()); for i := 1 to Length(text) do begin ch := text[i]; t := f.GetChar(ch); if t <> nil then r_Draw_Texture(t, xoff, y, t.width, t.height, false, r, g, b, a, false); - Inc(xoff, f.GetWidth(ch) + f.GetSpace()); + Inc(xoff, f.GetWidth(ch) + spc); + 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 := MAX(0, f.GetSpace()); + for i := 1 to len - 1 do + Inc(w, f.GetWidth(text[i]) + spc); + Inc(w, f.GetWidth(text[len])); end; end;