33 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
33 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
34 procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
34 procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
35 procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
35 procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
36 procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
36 procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
37 procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
37 procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
38 function RenderString(s: string; Color: integer; 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 function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; |
41 function LoadImage(filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
42 |
42 |
43 var PixelFormat: PSDL_PixelFormat; |
43 var PixelFormat: PSDL_PixelFormat; |
44 SDLPrimSurface: PSDL_Surface; |
44 SDLPrimSurface: PSDL_Surface; |
45 PauseSurface: PSDL_Surface; |
45 PauseSurface: PSDL_Surface; |
46 |
46 |
50 var StoreSurface, |
50 var StoreSurface, |
51 HHSurface: PSDL_Surface; |
51 HHSurface: PSDL_Surface; |
52 |
52 |
53 procedure StoreInit; |
53 procedure StoreInit; |
54 begin |
54 begin |
55 StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
55 StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
56 TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); |
56 TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); |
57 SDL_FillRect(StoreSurface, nil, 0); |
57 SDL_FillRect(StoreSurface, nil, 0); |
58 |
58 |
59 TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
59 TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
60 end; |
60 end; |
61 |
61 |
62 procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); |
62 procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); |
63 var tmpsurf: PSDL_Surface; |
63 var tmpsurf: PSDL_Surface; |
64 rr: TSDL_Rect; |
64 rr: TSDL_Rect; |
65 begin |
65 begin |
66 tmpsurf:= LoadImage(Filename, false); |
66 tmpsurf:= LoadImage(Filename, false, true, false); |
67 rr.x:= X; |
67 rr.x:= X; |
68 rr.y:= Y; |
68 rr.y:= Y; |
69 SDL_UpperBlit(tmpsurf, nil, Surface, @rr); |
69 SDL_UpperBlit(tmpsurf, nil, Surface, @rr); |
70 SDL_FreeSurface(tmpsurf); |
70 SDL_FreeSurface(tmpsurf); |
71 end; |
71 end; |
72 |
72 |
73 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; const Clear: boolean = true); |
73 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
74 var r: TSDL_Rect; |
74 var r: TSDL_Rect; |
75 begin |
75 begin |
76 r:= rect^; |
76 r:= rect^; |
77 if Clear then SDL_FillRect(Surface, @r, 0); |
77 if Clear then SDL_FillRect(Surface, @r, 0); |
78 r.y:= rect.y + 1; |
78 r.y:= rect^.y + 1; |
79 r.h:= rect.h - 2; |
79 r.h:= rect^.h - 2; |
80 SDL_FillRect(Surface, @r, BorderColor); |
80 SDL_FillRect(Surface, @r, BorderColor); |
81 r.x:= rect.x + 1; |
81 r.x:= rect^.x + 1; |
82 r.w:= rect.w - 2; |
82 r.w:= rect^.w - 2; |
83 r.y:= rect.y; |
83 r.y:= rect^.y; |
84 r.h:= rect.h; |
84 r.h:= rect^.h; |
85 SDL_FillRect(Surface, @r, BorderColor); |
85 SDL_FillRect(Surface, @r, BorderColor); |
86 r.x:= rect.x + 2; |
86 r.x:= rect^.x + 2; |
87 r.y:= rect.y + 1; |
87 r.y:= rect^.y + 1; |
88 r.w:= rect.w - 4; |
88 r.w:= rect^.w - 4; |
89 r.h:= rect.h - 2; |
89 r.h:= rect^.h - 2; |
90 SDL_FillRect(Surface, @r, FillColor); |
90 SDL_FillRect(Surface, @r, FillColor); |
91 r.x:= rect.x + 1; |
91 r.x:= rect^.x + 1; |
92 r.y:= rect.y + 2; |
92 r.y:= rect^.y + 2; |
93 r.w:= rect.w - 2; |
93 r.w:= rect^.w - 2; |
94 r.h:= rect.h - 4; |
94 r.h:= rect^.h - 4; |
95 SDL_FillRect(Surface, @r, FillColor) |
95 SDL_FillRect(Surface, @r, FillColor) |
96 end; |
96 end; |
97 |
97 |
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: integer; |
99 var w, h: LongInt; |
100 tmpsurf: PSDL_Surface; |
100 tmpsurf: PSDL_Surface; |
101 clr: TSDL_Color; |
101 clr: TSDL_Color; |
102 begin |
102 Result: TSDL_Rect; |
103 TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), w, h); |
103 ps: array[byte] of char; |
|
104 begin |
|
105 ps:= s; |
|
106 TTF_SizeUTF8(Fontz[Font].Handle, @ps, w, h); |
104 Result.x:= X; |
107 Result.x:= X; |
105 Result.y:= Y; |
108 Result.y:= Y; |
106 Result.w:= w + FontBorder * 2 + 4; |
109 Result.w:= w + FontBorder * 2 + 4; |
107 Result.h:= h + FontBorder * 2; |
110 Result.h:= h + FontBorder * 2; |
108 DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface); |
111 DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
109 clr.r:= Color shr 16; |
112 clr.r:= Color shr 16; |
110 clr.g:= (Color shr 8) and $FF; |
113 clr.g:= (Color shr 8) and $FF; |
111 clr.b:= Color and $FF; |
114 clr.b:= Color and $FF; |
112 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr.value); |
115 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, @ps, clr.value); |
113 Result.x:= X + FontBorder + 2; |
116 Result.x:= X + FontBorder + 2; |
114 Result.y:= Y + FontBorder; |
117 Result.y:= Y + FontBorder; |
115 SDLTry(tmpsurf <> nil, true); |
118 SDLTry(tmpsurf <> nil, true); |
116 SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
119 SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
117 SDL_FreeSurface(tmpsurf); |
120 SDL_FreeSurface(tmpsurf); |
118 Result.x:= X; |
121 Result.x:= X; |
119 Result.y:= Y; |
122 Result.y:= Y; |
120 Result.w:= w + FontBorder * 2 + 4; |
123 Result.w:= w + FontBorder * 2 + 4; |
121 Result.h:= h + FontBorder * 2 |
124 Result.h:= h + FontBorder * 2; |
|
125 WriteInRoundRect:= Result |
122 end; |
126 end; |
123 |
127 |
124 procedure StoreLoad; |
128 procedure StoreLoad; |
125 var i: TStuff; |
129 var i: TStuff; |
126 ii: TSprite; |
130 ii: TSprite; |
139 drY:= cScreenHeight - 4; |
143 drY:= cScreenHeight - 4; |
140 Team:= TeamsList; |
144 Team:= TeamsList; |
141 while Team<>nil do |
145 while Team<>nil do |
142 begin |
146 begin |
143 r.w:= 104; |
147 r.w:= 104; |
144 Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font); |
148 Team^.NameTag:= RenderString(Team^.TeamName, Team^.Color, Font); |
145 r.w:= cTeamHealthWidth + 5; |
149 r.w:= cTeamHealthWidth + 5; |
146 r.h:= Team.NameTag.h; |
150 r.h:= Team^.NameTag^.h; |
147 DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface); |
151 DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface, true); |
148 Team.HealthRect:= r; |
152 Team^.HealthRect:= r; |
149 rr:= r; |
153 rr:= r; |
150 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
154 inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
151 DrawRoundRect(@rr, Team.AdjColor, Team.AdjColor, StoreSurface, false); |
155 DrawRoundRect(@rr, Team^.AdjColor, Team^.AdjColor, StoreSurface, false); |
152 inc(r.y, r.h); |
156 inc(r.y, r.h); |
153 dec(drY, r.h + 2); |
157 dec(drY, r.h + 2); |
154 Team.DrawHealthY:= drY; |
158 Team^.DrawHealthY:= drY; |
155 for i:= 0 to 7 do |
159 for i:= 0 to 7 do |
156 with Team.Hedgehogs[i] do |
160 with Team^.Hedgehogs[i] do |
157 if Gear <> nil then |
161 if Gear <> nil then |
158 NameTag:= RenderString(Name, Team.Color, fnt16); |
162 NameTag:= RenderString(Name, Team^.Color, fnt16); |
159 Team:= Team.Next |
163 Team:= Team^.Next |
160 end; |
164 end; |
161 end; |
165 end; |
162 |
166 |
163 procedure MakeCrossHairs; |
167 procedure MakeCrossHairs; |
164 var Team: PTeam; |
168 var Team: PTeam; |
165 tmpsurf: PSDL_Surface; |
169 tmpsurf: PSDL_Surface; |
166 s: string; |
170 s: string; |
167 begin |
171 begin |
168 s:= Pathz[ptGraphics] + '/' + cCHFileName; |
172 s:= Pathz[ptGraphics] + '/' + cCHFileName; |
169 tmpsurf:= LoadImage(PChar(s), true, true, false); |
173 tmpsurf:= LoadImage(s, true, true, false); |
170 |
174 |
171 Team:= TeamsList; |
175 Team:= TeamsList; |
172 while Team<>nil do |
176 while Team<>nil do |
173 begin |
177 begin |
174 Team.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf.w, tmpsurf.h, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
178 Team^.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
175 TryDo(Team.CrosshairSurf <> nil, errmsgCreateSurface, true); |
179 TryDo(Team^.CrosshairSurf <> nil, errmsgCreateSurface, true); |
176 SDL_FillRect(Team.CrosshairSurf, nil, Team.AdjColor); |
180 SDL_FillRect(Team^.CrosshairSurf, nil, Team^.AdjColor); |
177 SDL_UpperBlit(tmpsurf, nil, Team.CrosshairSurf, nil); |
181 SDL_UpperBlit(tmpsurf, nil, Team^.CrosshairSurf, nil); |
178 TryDo(SDL_SetColorKey(Team.CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
182 TryDo(SDL_SetColorKey(Team^.CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
179 Team:= Team.Next |
183 Team:= Team^.Next |
180 end; |
184 end; |
181 |
185 |
182 SDL_FreeSurface(tmpsurf) |
186 SDL_FreeSurface(tmpsurf) |
183 end; |
187 end; |
184 |
188 |
185 procedure InitHealth; |
189 procedure InitHealth; |
186 var p: PTeam; |
190 var p: PTeam; |
203 p:= TeamsList; |
207 p:= TeamsList; |
204 l:= 512; |
208 l:= 512; |
205 while p <> nil do |
209 while p <> nil do |
206 begin |
210 begin |
207 dec(l, 32); |
211 dec(l, 32); |
208 if p.GraveName = '' then p.GraveName:= 'Simple'; |
212 if p^.GraveName = '' then p^.GraveName:= 'Simple'; |
209 LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName, StoreSurface, l, 512); |
213 LoadToSurface(Pathz[ptGraves] + '/' + p^.GraveName, StoreSurface, l, 512); |
210 p.GraveRect.x:= l; |
214 p^.GraveRect.x:= l; |
211 p.GraveRect.y:= 512; |
215 p^.GraveRect.y:= 512; |
212 p.GraveRect.w:= 32; |
216 p^.GraveRect.w:= 32; |
213 p.GraveRect.h:= 256; |
217 p^.GraveRect.h:= 256; |
214 p:= p.Next |
218 p:= p^.Next |
215 end |
219 end |
216 end; |
220 end; |
217 |
221 |
218 procedure GetSkyColor; |
222 procedure GetSkyColor; |
219 var p: PByteArray; |
223 var p: PByteArray; |
220 begin |
224 begin |
221 if SDL_MustLock(SpritesData[sprSky].Surface) then |
225 if SDL_MustLock(SpritesData[sprSky].Surface) then |
222 SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
226 SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
223 p:= SpritesData[sprSky].Surface.pixels; |
227 p:= SpritesData[sprSky].Surface^.pixels; |
224 case SpritesData[sprSky].Surface.format.BytesPerPixel of |
228 case SpritesData[sprSky].Surface^.format^.BytesPerPixel of |
225 1: cSkyColor:= PByte(p)^; |
229 1: cSkyColor:= PByte(p)^; |
226 2: cSkyColor:= PWord(p)^; |
230 2: cSkyColor:= PWord(p)^; |
227 3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
231 3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
228 4: cSkyColor:= PLongword(p)^; |
232 4: cSkyColor:= PLongword(p)^; |
229 end; |
233 end; |
235 var f: textfile; |
239 var f: textfile; |
236 c: integer; |
240 c: integer; |
237 begin |
241 begin |
238 s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
242 s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
239 WriteToConsole(msgLoading + s + ' '); |
243 WriteToConsole(msgLoading + s + ' '); |
240 AssignFile(f, s); |
244 Assign(f, s); |
241 {$I-} |
245 {$I-} |
242 Reset(f); |
246 Reset(f); |
243 Readln(f, s); |
247 Readln(f, s); |
244 Closefile(f); |
248 Close(f); |
245 {$I+} |
249 {$I+} |
246 TryDo(IOResult = 0, msgFailed, true); |
250 TryDo(IOResult = 0, msgFailed, true); |
247 WriteLnToConsole(msgOK); |
251 WriteLnToConsole(msgOK); |
248 val(s, cExplosionBorderColor, c); |
252 val(s, cExplosionBorderColor, c); |
249 AdjustColor(cExplosionBorderColor); |
253 AdjustColor(cExplosionBorderColor); |
250 end; |
254 end; |
251 |
255 |
|
256 var ps: array[byte] of char; |
|
257 |
252 begin |
258 begin |
253 for fi:= Low(THWFont) to High(THWFont) do |
259 for fi:= Low(THWFont) to High(THWFont) do |
254 with Fontz[fi] do |
260 with Fontz[fi] do |
255 begin |
261 begin |
256 s:= Pathz[ptFonts] + '/' + Name; |
262 s:= Pathz[ptFonts] + '/' + Name; |
257 WriteToConsole(msgLoading + s + '... '); |
263 WriteToConsole(msgLoading + s + '... '); |
258 Handle:= TTF_OpenFont(PChar(s), Height); |
264 ps:= s; |
|
265 Handle:= TTF_OpenFont(@ps, Height); |
259 SDLTry(Handle <> nil, true); |
266 SDLTry(Handle <> nil, true); |
260 TTF_SetFontStyle(Handle, style); |
267 TTF_SetFontStyle(Handle, style); |
261 WriteLnToConsole(msgOK) |
268 WriteLnToConsole(msgOK) |
262 end; |
269 end; |
263 AddProgress; |
270 AddProgress; |
287 AddProgress; |
294 AddProgress; |
288 for ii:= Low(TSprite) to High(TSprite) do |
295 for ii:= Low(TSprite) to High(TSprite) do |
289 with SpritesData[ii] do |
296 with SpritesData[ii] do |
290 begin |
297 begin |
291 if AltPath = ptNone then |
298 if AltPath = ptNone then |
292 Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha) |
299 Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true) |
293 else begin |
300 else begin |
294 Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false); |
301 Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true); |
295 if Surface = nil then |
302 if Surface = nil then |
296 Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha) |
303 Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true) |
297 end; |
304 end; |
298 if Width = 0 then Width:= Surface.w; |
305 if Width = 0 then Width:= Surface^.w; |
299 if Height = 0 then Height:= Surface.h |
306 if Height = 0 then Height:= Surface^.h |
300 end; |
307 end; |
301 |
308 |
302 GetSkyColor; |
309 GetSkyColor; |
303 |
310 |
304 AddProgress; |
311 AddProgress; |
305 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false); |
312 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false, true, true); |
306 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
313 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
307 HHSurface:= SDL_DisplayFormat(tmpsurf); |
314 HHSurface:= SDL_DisplayFormat(tmpsurf); |
308 SDL_FreeSurface(tmpsurf); |
315 SDL_FreeSurface(tmpsurf); |
309 |
316 |
310 InitHealth; |
317 InitHealth; |
360 |
367 |
361 procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); |
368 procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); |
362 var r: TSDL_Rect; |
369 var r: TSDL_Rect; |
363 begin |
370 begin |
364 r.x:= 0; |
371 r.x:= 0; |
365 r.w:= Source.w; |
372 r.w:= Source^.w; |
366 r.y:= Frame * Height; |
373 r.y:= Frame * Height; |
367 r.h:= Height; |
374 r.h:= Height; |
368 DrawFromRect(X, Y, @r, Source, Surface) |
375 DrawFromRect(X, Y, @r, Source, Surface) |
369 end; |
376 end; |
370 |
377 |
371 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
378 procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
372 var clr: TSDL_Color; |
379 var clr: TSDL_Color; |
373 tmpsurf: PSDL_Surface; |
380 tmpsurf: PSDL_Surface; |
374 r: TSDL_Rect; |
381 r: TSDL_Rect; |
|
382 ps: array[byte] of Char; |
375 begin |
383 begin |
376 r.x:= X; |
384 r.x:= X; |
377 r.y:= Y; |
385 r.y:= Y; |
378 clr.r:= $FF; |
386 clr.r:= $FF; |
379 clr.g:= $FF; |
387 clr.g:= $FF; |
380 clr.b:= $FF; |
388 clr.b:= $FF; |
381 tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr.value); |
389 ps:= s; |
|
390 tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, @ps, clr.value); |
382 if tmpsurf = nil then |
391 if tmpsurf = nil then |
383 begin |
392 begin |
384 SetKB(1); |
393 SetKB(1); |
385 exit |
394 exit |
386 end; |
395 end; |
433 SDL_FreeSurface( HHSurface ); |
442 SDL_FreeSurface( HHSurface ); |
434 SDL_FreeSurface(LandSurface ); |
443 SDL_FreeSurface(LandSurface ); |
435 SDL_FreeSurface(StoreSurface ) |
444 SDL_FreeSurface(StoreSurface ) |
436 end; |
445 end; |
437 |
446 |
438 function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
447 function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
439 var w, h: integer; |
448 var w, h: Longint; |
440 begin |
449 ps: array[byte] of Char; |
441 TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
450 Result: PSDL_Surface; |
|
451 begin |
|
452 ps:= s; |
|
453 TTF_SizeUTF8(Fontz[font].Handle, @ps, w, h); |
442 Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
454 Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
443 cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
455 cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
444 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
456 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
445 WriteInRoundRect(Result, 0, 0, Color, font, s); |
457 WriteInRoundRect(Result, 0, 0, Color, font, s); |
446 TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
458 TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
459 RenderString:= Result |
447 end; |
460 end; |
448 |
461 |
449 procedure RenderHealth(var Hedgehog: THedgehog); |
462 procedure RenderHealth(var Hedgehog: THedgehog); |
450 var s: shortstring; |
463 var s: shortstring; |
451 begin |
464 begin |
452 str(Hedgehog.Gear.Health, s); |
465 str(Hedgehog.Gear^.Health, s); |
453 if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
466 if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
454 Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
467 Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
455 end; |
468 end; |
456 |
469 |
457 procedure AddProgress; |
470 procedure AddProgress; |
478 WriteLnToConsole('Freeing progress surface... '); |
491 WriteLnToConsole('Freeing progress surface... '); |
479 SDL_FreeSurface(ProgrSurf) |
492 SDL_FreeSurface(ProgrSurf) |
480 end; |
493 end; |
481 end; |
494 end; |
482 |
495 |
483 function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; |
496 function LoadImage(filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
484 var tmpsurf: PSDL_Surface; |
497 var tmpsurf: PSDL_Surface; |
|
498 ps: array[byte] of char; |
|
499 Result: PSDL_Surface; |
485 begin |
500 begin |
486 WriteToConsole(msgLoading + filename + '... '); |
501 WriteToConsole(msgLoading + filename + '... '); |
487 tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png')); |
502 ps:= filename + '.' + cBitsStr + '.png'; |
|
503 tmpsurf:= IMG_Load(@ps); |
|
504 |
488 if tmpsurf = nil then |
505 if tmpsurf = nil then |
489 tmpsurf:= IMG_Load(PChar(filename + '.png')); |
506 begin |
|
507 ps:= filename + '.png'; |
|
508 tmpsurf:= IMG_Load(ps); |
|
509 end; |
490 |
510 |
491 if tmpsurf = nil then |
511 if tmpsurf = nil then |
492 if critical then OutError(msgFailed, true) |
512 if critical then OutError(msgFailed, true) |
493 else begin |
513 else begin |
494 WriteLnToConsole(msgFailed); |
514 WriteLnToConsole(msgFailed); |
495 Result:= nil; |
515 exit(nil) |
496 exit |
|
497 end; |
516 end; |
498 |
517 |
499 if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
518 if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
500 if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
519 if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
501 else Result:= SDL_DisplayFormat(tmpsurf); |
520 else Result:= SDL_DisplayFormat(tmpsurf); |
502 WriteLnToConsole(msgOK) |
521 WriteLnToConsole(msgOK); |
|
522 LoadImage:= Result |
503 end; |
523 end; |
504 |
524 |
505 end. |
525 end. |