hedgewars/uRenderUtils.pas
changeset 6750 5eb087708fbd
parent 6749 6bb0cea803bd
child 6982 8d41d22a291d
equal deleted inserted replaced
6749:6bb0cea803bd 6750:5eb087708fbd
    68 
    68 
    69 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord = 0): TSDL_Rect;
    69 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord = 0): TSDL_Rect;
    70 var w, h: LongInt;
    70 var w, h: LongInt;
    71     tmpsurf: PSDL_Surface;
    71     tmpsurf: PSDL_Surface;
    72     clr: TSDL_Color;
    72     clr: TSDL_Color;
    73     finalRect: TSDL_Rect;
    73     finalRect, textRect: TSDL_Rect;
    74 begin
    74 begin
    75     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h);
    75     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h);
    76     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    76     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    77     finalRect.x:= X;
    77     finalRect.x:= X;
    78     finalRect.y:= Y;
    78     finalRect.y:= Y;
    79     finalRect.w:= w + FontBorder * 2 + 4;
    79     finalRect.w:= w + FontBorder * 2 + 4;
    80     finalRect.h:= h + FontBorder * 2;
    80     finalRect.h:= h + FontBorder * 2;
       
    81     textRect.x:= X;
       
    82     textRect.y:= Y;
       
    83     textRect.w:= w;
       
    84     textRect.h:= h;
    81     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
    85     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
    82     clr.r:= (Color shr 16) and $FF;
    86     clr.r:= (Color shr 16) and $FF;
    83     clr.g:= (Color shr 8) and $FF;
    87     clr.g:= (Color shr 8) and $FF;
    84     clr.b:= Color and $FF;
    88     clr.b:= Color and $FF;
    85     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
    89     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
    86     finalRect.x:= X + FontBorder + 2;
    90     finalRect.x:= X + FontBorder + 2;
    87     finalRect.y:= Y + FontBorder;
    91     finalRect.y:= Y + FontBorder;
    88     SDLTry(tmpsurf <> nil, true);
    92     SDLTry(tmpsurf <> nil, true);
    89     SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
    93     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
    90     SDL_FreeSurface(tmpsurf);
    94     SDL_FreeSurface(tmpsurf);
    91     finalRect.x:= X;
    95     finalRect.x:= X;
    92     finalRect.y:= Y;
    96     finalRect.y:= Y;
    93     finalRect.w:= w + FontBorder * 2 + 4;
    97     finalRect.w:= w + FontBorder * 2 + 4;
    94     finalRect.h:= h + FontBorder * 2;
    98     finalRect.h:= h + FontBorder * 2;