source: oup/releases/0.18a2/Unit5_preview.pas@ 1088

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