hedgewars/uRenderUtils.pas
changeset 6286 835392304f81
parent 4976 088d40d8aba2
child 6580 6155187bf599
equal deleted inserted replaced
6285:2c3a6bece643 6286:835392304f81
    66 var w, h: LongInt;
    66 var w, h: LongInt;
    67     tmpsurf: PSDL_Surface;
    67     tmpsurf: PSDL_Surface;
    68     clr: TSDL_Color;
    68     clr: TSDL_Color;
    69     finalRect: TSDL_Rect;
    69     finalRect: TSDL_Rect;
    70 begin
    70 begin
    71     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
    71     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h);
    72     finalRect.x:= X;
    72     finalRect.x:= X;
    73     finalRect.y:= Y;
    73     finalRect.y:= Y;
    74     finalRect.w:= w + FontBorder * 2 + 4;
    74     finalRect.w:= w + FontBorder * 2 + 4;
    75     finalRect.h:= h + FontBorder * 2;
    75     finalRect.h:= h + FontBorder * 2;
    76     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
    76     DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true);
   171     finalSurface: PSDL_Surface;
   171     finalSurface: PSDL_Surface;
   172 begin
   172 begin
   173     if length(s) = 0 then s:= ' ';
   173     if length(s) = 0 then s:= ' ';
   174     font:= CheckCJKFont(s, font);
   174     font:= CheckCJKFont(s, font);
   175     w:= 0; h:= 0; // avoid compiler hints
   175     w:= 0; h:= 0; // avoid compiler hints
   176     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   176     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   177 
   177 
   178     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   178     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   179             32, RMask, GMask, BMask, AMask);
   179             32, RMask, GMask, BMask, AMask);
   180 
   180 
   181     TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   181     TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   227     numLines:= 0;
   227     numLines:= 0;
   228 
   228 
   229     if length(s) = 0 then s:= '...';
   229     if length(s) = 0 then s:= '...';
   230     font:= CheckCJKFont(s, font);
   230     font:= CheckCJKFont(s, font);
   231     w:= 0; h:= 0; // avoid compiler hints
   231     w:= 0; h:= 0; // avoid compiler hints
   232     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   232     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   233     if w<8 then w:= 8;
   233     if w<8 then w:= 8;
   234     j:= 0;
   234     j:= 0;
   235     if (length(s) > 20) then
   235     if (length(s) > 20) then
   236         begin
   236         begin
   237         w:= 0;
   237         w:= 0;
   246                 inc(numlines);
   246                 inc(numlines);
   247                 if s[pos] <> #1 then inc(pos);
   247                 if s[pos] <> #1 then inc(pos);
   248                 while s[prevpos+1] = ' ' do inc(prevpos);
   248                 while s[prevpos+1] = ' ' do inc(prevpos);
   249                 substr:= copy(s, prevpos+1, pos-prevpos-1);
   249                 substr:= copy(s, prevpos+1, pos-prevpos-1);
   250                 i:= 0; j:= 0;
   250                 i:= 0; j:= 0;
   251                 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j);
   251                 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j);
   252                 if i > w then w:= i;
   252                 if i > w then w:= i;
   253                 prevpos:= pos;
   253                 prevpos:= pos;
   254                 end;
   254                 end;
   255             inc(pos);
   255             inc(pos);
   256             end;
   256             end;