source: oup/current/Unit5_preview.pas@ 17

Last change on this file since 17 was 10, checked in by alloc, 18 years ago
  • Property svn:executable set to *
File size: 8.6 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 PreviewTXAN;
36 PROCEDURE PreviewTXMB;
37 PROCEDURE PreviewTXMP;
38 PROCEDURE PreviewPSpc;
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)='PSpc' THEN PreviewPSpc
129 ELSE
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.PreviewPSpc;
144 VAR
145 OniImage:TOniImage;
146 data:Tdata;
147 BEGIN
148 SetLength(memstreams,1);
149 OniImage:=TOniImage.Create;
150 OniImage.LoadFromPSpc(_fileid);
151 data:=OniImage.GetAsBMP;
152 OniImage.Free;
153
154 memstreams[0].Clear;
155 memstreams[0].Write(data[0],Length(data));
156 memstreams[0].Seek(0,soFromBeginning);
157
158 Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
159 END;
160
161
162PROCEDURE TForm5.PreviewTXMB;
163 VAR
164 OniImage:TOniImage;
165 data:Tdata;
166 BEGIN
167 SetLength(memstreams,1);
168 OniImage:=TOniImage.Create;
169 OniImage.LoadFromTXMB(_fileid);
170 data:=OniImage.GetAsBMP;
171 OniImage.Free;
172
173 memstreams[0].Clear;
174 memstreams[0].Write(data[0],Length(data));
175 memstreams[0].Seek(0,soFromBeginning);
176
177 Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
178 END;
179
180PROCEDURE TForm5.PreviewTXMP;
181 VAR
182 OniImage:TOniImage;
183 data:Tdata;
184 BEGIN
185 SetLength(memstreams,1);
186 OniImage:=TOniImage.Create;
187 OniImage.LoadFromTXMP(_fileid);
188 data:=OniImage.GetAsBMP;
189 OniImage.Free;
190
191 memstreams[0].Clear;
192 memstreams[0].Write(data[0],Length(data));
193 memstreams[0].Seek(0,soFromBeginning);
194
195 Self.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
196 END;
197
198PROCEDURE TForm5.PreviewTXAN;
199 VAR
200 loop_speed:Word;
201 linkcount:LongWord;
202 link:LongWord;
203 i:Byte;
204 data:Tdata;
205 OniImage:TOniImage;
206 BEGIN
207 OniDataConnection.LoadDatFilePart(_fileid,$14,SizeOf(loop_speed),@loop_speed);
208 OniDataConnection.LoadDatFilePart(_fileid,$1C,SizeOf(linkcount),@linkcount);
209 SetLength(memstreams,linkcount);
210 FOR i:=0 TO linkcount-1 DO BEGIN
211 OniDataConnection.LoadDatFilePart(_fileid,$20+i*4,SizeOf(link),@link);
212 link:=link DIV 256;
213 IF link=0 THEN link:=_fileid-1;
214 memstreams[i]:=TMemoryStream.Create;
215 OniImage:=TOniImage.Create;
216 OniImage.LoadFromTXMP(link);
217 data:=OniImage.GetAsBMP;
218 OniImage.Free;
219 memstreams[i].Clear;
220 memstreams[i].Write(data[0],Length(data));
221 memstreams[i].Seek(0,soFromBeginning);
222 END;
223 actualimg:=254;
224 Self.timer.Interval:=Floor(loop_speed*(1/60)*1000);
225 Self.timer.Enabled:=False;
226 Self.btn_startstopClick(Self);
227 Self.panel_buttons.Visible:=True;
228 END;
229
230
231PROCEDURE TForm5.FormCreate(Sender: TObject);
232 BEGIN
233 SetLength(memstreams,1);
234 memstreams[0]:=TMemoryStream.Create;
235 Self.Width:=260;
236 Self.Height:=300;
237 END;
238
239PROCEDURE TForm5.timerTimer(Sender: TObject);
240 BEGIN
241 Inc(actualimg);
242 IF actualimg>=Length(memstreams) THEN actualimg:=0;
243 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
244 memstreams[actualimg].Seek(0,soFromBeginning);
245 Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
246 END;
247
248PROCEDURE TForm5.panel_buttonsResize(Sender: TObject);
249 BEGIN
250 btn_startstop.Width:=panel_buttons.Width-45;
251 btn_inc.Left:=panel_buttons.Width-23;
252 END;
253
254PROCEDURE TForm5.btn_startstopClick(Sender: TObject);
255 BEGIN
256 Self.timer.Enabled:=NOT Self.timer.Enabled;
257 Self.btn_dec.Enabled:=NOT Self.timer.Enabled;
258 Self.btn_inc.Enabled:=NOT Self.timer.Enabled;
259 IF Self.timer.Enabled THEN
260 Self.btn_startstop.Caption:='Stop automatic'
261 ELSE
262 Self.btn_startstop.Caption:='Start automatic';
263 END;
264
265PROCEDURE TForm5.FormResize(Sender: TObject);
266 BEGIN
267 IF Self.Width>=300 THEN BEGIN
268 END ELSE Self.Width:=300;
269 IF Self.Height>=200 THEN BEGIN
270 END ELSE Self.Height:=200;
271 END;
272
273PROCEDURE TForm5.btn_decClick(Sender: TObject);
274 BEGIN
275 IF actualimg>0 THEN
276 Dec(actualimg)
277 ELSE
278 actualimg:=High(memstreams);
279 Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
280 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
281 memstreams[actualimg].Seek(0,soFromBeginning);
282 END;
283
284PROCEDURE TForm5.btn_incClick(Sender: TObject);
285 BEGIN
286 IF actualimg<High(memstreams) THEN
287 Inc(actualimg)
288 ELSE
289 actualimg:=0;
290 Self.Caption:='Preview '+OniDataConnection.GetFileInfo(_fileid).FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
291 Self.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
292 memstreams[actualimg].Seek(0,soFromBeginning);
293 END;
294
295
296PROCEDURE TForm5.FormClose(Sender: TObject; var Action: TCloseAction);
297 BEGIN
298 Action:=caFree;
299 END;
300
301END.
Note: See TracBrowser for help on using the repository browser.