Repository navigation
Expand file tree
/
Copy pathspacehackcontrolsilluminatedbutton.pas
More file actions
88 lines (76 loc) · 1.95 KB
/
Copy pathspacehackcontrolsilluminatedbutton.pas
File metadata and controls
88 lines (76 loc) · 1.95 KB
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
unit spacehackcontrolsilluminatedbutton;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
StdCtrls, controls, Graphics,
ExtCtrls, ComCtrls, Buttons, MQTTComponent, spacehackcontrols;
type
TSpacehackGameControlIlluminatedButton = class(TSpacehackGameControl)
lightIsOn: boolean;
lblLight: TLabel;
theButton: TButton;
panelWidth: integer;
procedure initUI(thisPanel:TPanel) override;
procedure handleButtonUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure handleButtonDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure updateUI override;
end;
implementation
procedure TSpacehackGameControlIlluminatedButton.initUI(thisPanel: TPanel);
begin;
inherited;
lblLight := TLabel.Create(thisPanel);
panelWidth := thisPanel.Width;
with lblLight do begin
top := 40;
left := 0;
AutoSize:=true;
Font.Size:=20;
Parent:= thisPanel;
Visible:=true;
end;
updateUI;
theButton := TButton.Create(thisPanel);
with theButton do begin
width := 100;
height := 100;
top := 90;
left := 50;
parent := thisPanel;
Visible:=true;
tag := 1;
OnMouseDown:= @handleButtonDown;
OnMouseUp:= @handleButtonUp;
end;
end;
procedure TSpacehackGameControlIlluminatedButton.handleButtonUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
lightIsOn := false;
;
end;
procedure TSpacehackGameControlIlluminatedButton.handleButtonDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin;
lightIsOn := true;
end;
procedure TSpacehackGameControlIlluminatedButton.updateUI;
begin
with lblLight do
begin;
if lightIsOn then
begin
Caption:= 'ON';
Color:=clGreen;
end else
begin
Caption:= 'OFF';
Color:=clRed;
end;
left := round((panelWidth/2) - (width/2));
end;
end;
end.