hedgewars/uCaptions.pas
author nemo
Sat, 08 Oct 2011 00:34:41 -0400
changeset 6097 db10abae541f
parent 5303 e06bf3954a83
child 5727 6e4aceba8cde
child 6371 c6f73d8e87e2
permissions -rw-r--r--
Couple more, add back misplaced clearing of Land
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     2
 * Hedgewars, a free turn based strategy game
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     3
 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    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
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    20
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    21
unit uCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    22
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    23
interface
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    24
uses uTypes;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    25
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    26
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    27
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    28
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    29
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    30
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    31
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    32
implementation
4850
434cd1284204 code cleanup
koda
parents: 4808
diff changeset
    33
uses uTextures, uRenderUtils, uVariables, uRender;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    34
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    35
type TCaptionStr = record
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    36
                   Tex: PTexture;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    37
                   EndTime: LongWord;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    38
                   end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    39
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    40
    Captions: array[TCapGroup] of TCaptionStr;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    41
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    42
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    43
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    44
    if Captions[Group].Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    45
        FreeTexture(Captions[Group].Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    46
    Captions[Group].Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    47
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    48
    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    49
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    50
    case Group of
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    51
        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    52
    else
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    53
        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    54
    end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    55
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    56
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    57
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    58
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    59
    grp: TCapGroup;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    60
    offset: LongInt;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    61
begin
4808
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    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
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    64
{$ELSE}
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    65
    offset:= 8;
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    66
{$ENDIF}
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    67
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    68
    for grp:= Low(TCapGroup) to High(TCapGroup) do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    69
        with Captions[grp] do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    70
            if Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    71
            begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    72
                DrawCentered(0, offset, Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    73
                inc(offset, Tex^.h + 2);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    74
                if EndTime <= RealTicks then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    75
                begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    76
                    FreeTexture(Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    77
                    Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    78
                    EndTime:= 0
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    79
                end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    80
            end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    81
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    82
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    83
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    84
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    85
    FillChar(Captions, sizeof(Captions), 0)
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    86
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    87
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    88
procedure freeModule;
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    89
var
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    90
    group: TCapGroup;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    91
begin
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    92
    for group:= Low(TCapGroup) to High(TCapGroup) do
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    93
    begin
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    94
        FreeTexture(Captions[group].Tex);
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    95
    end;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    96
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    97
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    98
end.