# HG changeset patch # User nemo # Date 1330387304 18000 # Node ID 6bb0cea803bdaa4e4b64292395f5b4df9d003aa5 # Parent 9d8763deee4296473d9b5811117cd9aec0d5a4d4 Clamp name/team name textures to avoid long team / hog name abuse. Limit width in px instead of chars to avoid unicode issues. diff -r 9d8763deee42 -r 6bb0cea803bd hedgewars/uRenderUtils.pas --- a/hedgewars/uRenderUtils.pas Sun Feb 26 18:13:26 2012 -0500 +++ b/hedgewars/uRenderUtils.pas Mon Feb 27 19:01:44 2012 -0500 @@ -29,7 +29,7 @@ procedure copyToXY(src, dest: PSDL_Surface; srcX, srcY, srcW, srcH, destX, destY: LongInt); procedure DrawSprite2Surf(sprite: TSprite; dest: PSDL_Surface; x,y: LongInt; frame: LongInt = 0); procedure DrawLine2Surf(dest: PSDL_Surface; x0,y0,x1,y1:LongInt; r,g,b: byte); -function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; +function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture; function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); @@ -66,13 +66,14 @@ SDL_FillRect(Surface, @r, FillColor) end; -function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect; +function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord = 0): TSDL_Rect; var w, h: LongInt; tmpsurf: PSDL_Surface; clr: TSDL_Color; finalRect: TSDL_Rect; begin TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h); + if (maxLength <> 0) and (w > maxLength) then w := maxLength; finalRect.x:= X; finalRect.y:= Y; finalRect.w:= w + FontBorder * 2 + 4; @@ -229,7 +230,7 @@ end; end; -function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; +function RenderStringTex(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord = 0): PTexture; var w, h: LongInt; finalSurface: PSDL_Surface; begin @@ -237,13 +238,14 @@ font:= CheckCJKFont(s, font); w:= 0; h:= 0; // avoid compiler hints TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); + if (maxLength <> 0) and (w > maxLength) then w := maxLength; finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, 32, RMask, GMask, BMask, AMask); TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); - WriteInRoundRect(finalSurface, 0, 0, Color, font, s); + WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength); TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); diff -r 9d8763deee42 -r 6bb0cea803bd hedgewars/uStore.pas --- a/hedgewars/uStore.pas Sun Feb 26 18:13:26 2012 -0500 +++ b/hedgewars/uStore.pas Mon Feb 27 19:01:44 2012 -0500 @@ -133,7 +133,7 @@ for t:= 0 to Pred(TeamsCount) do with TeamsArray[t]^ do begin - NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); + NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font, cTeamHealthWidth); r.w:= cTeamHealthWidth + 5; r.h:= NameTagTex^.h; @@ -199,7 +199,7 @@ with Hedgehogs[i] do if Gear <> nil then begin - NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); + NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16, cTeamHealthWidth); if Hat <> 'NoHat' then begin if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then