author | unc0rr |
Sun, 04 Sep 2011 10:58:42 +0400 | |
changeset 5752 | ea95ee97c805 |
parent 5303 | e06bf3954a83 |
child 5727 | 6e4aceba8cde |
child 6371 | c6f73d8e87e2 |
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; |
|
38 |
end; |
|
39 |
var |
|
40 |
Captions: array[TCapGroup] of TCaptionStr; |
|
41 |
||
42 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); |
|
43 |
begin |
|
44 |
if Captions[Group].Tex <> nil then |
|
45 |
FreeTexture(Captions[Group].Tex); |
|
46 |
Captions[Group].Tex:= nil; |
|
47 |
||
48 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
|
49 |
||
50 |
case Group of |
|
51 |
capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200 |
|
52 |
else |
|
53 |
Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3; |
|
54 |
end; |
|
55 |
end; |
|
56 |
||
57 |
procedure DrawCaptions; |
|
58 |
var |
|
59 |
grp: TCapGroup; |
|
60 |
offset: LongInt; |
|
61 |
begin |
|
4808 | 62 |
{$IFDEF IPHONEOS} |
5303
e06bf3954a83
this should fix captions on iOS (and android), though I can't check
Henek
parents:
4976
diff
changeset
|
63 |
offset:= 48; |
4808 | 64 |
{$ELSE} |
65 |
offset:= 8; |
|
66 |
{$ENDIF} |
|
4393 | 67 |
|
68 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
69 |
with Captions[grp] do |
|
70 |
if Tex <> nil then |
|
71 |
begin |
|
72 |
DrawCentered(0, offset, Tex); |
|
73 |
inc(offset, Tex^.h + 2); |
|
74 |
if EndTime <= RealTicks then |
|
75 |
begin |
|
76 |
FreeTexture(Tex); |
|
77 |
Tex:= nil; |
|
78 |
EndTime:= 0 |
|
79 |
end; |
|
80 |
end; |
|
81 |
end; |
|
82 |
||
83 |
procedure initModule; |
|
84 |
begin |
|
85 |
FillChar(Captions, sizeof(Captions), 0) |
|
86 |
end; |
|
87 |
||
88 |
procedure freeModule; |
|
4901 | 89 |
var |
90 |
group: TCapGroup; |
|
4393 | 91 |
begin |
4901 | 92 |
for group:= Low(TCapGroup) to High(TCapGroup) do |
93 |
begin |
|
94 |
FreeTexture(Captions[group].Tex); |
|
95 |
end; |
|
4393 | 96 |
end; |
97 |
||
98 |
end. |