source: oup/releases/0.31a/Unit5_preview.pas@ 916

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