-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNEWDLG.PAS
More file actions
241 lines (212 loc) · 6.48 KB
/
Copy pathNEWDLG.PAS
File metadata and controls
241 lines (212 loc) · 6.48 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
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
{$I COMPILER.INC}
unit NewDlg;
interface
uses
AplObj,
AplTypes,
AplConst,
Standard,
Dialogs,
Controls,
Editors,
Views,
Drawing,
ListView,
Graphics,
Veridian,
VeriCons,
VeriType,
FontType;
type
PNewFontDialog = ^TNewFontDialog;
TNewFontDialog = object(TDialog)
private
public
FontIdLabel: PLabel;
FontIdEntry: PEdit;
FontFormatLabel: PLabel;
FontFormatEntry: PDropDownList;
MaxWidthLabel: PLabel;
MaxWidthEntry: PNumericUpDown;
HeightLabel: PLabel;
HeightEntry: PNumericUpDown;
SpacingLabel: PLabel;
SpacingEntry: PNumericUpDown;
function Execute(var AProperties: PFontProperties): TModalResult; virtual;
function CanExecute(AActionId: word): boolean; virtual;
procedure Init; virtual;
procedure Layout; virtual;
procedure Paint(ARect: TRect); virtual;
procedure AfterShow; virtual;
end;
implementation
uses
AplStr,
AplUtils,
AplMath,
Strings;
procedure FontFormatChanged(var AEvent: TIndexChangedEvent);
var
formatEntry: PDropDownList;
dialog: PNewFontDialog;
begin
formatEntry := PDropDownList(AEvent.Sender);
dialog := PNewFontDialog(formatEntry^.Parent);
case TFontFormat(AEvent.NewIndex) of
ffMonoSpace, ffProportional, ffColored: begin
dialog^.MaxWidthEntry^.SetEnabled(true);
dialog^.HeightEntry^.SetEnabled(true);
end;
ffSystem: begin
VeridianApp^.DisableDrawing;
dialog^.MaxWidthEntry^.SetValue(8);
dialog^.HeightEntry^.SetValue(16);
VeridianApp^.EnableDrawing;
dialog^.MaxWidthEntry^.SetEnabled(false);
dialog^.HeightEntry^.SetEnabled(false);
end;
end;
end;
procedure TNewFontDialog.Init;
var
formatIndex: TFontFormat;
begin
inherited Init;
VeridianApp^.PushState;
VeridianApp^.State.DrawEnabled := false;
InitialLocation := wpScreenCenter;
Exclude(WindowOptions, woResizeable);
FontIdLabel := New(PLabel, CreateCaption('FontIdLabel', 'Font Id: ', @self));
FontIdEntry := New(PEdit, CreateParent('FontIdEntry', @self));
FontIdEntry^.MaxLength := 20;
FontFormatLabel := New(PLabel, CreateCaption('FontFormatLabel', 'Type: ', @self));
FontFormatEntry := New(PDropDownList, CreateParent('FontFormatEntry', @self));
for formatIndex := Low(TFontFormat) to High(TFontFormat) do begin
if formatIndex in SupportedFontFormats then
FontFormatEntry^.List^.AddItemTag(FontFormatNames[formatIndex], byte(formatIndex));
end;
FontFormatEntry^.OnSelectedIndexChanged := @FontFormatChanged;
MaxWidthLabel := New(PLabel, CreateCaption('MaxWidthLabel', 'Max Width: ', @self));
MaxWidthEntry := New(PNumericUpDown, CreateParent('MaxWidthEntry', @self));
MaxWidthEntry^.SetMinValue(2);
MaxWidthEntry^.SetMaxValue(16);
MaxWidthEntry^.SetValue(8);
HeightLabel := New(PLabel, CreateCaption('HeightLabel', 'Height: ', @self));
HeightEntry := New(PNumericUpDown, CreateParent('HeightEntry', @self));
HeightEntry^.SetMinValue(2);
HeightEntry^.SetMaxValue(24);
HeightEntry^.SetValue(16);
SpacingLabel := New(PLabel, CreateCaption('SpacingLabel', 'Spacing: ', @self));
SpacingEntry := New(PNumericUpDown, CreateParent('SpacingEntry', @self));
SpacingEntry^.SetMinValue(0);
SpacingEntry^.SetMaxValue(8);
SpacingEntry^.SetValue(1);
Padding.CreateAll(4, 4, 4, 2);
InitialLocation := wpScreenCenter;
VeridianApp^.PopState;
end;
procedure TNewFontDialog.Layout;
var
xPos, yPos: integer;
entryWidth, entryHeight: integer;
numEntryX, offset: integer;
size: integer;
begin
inherited Layout;
VeridianApp^.PushState;
VeridianApp^.State.DrawEnabled := false;
xPos := 0;
yPos := 3;
entryHeight := FontIdLabel^.Font^.Height + 6;
size := 55;
entryWidth := 100;
offset := 4;
if Graph^.Mode^.Width < 512 then begin
size := 35;
entryWidth := 75;
offset := 3;
end;
FontIdLabel^.SetXY(xPos, yPos + 4);
Inc(xPos, FontIdLabel^.Width + offset);
FontIdEntry^.SetBounds(xPos, yPos + 1, entryWidth, entryHeight);
FontIdEntry^.ValidChars := AlphaNumericSpace;
FontIdEntry^.MaxLength := 20;
xPos := 0;
Inc(yPos, FontIdEntry^.Height + 6);
FontFormatLabel^.SetXY(xPos, yPos + 3);
FontFormatEntry^.Height := entryHeight;
FontFormatEntry^.SetXY(FontIdEntry^.X, yPos);
Inc(yPos, FontFormatEntry^.Height + 6);
MaxWidthLabel^.SetXY(xPos, yPos + offset);
Inc(xPos, MaxWidthLabel^.Width + offset);
numEntryX := xPos;
MaxWidthEntry^.SetBounds(xPos, yPos, size, entryHeight);
xPos := 0;
Inc(yPos, MaxWidthEntry^.Height + 6);
HeightLabel^.SetXY(xPos, yPos + offset);
HeightEntry^.SetBounds(numEntryX, yPos, size, entryHeight);
Inc(yPos, HeightEntry^.Height + 6);
SpacingLabel^.SetXY(xPos, yPos + offset);
SpacingEntry^.SetBounds(numEntryX, yPos, size, entryHeight);
Inc(yPos, SpacingEntry^.Height + 6);
Width := 200;
Height := 180;
if Graph^.Mode^.Width < 512 then begin
Width := 145;
Height := 120;
end;
VeridianApp^.PopState;
end;
procedure TNewFontDialog.Paint(ARect: TRect);
begin
inherited Paint(ARect);
end;
procedure TNewFontDialog.AfterShow;
begin
inherited AfterShow;
FontIdEntry^.TabOrder := 0;
FontFormatEntry^.TabOrder := 1;
MaxWidthEntry^.TabOrder := 2;
HeightEntry^.TabOrder := 3;
SpacingEntry^.TabOrder := 4;
SetButtonTabOrders(5);
FontIdEntry^.Focus;
end;
function TNewFontDialog.CanExecute(AActionId: word): boolean;
begin
CanExecute := inherited CanExecute(AActionId);
case AActionId of
acDialogOk: begin
if IsWhiteSpace(FontIdEntry^.GetText) then begin
ShowMessage('Invalid Entry', 'Font ID cannot be empty.');
CanExecute := false;
end;
end;
end;
end;
function TNewFontDialog.Execute(var AProperties: PFontProperties): TModalResult;
var
result: TModalResult;
begin
if not Assigned(AProperties) then
AProperties := New(PFontProperties, Create);
VeridianApp^.PushState;
VeridianApp^.State.DrawEnabled := false;
if Assigned(AProperties^.Id) then
FontIdEntry^.SetText(StrPas(AProperties^.Id));
FontFormatEntry^.SetSelectedIndex(ord(AProperties^.Format));
MaxWidthEntry^.SetValue(AProperties^.MaxWidth);
HeightEntry^.SetValue(AProperties^.Height);
SpacingEntry^.SetValue(AProperties^.Spacing);
VeridianApp^.PopState;
result := ShowDialog;
if result = mrOK then begin
TString.AssignString(AProperties^.Id, FontIdEntry^.GetText);
AProperties^.Format := TFontFormat(FontFormatEntry^.SelectedIndex);
AProperties^.MaxWidth := MaxWidthEntry^.Value;
AProperties^.Height := HeightEntry^.Value;
AProperties^.Spacing := SpacingEntry^.Value;
end;
Execute := result;
end;
end.