forked from Villavu/Simba
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathform.simba
More file actions
171 lines (146 loc) · 4.59 KB
/
form.simba
File metadata and controls
171 lines (146 loc) · 4.59 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
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
// Simple form example doing random things.
var
Form: TLazForm;
// Called when the mouse the mouse is pressed on the form
procedure FormMouseDown(Sender: TLazObject; Button: ELazMouseButton; Shift: ELazShiftStates; X, Y: Integer);
begin
WriteLn('FormMouseDown: ', Button, ', ', Shift, ' at ', X, ', ', Y);
if (ELazShiftStates.Shift in Shift) then
WriteLn('Shift is pressed too!');
if (ELazShiftStates.Ctrl in Shift) then
WriteLn('Control is pressed too!');
end;
// Called when the mouse the mouse is released on the form
procedure FormMouseUp(Sender: TLazObject; Button: ELazMouseButton; Shift: ELazShiftStates; X, Y: Integer);
begin
WriteLn('FormMouseUp: ', Button, ', ', Shift, ' at ', X, ', ', Y);
end;
procedure DoButtonClick(Sender: TLazObject);
begin
WriteLn('Button clicked: ', TLazButton(Sender).Caption);
if (TLazButton(Sender).Caption = 'Close this form') then
Form.Close();
end;
procedure DoSelectionChange(Sender: TLazObject; User: Boolean);
begin
WriteLn('List selection changed to: ', TLazListBox(Sender).GetSelectedText());
end;
procedure DoTabChange(Sender: TLazObject);
begin
WriteLn('Tab changed to tab #', TLazPageControl(Sender).ActiveTabIndex);
end;
procedure ShowMyForm;
var
Button: TLazButton;
List: TLazListBox;
Lbl: TLazLabel;
Panel: TLazPanel;
Img: TLazImage;
SimbaImg: TImage;
Tabs: TLazPageControl;
Tab1, Tab2: TLazTabSheet;
SpeedButton: TLazSpeedButton;
LazBmp: TLazBitmap;
Group: TLazGroupBox;
begin
Form := TLazForm.Create();
Form.Caption := 'Example form';
Form.OnMouseDown := @FormMouseDown;
Form.OnMouseUp := @FormMouseUp;
Form.Width := 700;
Form.Height := 700;
Form.Position := ELazFormPosition.ScreenCenter;
Form.Color := Colors.DARK_GREY;
Form.BorderStyle := ELazFormBorderStyle.Single; // Do not allow resizing
SimbaImg := Target.GetImage([0,0,400,400]);
Group := TLazGroupBox.Create(Form);
Group.Parent := Form;
Group.SetBounds(400,200,200,200);
Group.AutoSize := True;
Group.Caption := 'Target image';
Group.Font.Size := 15;
Img := TLazImage.Create(Group);
Img.Parent := Group;
Img.SetBounds(400,200,200,200);
Img.Stretch := True;
Img.Picture.Bitmap := SimbaImg.ToLazBitmap();
Img.BorderSpacing.Around := 10;
Button := TLazButton.Create(Form);
Button.Parent := Form;
Button.AutoSize := True;
Button.Left := 300;
Button.Top := 50;
Button.ShowHint := True;
Button.Hint := 'Mouse over hint';
Button.Caption := 'This is a button';
Button.Font.Size := 12;
Button.OnClick := @DoButtonClick;
Button := TLazButton.Create(Form);
Button.Parent := Form;
Button.AutoSize := True;
Button.Left := 300;
Button.Top := 100;
Button.Caption := 'This is a bigger button';
Button.Font.Size := 18;
Button.OnClick := @DoButtonClick;
Button := TLazButton.Create(Form);
Button.Parent := Form;
Button.AutoSize := True;
Button.Left := 25;
Button.Top := 300;
Button.Caption := 'Close this form';
Button.Font.Size := 12;
Button.OnClick := @DoButtonClick;
// Create a panel add a label and listbox in it, which are auto positioned&sized with SetAlign
Panel := TLazPanel.Create(Form);
Panel.Parent := Form;
Panel.SetBounds(25,25,250,250);
Panel.BevelOuter := ELazPanelBevel.None;
Lbl := TLazLabel.Create(Panel);
Lbl.Parent := Panel;
Lbl.Caption := 'List box:';
Lbl.Align := ELazAlign.Top;
List := TLazListBox.Create(Panel);
List.Parent := Panel;
List.Align := ELazAlign.Client;
List.Items.Add('Item 1');
List.Items.Add('Item 2');
List.Items.Add('Item 3');
List.OnSelectionChange := @DoSelectionChange;
Tabs := TLazPageControl.Create(Form);
Tabs.Parent := Form;
Tabs.Top := 450;
Tabs.Left := 50;
Tabs.Width := 400;
Tabs.OnChange := @DoTabChange;
Tab1 := Tabs.AddTab();
Tab1.Caption := 'Tab 1';
Tab2 := Tabs.AddTab();
Tab2.Caption := 'Tab 2';
Button := TLazButton.Create(Tab1);
Button.Parent := Tab1;
Button.AutoSize := True;
Button.Caption := 'This button is on tab 1!';
Button.Cursor := ELazCursor.SIZE;
Button := TLazButton.Create(Tab2);
Button.Parent := Tab2;
Button.AutoSize := True;
Button.Caption := 'This button is on tab 2!';
LazBmp := TLazBitmap.Create();
LazBmp.Width := 25;
LazBmp.Height := 25;
LazBmp.Canvas.Pen.Color := Colors.RED;
LazBmp.Canvas.Brush.Color := Colors.WHITE;
LazBmp.Canvas.Rectangle(0,0,25,25);
SpeedButton := TLazSpeedButton.Create(Form);
SpeedButton.Parent := Form;
SpeedButton.SetBounds(200,350,150,50);
SpeedButton.Caption := 'Hello World';
SpeedButton.Glyph := LazBmp;
SpeedButton.AutoSize := True;
Form.ShowModal();
WriteLn('Form has been closed.');
end;
begin
ShowMyForm();
end.