hedgewars/uCaptions.pas
author koda
Sat, 19 Feb 2011 01:38:40 +0100
changeset 4948 c3dc41ae68fa
parent 4901 d1e2d82d9ccc
child 4976 088d40d8aba2
permissions -rw-r--r--
remove unused ios code
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;
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    69
var
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    70
    group: TCapGroup;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    71
begin
4901
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    72
    for group:= Low(TCapGroup) to High(TCapGroup) do
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    73
    begin
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    74
        FreeTexture(Captions[group].Tex);
d1e2d82d9ccc Thou shalt not leak!
sheepluva
parents: 4850
diff changeset
    75
    end;
4393
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    76
end;
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    77
883b979697e4 uCaptions
unc0rr
parents:
diff changeset
    78
end.