36 procedure DrawFromStoreRect(X, Y: LongInt; Rect: PSDL_Rect; Surface: PSDL_Surface); |
36 procedure DrawFromStoreRect(X, Y: LongInt; Rect: PSDL_Rect; Surface: PSDL_Surface); |
37 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
37 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
38 function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
38 function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
39 procedure RenderHealth(var Hedgehog: THedgehog); |
39 procedure RenderHealth(var Hedgehog: THedgehog); |
40 procedure AddProgress; |
40 procedure AddProgress; |
|
41 procedure FinishProgress; |
41 function LoadImage(filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
42 function LoadImage(filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
42 |
43 |
43 var PixelFormat: PSDL_PixelFormat; |
44 var PixelFormat: PSDL_PixelFormat; |
44 SDLPrimSurface: PSDL_Surface; |
45 SDLPrimSurface: PSDL_Surface; |
45 PauseSurface: PSDL_Surface; |
46 PauseSurface: PSDL_Surface; |
457 str(Hedgehog.Gear^.Health, s); |
458 str(Hedgehog.Gear^.Health, s); |
458 if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
459 if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
459 Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
460 Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
460 end; |
461 end; |
461 |
462 |
462 procedure AddProgress; |
|
463 const Step: Longword = 0; |
|
464 ProgrSurf: PSDL_Surface = nil; |
|
465 MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
|
466 var r: TSDL_Rect; |
|
467 begin |
|
468 if Step = 0 then |
|
469 begin |
|
470 WriteToConsole(msgLoading + 'progress sprite: '); |
|
471 ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false, true, true); |
|
472 end; |
|
473 SDL_FillRect(SDLPrimSurface, nil, 0); |
|
474 r.x:= 0; |
|
475 r.w:= 32; |
|
476 r.h:= 32; |
|
477 r.y:= (Step mod 10) * 32; |
|
478 DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface); |
|
479 SDL_Flip(SDLPrimSurface); |
|
480 inc(Step); |
|
481 if Step = MaxCalls then |
|
482 begin |
|
483 WriteLnToConsole('Freeing progress surface... '); |
|
484 SDL_FreeSurface(ProgrSurf) |
|
485 end; |
|
486 end; |
|
487 |
|
488 function LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
463 function LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
489 var tmpsurf: PSDL_Surface; |
464 var tmpsurf: PSDL_Surface; |
490 Result: PSDL_Surface; |
465 Result: PSDL_Surface; |
491 s: shortstring; |
466 s: shortstring; |
492 begin |
467 begin |
512 else Result:= SDL_DisplayFormat(tmpsurf); |
487 else Result:= SDL_DisplayFormat(tmpsurf); |
513 WriteLnToConsole(msgOK); |
488 WriteLnToConsole(msgOK); |
514 LoadImage:= Result |
489 LoadImage:= Result |
515 end; |
490 end; |
516 |
491 |
|
492 //////////////////////////////////////////////////////////////////////////////// |
|
493 var ProgrSurf: PSDL_Surface = nil; |
|
494 Step: Longword = 0; |
|
495 |
|
496 procedure AddProgress; |
|
497 var r: TSDL_Rect; |
|
498 begin |
|
499 if Step = 0 then |
|
500 begin |
|
501 WriteToConsole(msgLoading + 'progress sprite: '); |
|
502 ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
503 end; |
|
504 SDL_FillRect(SDLPrimSurface, nil, 0); |
|
505 r.x:= 0; |
|
506 r.w:= ProgrSurf^.w; |
|
507 r.h:= ProgrSurf^.w; |
|
508 r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
509 DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
|
510 (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
511 SDL_Flip(SDLPrimSurface); |
|
512 inc(Step); |
|
513 end; |
|
514 |
|
515 procedure FinishProgress; |
|
516 begin |
|
517 WriteLnToConsole('Freeing progress surface... '); |
|
518 SDL_FreeSurface(ProgrSurf) |
|
519 end; |
|
520 |
517 end. |
521 end. |