author | koda |
Tue, 15 Nov 2011 02:02:08 +0100 | |
changeset 6382 | 0e76c5cd4250 |
parent 6379 | ef4288298e57 |
child 6383 | c34a8b98d78c |
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; |
|
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
28 |
procedure ReloadCaptions; |
4393 | 29 |
|
30 |
procedure initModule; |
|
31 |
procedure freeModule; |
|
32 |
||
33 |
implementation |
|
4850 | 34 |
uses uTextures, uRenderUtils, uVariables, uRender; |
4393 | 35 |
|
36 |
type TCaptionStr = record |
|
37 |
Tex: PTexture; |
|
38 |
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
|
39 |
Text: shortstring; |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
40 |
Color: Longword |
4393 | 41 |
end; |
42 |
var |
|
43 |
Captions: array[TCapGroup] of TCaptionStr; |
|
44 |
||
45 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
46 |
begin |
|
6379 | 47 |
if Captions[Group].Text <> s then |
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 |
begin |
4393 | 49 |
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
|
50 |
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
|
51 |
end; |
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
52 |
|
6374 | 53 |
if Captions[Group].Tex = nil then |
6371
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
54 |
begin |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
55 |
Captions[Group].Color:= Color; |
6371
c6f73d8e87e2
Skip rerendering the caption if the text is unchanged. Scripts make heavy use of caption, often onGameTick
nemo
parents:
5303
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
end; |
4393 | 59 |
|
60 |
case Group of |
|
61 |
capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 |
|
62 |
else |
|
63 |
Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3; |
|
64 |
end; |
|
65 |
end; |
|
6382
0e76c5cd4250
move the order of reloading texture to workaround buggy drivers
koda
parents:
6379
diff
changeset
|
66 |
|
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
67 |
// For uStore texture recreation |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
68 |
procedure ReloadCaptions; |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
69 |
var Group: TCapGroup; |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
70 |
begin |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
71 |
for Group:= Low(TCapGroup) to High(TCapGroup) do |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
72 |
begin |
6379 | 73 |
FreeTexture(Captions[Group].Tex); |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
74 |
Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig) |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
75 |
end |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
76 |
end; |
4393 | 77 |
|
78 |
procedure DrawCaptions; |
|
79 |
var |
|
80 |
grp: TCapGroup; |
|
81 |
offset: LongInt; |
|
82 |
begin |
|
4808 | 83 |
{$IFDEF IPHONEOS} |
5303
e06bf3954a83
this should fix captions on iOS (and android), though I can't check
Henek
parents:
4976
diff
changeset
|
84 |
offset:= 48; |
4808 | 85 |
{$ELSE} |
86 |
offset:= 8; |
|
87 |
{$ENDIF} |
|
4393 | 88 |
|
89 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
90 |
with Captions[grp] do |
|
91 |
if Tex <> nil then |
|
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
92 |
begin |
4393 | 93 |
DrawCentered(0, offset, Tex); |
94 |
inc(offset, Tex^.h + 2); |
|
95 |
if EndTime <= RealTicks then |
|
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
96 |
begin |
4393 | 97 |
FreeTexture(Tex); |
98 |
Tex:= nil; |
|
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
99 |
Text:= ''; |
4393 | 100 |
EndTime:= 0 |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
101 |
end; |
4393 | 102 |
end; |
103 |
end; |
|
104 |
||
105 |
procedure initModule; |
|
106 |
begin |
|
107 |
FillChar(Captions, sizeof(Captions), 0) |
|
108 |
end; |
|
109 |
||
110 |
procedure freeModule; |
|
4901 | 111 |
var |
112 |
group: TCapGroup; |
|
4393 | 113 |
begin |
4901 | 114 |
for group:= Low(TCapGroup) to High(TCapGroup) do |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
115 |
begin |
4901 | 116 |
FreeTexture(Captions[group].Tex); |
6377
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
117 |
Captions[group].Tex:= nil |
3ce19204b14b
Since I'm storing the text string anyway, might as well recreate captions on resize as well
nemo
parents:
6374
diff
changeset
|
118 |
end |
4393 | 119 |
end; |
120 |
||
121 |
end. |