source: oup/releases/0.29a3/Unit5_preview.pas

Last change on this file was 31, checked in by alloc, 18 years ago
File size: 8.0 KB
RevLine 
[31]1UNIT Unit5_preview;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, Math, ExtCtrls, Unit2_functions, Unit3_data, Unit4_exporters, Unit6_imgfuncs,
6 StdCtrls, StrUtils, Menus;
7
8TYPE
9 TForm5 = Class(TForm)
10 timer: TTimer;
11 panel_preview: TPanel;
12 img: TImage;
13 panel_buttons: TPanel;
14 btn_dec: TButton;
15 btn_startstop: TButton;
16 btn_inc: TButton;
17 Splitter1: TSplitter;
18 lbl_notpossible: TLabel;
19 panel_files: TPanel;
20 list: TListBox;
21 panel_extension: TPanel;
22 lbl_filter: TLabel;
23 combo_extension: TComboBox;
24 check_zerobyte: TCheckBox;
25 edit_filtername: TEdit;
26 check_filtername: TCheckBox;
27 PROCEDURE LoadFileNames;
28 PROCEDURE check_filternameClick(Sender: TObject);
29 PROCEDURE check_zerobyteClick(Sender: TObject);
30 PROCEDURE combo_extensionClick(Sender: TObject);
31 PROCEDURE panel_extensionResize(Sender: TObject);
32 PROCEDURE listClick(Sender: TObject);
33 PROCEDURE Recreatelist;
34
35 PROCEDURE FormActivate(Sender: TObject);
36 PROCEDURE PreviewTXAN;
37 PROCEDURE PreviewTXMB;
38 PROCEDURE PreviewTXMP;
39 PROCEDURE btn_incClick(Sender: TObject);
40 PROCEDURE btn_decClick(Sender: TObject);
41 PROCEDURE FormResize(Sender: TObject);
42 PROCEDURE btn_startstopClick(Sender: TObject);
43 PROCEDURE panel_buttonsResize(Sender: TObject);
44 PROCEDURE timerTimer(Sender: TObject);
45 PROCEDURE FormCreate(Sender: TObject);
46 PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
47 PRIVATE
48 PUBLIC
49 END;
50
51VAR
52 Form5: TForm5;
53
54IMPLEMENTATION
55{$R *.dfm}
56USES Unit1_main;
57VAR
58 memstreams:Array OF TMemoryStream;
59 actualimg:Byte;
60 _fileid:LongWord;
61
62
63
64PROCEDURE TForm5.Recreatelist;
65 VAR
66 i:LongWord;
67 exts:TStringList;
68 BEGIN
69 combo_extension.Items.Clear;
70 combo_extension.Items.Add('_All files_ ('+IntToStr(GetFilesCount)+')');
71 exts:=GetExtensionsList;
72 FOR i:=0 TO High(exts) DO
73 combo_extension.Items.Add(exts[i]);
74 combo_extension.ItemIndex:=0;
75 combo_extensionClick(Self);
76 END;
77
78PROCEDURE TForm5.LoadFileNames;
79 VAR
80 Extension:String[4];
81 no_zero_bytes:Boolean;
82 pattern:String;
83 files:TStringList;
84 i:LongWord;
85 BEGIN
86 Extension:=MidStr(combo_extension.Items.Strings[combo_extension.ItemIndex],1,4);
87 no_zero_bytes:=NOT check_zerobyte.Checked;
88 pattern:='';
89 IF check_filtername.Checked THEN pattern:=edit_filtername.Text;
90 IF Extension='_All' THEN Extension:='';
91
92 files:=GetFilesList(extension,pattern,no_zero_bytes);
93 list.Items.Clear;
94 IF Length(files)>0 THEN
95 FOR i:=0 TO High(files) DO
96 list.Items.Add(files[i]);
97 END;
98
99PROCEDURE TForm5.panel_extensionResize(Sender: TObject);
100 BEGIN
101 combo_extension.Width:=panel_extension.Width-5;
102 edit_filtername.Width:=panel_extension.Width-5;
103 END;
104
105PROCEDURE TForm5.combo_extensionClick(Sender: TObject);
106 BEGIN
107 LoadFileNames;
108 END;
109
110PROCEDURE TForm5.check_zerobyteClick(Sender: TObject);
111 VAR
112 i:Byte;
113 BEGIN
114 LoadFileNames;
115 END;
116
117PROCEDURE TForm5.check_filternameClick(Sender: TObject);
118 BEGIN
119 edit_filtername.Enabled:=NOT check_filtername.Checked;
120 LoadFileNames;
121 END;
122
123PROCEDURE TForm5.listClick(Sender: TObject);
124 BEGIN
125 _fileid:=GetFileIDByName(list.Items.Strings[list.ItemIndex]);
126 lbl_notpossible.Visible:=False;
127 Self.img.Visible:=True;
128 Self.timer.Enabled:=False;
129 Self.panel_buttons.Visible:=False;
130 IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXAN' THEN PreviewTXAN
131 ELSE
132 IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXMB' THEN PreviewTXMB
133 ELSE
134 IF RightStr(list.Items.Strings[list.ItemIndex],4)='TXMP' THEN PreviewTXMP
135 ELSE BEGIN
136 Self.lbl_notpossible.Visible:=True;
137 Self.img.Visible:=False;
138 END;
139 END;
140
141
142
143PROCEDURE TForm5.PreviewTXMB;
144 VAR
145 data:Tdata;
146 img:TImgPackage;
147 BEGIN
148 SetLength(memstreams,1);
149 img:=LoadTXMBconnected(_fileid);
150 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
151
152 memstreams[0].Clear;
153 memstreams[0].Write(data[0],Length(data));
154 memstreams[0].Seek(0,soFromBeginning);
155
156 Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
157 END;
158
159PROCEDURE TForm5.PreviewTXMP;
160 VAR
161 data:Tdata;
162 img:TImgPackage;
163 BEGIN
164 SetLength(memstreams,1);
165 img:=LoadImgData(_fileid);
166 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
167
168 memstreams[0].Clear;
169 memstreams[0].Write(data[0],Length(data));
170 memstreams[0].Seek(0,soFromBeginning);
171
172 Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
173 END;
174
175PROCEDURE TForm5.PreviewTXAN;
176 VAR
177 loop_speed:Word;
178 linkcount:LongWord;
179 link:LongWord;
180 i:Byte;
181 data:Tdata;
182 img:TImgPackage;
183 BEGIN
184 LoadDatFilePart(_fileid,$14,SizeOf(loop_speed),@loop_speed);
185 LoadDatFilePart(_fileid,$1C,SizeOf(linkcount),@linkcount);
186 SetLength(memstreams,linkcount);
187 FOR i:=0 TO linkcount-1 DO BEGIN
188 LoadDatFilePart(_fileid,$20+i*4,SizeOf(link),@link);
189 link:=link DIV 256;
190 IF link=0 THEN link:=_fileid-1;
191 memstreams[i]:=TMemoryStream.Create;
192 img:=LoadImgData(link);
193 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
194 memstreams[i].Clear;
195 memstreams[i].Write(data[0],Length(data));
196 memstreams[i].Seek(0,soFromBeginning);
197 END;
198 actualimg:=254;
199 Self.timer.Interval:=Floor(loop_speed*(1/60)*1000);
200 Self.timer.Enabled:=False;
201 Self.btn_startstopClick(Self);
202 Self.panel_buttons.Visible:=True;
203 END;
204
205
206PROCEDURE TForm5.FormCreate(Sender: TObject);
207 BEGIN
208 SetLength(memstreams,1);
209 memstreams[0]:=TMemoryStream.Create;
210 Self.Width:=260;
211 Self.Height:=300;
212 END;
213
214PROCEDURE TForm5.timerTimer(Sender: TObject);
215 BEGIN
216 Inc(actualimg);
217 IF actualimg>=Length(memstreams) THEN actualimg:=0;
218 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
219 memstreams[actualimg].Seek(0,soFromBeginning);
220 Self.Caption:='Preview '+GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
221 END;
222
223PROCEDURE TForm5.panel_buttonsResize(Sender: TObject);
224 BEGIN
225 btn_startstop.Width:=panel_buttons.Width-45;
226 btn_inc.Left:=panel_buttons.Width-23;
227 END;
228
229PROCEDURE TForm5.btn_startstopClick(Sender: TObject);
230 BEGIN
231 Self.timer.Enabled:=NOT Self.timer.Enabled;
232 Self.btn_dec.Enabled:=NOT Self.timer.Enabled;
233 Self.btn_inc.Enabled:=NOT Self.timer.Enabled;
234 IF Self.timer.Enabled THEN
235 Self.btn_startstop.Caption:='Stop automatic'
236 ELSE
237 Self.btn_startstop.Caption:='Start automatic';
238 END;
239
240PROCEDURE TForm5.FormResize(Sender: TObject);
241 BEGIN
242 IF Self.Width>=300 THEN BEGIN
243 END ELSE Self.Width:=300;
244 IF Self.Height>=200 THEN BEGIN
245 END ELSE Self.Height:=200;
246 END;
247
248PROCEDURE TForm5.btn_decClick(Sender: TObject);
249 BEGIN
250 IF actualimg>0 THEN
251 Dec(actualimg)
252 ELSE
253 actualimg:=High(memstreams);
254 Self.Caption:='Preview '+GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
255 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
256 memstreams[actualimg].Seek(0,soFromBeginning);
257 END;
258
259PROCEDURE TForm5.btn_incClick(Sender: TObject);
260 BEGIN
261 IF actualimg<High(memstreams) THEN
262 Inc(actualimg)
263 ELSE
264 actualimg:=0;
265 Self.Caption:='Preview '+GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
266 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
267 memstreams[actualimg].Seek(0,soFromBeginning);
268 END;
269
270
271PROCEDURE TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
272 BEGIN
273 Action:=caFree;
274 Form1.close_window(Self.Name);
275 END;
276
277
278PROCEDURE TForm5.FormActivate(Sender: TObject);
279 BEGIN
280 Form1.SetActiveWindow(Self.Name);
281 END;
282
283END.
Note: See TracBrowser for help on using the repository browser.