hedgewars/uRenderUtils.pas
changeset 6982 8d41d22a291d
parent 6750 5eb087708fbd
child 6986 409dd3851309
equal deleted inserted replaced
6981:045e8162c9cd 6982:8d41d22a291d
    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 + cFontBorder * 2 + 4;
    80     finalRect.h:= h + FontBorder * 2;
    80     finalRect.h:= h + cFontBorder * 2;
    81     textRect.x:= X;
    81     textRect.x:= X;
    82     textRect.y:= Y;
    82     textRect.y:= Y;
    83     textRect.w:= w;
    83     textRect.w:= w;
    84     textRect.h:= h;
    84     textRect.h:= h;
    85     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
    85     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
    86     clr.r:= (Color shr 16) and $FF;
    86     clr.r:= (Color shr 16) and $FF;
    87     clr.g:= (Color shr 8) and $FF;
    87     clr.g:= (Color shr 8) and $FF;
    88     clr.b:= Color and $FF;
    88     clr.b:= Color and $FF;
    89     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
    89     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
    90     finalRect.x:= X + FontBorder + 2;
    90     finalRect.x:= X + cFontBorder + 2;
    91     finalRect.y:= Y + FontBorder;
    91     finalRect.y:= Y + cFontBorder;
    92     SDLTry(tmpsurf <> nil, true);
    92     SDLTry(tmpsurf <> nil, true);
    93     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
    93     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
    94     SDL_FreeSurface(tmpsurf);
    94     SDL_FreeSurface(tmpsurf);
    95     finalRect.x:= X;
    95     finalRect.x:= X;
    96     finalRect.y:= Y;
    96     finalRect.y:= Y;
    97     finalRect.w:= w + FontBorder * 2 + 4;
    97     finalRect.w:= w + cFontBorder * 2 + 4;
    98     finalRect.h:= h + FontBorder * 2;
    98     finalRect.h:= h + cFontBorder * 2;
    99     WriteInRoundRect:= finalRect;
    99     WriteInRoundRect:= finalRect;
   100 end;
   100 end;
   101 
   101 
   102 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
   102 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
   103 var y, x, i, j: LongInt;
   103 var y, x, i, j: LongInt;
   242     font:= CheckCJKFont(s, font);
   242     font:= CheckCJKFont(s, font);
   243     w:= 0; h:= 0; // avoid compiler hints
   243     w:= 0; h:= 0; // avoid compiler hints
   244     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   244     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   245     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   245     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   246 
   246 
   247     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   247     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
   248             32, RMask, GMask, BMask, AMask);
   248             32, RMask, GMask, BMask, AMask);
   249 
   249 
   250     TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   250     TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   251 
   251 
   252     WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength);
   252     WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength);