hedgewars/uCaptions.pas
author nemo
Fri, 25 Mar 2011 19:42:00 -0400
changeset 5050 8eb096ee828e
parent 4976 088d40d8aba2
child 5303 e06bf3954a83
permissions -rw-r--r--
unbreak SDL 1.2 build. Koda needs to look at this
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
 *)
088d40d8aba2 Happy 2011 :)
koda
parents: 4901
diff changeset
    18
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    19
unit uCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    20
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    21
interface
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    22
uses uTypes;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    23
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    24
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    25
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    26
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    27
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    28
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    29
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    30
implementation
4850
434cd1284204 code cleanup
koda
parents: 4808
diff changeset
    31
uses uTextures, uRenderUtils, uVariables, uRender;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    32
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    33
type TCaptionStr = record
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    34
                   Tex: PTexture;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    35
                   EndTime: LongWord;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    36
                   end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    37
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    38
    Captions: array[TCapGroup] of TCaptionStr;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    39
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    40
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    41
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    42
    if Captions[Group].Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    43
        FreeTexture(Captions[Group].Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    44
    Captions[Group].Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    45
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    46
    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    47
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    48
    case Group of
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    49
        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    50
    else
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    51
        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    52
    end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    53
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    54
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    55
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    56
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    57
    grp: TCapGroup;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    58
    offset: LongInt;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    59
begin
4808
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    60
{$IFDEF IPHONEOS}
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    61
    offset:= 40;
4808
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    62
{$ELSE}
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    63
    offset:= 8;
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    64
{$ENDIF}
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    65
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    66
    for grp:= Low(TCapGroup) to High(TCapGroup) do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    67
        with Captions[grp] do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    68
            if Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    69
            begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    70
                DrawCentered(0, offset, Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    71
                inc(offset, Tex^.h + 2);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    72
                if EndTime <= RealTicks then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    73
                begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    74
                    FreeTexture(Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    75
                    Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    76
                    EndTime:= 0
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    77
                end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    78
            end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    79
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    80
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    81
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    82
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    83
    FillChar(Captions, sizeof(Captions), 0)
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    84
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    85
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    86
procedure freeModule;
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    87
var
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    88
    group: TCapGroup;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    89
begin
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    90
    for group:= Low(TCapGroup) to High(TCapGroup) do
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    91
    begin
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    92
        FreeTexture(Captions[group].Tex);
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    93
    end;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    94
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    95
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    96
end.