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