hedgewars/uCaptions.pas
author koda
Tue, 18 Jan 2011 00:12:39 +0100
changeset 4850 434cd1284204
parent 4808 7c3e5b52344a
child 4901 d1e2d82d9ccc
permissions -rw-r--r--
code cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     1
unit uCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     2
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     3
interface
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     4
uses uTypes;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     5
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     6
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     7
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     8
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
     9
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    10
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    11
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    12
implementation
4850
434cd1284204 code cleanup
koda
parents: 4808
diff changeset
    13
uses uTextures, uRenderUtils, uVariables, uRender;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    14
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    15
type TCaptionStr = record
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    16
                   Tex: PTexture;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    17
                   EndTime: LongWord;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    18
                   end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    19
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    20
    Captions: array[TCapGroup] of TCaptionStr;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    21
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    22
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    23
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    24
    if Captions[Group].Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    25
        FreeTexture(Captions[Group].Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    26
    Captions[Group].Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    27
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    28
    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    29
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    30
    case Group of
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    31
        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    32
    else
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    33
        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    34
    end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    35
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    36
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    37
procedure DrawCaptions;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    38
var
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    39
    grp: TCapGroup;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    40
    offset: LongInt;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    41
begin
4808
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    42
{$IFDEF IPHONEOS}
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    43
    offset:= 40;
4808
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    44
{$ELSE}
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    45
    offset:= 8;
7c3e5b52344a remove obsolete TrainingFlags code
koda
parents: 4393
diff changeset
    46
{$ENDIF}
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    47
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    48
    for grp:= Low(TCapGroup) to High(TCapGroup) do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    49
        with Captions[grp] do
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    50
            if Tex <> nil then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    51
            begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    52
                DrawCentered(0, offset, Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    53
                inc(offset, Tex^.h + 2);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    54
                if EndTime <= RealTicks then
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    55
                begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    56
                    FreeTexture(Tex);
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    57
                    Tex:= nil;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    58
                    EndTime:= 0
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    59
                end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    60
            end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    61
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    62
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    63
procedure initModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    64
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    65
    FillChar(Captions, sizeof(Captions), 0)
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    66
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    67
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    68
procedure freeModule;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    69
begin
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    70
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    71
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    72
end.