hedgewars/uRenderUtils.pas
changeset 10689 692649e341fc
parent 10687 2e921409b5b1
child 10690 c3b73dc33294
equal deleted inserted replaced
10688:9459c45b5190 10689:692649e341fc
   302 
   302 
   303         SDL_FreeSurface(finalSurface);
   303         SDL_FreeSurface(finalSurface);
   304         end;
   304         end;
   305 end;
   305 end;
   306 
   306 
   307 function GetNextSpeechLine(s: ansistring; ldelim: char; var startFrom: LongInt; out substr: shortstring): boolean;
   307 function GetNextSpeechLine(s: ansistring; ldelim: char; var startFrom: LongInt; out substr: ansistring): boolean;
   308 var p, l, m, r: Integer;
   308 var p, l, m, r: Integer;
   309     newl      : boolean;
   309     newl      : boolean;
   310     c         : char;
   310     c         : char;
   311 begin
   311 begin
   312     m:= Length(s);
   312     m:= Length(s);
   313 
   313 
   314     SetLength(substr, m);
   314     SetLengthA(substr, m);
   315 
   315 
   316     // number of chars read
   316     // number of chars read
   317     r:= 0;
   317     r:= 0;
   318 
   318 
   319     // number of chars to be written
   319     // number of chars to be written
   338         substr[l]:= c;
   338         substr[l]:= c;
   339         end;
   339         end;
   340 
   340 
   341     inc(startFrom, r);
   341     inc(startFrom, r);
   342 
   342 
   343     SetLength(substr, l);
   343     SetLengthA(substr, l);
   344 
   344 
   345     GetNextSpeechLine:= (l > 0);
   345     GetNextSpeechLine:= (l > 0);
   346 end;
   346 end;
   347 
   347 
   348 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   348 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   350     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   350     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   351     rect: TSDL_Rect;
   351     rect: TSDL_Rect;
   352     {$IFNDEF PAS2C}
   352     {$IFNDEF PAS2C}
   353     chars: set of char = [#9,' ',';',':','?','!',','];
   353     chars: set of char = [#9,' ',';',':','?','!',','];
   354     {$ENDIF}
   354     {$ENDIF}
   355     substr: shortstring;
   355     substr: ansistring;
   356     edge, corner, tail: TSPrite;
   356     edge, corner, tail: TSPrite;
   357 begin
   357 begin
   358     if cOnlyStats then exit(nil);
   358     if cOnlyStats then exit(nil);
   359 
   359 
   360     case SpeechType of
   360     case SpeechType of
   406     // Find the longest line for the purposes of centring the text.  Font dependant.
   406     // Find the longest line for the purposes of centring the text.  Font dependant.
   407         while GetNextSpeechLine(s, #1, pos, substr) do
   407         while GetNextSpeechLine(s, #1, pos, substr) do
   408             begin
   408             begin
   409             inc(numLines);
   409             inc(numLines);
   410             i:= 0; j:= 0;
   410             i:= 0; j:= 0;
   411             TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j);
   411             TTF_SizeUTF8(Fontz[font].Handle, PChar(substr), @i, @j);
   412             if i > w then
   412             if i > w then
   413                 w:= i;
   413                 w:= i;
   414             end;
   414             end;
   415         end
   415         end
   416     else numLines := 1;
   416     else numLines := 1;
   507     SDL_FillRect(finalSurface, @rect, cWhiteColor);
   507     SDL_FillRect(finalSurface, @rect, cWhiteColor);
   508 
   508 
   509     pos:= 1; line:= 0;
   509     pos:= 1; line:= 0;
   510     while GetNextSpeechLine(s, #1, pos, substr) do
   510     while GetNextSpeechLine(s, #1, pos, substr) do
   511         begin
   511         begin
   512         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels);
   512         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(substr), cNearBlackColorChannels);
   513         rect.x:= edgeHeight + 1 + ((i - w) div 2);
   513         rect.x:= edgeHeight + 1 + ((i - w) div 2);
   514         // trying to more evenly position the text, vertically
   514         // trying to more evenly position the text, vertically
   515         rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
   515         rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
   516         SDLTry(tmpsurf <> nil, true);
   516         SDLTry(tmpsurf <> nil, true);
   517         SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);
   517         SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);