source: oup/releases/0.18a/Unit5_preview.pas@ 845

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