author | nemo |
Tue, 09 Feb 2010 03:21:09 +0000 | |
changeset 2776 | 9572aae13d49 |
parent 2753 | 2305bb5dc5f2 |
child 2786 | 85f6425a4d74 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 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 |
||
2623 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uStore; |
22 |
interface |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
23 |
uses sysutils, uConsts, uTeams, SDLh, uFloat, |
2152 | 24 |
{$IFDEF GLES11} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
25 |
gles11; |
1906 | 26 |
{$ELSE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
27 |
GL, GLext; |
1906 | 28 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
29 |
|
4 | 30 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
31 |
var PixelFormat: PSDL_PixelFormat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
32 |
SDLPrimSurface: PSDL_Surface; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
33 |
PauseTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
34 |
SyncTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
35 |
ConfirmTexture: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
36 |
cScaleFactor: GLfloat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
37 |
SupportNPOTT: Boolean; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
38 |
Step: LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
39 |
squaresize : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
40 |
numsquares : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
41 |
ProgrTex: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
42 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
43 |
procedure init_uStore; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
44 |
procedure free_uStore; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
45 |
|
4 | 46 |
procedure StoreLoad; |
47 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
48 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
49 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
50 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 51 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
52 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 53 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
1251 | 54 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
2597 | 55 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
822 | 56 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 57 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 58 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 59 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
60 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
61 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 62 |
procedure DrawFillRect(r: TSDL_Rect); |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
63 |
function CheckCJKFont(s: string; font: THWFont): THWFont; |
762 | 64 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 65 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
66 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
67 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
68 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
69 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 70 |
procedure RenderHealth(var Hedgehog: THedgehog); |
71 |
procedure AddProgress; |
|
510 | 72 |
procedure FinishProgress; |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
73 |
function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
753 | 74 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
75 |
procedure SetScale(f: GLfloat); |
2747 | 76 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
77 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
78 |
procedure FreeWeaponTooltip; |
|
4 | 79 |
|
80 |
implementation |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
81 |
uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF}; |
4 | 82 |
|
2735 | 83 |
type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
84 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
85 |
var HHTexture: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
86 |
MaxTextureSize: Integer; |
2735 | 87 |
cGPUVendor: TGPUVendor; |
4 | 88 |
|
351 | 89 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 90 |
var r: TSDL_Rect; |
91 |
begin |
|
92 |
r:= rect^; |
|
83 | 93 |
if Clear then SDL_FillRect(Surface, @r, 0); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
94 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
95 |
BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
96 |
FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
97 |
|
351 | 98 |
r.y:= rect^.y + 1; |
99 |
r.h:= rect^.h - 2; |
|
47 | 100 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 101 |
r.x:= rect^.x + 1; |
102 |
r.w:= rect^.w - 2; |
|
103 |
r.y:= rect^.y; |
|
104 |
r.h:= rect^.h; |
|
47 | 105 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 106 |
r.x:= rect^.x + 2; |
107 |
r.y:= rect^.y + 1; |
|
108 |
r.w:= rect^.w - 4; |
|
109 |
r.h:= rect^.h - 2; |
|
47 | 110 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 111 |
r.x:= rect^.x + 1; |
112 |
r.y:= rect^.y + 2; |
|
113 |
r.w:= rect^.w - 2; |
|
114 |
r.h:= rect^.h - 4; |
|
47 | 115 |
SDL_FillRect(Surface, @r, FillColor) |
116 |
end; |
|
117 |
||
371 | 118 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 119 |
var w, h: LongInt; |
4 | 120 |
tmpsurf: PSDL_Surface; |
121 |
clr: TSDL_Color; |
|
2695 | 122 |
finalRect: TSDL_Rect; |
4 | 123 |
begin |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
124 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
2695 | 125 |
finalRect.x:= X; |
126 |
finalRect.y:= Y; |
|
127 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
128 |
finalRect.h:= h + FontBorder * 2; |
|
129 |
DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
|
2670 | 130 |
clr.r:= (Color shr 16) and $FF; |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
131 |
clr.g:= (Color shr 8) and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
132 |
clr.b:= Color and $FF; |
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
133 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
2695 | 134 |
finalRect.x:= X + FontBorder + 2; |
135 |
finalRect.y:= Y + FontBorder; |
|
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
136 |
SDLTry(tmpsurf <> nil, true); |
2695 | 137 |
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
138 |
SDL_FreeSurface(tmpsurf); |
2695 | 139 |
finalRect.x:= X; |
140 |
finalRect.y:= Y; |
|
141 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
142 |
finalRect.h:= h + FontBorder * 2; |
|
143 |
WriteInRoundRect:= finalRect; |
|
4 | 144 |
end; |
145 |
||
2747 | 146 |
function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
147 |
var w, h: LongInt; |
|
148 |
tmpsurf: PSDL_Surface; |
|
149 |
clr: TSDL_Color; |
|
150 |
finalRect: TSDL_Rect; |
|
151 |
begin |
|
152 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
|
153 |
finalRect.x:= X + FontBorder + 2; |
|
154 |
finalRect.y:= Y + FontBorder; |
|
155 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
156 |
finalRect.h:= h + FontBorder * 2; |
|
157 |
clr.r:= Color shr 16; |
|
158 |
clr.g:= (Color shr 8) and $FF; |
|
159 |
clr.b:= Color and $FF; |
|
160 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
|
161 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
162 |
SDLTry(tmpsurf <> nil, true); |
|
163 |
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
|
164 |
SDL_FreeSurface(tmpsurf); |
|
165 |
finalRect.x:= X; |
|
166 |
finalRect.y:= Y; |
|
167 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
168 |
finalRect.h:= h + FontBorder * 2; |
|
169 |
WriteInRect:= finalRect |
|
170 |
end; |
|
171 |
||
4 | 172 |
procedure StoreLoad; |
844 | 173 |
var s: string; |
4 | 174 |
|
1185 | 175 |
procedure WriteNames(Font: THWFont); |
176 |
var t: LongInt; |
|
177 |
i: LongInt; |
|
178 |
r, rr: TSDL_Rect; |
|
179 |
drY: LongInt; |
|
2747 | 180 |
texsurf, flagsurf: PSDL_Surface; |
1185 | 181 |
begin |
182 |
r.x:= 0; |
|
183 |
r.y:= 0; |
|
184 |
drY:= - 4; |
|
185 |
for t:= 0 to Pred(TeamsCount) do |
|
186 |
with TeamsArray[t]^ do |
|
187 |
begin |
|
188 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 189 |
|
1185 | 190 |
r.w:= cTeamHealthWidth + 5; |
191 |
r.h:= NameTagTex^.h; |
|
690 | 192 |
|
1185 | 193 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
194 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
195 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 196 |
|
2666 | 197 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
1185 | 198 |
rr:= r; |
199 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
200 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
201 |
HealthTex:= Surface2Tex(texsurf, false); |
1185 | 202 |
SDL_FreeSurface(texsurf); |
690 | 203 |
|
2747 | 204 |
r.x:= 0; |
205 |
r.y:= 0; |
|
206 |
r.w:= 32; |
|
207 |
r.h:= 32; |
|
208 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
|
209 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
210 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
211 |
||
212 |
r.w:= 26; |
|
213 |
r.h:= 19; |
|
214 |
||
215 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
|
216 |
||
2751 | 217 |
// overwrite flag for cpu teams and keep players from using it |
218 |
if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then |
|
219 |
Flag:= 'cpu' |
|
220 |
else if Flag = 'cpu' then |
|
221 |
Flag:= 'hedgewars'; |
|
222 |
||
2747 | 223 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
224 |
if flagsurf = nil then |
|
225 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
|
226 |
TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
|
227 |
copyToXY(flagsurf, texsurf, 2, 2); |
|
228 |
SDL_FreeSurface(flagsurf); |
|
229 |
||
230 |
// restore black border pixels inside the flag |
|
231 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
|
232 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
|
233 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
|
234 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
|
235 |
||
236 |
FlagTex:= Surface2Tex(texsurf, false); |
|
237 |
||
1185 | 238 |
dec(drY, r.h + 2); |
239 |
DrawHealthY:= drY; |
|
240 |
for i:= 0 to 7 do |
|
241 |
with Hedgehogs[i] do |
|
242 |
if Gear <> nil then |
|
1242 | 243 |
begin |
1185 | 244 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
245 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
246 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
247 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
1698 | 248 |
if texsurf <> nil then |
249 |
begin |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
250 |
HatTex:= Surface2Tex(texsurf, true); |
1698 | 251 |
SDL_FreeSurface(texsurf) |
252 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
253 |
end |
1242 | 254 |
end; |
1185 | 255 |
end; |
256 |
end; |
|
4 | 257 |
|
1185 | 258 |
procedure MakeCrossHairs; |
259 |
var t: LongInt; |
|
260 |
tmpsurf, texsurf: PSDL_Surface; |
|
261 |
Color, i: Longword; |
|
262 |
begin |
|
263 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
264 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 265 |
|
1185 | 266 |
for t:= 0 to Pred(TeamsCount) do |
267 |
with TeamsArray[t]^ do |
|
268 |
begin |
|
269 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
270 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
271 |
|
1185 | 272 |
Color:= Clan^.Color; |
273 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
274 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
275 |
|
1185 | 276 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 277 |
|
1185 | 278 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 279 |
|
1185 | 280 |
if SDL_MustLock(texsurf) then |
281 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 282 |
|
1185 | 283 |
// make black pixel be alpha-transparent |
284 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
2592 | 285 |
if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
777 | 286 |
|
1185 | 287 |
if SDL_MustLock(texsurf) then |
288 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
289 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
290 |
CrosshairTex:= Surface2Tex(texsurf, false); |
1185 | 291 |
SDL_FreeSurface(texsurf) |
292 |
end; |
|
351 | 293 |
|
1185 | 294 |
SDL_FreeSurface(tmpsurf) |
295 |
end; |
|
4 | 296 |
|
1185 | 297 |
procedure InitHealth; |
298 |
var i, t: LongInt; |
|
299 |
begin |
|
300 |
for t:= 0 to Pred(TeamsCount) do |
|
301 |
if TeamsArray[t] <> nil then |
|
302 |
with TeamsArray[t]^ do |
|
303 |
begin |
|
304 |
for i:= 0 to cMaxHHIndex do |
|
305 |
if Hedgehogs[i].Gear <> nil then |
|
306 |
RenderHealth(Hedgehogs[i]); |
|
307 |
end |
|
308 |
end; |
|
4 | 309 |
|
1185 | 310 |
procedure LoadGraves; |
311 |
var t: LongInt; |
|
312 |
texsurf: PSDL_Surface; |
|
313 |
begin |
|
314 |
for t:= 0 to Pred(TeamsCount) do |
|
315 |
if TeamsArray[t] <> nil then |
|
316 |
with TeamsArray[t]^ do |
|
317 |
begin |
|
318 |
if GraveName = '' then GraveName:= 'Simple'; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
319 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
320 |
GraveTex:= Surface2Tex(texsurf, false); |
1185 | 321 |
SDL_FreeSurface(texsurf) |
322 |
end |
|
323 |
end; |
|
4 | 324 |
|
844 | 325 |
var ii: TSprite; |
326 |
fi: THWFont; |
|
327 |
ai: TAmmoType; |
|
328 |
tmpsurf: PSDL_Surface; |
|
329 |
i: LongInt; |
|
4 | 330 |
begin |
2222 | 331 |
|
4 | 332 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 333 |
with Fontz[fi] do |
334 |
begin |
|
335 |
s:= Pathz[ptFonts] + '/' + Name; |
|
336 |
WriteToConsole(msgLoading + s + '... '); |
|
337 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
338 |
SDLTry(Handle <> nil, true); |
|
339 |
TTF_SetFontStyle(Handle, style); |
|
340 |
WriteLnToConsole(msgOK) |
|
341 |
end; |
|
53 | 342 |
|
4 | 343 |
WriteNames(fnt16); |
70 | 344 |
MakeCrossHairs; |
4 | 345 |
LoadGraves; |
346 |
||
347 |
AddProgress; |
|
348 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 349 |
with SpritesData[ii] do |
2145 | 350 |
// FIXME - add a sprite attribute |
2426 | 351 |
if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
352 |
begin |
1185 | 353 |
if AltPath = ptNone then |
2426 | 354 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
355 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
356 |
else |
|
357 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 358 |
else begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
359 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 360 |
if tmpsurf = nil then |
2610 | 361 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 362 |
end; |
2426 | 363 |
|
364 |
if tmpsurf <> nil then |
|
2630 | 365 |
begin |
2610 | 366 |
if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
367 |
if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
|
2426 | 368 |
if Width = 0 then Width:= tmpsurf^.w; |
369 |
if Height = 0 then Height:= tmpsurf^.h; |
|
2452 | 370 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
2426 | 371 |
Texture:= Surface2Tex(tmpsurf, true) |
372 |
else |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
373 |
begin |
2426 | 374 |
Texture:= Surface2Tex(tmpsurf, false); |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
375 |
if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
2630 | 376 |
begin |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
377 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
378 |
end; |
2630 | 379 |
end; |
2426 | 380 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
381 |
end |
|
382 |
else |
|
383 |
Surface:= nil |
|
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
384 |
end; |
80 | 385 |
|
4 | 386 |
AddProgress; |
567 | 387 |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
388 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
389 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 390 |
SDL_FreeSurface(tmpsurf); |
4 | 391 |
|
392 |
InitHealth; |
|
393 |
||
2623 | 394 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig); |
395 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig); |
|
396 |
SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
397 |
|
2601 | 398 |
AddProgress; |
399 |
||
2670 | 400 |
// name of weapons in ammo menu |
843 | 401 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
402 |
with Ammoz[ai] do |
|
403 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
404 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels); |
2670 | 405 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
406 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 407 |
SDL_FreeSurface(tmpsurf) |
408 |
end; |
|
2376 | 409 |
|
2670 | 410 |
// number of weapons in ammo menu |
844 | 411 |
for i:= Low(CountTexz) to High(CountTexz) do |
412 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
413 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
2670 | 414 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
415 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 416 |
SDL_FreeSurface(tmpsurf) |
417 |
end; |
|
418 |
||
4 | 419 |
{$IFDEF DUMP} |
2601 | 420 |
//not working anymore, where are LandSurface and StoreSurface defined? |
421 |
//SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
422 |
//SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
4 | 423 |
{$ENDIF} |
2222 | 424 |
AddProgress; |
2669 | 425 |
|
2672 | 426 |
{$IFDEF SDL_IMAGE_NEWER} |
2669 | 427 |
IMG_Quit(); |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
428 |
{$ENDIF} |
4 | 429 |
end; |
430 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
431 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 432 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
433 |
_l, _r, _t, _b: real; |
1916 | 434 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 435 |
begin |
2428 | 436 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 437 |
rr.x:= X; |
438 |
rr.y:= Y; |
|
351 | 439 |
rr.w:= r^.w; |
440 |
rr.h:= r^.h; |
|
755 | 441 |
|
1896 | 442 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
443 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
444 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
445 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 446 |
|
447 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
448 |
||
1916 | 449 |
VertexBuffer[0].X:= X; |
450 |
VertexBuffer[0].Y:= Y; |
|
451 |
VertexBuffer[1].X:= rr.w + X; |
|
452 |
VertexBuffer[1].Y:= Y; |
|
453 |
VertexBuffer[2].X:= rr.w + X; |
|
454 |
VertexBuffer[2].Y:= rr.h + Y; |
|
455 |
VertexBuffer[3].X:= X; |
|
456 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 457 |
|
1916 | 458 |
TextureBuffer[0].X:= _l; |
459 |
TextureBuffer[0].Y:= _t; |
|
460 |
TextureBuffer[1].X:= _r; |
|
461 |
TextureBuffer[1].Y:= _t; |
|
462 |
TextureBuffer[2].X:= _r; |
|
463 |
TextureBuffer[2].Y:= _b; |
|
464 |
TextureBuffer[3].X:= _l; |
|
465 |
TextureBuffer[3].Y:= _b; |
|
755 | 466 |
|
1916 | 467 |
glEnableClientState(GL_VERTEX_ARRAY); |
468 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 469 |
|
1916 | 470 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
471 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
472 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
473 |
||
474 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
475 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 476 |
end; |
477 |
||
478 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
479 |
begin |
|
1904 | 480 |
glPushMatrix; |
481 |
glTranslatef(X, Y, 0); |
|
482 |
||
762 | 483 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
484 |
||
1904 | 485 |
glEnableClientState(GL_VERTEX_ARRAY); |
486 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 487 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
488 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
489 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
490 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 491 |
|
492 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
493 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
494 |
||
495 |
glPopMatrix |
|
4 | 496 |
end; |
497 |
||
1251 | 498 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, Frames: LongInt); |
1242 | 499 |
var ft, fb: GLfloat; |
500 |
hw: LongInt; |
|
1916 | 501 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
1242 | 502 |
begin |
503 |
glPushMatrix; |
|
504 |
glTranslatef(X, Y, 0); |
|
2598 | 505 |
glScalef(Scale, Scale, 1.0); |
2597 | 506 |
|
507 |
if Dir < 0 then |
|
508 |
hw:= - 16 |
|
509 |
else |
|
510 |
hw:= 16; |
|
511 |
||
512 |
ft:= Frame / Frames * Texture^.ry; |
|
513 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
514 |
||
515 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
516 |
||
517 |
VertexBuffer[0].X:= -hw; |
|
518 |
VertexBuffer[0].Y:= -16; |
|
519 |
VertexBuffer[1].X:= hw; |
|
520 |
VertexBuffer[1].Y:= -16; |
|
521 |
VertexBuffer[2].X:= hw; |
|
522 |
VertexBuffer[2].Y:= 16; |
|
523 |
VertexBuffer[3].X:= -hw; |
|
524 |
VertexBuffer[3].Y:= 16; |
|
525 |
||
526 |
TextureBuffer[0].X:= 0; |
|
527 |
TextureBuffer[0].Y:= ft; |
|
528 |
TextureBuffer[1].X:= Texture^.rx; |
|
529 |
TextureBuffer[1].Y:= ft; |
|
530 |
TextureBuffer[2].X:= Texture^.rx; |
|
531 |
TextureBuffer[2].Y:= fb; |
|
532 |
TextureBuffer[3].X:= 0; |
|
533 |
TextureBuffer[3].Y:= fb; |
|
534 |
||
535 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
536 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
537 |
||
538 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
539 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
540 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
541 |
||
542 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
543 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
544 |
||
545 |
||
546 |
glPopMatrix |
|
547 |
end; |
|
548 |
||
549 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, Frames: LongInt; Angle: real); |
|
550 |
var ft, fb: GLfloat; |
|
551 |
hw: LongInt; |
|
552 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
|
553 |
begin |
|
554 |
glPushMatrix; |
|
555 |
glTranslatef(X, Y, 0); |
|
556 |
||
557 |
if Dir < 0 then |
|
558 |
glRotatef(Angle, 0, 0, -1) |
|
559 |
else |
|
560 |
glRotatef(Angle, 0, 0, 1); |
|
561 |
||
562 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
563 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
1242 | 564 |
|
565 |
if Dir < 0 then |
|
566 |
hw:= - 16 |
|
567 |
else |
|
568 |
hw:= 16; |
|
569 |
||
1896 | 570 |
ft:= Frame / Frames * Texture^.ry; |
571 |
fb:= (Frame + 1) / Frames * Texture^.ry; |
|
1242 | 572 |
|
573 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
574 |
||
1916 | 575 |
VertexBuffer[0].X:= -hw; |
576 |
VertexBuffer[0].Y:= -16; |
|
577 |
VertexBuffer[1].X:= hw; |
|
578 |
VertexBuffer[1].Y:= -16; |
|
579 |
VertexBuffer[2].X:= hw; |
|
580 |
VertexBuffer[2].Y:= 16; |
|
581 |
VertexBuffer[3].X:= -hw; |
|
582 |
VertexBuffer[3].Y:= 16; |
|
1242 | 583 |
|
1916 | 584 |
TextureBuffer[0].X:= 0; |
585 |
TextureBuffer[0].Y:= ft; |
|
586 |
TextureBuffer[1].X:= Texture^.rx; |
|
587 |
TextureBuffer[1].Y:= ft; |
|
588 |
TextureBuffer[2].X:= Texture^.rx; |
|
589 |
TextureBuffer[2].Y:= fb; |
|
590 |
TextureBuffer[3].X:= 0; |
|
591 |
TextureBuffer[3].Y:= fb; |
|
1242 | 592 |
|
1916 | 593 |
glEnableClientState(GL_VERTEX_ARRAY); |
594 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 595 |
|
1916 | 596 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
597 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
598 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
599 |
||
600 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
601 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
602 |
||
1242 | 603 |
|
604 |
glPopMatrix |
|
605 |
end; |
|
606 |
||
822 | 607 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 608 |
begin |
777 | 609 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 610 |
SpritesData[Sprite].Width, |
611 |
SpritesData[Sprite].Height, |
|
612 |
X, Y, Dir, Angle) |
|
777 | 613 |
end; |
614 |
||
853 | 615 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 616 |
begin |
617 |
glPushMatrix; |
|
809 | 618 |
glTranslatef(X, Y, 0); |
806 | 619 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
620 |
if Dir < 0 then |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
621 |
glRotatef(Angle, 0, 0, -1) |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
622 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
623 |
glRotatef(Angle, 0, 0, 1); |
853 | 624 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
625 |
||
626 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 627 |
|
628 |
glPopMatrix |
|
629 |
end; |
|
630 |
||
822 | 631 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 632 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 633 |
begin |
775 | 634 |
glPushMatrix; |
635 |
glTranslatef(X, Y, 0); |
|
822 | 636 |
|
637 |
if Dir < 0 then |
|
638 |
begin |
|
639 |
hw:= - hw; |
|
640 |
glRotatef(Angle, 0, 0, -1); |
|
641 |
end else |
|
642 |
glRotatef(Angle, 0, 0, 1); |
|
643 |
||
775 | 644 |
|
777 | 645 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 646 |
|
1916 | 647 |
VertexBuffer[0].X:= -hw; |
648 |
VertexBuffer[0].Y:= -hh; |
|
649 |
VertexBuffer[1].X:= hw; |
|
650 |
VertexBuffer[1].Y:= -hh; |
|
651 |
VertexBuffer[2].X:= hw; |
|
652 |
VertexBuffer[2].Y:= hh; |
|
653 |
VertexBuffer[3].X:= -hw; |
|
654 |
VertexBuffer[3].Y:= hh; |
|
775 | 655 |
|
1916 | 656 |
glEnableClientState(GL_VERTEX_ARRAY); |
657 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 658 |
|
1916 | 659 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
660 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
661 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 662 |
|
1916 | 663 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
664 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 665 |
|
666 |
glPopMatrix |
|
667 |
end; |
|
668 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
669 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 670 |
begin |
671 |
r.y:= r.y + Height * Position; |
|
672 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
673 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 674 |
end; |
675 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
676 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
677 |
var row, col, numFramesFirstCol: LongInt; |
4 | 678 |
begin |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
679 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
680 |
row:= Frame mod numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
681 |
col:= Frame div numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
682 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 683 |
end; |
684 |
||
1939 | 685 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
686 |
var r: TSDL_Rect; |
|
687 |
begin |
|
688 |
r.x:= 0; |
|
689 |
r.y:= 0; |
|
690 |
r.w:= SpritesData[Sprite].Width; |
|
691 |
r.h:= SpritesData[Sprite].Height; |
|
692 |
||
693 |
if (X < LeftX) then |
|
694 |
r.x:= LeftX - X; |
|
695 |
if (Y < TopY) then |
|
696 |
r.y:= TopY - Y; |
|
697 |
||
698 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
699 |
r.h:= BottomY - Y + 1; |
|
700 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
701 |
r.w:= RightX - X + 1; |
|
702 |
||
703 |
dec(r.h, r.y); |
|
704 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
705 |
|
1939 | 706 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
707 |
end; |
|
708 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
709 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 710 |
var r: TSDL_Rect; |
711 |
begin |
|
712 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
713 |
r.w:= SpritesData[Sprite].Width; |
|
714 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
715 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
716 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 717 |
end; |
718 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
719 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
720 |
var r: TSDL_Rect; |
198 | 721 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
722 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
723 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
724 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
725 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
726 |
DrawFromRect(X, Y, @r, Source) |
198 | 727 |
end; |
728 |
||
762 | 729 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 730 |
begin |
2567 | 731 |
DrawTexture(X - Source^.w shr 1, Top, Source) |
4 | 732 |
end; |
733 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
734 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 735 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
736 |
(x: -16; y: -16), |
|
737 |
(x: 16; y: -16), |
|
738 |
(x: 16; y: 16), |
|
739 |
(x: -16; y: 16)); |
|
761 | 740 |
var l, r, t, b: real; |
1916 | 741 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 742 |
begin |
761 | 743 |
|
744 |
t:= Pos * 32 / HHTexture^.h; |
|
745 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
746 |
||
747 |
if Dir = -1 then |
|
748 |
begin |
|
749 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
750 |
r:= Step * 32 / HHTexture^.w |
|
751 |
end else |
|
752 |
begin |
|
753 |
l:= Step * 32 / HHTexture^.w; |
|
754 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
755 |
end; |
|
756 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
757 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
758 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
759 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
760 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
761 |
|
761 | 762 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
763 |
||
1916 | 764 |
TextureBuffer[0].X:= l; |
765 |
TextureBuffer[0].Y:= t; |
|
766 |
TextureBuffer[1].X:= r; |
|
767 |
TextureBuffer[1].Y:= t; |
|
768 |
TextureBuffer[2].X:= r; |
|
769 |
TextureBuffer[2].Y:= b; |
|
770 |
TextureBuffer[3].X:= l; |
|
771 |
TextureBuffer[3].Y:= b; |
|
761 | 772 |
|
1916 | 773 |
glEnableClientState(GL_VERTEX_ARRAY); |
774 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 775 |
|
1916 | 776 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
777 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
778 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 779 |
|
1916 | 780 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
781 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 782 |
|
1854 | 783 |
|
784 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
785 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
786 |
glPopMatrix |
4 | 787 |
end; |
788 |
||
1431 | 789 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 790 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 791 |
begin |
792 |
glDisable(GL_TEXTURE_2D); |
|
793 |
||
794 |
glColor4ub(0, 0, 0, 127); |
|
795 |
||
1916 | 796 |
VertexBuffer[0].X:= r.x; |
797 |
VertexBuffer[0].Y:= r.y; |
|
798 |
VertexBuffer[1].X:= r.x + r.w; |
|
799 |
VertexBuffer[1].Y:= r.y; |
|
800 |
VertexBuffer[2].X:= r.x + r.w; |
|
801 |
VertexBuffer[2].Y:= r.y + r.h; |
|
802 |
VertexBuffer[3].X:= r.x; |
|
803 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 804 |
|
1916 | 805 |
glEnableClientState(GL_VERTEX_ARRAY); |
806 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
807 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
808 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 809 |
|
810 |
glColor4f(1, 1, 1, 1); |
|
811 |
glEnable(GL_TEXTURE_2D) |
|
812 |
end; |
|
813 |
||
4 | 814 |
procedure StoreRelease; |
815 |
var ii: TSprite; |
|
816 |
begin |
|
817 |
for ii:= Low(TSprite) to High(TSprite) do |
|
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
818 |
begin |
759 | 819 |
FreeTexture(SpritesData[ii].Texture); |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
820 |
if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface) |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
821 |
end; |
761 | 822 |
|
1806 | 823 |
FreeTexture(HHTexture) |
4 | 824 |
end; |
825 |
||
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
826 |
|
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
827 |
function CheckCJKFont(s: string; font: THWFont): THWFont; |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
828 |
var l, i : LongInt; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
829 |
u: WideChar; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
830 |
tmpstr: array[0..256] of WideChar; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
831 |
begin |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
832 |
if font >= CJKfntSmall then exit(font); |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
833 |
|
2684
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
834 |
l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
835 |
i:= 0; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
836 |
while i < l do |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
837 |
begin |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
838 |
u:= tmpstr[i]; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
839 |
if (#$2E80 <= u) and ( |
2684
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
840 |
(u <= #$2FDF ) or // CJK Radicals Supplement / Kangxi Radicals |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
841 |
((#$2FF0 <= u) and (u <= #$303F)) or // Ideographic Description Characters / CJK Radicals Supplement |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
842 |
((#$31C0 <= u) and (u <= #$31EF)) or // CJK Strokes |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
843 |
((#$3200 <= u) and (u <= #$4DBF)) or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
844 |
((#$4E00 <= u) and (u <= #$9FFF)) or // CJK Unified Ideographs |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
845 |
((#$F900 <= u) and (u <= #$FAFF)) or // CJK Compatibility Ideographs |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
846 |
((#$FE30 <= u) and (u <= #$FE4F))) // CJK Compatibility Forms |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
847 |
then exit(THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) )); |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
848 |
inc(i) |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
849 |
end; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
850 |
exit(font); |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
851 |
(* two more to check. pascal WideChar is only 16 bit though |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
852 |
((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
853 |
((#$2F800 <= u) and (u >= #$2FA1F))) // CJK Compatibility Ideographs Supplement *) |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
854 |
end; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
855 |
|
762 | 856 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
857 |
var w, h : LongInt; |
2695 | 858 |
finalSurface: PSDL_Surface; |
95 | 859 |
begin |
1989 | 860 |
if length(s) = 0 then s:= ' '; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
861 |
font:= CheckCJKFont(s, font); |
355 | 862 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 863 |
|
2695 | 864 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
762 | 865 |
32, RMask, GMask, BMask, AMask); |
785 | 866 |
|
2695 | 867 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
785 | 868 |
|
2695 | 869 |
WriteInRoundRect(finalSurface, 0, 0, Color, font, s); |
785 | 870 |
|
2695 | 871 |
TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 872 |
|
2695 | 873 |
RenderStringTex:= Surface2Tex(finalSurface, false); |
785 | 874 |
|
2695 | 875 |
SDL_FreeSurface(finalSurface); |
95 | 876 |
end; |
877 |
||
2017 | 878 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
879 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2695 | 880 |
finalSurface, tmpsurf, rotatedEdge: PSDL_Surface; |
2017 | 881 |
rect: TSDL_Rect; |
882 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
883 |
substr: shortstring; |
|
884 |
edge, corner, tail: TSPrite; |
|
885 |
begin |
|
886 |
||
887 |
case SpeechType of |
|
2376 | 888 |
1: begin; |
889 |
edge:= sprSpeechEdge; |
|
2017 | 890 |
corner:= sprSpeechCorner; |
891 |
tail:= sprSpeechTail; |
|
892 |
end; |
|
2376 | 893 |
2: begin; |
2017 | 894 |
edge:= sprThoughtEdge; |
2376 | 895 |
corner:= sprThoughtCorner; |
2017 | 896 |
tail:= sprThoughtTail; |
897 |
end; |
|
2376 | 898 |
3: begin; |
2017 | 899 |
edge:= sprShoutEdge; |
900 |
corner:= sprShoutCorner; |
|
901 |
tail:= sprShoutTail; |
|
902 |
end; |
|
903 |
end; |
|
904 |
edgeHeight:= SpritesData[edge].Height; |
|
905 |
edgeWidth:= SpritesData[edge].Width; |
|
906 |
cornerWidth:= SpritesData[corner].Width; |
|
907 |
cornerHeight:= SpritesData[corner].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
908 |
// This one screws up WrapText |
2022 | 909 |
//s:= 'This is the song that never ends. ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...'; |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2153
diff
changeset
|
910 |
// This one does not |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
911 |
//s:= 'This is the song that never ends. cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... '; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
912 |
|
2022 | 913 |
numLines:= 0; |
2017 | 914 |
|
915 |
if length(s) = 0 then s:= '...'; |
|
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
916 |
font:= CheckCJKFont(s, font); |
2017 | 917 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
2332
351abbbb12f3
Lower bound on speech text width for proper rendering
nemo
parents:
2292
diff
changeset
|
918 |
if w<8 then w:= 8; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
919 |
j:= 0; |
2017 | 920 |
if (length(s) > 20) then |
921 |
begin |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
922 |
w:= 0; |
2017 | 923 |
i:= round(Sqrt(length(s)) * 2); |
924 |
s:= WrapText(s, #1, chars, i); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
925 |
pos:= 1; prevpos:= 0; line:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
926 |
// Find the longest line for the purposes of centring the text. Font dependant. |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
927 |
while pos <= length(s) do |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
928 |
begin |
2017 | 929 |
if (s[pos] = #1) or (pos = length(s)) then |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
930 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
931 |
inc(numlines); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
932 |
if s[pos] <> #1 then inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
933 |
while s[prevpos+1] = ' ' do inc(prevpos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
934 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
935 |
i:= 0; j:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
936 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
937 |
if i > w then w:= i; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
938 |
prevpos:= pos; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
939 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
940 |
inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
941 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
942 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
943 |
else numLines := 1; |
2017 | 944 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
945 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 946 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 947 |
|
2022 | 948 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 949 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
950 |
rect.x:= 0; |
|
951 |
rect.y:= 0; |
|
2022 | 952 |
rect.w:= textWidth + (cornerWidth * 2); |
953 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
954 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 955 |
|
2695 | 956 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
2017 | 957 |
|
2695 | 958 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
2017 | 959 |
|
960 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
2695 | 961 |
copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
2017 | 962 |
|
963 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
964 |
x:= 0; |
|
965 |
y:= textHeight + cornerHeight -1; |
|
2695 | 966 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW |
2017 | 967 |
|
968 |
flipSurface(SpritesData[corner].Surface, false); |
|
969 |
x:= rect.w-cornerWidth-1; |
|
970 |
y:= textHeight + cornerHeight -1; |
|
2695 | 971 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE |
2017 | 972 |
|
973 |
flipSurface(SpritesData[corner].Surface, true); |
|
974 |
x:= rect.w-cornerWidth-1; |
|
975 |
y:= 0; |
|
2695 | 976 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE |
2017 | 977 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
978 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
979 |
||
980 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
981 |
x:= cornerWidth; |
|
982 |
y:= 0; |
|
983 |
while x < rect.w-cornerWidth-1 do |
|
984 |
begin |
|
2695 | 985 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge |
2017 | 986 |
inc(x,edgeWidth); |
987 |
end; |
|
988 |
flipSurface(SpritesData[edge].Surface, true); |
|
989 |
x:= cornerWidth; |
|
990 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
991 |
while x < rect.w-cornerWidth-1 do |
|
992 |
begin |
|
2695 | 993 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge |
2017 | 994 |
inc(x,edgeWidth); |
995 |
end; |
|
996 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
997 |
||
998 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
999 |
x:= rect.w - edgeHeight - 1; |
|
1000 |
y:= cornerHeight; |
|
1001 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
1002 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
1003 |
while y < textHeight + cornerHeight do |
|
1004 |
begin |
|
2695 | 1005 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 1006 |
inc(y,edgeWidth); |
1007 |
end; |
|
1008 |
flipSurface(rotatedEdge, false); // restore original position |
|
1009 |
x:= 0; |
|
1010 |
y:= cornerHeight; |
|
1011 |
while y < textHeight + cornerHeight do |
|
1012 |
begin |
|
2695 | 1013 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 1014 |
inc(y,edgeWidth); |
1015 |
end; |
|
1016 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
1017 |
||
1018 |
x:= cornerWidth; |
|
1019 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
2695 | 1020 |
copyToXY(SpritesData[tail].Surface, finalSurface, x, y); |
2017 | 1021 |
|
1022 |
rect.x:= edgeHeight; |
|
1023 |
rect.y:= edgeHeight; |
|
1024 |
rect.w:= rect.w - edgeHeight * 2; |
|
1025 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1026 |
i:= rect.w; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1027 |
j:= rect.h; |
2695 | 1028 |
SDL_FillRect(finalSurface, @rect, cWhiteColor); |
2017 | 1029 |
|
1030 |
pos:= 1; prevpos:= 0; line:= 0; |
|
1031 |
while pos <= length(s) do |
|
1032 |
begin |
|
1033 |
if (s[pos] = #1) or (pos = length(s)) then |
|
1034 |
begin |
|
1035 |
if s[pos] <> #1 then inc(pos); |
|
1036 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
1037 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
1038 |
if Length(substr) <> 0 then |
|
1039 |
begin |
|
2666 | 1040 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1041 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 1042 |
// trying to more evenly position the text, vertically |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1043 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 1044 |
SDLTry(tmpsurf <> nil, true); |
2695 | 1045 |
SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
2017 | 1046 |
SDL_FreeSurface(tmpsurf); |
1047 |
inc(line); |
|
1048 |
prevpos:= pos; |
|
1049 |
end; |
|
1050 |
end; |
|
1051 |
inc(pos); |
|
1052 |
end; |
|
1053 |
||
2695 | 1054 |
//TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
1055 |
RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
|
2017 | 1056 |
|
1057 |
SDL_FreeSurface(rotatedEdge); |
|
2695 | 1058 |
SDL_FreeSurface(finalSurface); |
2017 | 1059 |
end; |
1060 |
||
4 | 1061 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 1062 |
var s: shortstring; |
4 | 1063 |
begin |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1064 |
str(Hedgehog.Gear^.Health, s); |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1065 |
if Hedgehog.HealthTagTex <> nil then |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1066 |
FreeTexture(Hedgehog.HealthTagTex); |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1067 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 1068 |
end; |
1069 |
||
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1070 |
function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
30 | 1071 |
var tmpsurf: PSDL_Surface; |
355 | 1072 |
s: shortstring; |
4 | 1073 |
begin |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1074 |
WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... '); |
2426 | 1075 |
|
2630 | 1076 |
s:= filename + '.png'; |
1077 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
2254 | 1078 |
|
2630 | 1079 |
if (imageFlags and ifLowRes) <> 0 then |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1080 |
begin |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1081 |
s:= filename + '-lowres.png'; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1082 |
if (tmpsurf <> nil) then |
2376 | 1083 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1084 |
if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1085 |
begin |
2426 | 1086 |
SDL_FreeSurface(tmpsurf); |
2630 | 1087 |
{$IFDEF DEBUGFILE} |
1088 |
AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
|
1089 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1090 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1091 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1092 |
end |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1093 |
else |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1094 |
begin |
2630 | 1095 |
{$IFDEF DEBUGFILE} |
1096 |
AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
|
1097 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1098 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1099 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1100 |
end; |
2376 | 1101 |
|
2630 | 1102 |
if tmpsurf = nil then |
2153 | 1103 |
begin |
2630 | 1104 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1105 |
exit(nil) |
|
2153 | 1106 |
end; |
1107 |
||
2630 | 1108 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 1109 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1110 |
SDL_FreeSurface(tmpsurf); |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1111 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2630 | 1112 |
// dummy surface to replace non-critical textures that failed to load due to their size |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1113 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 1114 |
end; |
351 | 1115 |
|
2630 | 1116 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
1117 |
||
1118 |
if (imageFlags and ifTransparent) <> 0 then |
|
1119 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
1120 |
||
1121 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
|
1122 |
WriteLnToConsole(msgOK); |
|
1123 |
||
1124 |
LoadImage:= tmpsurf //Result |
|
753 | 1125 |
end; |
1126 |
||
2428 | 1127 |
function glLoadExtension(extension : string) : boolean; |
1128 |
begin |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1129 |
{$IFDEF IPHONEOS} |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1130 |
glLoadExtension:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1131 |
{$ELSE} |
2428 | 1132 |
glLoadExtension:= glext_LoadExtension(extension); |
2438 | 1133 |
{$ENDIF} |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1134 |
{$IFDEF DEBUGFILE} |
2428 | 1135 |
if not glLoadExtension then |
2575 | 1136 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
2428 | 1137 |
else |
2575 | 1138 |
AddFileLog('OpenGL - "' + extension + '" loaded'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1139 |
{$ENDIF} |
2428 | 1140 |
end; |
1141 |
||
753 | 1142 |
procedure SetupOpenGL; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1143 |
var vendor: shortstring; |
753 | 1144 |
begin |
2697 | 1145 |
{$IFDEF IPHONEOS} |
1146 |
//these are good performance savers, perhaps we could enable them by default |
|
1147 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); |
|
1148 |
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); |
|
1149 |
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
|
1150 |
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
|
1151 |
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
|
1152 |
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
|
1153 |
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
|
1154 |
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
|
1155 |
//SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
|
1156 |
{$ELSE} |
|
1157 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
|
1158 |
{$ENDIF} |
|
1159 |
||
1160 |
{$IFNDEF SDL13} |
|
1161 |
// this attribute is default in 1.3 and must be enabled in MacOSX |
|
1162 |
{$IFNDEF DARWIN} |
|
1163 |
if cVSyncInUse then |
|
1164 |
{$ENDIF} |
|
1165 |
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
|
1166 |
{$ENDIF} |
|
1167 |
||
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1168 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2697 | 1169 |
|
2698 | 1170 |
vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR)))); |
2697 | 1171 |
{$IFDEF DEBUGFILE} |
2701
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2699
diff
changeset
|
1172 |
AddFileLog('OpenGL-- Renderer: ' + string(pchar(glGetString(GL_RENDERER)))); |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1173 |
AddFileLog(' |----- Vendor: ' + vendor); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1174 |
AddFileLog(' |----- Version: ' + string(pchar(glGetString(GL_VERSION)))); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1175 |
AddFileLog(' \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
2153 | 1176 |
{$ENDIF} |
2252 | 1177 |
|
2697 | 1178 |
if MaxTextureSize <= 0 then |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1179 |
begin |
2633 | 1180 |
MaxTextureSize:= 1024; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1181 |
{$IFDEF DEBUGFILE} |
2633 | 1182 |
AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1183 |
{$ENDIF} |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1184 |
end; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1185 |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1186 |
{$IFNDEF IPHONEOS} |
2697 | 1187 |
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
1188 |
cGPUVendor:= gvNVIDIA |
|
1189 |
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
|
1190 |
cGPUVendor:= gvATI |
|
1191 |
else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
|
1192 |
cGPUVendor:= gvIntel; |
|
2647 | 1193 |
//SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
2735 | 1194 |
{$ELSE} |
1195 |
cGPUVendor:= gvApple; |
|
1196 |
{$ENDIF} |
|
1197 |
||
1198 |
{$IFDEF DEBUGFILE} |
|
1199 |
if cGPUVendor = gvUnknown then |
|
1200 |
AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
|
1201 |
{$ELSE} |
|
1202 |
// just avoid 'never used' compiler warning for now |
|
1203 |
if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown; |
|
2428 | 1204 |
{$ENDIF} |
1205 |
||
2697 | 1206 |
// set view port to whole window |
2724 | 1207 |
{$IFDEF IPHONEOS} |
1208 |
glViewport(0, 0, cScreenHeight, cScreenWidth); |
|
1209 |
{$ELSE} |
|
2697 | 1210 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
2724 | 1211 |
{$ENDIF} |
2428 | 1212 |
|
2697 | 1213 |
glMatrixMode(GL_MODELVIEW); |
1214 |
// prepare default translation/scaling |
|
1215 |
glLoadIdentity(); |
|
2724 | 1216 |
{$IFDEF IPHONEOS} |
1217 |
glRotatef(-90, 0, 0, 1); |
|
1218 |
{$ENDIF} |
|
2697 | 1219 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
1220 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
2428 | 1221 |
|
2697 | 1222 |
// enable alpha blending |
1223 |
glEnable(GL_BLEND); |
|
1224 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1225 |
end; |
1226 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1227 |
procedure SetScale(f: GLfloat); |
2724 | 1228 |
var |
1229 |
{$IFDEF IPHONEOS} |
|
1230 |
scale: GLfloat = 1.5; |
|
1231 |
{$ELSE} |
|
1232 |
scale: GLfloat = 2.0; |
|
1233 |
{$ENDIF} |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1234 |
begin |
2697 | 1235 |
// leave immediately if scale factor did not change |
1236 |
if f = cScaleFactor then exit; |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1237 |
|
2724 | 1238 |
if f = scale then glPopMatrix // "return" to default scaling |
1239 |
else // other scaling |
|
2428 | 1240 |
begin |
2724 | 1241 |
glPushMatrix; // save default scaling |
2697 | 1242 |
glLoadIdentity; |
2724 | 1243 |
{$IFDEF IPHONEOS} |
1244 |
glRotatef(-90, 0, 0, 1); |
|
1245 |
{$ENDIF} |
|
2697 | 1246 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
1247 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
2428 | 1248 |
end; |
2258 | 1249 |
|
2697 | 1250 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1251 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1252 |
|
510 | 1253 |
//////////////////////////////////////////////////////////////////////////////// |
1254 |
procedure AddProgress; |
|
1255 |
var r: TSDL_Rect; |
|
766 | 1256 |
texsurf: PSDL_Surface; |
510 | 1257 |
begin |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1258 |
if Step = 0 then |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1259 |
begin |
2697 | 1260 |
{$IFDEF SDL_IMAGE_NEWER} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1261 |
WriteToConsole('Init SDL_image... '); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1262 |
SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1263 |
WriteLnToConsole(msgOK); |
2697 | 1264 |
{$ENDIF} |
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1265 |
|
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1266 |
WriteToConsole(msgLoading + 'progress sprite: '); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1267 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1268 |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1269 |
ProgrTex:= Surface2Tex(texsurf, false); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1270 |
|
2697 | 1271 |
squaresize:= texsurf^.w shr 1; |
1272 |
numsquares:= texsurf^.h div squaresize; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1273 |
SDL_FreeSurface(texsurf); |
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
1274 |
end; |
1045 | 1275 |
|
2697 | 1276 |
TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
2284 | 1277 |
|
2697 | 1278 |
glClear(GL_COLOR_BUFFER_BIT); |
1279 |
glEnable(GL_TEXTURE_2D); |
|
1280 |
if Step < numsquares then r.x:= 0 |
|
1281 |
else r.x:= squaresize; |
|
1282 |
||
1283 |
r.y:= (Step mod numsquares) * squaresize; |
|
1284 |
r.w:= squaresize; |
|
1285 |
r.h:= squaresize; |
|
1286 |
||
1287 |
DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1288 |
|
2697 | 1289 |
glDisable(GL_TEXTURE_2D); |
1290 |
SDL_GL_SwapBuffers(); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1291 |
{$IFDEF SDL13} |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1292 |
SDL_RenderPresent(); |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1293 |
{$ENDIF} |
2697 | 1294 |
inc(Step); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1295 |
|
510 | 1296 |
end; |
1297 |
||
2222 | 1298 |
|
510 | 1299 |
procedure FinishProgress; |
1300 |
begin |
|
2697 | 1301 |
WriteLnToConsole('Freeing progress surface... '); |
1302 |
FreeTexture(ProgrTex); |
|
2689 | 1303 |
|
1304 |
{$IFDEF IPHONEOS} |
|
2697 | 1305 |
// show overlay buttons |
1306 |
IPH_showControls; |
|
2689 | 1307 |
{$ENDIF} |
510 | 1308 |
end; |
1309 |
||
2017 | 1310 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1311 |
var y, x, i, j: LongInt; |
|
1312 |
tmpPixel: Longword; |
|
1313 |
pixels: PLongWordArray; |
|
1314 |
begin |
|
1315 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1316 |
pixels:= Surface^.pixels; |
|
1317 |
if Vertical then |
|
1318 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1319 |
for x := 0 to Surface^.w - 1 do |
|
1320 |
begin |
|
1321 |
i:= y * Surface^.w + x; |
|
1322 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1323 |
tmpPixel:= pixels^[i]; |
|
1324 |
pixels^[i]:= pixels^[j]; |
|
1325 |
pixels^[j]:= tmpPixel; |
|
1326 |
end |
|
1327 |
else |
|
1328 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1329 |
for y := 0 to Surface^.h -1 do |
|
1330 |
begin |
|
1331 |
i:= y*Surface^.w + x; |
|
1332 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1333 |
tmpPixel:= pixels^[i]; |
|
1334 |
pixels^[i]:= pixels^[j]; |
|
1335 |
pixels^[j]:= tmpPixel; |
|
1336 |
end; |
|
1337 |
end; |
|
1338 |
||
1339 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1340 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1341 |
srcPixels, destPixels: PLongWordArray; |
|
1342 |
begin |
|
1343 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1344 |
srcPixels:= src^.pixels; |
|
1345 |
destPixels:= dest^.pixels; |
|
1346 |
||
1347 |
for srcX:= 0 to src^.w - 1 do |
|
1348 |
for srcY:= 0 to src^.h - 1 do |
|
1349 |
begin |
|
1350 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1351 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1352 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
2592 | 1353 |
if (i < maxDest) and (AMask and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
2017 | 1354 |
end; |
1355 |
end; |
|
1356 |
||
1357 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1358 |
var y, x, i, j: LongInt; |
|
1359 |
srcPixels, destPixels: PLongWordArray; |
|
1360 |
begin |
|
1361 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1362 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1363 |
||
1364 |
srcPixels:= src^.pixels; |
|
1365 |
destPixels:= dest^.pixels; |
|
1366 |
||
1367 |
j:= 0; |
|
1368 |
for x := 0 to src^.w - 1 do |
|
1369 |
for y := 0 to src^.h - 1 do |
|
1370 |
begin |
|
1371 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1372 |
destPixels^[j]:= srcPixels^[i]; |
|
1373 |
inc(j) |
|
1374 |
end; |
|
1375 |
end; |
|
1376 |
||
2747 | 1377 |
function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
1378 |
var tmpsurf: PSDL_SURFACE; |
|
1379 |
w, h, i, j: LongInt; |
|
1380 |
font: THWFont; |
|
1381 |
r, r2: TSDL_Rect; |
|
1382 |
wa, ha: LongInt; |
|
1383 |
tmpline, tmpline2, tmpdesc: shortstring; |
|
1384 |
begin |
|
1385 |
font:= fnt16; |
|
1386 |
||
1387 |
// make sure there is a caption as well as a sub caption - description is optional |
|
1388 |
if caption = '' then caption:= '???'; |
|
1389 |
if subcaption = '' then subcaption:= ' '; |
|
1390 |
||
1391 |
w:= 0; |
|
1392 |
h:= 0; |
|
1393 |
wa:= FontBorder * 2 + 4; |
|
1394 |
ha:= FontBorder * 2; |
|
1395 |
||
1396 |
// TODO: Recheck height/position calculation |
|
1397 |
||
1398 |
// get caption's dimensions |
|
1399 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j); |
|
1400 |
// width adds 36 px (image + space) |
|
1401 |
w:= i + 36 + wa; |
|
1402 |
h:= j + ha; |
|
1403 |
||
1404 |
// get sub caption's dimensions |
|
1405 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), i, j); |
|
1406 |
// width adds 36 px (image + space) |
|
1407 |
if w < (i + 36 + wa) then w:= i + 36 + wa; |
|
1408 |
inc(h, j + ha); |
|
1409 |
||
1410 |
// get description's dimensions |
|
1411 |
tmpdesc:= description; |
|
1412 |
while tmpdesc <> '' do |
|
1413 |
begin |
|
1414 |
tmpline:= tmpdesc; |
|
1415 |
SplitByChar(tmpline, tmpdesc, '|'); |
|
1416 |
if tmpline <> '' then |
|
1417 |
begin |
|
1418 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j); |
|
1419 |
if w < (i + wa) then w:= i + wa; |
|
1420 |
inc(h, j + ha) |
|
1421 |
end |
|
1422 |
end; |
|
1423 |
||
1424 |
if extra <> '' then |
|
1425 |
begin |
|
1426 |
// get extra label's dimensions |
|
1427 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j); |
|
1428 |
if w < (i + wa) then w:= i + wa; |
|
1429 |
inc(h, j + ha); |
|
1430 |
end; |
|
1431 |
||
1432 |
// add borders space |
|
1433 |
inc(w, wa); |
|
1434 |
inc(h, ha + 8); |
|
1435 |
||
1436 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask); |
|
1437 |
TryDo(tmpsurf <> nil, 'RenderHelpWindow: fail to create surface', true); |
|
1438 |
||
1439 |
// render border and background |
|
1440 |
r.x:= 0; |
|
1441 |
r.y:= 0; |
|
1442 |
r.w:= w; |
|
1443 |
r.h:= h; |
|
1444 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, tmpsurf, true); |
|
1445 |
||
1446 |
// render caption |
|
1447 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, ha, $ffffffff, font, caption); |
|
1448 |
// render sub caption |
|
1449 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption); |
|
1450 |
||
1451 |
// render all description lines |
|
1452 |
tmpdesc:= description; |
|
1453 |
while tmpdesc <> '' do |
|
1454 |
begin |
|
1455 |
tmpline:= tmpdesc; |
|
1456 |
SplitByChar(tmpline, tmpdesc, '|'); |
|
1457 |
r2:= r; |
|
1458 |
if tmpline <> '' then |
|
1459 |
begin |
|
1460 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline); |
|
1461 |
||
1462 |
// render highlighted caption (if there's a ':') |
|
1463 |
SplitByChar(tmpline, tmpline2, ':'); |
|
1464 |
if tmpline2 <> '' then |
|
1465 |
WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':'); |
|
1466 |
end |
|
1467 |
end; |
|
1468 |
||
1469 |
if extra <> '' then |
|
1470 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra); |
|
1471 |
||
1472 |
r.x:= FontBorder + 6; |
|
1473 |
r.y:= FontBorder + 4; |
|
1474 |
r.w:= 32; |
|
1475 |
r.h:= 32; |
|
1476 |
SDL_FillRect(tmpsurf, @r, $ffffffff); |
|
1477 |
SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r); |
|
1478 |
||
1479 |
RenderHelpWindow:= Surface2Tex(tmpsurf, true); |
|
1480 |
SDL_FreeSurface(tmpsurf) |
|
1481 |
end; |
|
1482 |
||
1483 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
|
2753 | 1484 |
{$IFNDEF IPHONEOS} |
2747 | 1485 |
var r: TSDL_Rect; |
1486 |
i: LongInt; |
|
1487 |
extra: string; |
|
1488 |
extracolor: LongInt; |
|
1489 |
begin |
|
1490 |
// don't do anything if the window shouldn't be shown |
|
1491 |
if not cWeaponTooltips then |
|
1492 |
begin |
|
1493 |
WeaponTooltipTex:= nil; |
|
1494 |
exit |
|
1495 |
end; |
|
1496 |
||
1497 |
// free old texture |
|
1498 |
FreeWeaponTooltip; |
|
1499 |
||
1500 |
// image region |
|
1501 |
i:= LongInt(atype) - 1; |
|
1502 |
r.x:= (i shr 5) * 32; |
|
1503 |
r.y:= (i mod 32) * 32; |
|
1504 |
r.w:= 32; |
|
1505 |
r.h:= 32; |
|
1506 |
||
1507 |
// default (no extra text) |
|
1508 |
extra:= ''; |
|
1509 |
extracolor:= 0; |
|
1510 |
||
1511 |
if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available |
|
1512 |
begin |
|
1513 |
extra:= trmsg[sidNotYetAvailable]; |
|
1514 |
extracolor:= LongInt($ffc77070); |
|
1515 |
end |
|
1516 |
else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn |
|
1517 |
begin |
|
1518 |
extra:= trmsg[sidNoEndTurn]; |
|
1519 |
extracolor:= LongInt($ff70c770); |
|
1520 |
end |
|
1521 |
else |
|
1522 |
begin |
|
1523 |
extra:= ''; |
|
1524 |
extracolor:= 0; |
|
1525 |
end; |
|
1526 |
||
1527 |
// render window and return the texture |
|
1528 |
WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r) |
|
2753 | 1529 |
end; |
1530 |
{$ELSE} |
|
1531 |
begin end; |
|
2747 | 1532 |
{$ENDIF} |
1533 |
||
1534 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
1535 |
begin |
|
1536 |
{$IFNDEF IPHONEOS} |
|
1537 |
// draw the texture if it exists |
|
1538 |
if WeaponTooltipTex <> nil then |
|
1539 |
DrawTexture(x, y, WeaponTooltipTex) |
|
1540 |
{$ENDIF} |
|
1541 |
end; |
|
1542 |
||
1543 |
procedure FreeWeaponTooltip; |
|
1544 |
begin |
|
1545 |
{$IFNDEF IPHONEOS} |
|
1546 |
// free the existing texture (if there's any) |
|
1547 |
if WeaponTooltipTex = nil then |
|
1548 |
exit; |
|
1549 |
FreeTexture(WeaponTooltipTex); |
|
1550 |
WeaponTooltipTex:= nil |
|
1551 |
{$ENDIF} |
|
1552 |
end; |
|
1553 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1554 |
procedure init_uStore; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1555 |
begin |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1556 |
PixelFormat:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1557 |
SDLPrimSurface:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1558 |
{$IFNDEF IPHONEOS}cGPUVendor:= gvUnknown;{$ENDIF} |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1559 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1560 |
cScaleFactor:= 2.0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1561 |
SupportNPOTT:= false; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1562 |
Step:= 0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1563 |
ProgrTex:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1564 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1565 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1566 |
procedure free_uStore; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1567 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1568 |
|
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1569 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1570 |
|
4 | 1571 |
end. |