hedgewars/uRenderUtils.pas
changeset 10139 9046f69dae4c
parent 10127 7f29a65aa1e4
child 10142 adb804cb2638
equal deleted inserted replaced
10138:1a71d28392cb 10139:9046f69dae4c
   275 
   275 
   276 function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
   276 function RenderStringTexLim(s: ansistring; Color: Longword; font: THWFont; maxLength: LongWord): PTexture;
   277 var w, h: LongInt;
   277 var w, h: LongInt;
   278     finalSurface: PSDL_Surface;
   278     finalSurface: PSDL_Surface;
   279 begin
   279 begin
   280     if length(s) = 0 then s:= _S' ';
   280     if cOnlyStats then
   281     font:= CheckCJKFont(s, font);
   281         begin
   282     w:= 0; h:= 0; // avoid compiler hints
   282         RenderStringTexLim:= nil;
   283     TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h);
   283         end
   284     if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   284     else
   285 
   285         begin
   286     finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
   286         if length(s) = 0 then s:= _S' ';
   287             32, RMask, GMask, BMask, AMask);
   287         font:= CheckCJKFont(s, font);
   288 
   288         w:= 0; h:= 0; // avoid compiler hints
   289     TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   289         TTF_SizeUTF8(Fontz[font].Handle, PChar(s), @w, @h);
   290 
   290         if (maxLength <> 0) and (w > maxLength) then w := maxLength;
   291     WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength);
   291 
   292 
   292         finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + cFontBorder * 2 + 4, h + cFontBorder * 2,
   293     TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   293                 32, RMask, GMask, BMask, AMask);
   294 
   294 
   295     RenderStringTexLim:= Surface2Tex(finalSurface, false);
   295         TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true);
   296 
   296 
   297     SDL_FreeSurface(finalSurface);
   297         WriteInRoundRect(finalSurface, 0, 0, Color, font, s, maxLength);
       
   298 
       
   299         TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
       
   300 
       
   301         RenderStringTexLim:= Surface2Tex(finalSurface, false);
       
   302 
       
   303         SDL_FreeSurface(finalSurface);
       
   304         end;
   298 end;
   305 end;
   299 
   306 
   300 
   307 
   301 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   308 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;
   309 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   306     chars: set of char = [#9,' ',';',':','?','!',','];
   313     chars: set of char = [#9,' ',';',':','?','!',','];
   307     {$ENDIF}
   314     {$ENDIF}
   308     substr: shortstring;
   315     substr: shortstring;
   309     edge, corner, tail: TSPrite;
   316     edge, corner, tail: TSPrite;
   310 begin
   317 begin
   311       case SpeechType of
   318     if cOnlyStats then exit(nil);
       
   319 
       
   320     case SpeechType of
   312         1: begin;
   321         1: begin;
   313         edge:= sprSpeechEdge;
   322             edge:= sprSpeechEdge;
   314         corner:= sprSpeechCorner;
   323             corner:= sprSpeechCorner;
   315         tail:= sprSpeechTail;
   324             tail:= sprSpeechTail;
   316         end;
   325             end;
   317         2: begin;
   326         2: begin;
   318         edge:= sprThoughtEdge;
   327             edge:= sprThoughtEdge;
   319         corner:= sprThoughtCorner;
   328             corner:= sprThoughtCorner;
   320         tail:= sprThoughtTail;
   329             tail:= sprThoughtTail;
   321         end;
   330             end;
   322         3: begin;
   331         3: begin;
   323         edge:= sprShoutEdge;
   332             edge:= sprShoutEdge;
   324         corner:= sprShoutCorner;
   333             corner:= sprShoutCorner;
   325         tail:= sprShoutTail;
   334             tail:= sprShoutTail;
   326         end;
   335             end;
   327         end;
   336         end;
   328     edgeHeight:= SpritesData[edge].Height;
   337     edgeHeight:= SpritesData[edge].Height;
   329     edgeWidth:= SpritesData[edge].Width;
   338     edgeWidth:= SpritesData[edge].Width;
   330     cornerWidth:= SpritesData[corner].Width;
   339     cornerWidth:= SpritesData[corner].Width;
   331     cornerHeight:= SpritesData[corner].Height;
   340     cornerHeight:= SpritesData[corner].Height;