Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 36f152b

Browse files
committed
New map dialog improved
1 parent 4a8d646 commit 36f152b

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

forms/new_map.lfm

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
object NewMapForm: TNewMapForm
22
Left = 445
3-
Height = 200
3+
Height = 224
44
Top = 193
55
Width = 300
66
BorderStyle = bsDialog
77
Caption = 'New map'
8-
ClientHeight = 200
8+
ClientHeight = 224
99
ClientWidth = 300
1010
Constraints.MinHeight = 200
1111
Constraints.MinWidth = 300
12+
OnCreate = FormCreate
1213
Position = poMainFormCenter
1314
ShowInTaskBar = stNever
14-
LCLVersion = '1.6.3.0'
15+
LCLVersion = '1.8.1.0'
1516
object pnButtons: TPanel
1617
Left = 0
1718
Height = 43
18-
Top = 157
19+
Top = 181
1920
Width = 300
2021
Align = alBottom
2122
BevelOuter = bvNone
@@ -42,7 +43,7 @@ object NewMapForm: TNewMapForm
4243
object edWidth: TSpinEdit
4344
Left = 16
4445
Height = 23
45-
Top = 24
46+
Top = 72
4647
Width = 110
4748
Increment = 8
4849
MaxValue = 1024
@@ -54,34 +55,35 @@ object NewMapForm: TNewMapForm
5455
object edHeight: TSpinEdit
5556
Left = 152
5657
Height = 23
57-
Top = 24
58+
Top = 72
5859
Width = 110
5960
Increment = 8
6061
MaxValue = 1024
6162
MinValue = 8
63+
OnChange = edHeightChange
6264
TabOrder = 2
6365
Value = 32
6466
end
6567
object lbWidth: TLabel
6668
Left = 17
6769
Height = 15
68-
Top = 8
70+
Top = 56
6971
Width = 32
7072
Caption = 'Width'
7173
ParentColor = False
7274
end
7375
object lbHeight: TLabel
7476
Left = 152
7577
Height = 15
76-
Top = 8
78+
Top = 56
7779
Width = 36
7880
Caption = 'Height'
7981
ParentColor = False
8082
end
8183
object edLevels: TSpinEdit
8284
Left = 16
8385
Height = 23
84-
Top = 104
86+
Top = 144
8587
Width = 112
8688
MaxValue = 2
8789
MinValue = 1
@@ -91,20 +93,39 @@ object NewMapForm: TNewMapForm
9193
object lbLevels: TLabel
9294
Left = 16
9395
Height = 15
94-
Top = 88
96+
Top = 128
9597
Width = 32
9698
Caption = 'Levels'
9799
ParentColor = False
98100
end
99101
object cbSquare: TCheckBox
100102
Left = 16
101103
Height = 19
102-
Top = 56
104+
Top = 104
103105
Width = 83
104106
Caption = 'Square map'
105107
OnChange = cbSquareChange
106108
TabOrder = 4
107109
end
110+
object Label1: TLabel
111+
Left = 17
112+
Height = 15
113+
Top = 11
114+
Width = 72
115+
Caption = 'Standard size:'
116+
ParentColor = False
117+
end
118+
object StandardSize: TComboBox
119+
Left = 17
120+
Height = 23
121+
Top = 32
122+
Width = 245
123+
Anchors = [akTop, akLeft, akRight]
124+
ItemHeight = 15
125+
OnChange = StandardSizeChange
126+
Style = csDropDownList
127+
TabOrder = 5
128+
end
108129
object act: TActionList
109130
left = 208
110131
top = 96

forms/new_map.pas

+69
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ TNewMapForm = class(TForm)
3535
btOk: TButton;
3636
btCancel: TButton;
3737
cbSquare: TCheckBox;
38+
StandardSize: TComboBox;
39+
Label1: TLabel;
3840
lbWidth: TLabel;
3941
lbHeight: TLabel;
4042
lbLevels: TLabel;
@@ -45,9 +47,14 @@ TNewMapForm = class(TForm)
4547
procedure actCancelExecute(Sender: TObject);
4648
procedure actCreateExecute(Sender: TObject);
4749
procedure cbSquareChange(Sender: TObject);
50+
procedure edHeightChange(Sender: TObject);
4851
procedure edWidthChange(Sender: TObject);
52+
procedure FormCreate(Sender: TObject);
53+
procedure StandardSizeChange(Sender: TObject);
4954
private
5055
procedure UpdateControls;
56+
57+
procedure CheckStandardSize;
5158
public
5259
{ public declarations }
5360

@@ -59,6 +66,10 @@ implementation
5966

6067
uses math;
6168

69+
const
70+
STANDARD_SIZES : array[0..6] of Integer = (16, 36, 72, 108, 144, 252, 1024);
71+
STANDARD_SIZES_NAMES : array[0..6] of String = ('Min 16x16', 'S 36x36', 'M 72x72', 'L 108x108', 'XL 144x144', 'XXL 252x252', 'Max 1024x1024');
72+
6273
{$R *.lfm}
6374

6475
{ TNewMapForm }
@@ -68,6 +79,11 @@ procedure TNewMapForm.cbSquareChange(Sender: TObject);
6879
UpdateControls;
6980
end;
7081

82+
procedure TNewMapForm.edHeightChange(Sender: TObject);
83+
begin
84+
CheckStandardSize;
85+
end;
86+
7187
procedure TNewMapForm.actCreateExecute(Sender: TObject);
7288
begin
7389
ModalResult:=mrOK;
@@ -83,6 +99,31 @@ procedure TNewMapForm.edWidthChange(Sender: TObject);
8399
if cbSquare.Checked then
84100
begin
85101
edHeight.Value := edWidth.Value;
102+
end
103+
else
104+
begin
105+
CheckStandardSize;
106+
end;
107+
end;
108+
109+
procedure TNewMapForm.FormCreate(Sender: TObject);
110+
var
111+
idx: Integer;
112+
begin
113+
StandardSize.Items.Clear;
114+
115+
for idx := Low(STANDARD_SIZES) to High(STANDARD_SIZES) do
116+
begin
117+
StandardSize.Items.Add(STANDARD_SIZES_NAMES[idx]);
118+
end;
119+
end;
120+
121+
procedure TNewMapForm.StandardSizeChange(Sender: TObject);
122+
begin
123+
if StandardSize.ItemIndex >= 0 then
124+
begin
125+
cbSquare.Checked := true;
126+
edWidth.Value:=STANDARD_SIZES[StandardSize.ItemIndex];
86127
end;
87128
end;
88129

@@ -100,6 +141,34 @@ procedure TNewMapForm.UpdateControls;
100141
end;
101142
end;
102143

144+
procedure TNewMapForm.CheckStandardSize;
145+
var
146+
idx: Integer;
147+
found: Boolean;
148+
begin
149+
if edWidth.Value <> edHeight.Value then
150+
begin
151+
StandardSize.ItemIndex:=-1;
152+
Exit;
153+
end;
154+
155+
found := false;
156+
157+
for idx := Low(STANDARD_SIZES) to High(STANDARD_SIZES) do
158+
begin
159+
if edWidth.Value = STANDARD_SIZES[idx] then
160+
begin
161+
found := true;
162+
Break;
163+
end;
164+
end;
165+
166+
if not found then
167+
begin
168+
StandardSize.ItemIndex:=-1;
169+
end;
170+
end;
171+
103172
function TNewMapForm.Execute(out AParams: TMapCreateParams): boolean;
104173
begin
105174
Result := ShowModal() = mrOK;

0 commit comments

Comments
 (0)