author | nemo |
Mon, 14 Nov 2011 13:13:38 -0500 | |
branch | 0.9.17 |
changeset 6371 | c6f73d8e87e2 |
parent 5303 | e06bf3954a83 |
child 6374 | b024e279587c |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
5303
e06bf3954a83
this should fix captions on iOS (and android), though I can't check
Henek
parents:
4976
diff
changeset
|
18 |
|
e06bf3954a83
this should fix captions on iOS (and android), though I can't check
Henek
parents:
4976
diff
changeset
|
19 |
{$INCLUDE "options.inc"} |
4976 | 20 |
|
4393 | 21 |
unit uCaptions; |
22 |
||
23 |
interface |
|
24 |
uses uTypes; |
|
25 |
||
26 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
27 |
procedure DrawCaptions; |
|
28 |
||
29 |
procedure initModule; |
|
30 |
procedure freeModule; |
|
31 |
||
32 |
implementation |
|
4850 | 33 |
uses uTextures, uRenderUtils, uVariables, uRender; |
4393 | 34 |
|
35 |
type TCaptionStr = record |
|
36 |
Tex: PTexture; |
|
37 |
EndTime: LongWord; |
|
6371
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
38 |
Text: shortstring; |
4393 | 39 |
end; |
40 |
var |
|
41 |
Captions: array[TCapGroup] of TCaptionStr; |
|
42 |
||
43 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
44 |
begin |
|
6371
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
45 |
if (Captions[Group].Tex <> nil) and (Captions[Group].Text <> s) then |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
46 |
begin |
4393 | 47 |
FreeTexture(Captions[Group].Tex); |
6371
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
48 |
Captions[Group].Tex:= nil |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
49 |
end; |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
50 |
|
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
51 |
if Captions[Group].Text <> s then |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
52 |
begin |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
53 |
Captions[Group].Text:= s; |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
54 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig) |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
55 |
end; |
4393 | 56 |
|
57 |
case Group of |
|
58 |
capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 |
|
59 |
else |
|
60 |
Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3; |
|
61 |
end; |
|
62 |
end; |
|
63 |
||
64 |
procedure DrawCaptions; |
|
65 |
var |
|
66 |
grp: TCapGroup; |
|
67 |
offset: LongInt; |
|
68 |
begin |
|
4808 | 69 |
{$IFDEF IPHONEOS} |
5303
e06bf3954a83
this should fix captions on iOS (and android), though I can't check
Henek
parents:
4976
diff
changeset
|
70 |
offset:= 48; |
4808 | 71 |
{$ELSE} |
72 |
offset:= 8; |
|
73 |
{$ENDIF} |
|
4393 | 74 |
|
75 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
76 |
with Captions[grp] do |
|
77 |
if Tex <> nil then |
|
78 |
begin |
|
79 |
DrawCentered(0, offset, Tex); |
|
80 |
inc(offset, Tex^.h + 2); |
|
81 |
if EndTime <= RealTicks then |
|
82 |
begin |
|
83 |
FreeTexture(Tex); |
|
84 |
Tex:= nil; |
|
85 |
EndTime:= 0 |
|
86 |
end; |
|
87 |
end; |
|
88 |
end; |
|
89 |
||
90 |
procedure initModule; |
|
91 |
begin |
|
92 |
FillChar(Captions, sizeof(Captions), 0) |
|
93 |
end; |
|
94 |
||
95 |
procedure freeModule; |
|
4901 | 96 |
var |
97 |
group: TCapGroup; |
|
4393 | 98 |
begin |
4901 | 99 |
for group:= Low(TCapGroup) to High(TCapGroup) do |
100 |
begin |
|
101 |
FreeTexture(Captions[group].Tex); |
|
102 |
end; |
|
4393 | 103 |
end; |
104 |
||
105 |
end. |