source: oup/releases/0.13a/Unit5_preview.pas@ 1161

Last change on this file since 1161 was 21, checked in by alloc, 18 years ago
File size: 5.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;
7
8TYPE
9 TForm5 = Class(TForm)
10 img: TImage;
11 timer: TTimer;
12 panel_buttons: TPanel;
13 btn_dec: TButton;
14 btn_startstop: TButton;
15 btn_inc: TButton;
16 PROCEDURE btn_incClick(Sender: TObject);
17 PROCEDURE btn_decClick(Sender: TObject);
18 PROCEDURE FormResize(Sender: TObject);
19 PROCEDURE btn_startstopClick(Sender: TObject);
20 PROCEDURE panel_buttonsResize(Sender: TObject);
21 PROCEDURE timerTimer(Sender: TObject);
22 PROCEDURE FormCreate(Sender: TObject);
23 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
24 PROCEDURE ShowPreview(fileid:LongWord);
25 PRIVATE
26 PUBLIC
27 END;
28
29VAR
30 Form5: TForm5;
31
32IMPLEMENTATION
33{$R *.dfm}
34USES Unit1_main;
35VAR
36 memstreams:Array OF TMemoryStream;
37 actualimg:Byte;
38 _fileid:LongWord;
39
40PROCEDURE PreviewTXMB;
41 VAR
42 data:Tdata;
43 img:TImgPackage;
44 BEGIN
45 SetLength(memstreams,1);
46 img:=LoadTXMBconnected(_fileid);
47 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
48
49 memstreams[0].Clear;
50 memstreams[0].Write(data[0],Length(data));
51 memstreams[0].Seek(0,soFromBeginning);
52
53 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
54 END;
55
56PROCEDURE PreviewTXMP;
57 VAR
58 data:Tdata;
59 img:TImgPackage;
60 BEGIN
61 {
62 tempdata:=ResizeImage(imgx,imgy,imgdepth,tempdata);
63 imgx:=imgx DIV 2;
64 imgy:=imgy DIV 2;
65 datasize:=datasize DIV 4;
66 }
67 SetLength(memstreams,1);
68 img:=LoadImgData(_fileid);
69 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
70
71 memstreams[0].Clear;
72 memstreams[0].Write(data[0],Length(data));
73 memstreams[0].Seek(0,soFromBeginning);
74
75 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
76 END;
77
78PROCEDURE PreviewTXAN;
79 VAR
80 loop_speed:Word;
81 linkcount:LongWord;
82 link:LongWord;
83 i:Byte;
84 data:Tdata;
85 img:TImgPackage;
86 BEGIN
87 LoadDatFilePart(_fileid,$14,SizeOf(loop_speed),@loop_speed);
88 LoadDatFilePart(_fileid,$1C,SizeOf(linkcount),@linkcount);
89 SetLength(memstreams,linkcount);
90 FOR i:=0 TO linkcount-1 DO BEGIN
91 LoadDatFilePart(_fileid,$20+i*4,SizeOf(link),@link);
92 link:=link DIV 256;
93 IF link=0 THEN link:=_fileid-1;
94 memstreams[i]:=TMemoryStream.Create;
95 img:=LoadImgData(link);
96 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
97 memstreams[i].Clear;
98 memstreams[i].Write(data[0],Length(data));
99 memstreams[i].Seek(0,soFromBeginning);
100 END;
101 actualimg:=254;
102 Form5.timer.Interval:=Floor(loop_speed*(1/60)*1000);
103 Form5.timer.Enabled:=False;
104 Form5.btn_startstopClick(Form5);
105 Form5.panel_buttons.Visible:=True;
106 END;
107
108PROCEDURE TForm5.ShowPreview(fileid:LongWord);
109 BEGIN
110 _fileid:=fileid;
111 Form5.timer.Enabled:=False;
112 Form5.panel_buttons.Visible:=False;
113 Form5.Caption:='Preview '+dat_files[_fileid].FileName;
114 IF dat_files[fileid].Extension='TXAN' THEN PreviewTXAN;
115 IF dat_files[fileid].Extension='TXMB' THEN PreviewTXMB;
116 IF dat_files[fileid].Extension='TXMP' THEN PreviewTXMP;
117 END;
118
119PROCEDURE TForm5.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
120 BEGIN
121 CanClose:=False;
122 Form5.Visible:=False;
123 END;
124
125PROCEDURE TForm5.FormCreate(Sender: TObject);
126 BEGIN
127 SetLength(memstreams,1);
128 memstreams[0]:=TMemoryStream.Create;
129 Form5.Width:=170;
130 Form5.Height:=200;
131 END;
132
133PROCEDURE TForm5.timerTimer(Sender: TObject);
134 BEGIN
135 Inc(actualimg);
136 IF actualimg>=Length(memstreams) THEN actualimg:=0;
137 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
138 memstreams[actualimg].Seek(0,soFromBeginning);
139 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
140 END;
141
142PROCEDURE TForm5.panel_buttonsResize(Sender: TObject);
143 BEGIN
144 btn_startstop.Width:=panel_buttons.Width-45;
145 btn_inc.Left:=panel_buttons.Width-23;
146 END;
147
148PROCEDURE TForm5.btn_startstopClick(Sender: TObject);
149 BEGIN
150 Form5.timer.Enabled:=NOT Form5.timer.Enabled;
151 Form5.btn_dec.Enabled:=NOT Form5.timer.Enabled;
152 Form5.btn_inc.Enabled:=NOT Form5.timer.Enabled;
153 IF Form5.timer.Enabled THEN
154 Form5.btn_startstop.Caption:='Stop automatic'
155 ELSE
156 Form5.btn_startstop.Caption:='Start automatic';
157 END;
158
159PROCEDURE TForm5.FormResize(Sender: TObject);
160 BEGIN
161 IF Form5.Width>=150 THEN BEGIN
162 END ELSE Form5.Width:=150;
163 IF Form5.Height>=150 THEN BEGIN
164 END ELSE Form5.Height:=150;
165 END;
166
167PROCEDURE TForm5.btn_decClick(Sender: TObject);
168 BEGIN
169 IF actualimg>0 THEN
170 Dec(actualimg)
171 ELSE
172 actualimg:=High(memstreams);
173 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
174 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
175 memstreams[actualimg].Seek(0,soFromBeginning);
176 END;
177
178PROCEDURE TForm5.btn_incClick(Sender: TObject);
179 BEGIN
180 IF actualimg<High(memstreams) THEN
181 Inc(actualimg)
182 ELSE
183 actualimg:=0;
184 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
185 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
186 memstreams[actualimg].Seek(0,soFromBeginning);
187 END;
188
189END.
Note: See TracBrowser for help on using the repository browser.