hedgewars/uRenderUtils.pas
changeset 10105 8c5fa1d15bd5
parent 10104 cb0b750bd8a3
child 10106 4020864e3d79
equal deleted inserted replaced
10104:cb0b750bd8a3 10105:8c5fa1d15bd5
    75 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    75 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    76 begin
    76 begin
    77     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
    77     WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0);
    78 end;*)
    78 end;*)
    79 
    79 
    80 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord): TSDL_Rect;
    80 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar; maxLength: LongWord): TSDL_Rect;
    81 var w, h: LongInt;
    81 var w, h: LongInt;
    82     tmpsurf: PSDL_Surface;
    82     tmpsurf: PSDL_Surface;
    83     clr: TSDL_Color;
    83     clr: TSDL_Color;
    84     finalRect, textRect: TSDL_Rect;
    84     finalRect, textRect: TSDL_Rect;
    85 begin
    85 begin
    86     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h);
    86     TTF_SizeUTF8(Fontz[Font].Handle, s, @w, @h);
    87     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    87     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    88     finalRect.x:= X;
    88     finalRect.x:= X;
    89     finalRect.y:= Y;
    89     finalRect.y:= Y;
    90     finalRect.w:= w + cFontBorder * 2 + 4;
    90     finalRect.w:= w + cFontBorder * 2 + 4;
    91     finalRect.h:= h + cFontBorder * 2;
    91     finalRect.h:= h + cFontBorder * 2;
    95     textRect.h:= h;
    95     textRect.h:= h;
    96     DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
    96     DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
    97     clr.r:= (Color shr 16) and $FF;
    97     clr.r:= (Color shr 16) and $FF;
    98     clr.g:= (Color shr 8) and $FF;
    98     clr.g:= (Color shr 8) and $FF;
    99     clr.b:= Color and $FF;
    99     clr.b:= Color and $FF;
   100     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
   100     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr);
   101     finalRect.x:= X + cFontBorder + 2;
   101     finalRect.x:= X + cFontBorder + 2;
   102     finalRect.y:= Y + cFontBorder;
   102     finalRect.y:= Y + cFontBorder;
   103     SDLTry(tmpsurf <> nil, true);
   103     SDLTry(tmpsurf <> nil, true);
   104     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
   104     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
   105     SDL_FreeSurface(tmpsurf);
   105     SDL_FreeSurface(tmpsurf);