source: oup/releases/0.19a/Unit5_preview.pas@ 186

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