hedgewars/uRenderUtils.pas
changeset 10127 7f29a65aa1e4
parent 10116 dd27562b6f21
child 10139 9046f69dae4c
equal deleted inserted replaced
10126:2fa3bb7785ee 10127:7f29a65aa1e4
    80 var w, h: LongInt;
    80 var w, h: LongInt;
    81     tmpsurf: PSDL_Surface;
    81     tmpsurf: PSDL_Surface;
    82     clr: TSDL_Color;
    82     clr: TSDL_Color;
    83     finalRect, textRect: TSDL_Rect;
    83     finalRect, textRect: TSDL_Rect;
    84 begin
    84 begin
    85     TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h);
    85     TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), @w, @h);
    86     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    86     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
    87     finalRect.x:= X;
    87     finalRect.x:= X;
    88     finalRect.y:= Y;
    88     finalRect.y:= Y;
    89     finalRect.w:= w + cFontBorder * 2 + 4;
    89     finalRect.w:= w + cFontBorder * 2 + 4;
    90     finalRect.h:= h + cFontBorder * 2;
    90     finalRect.h:= h + cFontBorder * 2;
    94     textRect.h:= h;
    94     textRect.h:= h;
    95     DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
    95     DrawRoundRect(@finalRect, cWhiteColor, cNearBlackColor, Surface, true);
    96     clr.r:= (Color shr 16) and $FF;
    96     clr.r:= (Color shr 16) and $FF;
    97     clr.g:= (Color shr 8) and $FF;
    97     clr.g:= (Color shr 8) and $FF;
    98     clr.b:= Color and $FF;
    98     clr.b:= Color and $FF;
    99     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr);
    99     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr);
   100     finalRect.x:= X + cFontBorder + 2;
   100     finalRect.x:= X + cFontBorder + 2;
   101     finalRect.y:= Y + cFontBorder;
   101     finalRect.y:= Y + cFontBorder;
   102     SDLTry(tmpsurf <> nil, true);
   102     SDLTry(tmpsurf <> nil, true);
   103     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
   103     SDL_UpperBlit(tmpsurf, @textRect, Surface, @finalRect);
   104     SDL_FreeSurface(tmpsurf);
   104     SDL_FreeSurface(tmpsurf);
   278     finalSurface: PSDL_Surface;
   278     finalSurface: PSDL_Surface;
   279 begin
   279 begin
   280     if length(s) = 0 then s:= _S' ';
   280     if length(s) = 0 then s:= _S' ';
   281     font:= CheckCJKFont(s, font);
   281     font:= CheckCJKFont(s, font);
   282     w:= 0; h:= 0; // avoid compiler hints
   282     w:= 0; h:= 0; // avoid compiler hints
   283     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   283     TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h);
   284     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   284     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   285 
   285 
   286     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
   286     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
   287             32, RMask, GMask, BMask, AMask);
   287             32, RMask, GMask, BMask, AMask);
   288 
   288 
   300 
   300 
   301 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   301 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   302 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   302 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   303     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   303     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   304     rect: TSDL_Rect;
   304     rect: TSDL_Rect;
       
   305     {$IFNDEF PAS2C}
   305     chars: set of char = [#9,' ',';',':','?','!',','];
   306     chars: set of char = [#9,' ',';',':','?','!',','];
       
   307     {$ENDIF}
   306     substr: shortstring;
   308     substr: shortstring;
   307     edge, corner, tail: TSPrite;
   309     edge, corner, tail: TSPrite;
   308 begin
   310 begin
   309       case SpeechType of
   311       case SpeechType of
   310         1: begin;
   312         1: begin;
   336 
   338 
   337     if length(s) = 0 then
   339     if length(s) = 0 then
   338         s:= '...';
   340         s:= '...';
   339     font:= CheckCJKFont(s, font);
   341     font:= CheckCJKFont(s, font);
   340     w:= 0; h:= 0; // avoid compiler hints
   342     w:= 0; h:= 0; // avoid compiler hints
   341     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
   343     TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h);
   342     if w<8 then
   344     if w<8 then
   343         w:= 8;
   345         w:= 8;
   344     j:= 0;
   346     j:= 0;
   345     if (length(s) > 20) then
   347     if (length(s) > 20) then
   346         begin
   348         begin
   347         w:= 0;
   349         w:= 0;
   348         i:= round(Sqrt(length(s)) * 2);
   350         i:= round(Sqrt(length(s)) * 2);
       
   351         {$IFNDEF PAS2C}
   349         s:= WrapText(s, #1, chars, i);
   352         s:= WrapText(s, #1, chars, i);
       
   353         {$ENDIF}
   350         pos:= 1; prevpos:= 0; line:= 0;
   354         pos:= 1; prevpos:= 0; line:= 0;
   351     // Find the longest line for the purposes of centring the text.  Font dependant.
   355     // Find the longest line for the purposes of centring the text.  Font dependant.
   352         while pos <= length(s) do
   356         while pos <= length(s) do
   353             begin
   357             begin
   354             if (s[pos] = #1) or (pos = length(s)) then
   358             if (s[pos] = #1) or (pos = length(s)) then