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 |
*)
|
|
18 |
|
4393
|
19 |
unit uCaptions;
|
|
20 |
|
|
21 |
interface
|
|
22 |
uses uTypes;
|
|
23 |
|
|
24 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
|
|
25 |
procedure DrawCaptions;
|
|
26 |
|
|
27 |
procedure initModule;
|
|
28 |
procedure freeModule;
|
|
29 |
|
|
30 |
implementation
|
4850
|
31 |
uses uTextures, uRenderUtils, uVariables, uRender;
|
4393
|
32 |
|
|
33 |
type TCaptionStr = record
|
|
34 |
Tex: PTexture;
|
|
35 |
EndTime: LongWord;
|
|
36 |
end;
|
|
37 |
var
|
|
38 |
Captions: array[TCapGroup] of TCaptionStr;
|
|
39 |
|
|
40 |
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
|
|
41 |
begin
|
|
42 |
if Captions[Group].Tex <> nil then
|
|
43 |
FreeTexture(Captions[Group].Tex);
|
|
44 |
Captions[Group].Tex:= nil;
|
|
45 |
|
|
46 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
|
|
47 |
|
|
48 |
case Group of
|
|
49 |
capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
|
|
50 |
else
|
|
51 |
Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
|
|
52 |
end;
|
|
53 |
end;
|
|
54 |
|
|
55 |
procedure DrawCaptions;
|
|
56 |
var
|
|
57 |
grp: TCapGroup;
|
|
58 |
offset: LongInt;
|
|
59 |
begin
|
4808
|
60 |
{$IFDEF IPHONEOS}
|
4393
|
61 |
offset:= 40;
|
4808
|
62 |
{$ELSE}
|
|
63 |
offset:= 8;
|
|
64 |
{$ENDIF}
|
4393
|
65 |
|
|
66 |
for grp:= Low(TCapGroup) to High(TCapGroup) do
|
|
67 |
with Captions[grp] do
|
|
68 |
if Tex <> nil then
|
|
69 |
begin
|
|
70 |
DrawCentered(0, offset, Tex);
|
|
71 |
inc(offset, Tex^.h + 2);
|
|
72 |
if EndTime <= RealTicks then
|
|
73 |
begin
|
|
74 |
FreeTexture(Tex);
|
|
75 |
Tex:= nil;
|
|
76 |
EndTime:= 0
|
|
77 |
end;
|
|
78 |
end;
|
|
79 |
end;
|
|
80 |
|
|
81 |
procedure initModule;
|
|
82 |
begin
|
|
83 |
FillChar(Captions, sizeof(Captions), 0)
|
|
84 |
end;
|
|
85 |
|
|
86 |
procedure freeModule;
|
4901
|
87 |
var
|
|
88 |
group: TCapGroup;
|
4393
|
89 |
begin
|
4901
|
90 |
for group:= Low(TCapGroup) to High(TCapGroup) do
|
|
91 |
begin
|
|
92 |
FreeTexture(Captions[group].Tex);
|
|
93 |
end;
|
4393
|
94 |
end;
|
|
95 |
|
|
96 |
end.
|