hedgewars/uRenderUtils.pas
changeset 15957 e8d94f84d294
parent 15852 c4561095666a
child 15971 cee831693af1
equal deleted inserted replaced
15956:7125918637e9 15957:e8d94f84d294
   320     SDL_UnlockSurface(src);
   320     SDL_UnlockSurface(src);
   321     SDL_UnlockSurface(dest);
   321     SDL_UnlockSurface(dest);
   322 
   322 
   323 end;
   323 end;
   324 
   324 
       
   325 {$IFNDEF PAS2C}
       
   326 // Wraps the text s by inserting breakStr as newlines with
       
   327 // maximum column length maxCol.
       
   328 // Same as Pascal's WrapText, but without the annoying
       
   329 // behavior that text enclosed in " and ' disables word-wrapping
       
   330 function SimpleWrapText(s, breakStr: string; maxCol: integer): string;
       
   331 var
       
   332     breakChars: set of char = [#9,' ','-'];
       
   333 begin
       
   334     // escape the " and ' characters before calling WrapText
       
   335     // using ASCII ESC control character
       
   336     s:= StringReplace(s, '"', #27+'Q', [rfReplaceAll]);
       
   337     s:= StringReplace(s, '''', #27+'q', [rfReplaceAll]);
       
   338 
       
   339     s:= WrapText(s, #1, breakChars, maxCol);
       
   340 
       
   341     // Undo the escapes
       
   342     s:= StringReplace(s, #27+'Q', '"', [rfReplaceAll]);
       
   343     s:= StringReplace(s, #27+'q', '''', [rfReplaceAll]);
       
   344     SimpleWrapText:= s;
       
   345 end;
       
   346 {$ENDIF}
       
   347 
   325 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
   348 function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
   326 begin
   349 begin
   327     RenderStringTex:= RenderStringTexLim(s, Color, font, 0);
   350     RenderStringTex:= RenderStringTexLim(s, Color, font, 0);
   328 end;
   351 end;
   329 
   352 
   411 
   434 
   412 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   435 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   413 var textWidth, textHeight, x, y, w, h, i, j, pos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   436 var textWidth, textHeight, x, y, w, h, i, j, pos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   414     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   437     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   415     rect: TSDL_Rect;
   438     rect: TSDL_Rect;
   416     {$IFNDEF PAS2C}
       
   417     breakChars: set of char = [#9,' ','-'];
       
   418     {$ENDIF}
       
   419     substr: ansistring;
   439     substr: ansistring;
   420     edge, corner, tail: TSPrite;
   440     edge, corner, tail: TSPrite;
   421 begin
   441 begin
   422     if cOnlyStats then exit(nil);
   442     if cOnlyStats then exit(nil);
   423 
   443 
   442         end;
   462         end;
   443     edgeHeight:= SpritesData[edge].Height;
   463     edgeHeight:= SpritesData[edge].Height;
   444     edgeWidth:= SpritesData[edge].Width;
   464     edgeWidth:= SpritesData[edge].Width;
   445     cornerWidth:= SpritesData[corner].Width;
   465     cornerWidth:= SpritesData[corner].Width;
   446     cornerHeight:= SpritesData[corner].Height;
   466     cornerHeight:= SpritesData[corner].Height;
   447     // This one screws up WrapText
       
   448     //s:= 'This is the song that never ends.  ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...';
       
   449     // This one does not
       
   450     //s:= 'This is the song that never ends.  cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... ';
       
   451 
   467 
   452     numLines:= 0;
   468     numLines:= 0;
   453 
   469 
   454     if length(s) = 0 then
   470     if length(s) = 0 then
   455         s:= '...';
   471         s:= '...';
   462     if (length(s) > 20) then
   478     if (length(s) > 20) then
   463         begin
   479         begin
   464         w:= 0;
   480         w:= 0;
   465         i:= round(Sqrt(length(s)) * 2);
   481         i:= round(Sqrt(length(s)) * 2);
   466         {$IFNDEF PAS2C}
   482         {$IFNDEF PAS2C}
   467         s:= WrapText(s, #1, breakChars, i);
   483         s:= SimpleWrapText(s, #1, i);
   468         {$ENDIF}
   484         {$ENDIF}
   469         pos:= 1; line:= 0;
   485         pos:= 1; line:= 0;
   470     // Find the longest line for the purposes of centring the text.  Font dependant.
   486     // Find the longest line for the purposes of centring the text.  Font dependant.
   471         while GetNextSpeechLine(s, #1, pos, substr) do
   487         while GetNextSpeechLine(s, #1, pos, substr) do
   472             begin
   488             begin