-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettingsformunit.pas
294 lines (244 loc) · 8.32 KB
/
settingsformunit.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
292
293
unit SettingsFormUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
StdCtrls, Buttons, EditBtn, ComboEx, ButtonPanel, Spin, FPimage, FileCtrl, types;
type
{ TSettingsForm }
TSettingsForm = class(TForm)
Label16: TLabel;
NamesWithPathComboBox1: TComboBox;
Label15: TLabel;
MaxWidthComboBox: TComboBox;
NamesWithExtComboBox1: TComboBox;
SpritesMarginComboBox: TComboBox;
MaxHeightComboBox: TComboBox;
ClampWidthAndHeightComboBox: TComboBox;
SpritesOptimizationComboBox: TComboBox;
PreSortingComboBox: TComboBox;
SortingMethodComboBox: TComboBox;
SpritesRotationComboBox: TComboBox;
PostProcessComboBox: TComboBox;
OutputImageComboBox: TComboBox;
OutputDataComboBox: TComboBoxEx;
OutputDataFileNameEdit: TFileNameEdit;
OutputImageFileNameEdit: TFileNameEdit;
ImageList1: TImageList;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
NewButton: TSpeedButton;
PageControl1: TPageControl;
RemoveButton: TSpeedButton;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
ToolBar1: TToolBar;
procedure CheckBox1Change(Sender: TObject);
procedure MaxWidthComboBoxEnter(Sender: TObject);
procedure MaxWidthComboBoxKeyPress(Sender: TObject; var Key: char);
procedure FormShow(Sender: TObject);
procedure Label5Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure RemoveButtonClick(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure TabSheet1ContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
private
{ private declarations }
public
{ public declarations }
end;
var
SettingsForm: TSettingsForm;
implementation
Uses mainformunit, constantsunit, logformUnit, intfgraphics;
{$R *.lfm}
{ TSettingsForm }
procedure TSettingsForm.NewButtonClick(Sender: TObject);
begin
// page 1
MainForm.spritePacker.maxWidth := StrToIntDef(MaxWidthComboBox.Text,2048);
MainForm.spritePacker.maxHeight := StrToIntDef(MaxHeightComboBox.Text,2048);
MainForm.spritePacker.clampWidthAndHeight:=ClampWidthAndHeightComboBox.ItemIndex;
MainForm.spritePacker.spritesOptimization:=SpritesOptimizationComboBox.ItemIndex;
MainForm.spritePacker.spritesRotation:=SpritesRotationComboBox.ItemIndex;
MainForm.spritePacker.spritesMargin:=SpritesMarginComboBox.ItemIndex;
MainForm.spritePacker.preSorting:=PreSortingComboBox.ItemIndex;
MainForm.spritePacker.sortingMethod:=SortingMethodComboBox.ItemIndex;
MainForm.spritePacker.postProcess:=PostProcessComboBox.ItemIndex;
MainForm.spritePacker.namesWithPath:=NamesWithPathComboBox1.ItemIndex;
MainForm.spritePacker.namesWithExt:=NamesWithExtComboBox1.ItemIndex;
// page 2
MainForm.spritePacker.outputDataFileName:=ExtractFileNameWithoutExt(OutputDataFileNameEdit.Text);
if ( OutputDataComboBox.ItemIndex >= 0 ) and ( OutputDataComboBox.ItemIndex < OutputDataComboBox.ItemsEx.Count ) then begin
MainForm.spritePacker.outputDataFileFormat:=OutputDataComboBox.ItemsEx.Items[OutputDataComboBox.ItemIndex].Caption;
end else begin
MainForm.spritePacker.outputDataFileFormat:='';
end;
// page 3
MainForm.spritePacker.outputImageFileName:=ExtractFileNameWithoutExt(OutputImageFileNameEdit.Text);
MainForm.spritePacker.outputImageFileFormat:=OutputImageComboBox.Text;
//
MainForm.spritePacker.IsChanged:=true;
IsDocSaved:=false;
Close;
end;
procedure TSettingsForm.Label5Click(Sender: TObject);
begin
end;
procedure TSettingsForm.ListBox1Click(Sender: TObject);
begin
end;
procedure TSettingsForm.CheckBox1Change(Sender: TObject);
begin
end;
procedure TSettingsForm.MaxWidthComboBoxEnter(Sender: TObject);
begin
end;
procedure TSettingsForm.MaxWidthComboBoxKeyPress(Sender: TObject; var Key: char);
begin
if (( Key >= '0' ) and ( Key <= '9' )) or ( Key = #8 ) then begin
end else begin
Key:=#0;
end;
end;
function LoadImageIntoList(aFileName:String; aList:TImageList;out aImageIndex:Integer):Boolean;
var
mImage: TPicture;
mBitmap: TBitmap;
Begin
result:=False;
aImageIndex:=-1;
if aList<>NIl then
begin
if FileExists(aFilename) then
begin
mImage:=TPicture.Create;
try
(* Attempt to load image file *)
try
mImage.LoadFromFile(aFilename);
except
on exception do;
end;
(* image successfully loaded? *)
if (mImage.Width>0)
and (mImage.Height>0) then
begin
(* Draw image to a bitmap *)
mBitmap:=TBitmap.Create;
try
(* copy pixels + transparency info to bitmap *)
mBitmap.Assign(mImage.Graphic);
(* Add bitmap to image-list, return index *)
aImageIndex:=aList.add(mBitmap,NIL);
result:=true;
finally
mBitmap.Free;
end;
end;
finally
mImage.Free;
end;
end;
end;
end;
procedure TSettingsForm.FormShow(Sender: TObject);
var
Info:TSearchRec;
searchPath:AnsiString;
imageFileName:AnsiString;
dataFormatName:AnsiString;
itemIndex:integer;
i:integer;
imageIndex:integer;
begin
MaxWidthComboBox.Text:=inttostr(MainForm.spritePacker.maxWidth);
MaxHeightComboBox.Text:=inttostr(MainForm.spritePacker.maxHeight);
ClampWidthAndHeightComboBox.ItemIndex:=MainForm.spritePacker.clampWidthAndHeight;
SpritesOptimizationComboBox.ItemIndex:=MainForm.spritePacker.spritesOptimization;
SpritesRotationComboBox.ItemIndex:=MainForm.spritePacker.spritesRotation;
SpritesMarginComboBox.ItemIndex:=MainForm.spritePacker.spritesMargin;
PreSortingComboBox.ItemIndex:=MainForm.spritePacker.preSorting;
SortingMethodComboBox.ItemIndex:=MainForm.spritePacker.sortingMethod;
PostProcessComboBox.ItemIndex:=MainForm.spritePacker.postProcess;
NamesWithPathComboBox1.ItemIndex:=MainForm.spritePacker.namesWithPath;
NamesWithExtComboBox1.ItemIndex:=MainForm.spritePacker.namesWithExt;
OutputImageFileNameEdit.Text := MainForm.spritePacker.outputImageFileName;
OutputImageComboBox.Text := MainForm.spritePacker.outputImageFileFormat;
try
// Обновление скриптов экспорта
ImageList1.Clear;
OutputDataComboBox.Clear;
searchPath := ExtractFilePath(paramstr(0))+'export\';
itemIndex:=-1;
i:=0;
If FindFirst( searchPath + '*.psc', faAnyFile, Info) = 0 then begin
Repeat
if ( Info.Name <> '.' ) and ( Info.Name <> '..' ) then begin
if ( (Info.Attr and faDirectory ) = 0) then begin
imageIndex:=-1;
// icon
imageFileName := searchPath+ExtractFileNameWithoutExt(Info.Name)+'.png';
if ( FileExists( imageFileName ) ) then begin
if not LoadImageIntoList(imageFileName, ImageList1, imageIndex) then imageIndex:=-1;
end;
dataFormatName:=ExtractFileNameWithoutExt(Info.Name);
if ( MainForm.spritePacker.outputDataFileFormat = dataFormatName ) then begin
itemIndex:=i;
end;
OutputDataComboBox.ItemsEx.AddItem(dataFormatName,imageIndex,-1,imageIndex,-1,nil);
i:=i+1;
end;
end;
Until FindNext(Info)<>0;
end;
FindClose(Info);
except
on e:Exception do begin
AddLog(e.Message);
ShowLog;
end;
end;
OutputDataFileNameEdit.Text := MainForm.spritePacker.outputDataFileName;
OutputDataComboBox.ItemIndex:=itemIndex;
end;
procedure TSettingsForm.PageControl1Change(Sender: TObject);
begin
end;
procedure TSettingsForm.RemoveButtonClick(Sender: TObject);
begin
Close;
end;
procedure TSettingsForm.SpinEdit1Change(Sender: TObject);
begin
//
end;
procedure TSettingsForm.SpinEdit2Change(Sender: TObject);
begin
//
end;
procedure TSettingsForm.TabSheet1ContextPopup(Sender: TObject;
MousePos: TPoint; var Handled: Boolean);
begin
end;
end.