source: oup/releases/0.32a/Unit5_preview.pas@ 255

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