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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
unit UMenuButton;
interface
uses TextGL, UTexture, OpenGL12, UMenuText;
type
TButton = class
private
SelectBool: Boolean;
constructor Create(); overload;
public
Text: Array of TText;
Texture: TTexture; // Button Screen position and size
Texture2: TTexture; // second texture only used for fading full resolution covers
// Texture2Blend: real; // blending factor for second texture (0=invisible, 1=visible)
// now uses alpha
DeselectType: integer; // not used yet
Visible: boolean;
//Reflection Mod
Reflection: boolean;
Reflectionspacing: Real;
Selectable: boolean;
SelectColR: real;
SelectColG: real;
SelectColB: real;
SelectInt: real;
SelectTInt: real;
DeselectColR: real;
DeselectColG: real;
DeselectColB: real;
DeselectInt: real;
DeselectTInt: real;
procedure SetY(Value: real);
procedure SetSelect(Value: Boolean);
property X: real read Texture.x write Texture.x;
property Y: real read Texture.y write SetY;
property Z: real read Texture.z write Texture.z;
property W: real read Texture.w write Texture.w;
property H: real read Texture.h write Texture.h;
property Selected: Boolean read SelectBool write SetSelect;
procedure Draw;
constructor Create(Textura: TTexture); overload;
destructor Destroy; override;
end;
implementation
uses UDrawTexture, SysUtils;
procedure TButton.SetY(Value: real);
var
dY: real;
T: integer; // text
begin
dY := Value - Texture.y;
Texture.y := Value;
for T := 0 to High(Text) do
Text[T].Y := Text[T].Y + dY;
end;
procedure TButton.SetSelect(Value : Boolean);
var
T: integer;
begin
SelectBool := Value;
if (Value) then begin
Texture.ColR := SelectColR;
Texture.ColG := SelectColG;
Texture.ColB := SelectColB;
Texture.Int := SelectInt;
Texture2.ColR := SelectColR;
Texture2.ColG := SelectColG;
Texture2.ColB := SelectColB;
Texture2.Int := SelectInt;
for T := 0 to High(Text) do
Text[T].Int := SelectTInt;
end else begin
Texture.ColR := DeselectColR;
Texture.ColG := DeselectColG;
Texture.ColB := DeselectColB;
Texture.Int := DeselectInt;
Texture2.ColR := DeselectColR;
Texture2.ColG := DeselectColG;
Texture2.ColB := DeselectColB;
Texture2.Int := DeselectInt;
for T := 0 to High(Text) do
Text[T].Int := DeselectTInt;
end;
end;
constructor TButton.Create();
begin
inherited Create;
// We initialize all to 0, nil or false
Visible := true;
SelectBool := false;
DeselectType := 0;
Selectable := true;
//Reflection Mod
Reflection := true;
// Default
// SelectInt := 1;
// DeselectInt := 0.5;
{ SelectColR := 0.5;
SelectColG := 0.75;
SelectColB := 0;
SelectInt := 1;
SelectTInt := 1;
DeselectColR := 1;
DeselectColG := 1;
DeselectColB := 1;
DeselectInt := 0.5;
DeselectTInt := 1;}
SelectColR := 1;
SelectColG := 1;
SelectColB := 1;
SelectInt := 1;
SelectTInt := 1;
DeselectColR := 1;
DeselectColG := 1;
DeselectColB := 1;
DeselectInt := 0.5;
DeselectTInt := 1;
end;
// ***** Public methods ****** //
procedure TButton.Draw;
var
T: integer;
begin
if Visible then begin
DrawTexture(Texture);
if Texture2.Alpha > 0 then begin
Texture2.ScaleW := Texture.ScaleW;
Texture2.ScaleH := Texture.ScaleH;
Texture2.X := Texture.X;
Texture2.Y := Texture.Y;
Texture2.W := Texture.W;
Texture2.H := Texture.H;
Texture2.ColR := Texture.ColR;
Texture2.ColG := Texture.ColG;
Texture2.ColB := Texture.ColB;
Texture2.Int := Texture.Int;
Texture2.Z := Texture.Z;
DrawTexture(Texture2);
end;
//Reflection Mod
if (Reflection) then // Draw Reflections
begin
with Texture do
begin
//Bind Tex and GL Attributes
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthRange(0, 10);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, TexNum);
//Draw
glBegin(GL_QUADS);//Top Left
glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
glTexCoord2f(TexX1*TexW, TexY2*TexH);
glVertex3f(x, y+h*scaleH+ Reflectionspacing, z);
//Bottom Left
glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
glTexCoord2f(TexX1*TexW, {TexY1*TexH*}0.5);
glVertex3f(x, y+h*scaleH + h*scaleH/2 + Reflectionspacing, z);
//Bottom Right
glColor4f(ColR * Int, ColG * Int, ColB * Int, 0);
glTexCoord2f(TexX2*TexW, {TexY1*TexH*}0.5);
glVertex3f(x+w*scaleW, y+h*scaleH + h*scaleH/2 + Reflectionspacing, z);
//Top Right
glColor4f(ColR * Int, ColG * Int, ColB * Int, Alpha-0.3);
glTexCoord2f(TexX2*TexW, TexY2*TexH);
glVertex3f(x+w*scaleW, y+h*scaleH + Reflectionspacing, z);
glEnd;
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
end;
end;
for T := 0 to High(Text) do begin
Text[T].Draw;
end;
end;
end;
// ***** ****** //
destructor TButton.Destroy;
begin
inherited;
end;
constructor TButton.Create(Textura: TTexture);
begin
Create();
Texture := Textura;
Texture.ColR := 0;
Texture.ColG := 0.5;
Texture.ColB := 0;
Texture.Int := 1;
end;
end.
|