aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Menu/UMenuText.pas
blob: 5c435a182d3e7d5bf1e8c7c56e2c2319dfc69fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit UMenuText;

interface
uses TextGL, UTexture, OpenGL12, SysUtils;

type
  TText = class
    private
      SelectBool:   boolean;
    public
      X:      real;
      Y:      real;
//      W:      real;       // if text is wider than W then it is streched (not yet implemented)
//      H:      real;
      Size:   real;
      Text:   string;
      ColR:   real;
      ColG:   real;
      ColB:   real;
      Int:    real;
      Style:  integer;
      Visible:  boolean;
      Align:    integer; // 0 = left, 1 = center, 2 = right

      procedure SetSelect(Value: Boolean);
      property Selected: Boolean read SelectBool write SetSelect;

      procedure Draw;
      constructor Create; overload;
      constructor Create(X, Y: real; Tekst: string); overload;
      constructor Create(ParX, ParY: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string); overload;
  end;

implementation
uses UGraphic;

procedure TText.SetSelect(Value: Boolean);
begin
  SelectBool := Value;
end;

procedure TText.Draw;
var
  X2:     real;
  Text2:  string;
begin
  if Visible then begin
    SetFontStyle(Style);
    SetFontSize(Size);
    glColor3f(ColR*Int, ColG*Int, ColB*Int);
    if not SelectBool then
      Text2 := Text
    else
      Text2 := Text + '|';

    case Align of
      0: X2 := X;
      1: X2 := X - glTextWidth(pchar(Text2))/2;
      2: X2 := X - glTextWidth(pchar(Text2));
    end;

    SetFontPos(X2, Y);
    glPrint(PChar(Text2));
    SetFontStyle(0); // reset to default
  end;
end;

constructor TText.Create;
begin
  Create(0, 0, '');
end;

constructor TText.Create(X, Y: real; Tekst: string);
begin
  Create(X, Y, 0, 10, 0, 0, 0, 0, Tekst);
end;

constructor TText.Create(ParX, ParY: real; ParStyle: integer; ParSize, ParColR, ParColG, ParColB: real; ParAlign: integer; ParTekst: string);
begin
  inherited Create;
  X := ParX;
  Y := ParY;
  Style := ParStyle;
  Size := ParSize;
  Text := ParTekst;
  ColR := ParColR;
  ColG := ParColG;
  ColB := ParColB;
  Int := 1;
  Align := ParAlign;
  SelectBool := false;
  Visible := true;
end;


end.