# HG changeset patch # User unc0rr # Date 1161018630 0 # Node ID 6f00e0f4cb8823b4b7e77542176243ee7cd54244 # Parent 8a7123b84d1bb07400fe5a8f7838d17e9f4470c0 - New crosshair - Text rendering checks diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/SDLh.pas Mon Oct 16 17:10:30 2006 +0000 @@ -236,9 +236,9 @@ procedure TTF_Quit; cdecl; external SDL_TTFLibName; -function TTF_SizeUTF8(font : PTTF_Font; const text: PChar; var w, h: integer): LongInt; cdecl; external SDL_TTFLibName; -function TTF_RenderUTF8_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; -function TTF_RenderUTF8_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; +function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: integer): LongInt; cdecl; external SDL_TTFLibName; +function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; +function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; (* SDL_mixer *) diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/uAIAmmoTests.pas Mon Oct 16 17:10:30 2006 +0000 @@ -88,7 +88,7 @@ ExplR:= 0; Result:= BadTurn; repeat - rTime:= rTime + 150 + Level * 25 + random * 250; + rTime:= rTime + 300 + Level * 50 + random * 200; Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime; Vy:= cGravity * rTime / 2 - (Targ.Y - Me.Y) / rTime; r:= sqr(Vx) + sqr(Vy); diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/uConsts.pas Mon Oct 16 17:10:30 2006 +0000 @@ -68,6 +68,7 @@ errmsgUnknownVariable = 'Unknown variable'; errmsgIncorrectUse = 'Incorrect use'; errmsgShouldntRun = 'This program shouldn''t be run manually'; + errmsgRenderText = 'Cannot render text'; msgLoading = 'Loading '; msgOK = 'ok'; diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/uStore.pas Mon Oct 16 17:10:30 2006 +0000 @@ -28,6 +28,7 @@ procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); +procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); procedure DrawLand (X, Y: integer; Surface: PSDL_Surface); procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); @@ -37,7 +38,7 @@ function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; procedure RenderHealth(var Hedgehog: THedgehog); procedure AddProgress; -function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; +function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; var PixelFormat: PSDL_PixelFormat; SDLPrimSurface: PSDL_Surface; @@ -110,6 +111,7 @@ tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr); Result.x:= X + 3; Result.y:= Y + 1; +TryDo(tmpsurf <> nil, errmsgRenderText, true); SDL_UpperBlit(tmpsurf, nil, Surface, @Result); SDL_FreeSurface(tmpsurf); Result.x:= X; @@ -159,27 +161,20 @@ procedure MakeCrossHairs; var Team: PTeam; - r: TSDL_Rect; tmpsurf: PSDL_Surface; s: string; - TransColor: Longword; begin - r.x:= 0; - r.y:= 256; - r.w:= 16; - r.h:= 16; s:= Pathz[ptGraphics] + '/' + cCHFileName; - tmpsurf:= LoadImage(PChar(s), false); - TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF); - TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true); + tmpsurf:= LoadImage(PChar(s), true, true, false); Team:= TeamsList; while Team<>nil do begin - SDL_FillRect(StoreSurface, @r, Team.AdjColor); - SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r); - Team.CrossHairRect:= r; - inc(r.x, 16); + Team.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 24, 360, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); + TryDo(Team.CrosshairSurf <> nil, errmsgCreateSurface, true); + SDL_FillRect(Team.CrosshairSurf, nil, Team.AdjColor); + SDL_UpperBlit(tmpsurf, nil, Team.CrosshairSurf, nil); + TryDo(SDL_SetColorKey(Team.CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); Team:= Team.Next end; @@ -345,13 +340,8 @@ end; procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); -var r: TSDL_Rect; begin -r.x:= 0; -r.w:= SpritesData[Sprite].Width; -r.y:= Frame * SpritesData[Sprite].Height; -r.h:= SpritesData[Sprite].Height; -DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) +DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) end; procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); @@ -364,6 +354,16 @@ DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) end; +procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); +var r: TSDL_Rect; +begin +r.x:= 0; +r.w:= Source.w; +r.y:= Frame * Height; +r.h:= Height; +DrawFromRect(X, Y, @r, Source, Surface) +end; + procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); var clr: TSDL_Color; tmpsurf: PSDL_Surface; @@ -375,6 +375,7 @@ clr.g:= $FF; clr.b:= $FF; tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr); +TryDo(tmpsurf <> nil, errmsgRenderText, true); SDL_UpperBlit(tmpsurf, nil, Surface, @r); SDL_FreeSurface(tmpsurf) end; @@ -470,7 +471,7 @@ end; end; -function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; +function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; var tmpsurf: PSDL_Surface; begin WriteToConsole(msgLoading + filename + '... '); @@ -486,7 +487,7 @@ exit end; -TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); +if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf); WriteLnToConsole(msgOK) diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/uTeams.pas Mon Oct 16 17:10:30 2006 +0000 @@ -46,7 +46,7 @@ Ammos: array[0..cMaxHHIndex] of THHAmmo; CurrHedgehog: integer; NameTag: PSDL_Surface; - CrossHairRect, + CrosshairSurf: PSDL_Surface; GraveRect, HealthRect: TSDL_Rect; GraveName: string; FortName: string; diff -r 8a7123b84d1b -r 6f00e0f4cb88 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sat Oct 14 13:13:51 2006 +0000 +++ b/hedgewars/uWorld.pas Mon Oct 16 17:10:30 2006 +0000 @@ -230,12 +230,13 @@ and ((Gear.State and gstHHDriven) <> 0) then DrawSprite(sprFinger, round(Gear.X) - 16 + WorldDx, round(Gear.Y) - 64 + WorldDy, RealTicks div 32 mod 16, Surface); if (Gear.State and (gstMoving or gstDrowning or gstFalling)) = 0 then if (Gear.State and gstHHThinking) <> 0 then - DrawGear(sQuestion, Round(Gear.X) - 10 + WorldDx, Round(Gear.Y) - cHHRadius - 34 + WorldDy, Surface) + DrawGear(sQuestion, Round(Gear.X) - 10 + WorldDx, Round(Gear.Y) - cHHRadius - 34 + WorldDy, Surface) else if ShowCrosshair and ((Gear.State and gstAttacked) = 0) then - DrawCaption(Round(Gear.X + hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle)*60) + WorldDx, - Round(Gear.Y - Cos(Gear.Angle*pi/cMaxAngle)*60) + WorldDy - 4, - Team.CrossHairRect, Surface) + DrawSurfSprite(Round(Gear.X + hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle)*60) + WorldDx - 8, + Round(Gear.Y - Cos(Gear.Angle*pi/cMaxAngle)*60) + WorldDy - 12, + 24, 0, + Team.CrosshairSurf, Surface); end; team:= team.Next end; diff -r 8a7123b84d1b -r 6f00e0f4cb88 share/hedgewars/Data/Graphics/Crosshair.png Binary file share/hedgewars/Data/Graphics/Crosshair.png has changed