author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 161 | d8870bbf960e |
child 189 | 33d147c69a83 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uStore; |
|
20 |
interface |
|
21 |
uses uConsts, uTeams, SDLh; |
|
22 |
{$INCLUDE options.inc} |
|
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
27 |
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
28 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
161 | 29 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
43 | 30 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
4 | 31 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface); |
32 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
95 | 33 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
34 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
47 | 35 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
4 | 36 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
108 | 37 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
4 | 38 |
procedure RenderHealth(var Hedgehog: THedgehog); |
39 |
procedure AddProgress; |
|
80 | 40 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; |
4 | 41 |
|
42 |
var PixelFormat: PSDL_PixelFormat; |
|
43 |
SDLPrimSurface: PSDL_Surface; |
|
44 |
||
45 |
implementation |
|
53 | 46 |
uses uMisc, uIO, uConsole, uLand, uCollisions; |
4 | 47 |
|
48 |
var StoreSurface, |
|
49 |
HHSurface: PSDL_Surface; |
|
50 |
||
51 |
procedure StoreInit; |
|
52 |
begin |
|
74 | 53 |
StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); |
4 | 54 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); |
37 | 55 |
SDL_FillRect(StoreSurface, nil, 0); |
4 | 56 |
|
57 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
58 |
end; |
|
59 |
||
60 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); |
|
61 |
var tmpsurf: PSDL_Surface; |
|
62 |
rr: TSDL_Rect; |
|
63 |
begin |
|
35 | 64 |
tmpsurf:= LoadImage(Filename, false); |
4 | 65 |
rr.x:= X; |
66 |
rr.y:= Y; |
|
67 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr); |
|
68 |
SDL_FreeSurface(tmpsurf); |
|
69 |
end; |
|
70 |
||
83 | 71 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; const Clear: boolean = true); |
47 | 72 |
var r: TSDL_Rect; |
73 |
begin |
|
74 |
r:= rect^; |
|
83 | 75 |
if Clear then SDL_FillRect(Surface, @r, 0); |
47 | 76 |
r.y:= rect.y + 1; |
77 |
r.h:= rect.h - 2; |
|
78 |
SDL_FillRect(Surface, @r, BorderColor); |
|
79 |
r.x:= rect.x + 1; |
|
80 |
r.w:= rect.w - 2; |
|
81 |
r.y:= rect.y; |
|
82 |
r.h:= rect.h; |
|
83 |
SDL_FillRect(Surface, @r, BorderColor); |
|
84 |
r.x:= rect.x + 2; |
|
85 |
r.y:= rect.y + 1; |
|
86 |
r.w:= rect.w - 4; |
|
87 |
r.h:= rect.h - 2; |
|
88 |
SDL_FillRect(Surface, @r, FillColor); |
|
89 |
r.x:= rect.x + 1; |
|
90 |
r.y:= rect.y + 2; |
|
91 |
r.w:= rect.w - 2; |
|
92 |
r.h:= rect.h - 4; |
|
93 |
SDL_FillRect(Surface, @r, FillColor) |
|
94 |
end; |
|
95 |
||
4 | 96 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
97 |
var w, h: integer; |
|
98 |
tmpsurf: PSDL_Surface; |
|
99 |
clr: TSDL_Color; |
|
100 |
begin |
|
74 | 101 |
TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), w, h); |
4 | 102 |
Result.x:= X; |
103 |
Result.y:= Y; |
|
104 |
Result.w:= w + 6; |
|
74 | 105 |
Result.h:= h + 2; |
47 | 106 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface); |
4 | 107 |
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b); |
74 | 108 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr); |
4 | 109 |
Result.x:= X + 3; |
74 | 110 |
Result.y:= Y + 1; |
4 | 111 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
112 |
SDL_FreeSurface(tmpsurf); |
|
113 |
Result.x:= X; |
|
114 |
Result.y:= Y; |
|
115 |
Result.w:= w + 6; |
|
74 | 116 |
Result.h:= h + 2 |
4 | 117 |
end; |
118 |
||
119 |
procedure StoreLoad; |
|
120 |
var i: TStuff; |
|
121 |
ii: TSprite; |
|
122 |
fi: THWFont; |
|
123 |
s: string; |
|
124 |
tmpsurf: PSDL_Surface; |
|
125 |
||
126 |
procedure WriteNames(Font: THWFont); |
|
127 |
var Team: PTeam; |
|
128 |
i: integer; |
|
47 | 129 |
r, rr: TSDL_Rect; |
49 | 130 |
drY: integer; |
4 | 131 |
begin |
132 |
r.x:= 0; |
|
133 |
r.y:= 272; |
|
70 | 134 |
drY:= cScreenHeight - 4; |
4 | 135 |
Team:= TeamsList; |
136 |
while Team<>nil do |
|
137 |
begin |
|
47 | 138 |
r.w:= 104; |
95 | 139 |
Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font); |
47 | 140 |
r.w:= cTeamHealthWidth + 5; |
95 | 141 |
r.h:= Team.NameTag.h; |
47 | 142 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface); |
143 |
Team.HealthRect:= r; |
|
144 |
rr:= r; |
|
145 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
83 | 146 |
DrawRoundRect(@rr, Team.Color, Team.Color, StoreSurface, false); |
47 | 147 |
inc(r.y, r.h); |
49 | 148 |
dec(drY, r.h + 2); |
149 |
Team.DrawHealthY:= drY; |
|
4 | 150 |
for i:= 0 to 7 do |
95 | 151 |
with Team.Hedgehogs[i] do |
152 |
if Gear <> nil then |
|
153 |
NameTag:= RenderString(Name, Team.Color, fnt16); |
|
4 | 154 |
Team:= Team.Next |
155 |
end; |
|
156 |
end; |
|
157 |
||
158 |
procedure MakeCrossHairs; |
|
159 |
var Team: PTeam; |
|
160 |
r: TSDL_Rect; |
|
161 |
tmpsurf: PSDL_Surface; |
|
162 |
s: string; |
|
163 |
TransColor: Longword; |
|
164 |
begin |
|
165 |
r.x:= 0; |
|
166 |
r.y:= 256; |
|
167 |
r.w:= 16; |
|
168 |
r.h:= 16; |
|
53 | 169 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
74 | 170 |
tmpsurf:= LoadImage(PChar(s), false); |
4 | 171 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF); |
172 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true); |
|
173 |
||
174 |
Team:= TeamsList; |
|
175 |
while Team<>nil do |
|
176 |
begin |
|
177 |
SDL_FillRect(StoreSurface, @r, Team.Color); |
|
178 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r); |
|
179 |
Team.CrossHairRect:= r; |
|
180 |
inc(r.x, 16); |
|
181 |
Team:= Team.Next |
|
182 |
end; |
|
183 |
||
184 |
SDL_FreeSurface(tmpsurf) |
|
185 |
end; |
|
186 |
||
187 |
procedure InitHealth; |
|
188 |
var p: PTeam; |
|
95 | 189 |
i: integer; |
4 | 190 |
begin |
191 |
p:= TeamsList; |
|
192 |
while p <> nil do |
|
193 |
begin |
|
194 |
for i:= 0 to cMaxHHIndex do |
|
195 |
if p.Hedgehogs[i].Gear <> nil then |
|
196 |
RenderHealth(p.Hedgehogs[i]); |
|
197 |
p:= p.Next |
|
198 |
end |
|
199 |
end; |
|
200 |
||
201 |
procedure LoadGraves; |
|
202 |
var p: PTeam; |
|
203 |
l: integer; |
|
204 |
begin |
|
205 |
p:= TeamsList; |
|
206 |
l:= 512; |
|
207 |
while p <> nil do |
|
208 |
begin |
|
209 |
dec(l, 32); |
|
210 |
if p.GraveName = '' then p.GraveName:= 'Simple'; |
|
74 | 211 |
LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName, StoreSurface, l, 512); |
4 | 212 |
p.GraveRect.x:= l; |
213 |
p.GraveRect.y:= 512; |
|
214 |
p.GraveRect.w:= 32; |
|
215 |
p.GraveRect.h:= 256; |
|
216 |
p:= p.Next |
|
217 |
end |
|
218 |
end; |
|
219 |
||
220 |
procedure GetSkyColor; |
|
107 | 221 |
var p: PByteArray; |
4 | 222 |
begin |
80 | 223 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
224 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
107 | 225 |
p:= SpritesData[sprSky].Surface.pixels; |
80 | 226 |
case SpritesData[sprSky].Surface.format.BytesPerPixel of |
4 | 227 |
1: cSkyColor:= PByte(p)^; |
228 |
2: cSkyColor:= PWord(p)^; |
|
107 | 229 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 230 |
4: cSkyColor:= PLongword(p)^; |
231 |
end; |
|
80 | 232 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
233 |
SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 234 |
end; |
235 |
||
236 |
procedure GetExplosionBorderColor; |
|
237 |
var f: textfile; |
|
238 |
c: integer; |
|
239 |
begin |
|
80 | 240 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 241 |
WriteToConsole(msgLoading + s + ' '); |
242 |
AssignFile(f, s); |
|
243 |
{$I-} |
|
244 |
Reset(f); |
|
245 |
Readln(f, s); |
|
246 |
Closefile(f); |
|
247 |
{$I+} |
|
248 |
TryDo(IOResult = 0, msgFailed, true); |
|
249 |
WriteLnToConsole(msgOK); |
|
250 |
val(s, cExplosionBorderColor, c); |
|
251 |
if cFullScreen then |
|
252 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF, |
|
253 |
(cExplosionBorderColor shr 8) and $FF, |
|
254 |
cExplosionBorderColor and $FF) |
|
255 |
else |
|
256 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF, |
|
257 |
(cExplosionBorderColor shr 8) and $FF, |
|
258 |
cExplosionBorderColor and $FF) |
|
259 |
end; |
|
260 |
||
261 |
begin |
|
262 |
for fi:= Low(THWFont) to High(THWFont) do |
|
263 |
with Fontz[fi] do |
|
264 |
begin |
|
53 | 265 |
s:= Pathz[ptFonts] + '/' + Name; |
4 | 266 |
WriteToConsole(msgLoading + s + ' '); |
267 |
Handle:= TTF_OpenFont(PChar(s), Height); |
|
268 |
TryDo(Handle <> nil, msgFailed, true); |
|
269 |
WriteLnToConsole(msgOK) |
|
270 |
end; |
|
271 |
AddProgress; |
|
53 | 272 |
|
105 | 273 |
WriteToConsole('LandSurface tuning... '); |
4 | 274 |
tmpsurf:= LandSurface; |
275 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
276 |
if cFullScreen then |
|
277 |
begin |
|
278 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
279 |
SDL_FreeSurface(tmpsurf); |
|
280 |
end else LandSurface:= tmpsurf; |
|
35 | 281 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 282 |
WriteLnToConsole(msgOK); |
283 |
||
284 |
GetExplosionBorderColor; |
|
285 |
||
286 |
AddProgress; |
|
287 |
for i:= Low(TStuff) to High(TStuff) do |
|
53 | 288 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y); |
4 | 289 |
|
290 |
AddProgress; |
|
291 |
WriteNames(fnt16); |
|
70 | 292 |
MakeCrossHairs; |
4 | 293 |
LoadGraves; |
294 |
||
295 |
AddProgress; |
|
296 |
for ii:= Low(TSprite) to High(TSprite) do |
|
297 |
with SpritesData[ii] do |
|
80 | 298 |
begin |
299 |
if AltPath = ptNone then |
|
300 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha) |
|
301 |
else begin |
|
302 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false); |
|
303 |
if Surface = nil then |
|
304 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha) |
|
305 |
end; |
|
306 |
if Width = 0 then Width:= Surface.w; |
|
307 |
if Height = 0 then Height:= Surface.h |
|
308 |
end; |
|
309 |
||
310 |
GetSkyColor; |
|
4 | 311 |
|
312 |
AddProgress; |
|
53 | 313 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false); |
35 | 314 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
4 | 315 |
HHSurface:= SDL_DisplayFormat(tmpsurf); |
316 |
SDL_FreeSurface(tmpsurf); |
|
317 |
||
318 |
InitHealth; |
|
319 |
||
320 |
{$IFDEF DUMP} |
|
321 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
322 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
323 |
{$ENDIF} |
|
324 |
end; |
|
325 |
||
326 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
|
327 |
var rr: TSDL_Rect; |
|
328 |
begin |
|
329 |
rr.x:= X; |
|
330 |
rr.y:= Y; |
|
331 |
rr.w:= r.w; |
|
332 |
rr.h:= r.h; |
|
333 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
|
334 |
begin |
|
43 | 335 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 336 |
exit |
337 |
end; |
|
338 |
end; |
|
339 |
||
340 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
341 |
begin |
|
342 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
343 |
end; |
|
344 |
||
345 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
346 |
begin |
|
347 |
r.y:= r.y + Height * Position; |
|
348 |
r.h:= Height; |
|
349 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
350 |
end; |
|
351 |
||
161 | 352 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
4 | 353 |
var r: TSDL_Rect; |
354 |
begin |
|
355 |
r.x:= 0; |
|
356 |
r.w:= SpritesData[Sprite].Width; |
|
161 | 357 |
r.y:= Frame * SpritesData[Sprite].Height; |
4 | 358 |
r.h:= SpritesData[Sprite].Height; |
359 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
360 |
end; |
|
361 |
||
43 | 362 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
363 |
var r: TSDL_Rect; |
|
364 |
begin |
|
365 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
366 |
r.w:= SpritesData[Sprite].Width; |
|
367 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
368 |
r.h:= SpritesData[Sprite].Height; |
|
369 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
370 |
end; |
|
371 |
||
4 | 372 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
373 |
var clr: TSDL_Color; |
|
374 |
tmpsurf: PSDL_Surface; |
|
375 |
r: TSDL_Rect; |
|
376 |
begin |
|
377 |
r.x:= X; |
|
378 |
r.y:= Y; |
|
379 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b); |
|
74 | 380 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr); |
4 | 381 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
382 |
SDL_FreeSurface(tmpsurf) |
|
383 |
end; |
|
384 |
||
385 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface); |
|
386 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
|
387 |
begin |
|
388 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
389 |
end; |
|
390 |
||
47 | 391 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
392 |
begin |
|
393 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
394 |
end; |
|
395 |
||
95 | 396 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 397 |
begin |
95 | 398 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
399 |
end; |
|
400 |
||
401 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
402 |
var r: TSDL_Rect; |
|
403 |
begin |
|
404 |
r.x:= X - Source.w div 2; |
|
405 |
r.y:= Top; |
|
406 |
r.w:= Source.w; |
|
407 |
r.h:= Source.h; |
|
408 |
SDL_UpperBlit(Source, nil, Surface, @r) |
|
4 | 409 |
end; |
410 |
||
411 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
|
412 |
var r: TSDL_Rect; |
|
413 |
begin |
|
414 |
r.x:= Step * 32; |
|
415 |
r.y:= Pos * 32; |
|
416 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x; |
|
417 |
r.w:= 32; |
|
418 |
r.h:= 32; |
|
419 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
420 |
end; |
|
421 |
||
422 |
procedure StoreRelease; |
|
423 |
var ii: TSprite; |
|
424 |
begin |
|
425 |
for ii:= Low(TSprite) to High(TSprite) do |
|
426 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
427 |
SDL_FreeSurface( HHSurface ); |
|
428 |
SDL_FreeSurface(LandSurface ); |
|
429 |
SDL_FreeSurface(StoreSurface ) |
|
430 |
end; |
|
431 |
||
108 | 432 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
95 | 433 |
var w, h: integer; |
434 |
begin |
|
108 | 435 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
95 | 436 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); |
107 | 437 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 438 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
439 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
|
440 |
end; |
|
441 |
||
4 | 442 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 443 |
var s: shortstring; |
4 | 444 |
begin |
445 |
str(Hedgehog.Gear.Health, s); |
|
95 | 446 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
447 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
|
4 | 448 |
end; |
449 |
||
450 |
procedure AddProgress; |
|
451 |
const Step: Longword = 0; |
|
452 |
ProgrSurf: PSDL_Surface = nil; |
|
71 | 453 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
4 | 454 |
var r: TSDL_Rect; |
455 |
begin |
|
456 |
if Step = 0 then |
|
457 |
begin |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
458 |
WriteToConsole(msgLoading + 'progress sprite: '); |
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
459 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false); |
4 | 460 |
end; |
461 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
462 |
r.x:= 0; |
|
463 |
r.w:= 32; |
|
464 |
r.h:= 32; |
|
71 | 465 |
r.y:= (Step mod 10) * 32; |
4 | 466 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface); |
467 |
SDL_Flip(SDLPrimSurface); |
|
468 |
inc(Step); |
|
469 |
if Step = MaxCalls then |
|
470 |
begin |
|
471 |
WriteLnToConsole('Freeing progress surface... '); |
|
472 |
SDL_FreeSurface(ProgrSurf) |
|
473 |
end; |
|
474 |
end; |
|
475 |
||
80 | 476 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; |
30 | 477 |
var tmpsurf: PSDL_Surface; |
4 | 478 |
begin |
479 |
WriteToConsole(msgLoading + filename + '... '); |
|
74 | 480 |
tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png')); |
481 |
if tmpsurf = nil then |
|
482 |
tmpsurf:= IMG_Load(PChar(filename + '.png')); |
|
80 | 483 |
|
484 |
if tmpsurf = nil then |
|
485 |
if critical then OutError(msgFailed, true) |
|
486 |
else begin |
|
487 |
WriteLnToConsole(msgFailed); |
|
488 |
Result:= nil; |
|
489 |
exit |
|
490 |
end; |
|
491 |
||
35 | 492 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 493 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
494 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
4 | 495 |
WriteLnToConsole(msgOK) |
496 |
end; |
|
497 |
||
498 |
end. |