98 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
98 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
99 var w, h: LongInt; |
99 var w, h: LongInt; |
100 tmpsurf: PSDL_Surface; |
100 tmpsurf: PSDL_Surface; |
101 clr: TSDL_Color; |
101 clr: TSDL_Color; |
102 Result: TSDL_Rect; |
102 Result: TSDL_Rect; |
103 ps: array[byte] of char; |
103 begin |
104 begin |
104 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
105 ps:= s; |
|
106 TTF_SizeUTF8(Fontz[Font].Handle, @ps, w, h); |
|
107 Result.x:= X; |
105 Result.x:= X; |
108 Result.y:= Y; |
106 Result.y:= Y; |
109 Result.w:= w + FontBorder * 2 + 4; |
107 Result.w:= w + FontBorder * 2 + 4; |
110 Result.h:= h + FontBorder * 2; |
108 Result.h:= h + FontBorder * 2; |
111 DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
109 DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
112 clr.r:= Color shr 16; |
110 clr.r:= Color shr 16; |
113 clr.g:= (Color shr 8) and $FF; |
111 clr.g:= (Color shr 8) and $FF; |
114 clr.b:= Color and $FF; |
112 clr.b:= Color and $FF; |
115 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, @ps, clr.value); |
113 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
116 Result.x:= X + FontBorder + 2; |
114 Result.x:= X + FontBorder + 2; |
117 Result.y:= Y + FontBorder; |
115 Result.y:= Y + FontBorder; |
118 SDLTry(tmpsurf <> nil, true); |
116 SDLTry(tmpsurf <> nil, true); |
119 SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
117 SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
120 SDL_FreeSurface(tmpsurf); |
118 SDL_FreeSurface(tmpsurf); |
251 WriteLnToConsole(msgOK); |
249 WriteLnToConsole(msgOK); |
252 val(s, cExplosionBorderColor, c); |
250 val(s, cExplosionBorderColor, c); |
253 AdjustColor(cExplosionBorderColor); |
251 AdjustColor(cExplosionBorderColor); |
254 end; |
252 end; |
255 |
253 |
256 var ps: array[byte] of char; |
|
257 |
|
258 begin |
254 begin |
259 for fi:= Low(THWFont) to High(THWFont) do |
255 for fi:= Low(THWFont) to High(THWFont) do |
260 with Fontz[fi] do |
256 with Fontz[fi] do |
261 begin |
257 begin |
262 s:= Pathz[ptFonts] + '/' + Name; |
258 s:= Pathz[ptFonts] + '/' + Name; |
263 WriteToConsole(msgLoading + s + '... '); |
259 WriteToConsole(msgLoading + s + '... '); |
264 ps:= s; |
260 Handle:= TTF_OpenFont(Str2PChar(s), Height); |
265 Handle:= TTF_OpenFont(@ps, Height); |
|
266 SDLTry(Handle <> nil, true); |
261 SDLTry(Handle <> nil, true); |
267 TTF_SetFontStyle(Handle, style); |
262 TTF_SetFontStyle(Handle, style); |
268 WriteLnToConsole(msgOK) |
263 WriteLnToConsole(msgOK) |
269 end; |
264 end; |
270 AddProgress; |
265 AddProgress; |
377 |
372 |
378 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
373 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
379 var clr: TSDL_Color; |
374 var clr: TSDL_Color; |
380 tmpsurf: PSDL_Surface; |
375 tmpsurf: PSDL_Surface; |
381 r: TSDL_Rect; |
376 r: TSDL_Rect; |
382 ps: array[byte] of Char; |
|
383 begin |
377 begin |
384 r.x:= X; |
378 r.x:= X; |
385 r.y:= Y; |
379 r.y:= Y; |
386 clr.r:= $FF; |
380 clr.r:= $FF; |
387 clr.g:= $FF; |
381 clr.g:= $FF; |
388 clr.b:= $FF; |
382 clr.b:= $FF; |
389 ps:= s; |
383 tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
390 tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, @ps, clr.value); |
|
391 if tmpsurf = nil then |
384 if tmpsurf = nil then |
392 begin |
385 begin |
393 SetKB(1); |
386 SetKB(1); |
394 exit |
387 exit |
395 end; |
388 end; |
444 SDL_FreeSurface(StoreSurface ) |
437 SDL_FreeSurface(StoreSurface ) |
445 end; |
438 end; |
446 |
439 |
447 function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
440 function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
448 var w, h: Longint; |
441 var w, h: Longint; |
449 ps: array[byte] of Char; |
|
450 Result: PSDL_Surface; |
442 Result: PSDL_Surface; |
451 begin |
443 begin |
452 ps:= s; |
444 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
453 TTF_SizeUTF8(Fontz[font].Handle, @ps, w, h); |
|
454 Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
445 Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
455 cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
446 cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
456 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
447 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
457 WriteInRoundRect(Result, 0, 0, Color, font, s); |
448 WriteInRoundRect(Result, 0, 0, Color, font, s); |
458 TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
449 TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
493 end; |
484 end; |
494 end; |
485 end; |
495 |
486 |
496 function LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
487 function LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
497 var tmpsurf: PSDL_Surface; |
488 var tmpsurf: PSDL_Surface; |
498 ps: array[byte] of char; |
|
499 Result: PSDL_Surface; |
489 Result: PSDL_Surface; |
|
490 s: shortstring; |
500 begin |
491 begin |
501 WriteToConsole(msgLoading + filename + '... '); |
492 WriteToConsole(msgLoading + filename + '... '); |
502 ps:= filename + '.' + cBitsStr + '.png'; |
493 s:= filename + '.' + cBitsStr + '.png'; |
503 tmpsurf:= IMG_Load(@ps); |
494 tmpsurf:= IMG_Load(Str2PChar(s)); |
504 |
495 |
505 if tmpsurf = nil then |
496 if tmpsurf = nil then |
506 begin |
497 begin |
507 ps:= filename + '.png'; |
498 s:= filename + '.png'; |
508 tmpsurf:= IMG_Load(ps); |
499 tmpsurf:= IMG_Load(Str2PChar(s)); |
509 end; |
500 end; |
510 |
501 |
511 if tmpsurf = nil then |
502 if tmpsurf = nil then |
512 if critical then OutError(msgFailed, true) |
503 if critical then OutError(msgFailed, true) |
513 else begin |
504 else begin |