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 |
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); |