35 |
35 |
36 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
36 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
37 var r: TSDL_Rect; |
37 var r: TSDL_Rect; |
38 begin |
38 begin |
39 r:= rect^; |
39 r:= rect^; |
40 if Clear then SDL_FillRect(Surface, @r, 0); |
40 if Clear then |
|
41 SDL_FillRect(Surface, @r, 0); |
41 |
42 |
42 BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
43 BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
43 FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
44 FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
44 |
45 |
45 r.y:= rect^.y + 1; |
46 r.y:= rect^.y + 1; |
224 // This one does not |
225 // This one does not |
225 //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... '; |
226 //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... '; |
226 |
227 |
227 numLines:= 0; |
228 numLines:= 0; |
228 |
229 |
229 if length(s) = 0 then s:= '...'; |
230 if length(s) = 0 then |
|
231 s:= '...'; |
230 font:= CheckCJKFont(s, font); |
232 font:= CheckCJKFont(s, font); |
231 w:= 0; h:= 0; // avoid compiler hints |
233 w:= 0; h:= 0; // avoid compiler hints |
232 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); |
234 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h); |
233 if w<8 then w:= 8; |
235 if w<8 then |
|
236 w:= 8; |
234 j:= 0; |
237 j:= 0; |
235 if (length(s) > 20) then |
238 if (length(s) > 20) then |
236 begin |
239 begin |
237 w:= 0; |
240 w:= 0; |
238 i:= round(Sqrt(length(s)) * 2); |
241 i:= round(Sqrt(length(s)) * 2); |
247 if s[pos] <> #1 then inc(pos); |
250 if s[pos] <> #1 then inc(pos); |
248 while s[prevpos+1] = ' ' do inc(prevpos); |
251 while s[prevpos+1] = ' ' do inc(prevpos); |
249 substr:= copy(s, prevpos+1, pos-prevpos-1); |
252 substr:= copy(s, prevpos+1, pos-prevpos-1); |
250 i:= 0; j:= 0; |
253 i:= 0; j:= 0; |
251 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j); |
254 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j); |
252 if i > w then w:= i; |
255 if i > w then |
|
256 w:= i; |
253 prevpos:= pos; |
257 prevpos:= pos; |
254 end; |
258 end; |
255 inc(pos); |
259 inc(pos); |
256 end; |
260 end; |
257 end |
261 end |
345 pos:= 1; prevpos:= 0; line:= 0; |
349 pos:= 1; prevpos:= 0; line:= 0; |
346 while pos <= length(s) do |
350 while pos <= length(s) do |
347 begin |
351 begin |
348 if (s[pos] = #1) or (pos = length(s)) then |
352 if (s[pos] = #1) or (pos = length(s)) then |
349 begin |
353 begin |
350 if s[pos] <> #1 then inc(pos); |
354 if s[pos] <> #1 then |
351 while s[prevpos+1] = ' 'do inc(prevpos); |
355 inc(pos); |
|
356 while s[prevpos+1] = ' 'do |
|
357 inc(prevpos); |
352 substr:= copy(s, prevpos+1, pos-prevpos-1); |
358 substr:= copy(s, prevpos+1, pos-prevpos-1); |
353 if Length(substr) <> 0 then |
359 if Length(substr) <> 0 then |
354 begin |
360 begin |
355 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); |
361 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); |
356 rect.x:= edgeHeight + 1 + ((i - w) div 2); |
362 rect.x:= edgeHeight + 1 + ((i - w) div 2); |
357 // trying to more evenly position the text, vertically |
363 // trying to more evenly position the text, vertically |
358 rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
364 rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
359 SDLTry(tmpsurf <> nil, true); |
365 SDLTry(tmpsurf <> nil, true); |
360 SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
366 SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
361 SDL_FreeSurface(tmpsurf); |
367 SDL_FreeSurface(tmpsurf); |
362 inc(line); |
368 inc(line); |
363 prevpos:= pos; |
369 prevpos:= pos; |
364 end; |
370 end; |
365 end; |
371 end; |
366 inc(pos); |
372 inc(pos); |
367 end; |
373 end; |
368 |
374 |
369 RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
375 RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
370 |
376 |