-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuInterfaces.pas
291 lines (239 loc) · 6.53 KB
/
uInterfaces.pas
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
//* Àâòîð [Xakep] *//
unit uInterfaces;
interface
uses
GLTexture, JPEG, GLHUDObjects, GLObjects, GLBitmapFont, GLScene,
GLMaterial;
type
TPCursor = class(TGLHUDSprite)
public
TagBut: integer;
procedure Move(x,y: single);
end;
TIPanel = class(TGLDummyCube)
public
Enter: TGLHUDSprite;
Leav: TGLHUDSprite;
Kind: integer;
ki: integer;
Down: boolean;
Click: boolean;
Mouse: boolean;
Active: boolean;
procedure SetDown(ft: integer);
procedure SetUp(ft: integer; x,y: single);
function OnPoint(x,y: single) : boolean;
end;
//TPanels = array[0..999] of TIPanel;
TPanelsManager = class(TGLDummyCube)
public
BmpFont: TGLBitmapFont;
Cursor: TPCursor;
PanelCount: integer;
Panels: array[1..999] of TIPanel;
MaterialLibrary: TGLMaterialLibrary;
procedure Init;
function Panel(Name: String): TIPanel;
function Add(PX,PY,W,H: Single): TIPanel;
procedure OnMouseMove(x,y: single);
procedure OnMouseDown;
procedure OnMouseUp(x,y: single);
procedure FreePanels;
procedure Clear;
end;
procedure NewAlpha(Material: TGLMaterial; znak: char; k1,k2: single);
procedure SmoothHideObject(Material: TGLMaterial; Range: Single);
procedure SmoothHideObject2(Material: TGLMaterial; Range: Single);
procedure SmoothShowObject(Material: TGLMaterial; Range: Single);
procedure Blink(Material: TGLMaterial; var i: Integer);
function MenuEL(Obj: TGLHUDSprite; X,Y: integer) : boolean;
procedure SetGammaImage(Material: TGLMaterial; Gamma: Single);
implementation
procedure NewAlpha(Material: TGLMaterial; znak: char; k1,k2: single);
begin
if znak = '>' then
if Material.FrontProperties.Diffuse.Alpha > k1 then
Material.FrontProperties.Diffuse.Alpha:= Material.FrontProperties.Diffuse.Alpha + k2;
if znak = '<' then
if Material.FrontProperties.Diffuse.Alpha < k1 then
Material.FrontProperties.Diffuse.Alpha:= Material.FrontProperties.Diffuse.Alpha + k2;
end;
procedure SmoothHideObject(Material: TGLMaterial; Range: Single);
begin
NewAlpha(Material,'>',Range,-0.05);
end;
procedure SmoothHideObject2(Material: TGLMaterial; Range: Single);
begin
NewAlpha(Material,'>',Range,-0.01);
end;
procedure SmoothShowObject(Material: TGLMaterial; Range: Single);
begin
NewAlpha(Material,'<',Range, 0.05);
end;
procedure Blink(Material: TGLMaterial; var i: Integer);
begin
if Material.FrontProperties.Diffuse.Alpha <= 0.5 then i:= -i;
if Material.FrontProperties.Diffuse.Alpha >= 1 then i:= -i;
Material.FrontProperties.Diffuse.Alpha:= Material.FrontProperties.Diffuse.Alpha - (0.04 * i);
end;
function MenuEL(Obj: TGLHUDSprite; X,Y: integer) : boolean;
begin
result:= false;
if (Obj.Position.X - Obj.Width / 2 < X) and (Obj.Position.X + Obj.Width / 2 > X) and
(Obj.Position.Y - Obj.Height / 2 < Y) and (Obj.Position.Y + Obj.Height / 2 > Y) then result:= true;
end;
procedure SetGammaImage(Material: TGLMaterial; Gamma: Single);
begin
Material.FrontProperties.Diffuse.SetColor(1,1,1);
end;
//* TCursor *//
procedure TPCursor.Move(x,y: single);
begin
Position.X:= x + Width / 2;
Position.Y:= y + Height / 2;
end;
//* TPanel *//
function TIPanel.OnPoint(x,y: single) : boolean;
begin
try
Result:= false;
if (Leav.Position.X - Leav.Width / 2 < x) and (Leav.Position.X + Leav.Width / 2 > x) and
(Leav.Position.Y - Leav.Height / 2 < y) and (Leav.Position.Y + Leav.Height / 2 > y) then Result:= true;
except
end;
end;
procedure TIPanel.SetDown(ft: integer);
begin
case Kind of
1:
begin
Enter.Position.X:= Enter.Position.X + ki;
Enter.Position.Y:= Enter.Position.Y + ki;
end;
2:
begin
Enter.Width:= Enter.Width - ki;
Enter.Height:= Enter.Height - ki;
end;
end;
Down:= true;
Click:= false;
end;
procedure TIPanel.SetUp(ft: integer; x,y: single);
begin
case Kind of
1:
begin
Enter.Position.X:= Enter.Position.X - ki;
Enter.Position.Y:= Enter.Position.Y - ki;
end;
2:
begin
Enter.Width:= Enter.Width + ki;
Enter.Height:= Enter.Height + ki;
end;
end;
Down:= false;
if OnPoint(x,y) then Click:= true;
end;
//* TPanelManager *//
procedure TPanelsManager.Init;
begin
PanelCount:= 0;
//New(Panels);
end;
procedure TPanelsManager.OnMouseMove(x, y: single);
var
i: integer;
begin
Cursor.TagBut:= 0;
for i:= 1 to PanelCount do
if Panels[i] <> nil then
begin
if (Panels[i].OnPoint(x,y)) and (Panels[i].Active) then
begin
Cursor.TagBut:= i;
Panels[i].Enter.Visible:= true;
Panels[i].Leav.Visible:= false;
Panels[i].Mouse:= true;
end
else
if Panels[i].Active then
begin
Panels[i].Enter.Visible:= false;
Panels[i].Leav.Visible:= true;
Panels[i].Mouse:= false;
end;
end;
Cursor.Move(x,y);
end;
procedure TPanelsManager.OnMouseDown;
begin
if (Cursor.TagBut > 0) and (Panels[Cursor.TagBut].Active) then
Panels[Cursor.TagBut].SetDown(Cursor.TagBut);
end;
procedure TPanelsManager.OnMouseUp(x,y: single);
var
i: integer;
begin
for i:= 1 to PanelCount do
if (Panels[i].Down) and (Panels[i].Active) then
Panels[i].SetUp(i,x,y);
end;
function TPanelsManager.Add(PX,PY,W,H: Single): TIPanel;
begin
PanelCount:= PanelCount + 1;
Panels[PanelCount]:= TIPanel(Scene.Objects.AddNewChild(TIPanel));
with Panels[PanelCount] do
begin
Enter:= TGLHUDSprite(AddNewChild(TGLHUDSprite));
Leav:= TGLHUDSprite(AddNewChild(TGLHUDSprite));
Enter.Visible:= false;
Enter.Position.X:= PX;
Enter.Position.Y:= PY;
Leav.Position.X:= PX;
Leav.Position.Y:= PY;
Enter.Width:= W;
Leav.Width:= W;
Enter.Height:= H;
Leav.Height:= H;
Enter.Material.MaterialOptions:= [moNoLighting];
Leav.Material.MaterialOptions:= [moNoLighting];
Enter.Material.BlendingMode:= bmTransparency;
Leav.Material.BlendingMode:= bmTransparency;
Enter.Material.Texture.TextureMode:= tmModulate;
Leav.Material.Texture.TextureMode:= tmModulate;
end;
Result:= Panels[PanelCount]
end;
procedure TPanelsManager.FreePanels;
Var
i: Integer;
begin
PanelCount:= 0;
for i:= 1 to PanelCount do
begin
Panels[i].Enter.Destroy;
Panels[i].Leav.Destroy;
end;
end;
function TPanelsManager.Panel(Name: String): TIPanel;
Var
i: Integer;
begin
Result:= nil;
for i:= 1 to PanelCount do
if Panels[i].Name = Name then Result:= Panels[i];
end;
procedure TPanelsManager.Clear;
Var
i: Integer;
begin
for i:= 1 to PanelCount do
begin
//ShowMessage(Panels[i].Name);
Panels[i].Destroy;
end;
PanelCount:= 0;
end;
end.