source: oup/releases/0.14a/Unit5_preview.pas@ 933

Last change on this file since 933 was 21, checked in by alloc, 18 years ago
File size: 5.4 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 SetLength(memstreams,1);
62 img:=LoadImgData(_fileid);
63 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
64
65 memstreams[0].Clear;
66 memstreams[0].Write(data[0],Length(data));
67 memstreams[0].Seek(0,soFromBeginning);
68
69 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[0]);
70 END;
71
72PROCEDURE PreviewTXAN;
73 VAR
74 loop_speed:Word;
75 linkcount:LongWord;
76 link:LongWord;
77 i:Byte;
78 data:Tdata;
79 img:TImgPackage;
80 BEGIN
81 LoadDatFilePart(_fileid,$14,SizeOf(loop_speed),@loop_speed);
82 LoadDatFilePart(_fileid,$1C,SizeOf(linkcount),@linkcount);
83 SetLength(memstreams,linkcount);
84 FOR i:=0 TO linkcount-1 DO BEGIN
85 LoadDatFilePart(_fileid,$20+i*4,SizeOf(link),@link);
86 link:=link DIV 256;
87 IF link=0 THEN link:=_fileid-1;
88 memstreams[i]:=TMemoryStream.Create;
89 img:=LoadImgData(link);
90 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
91 memstreams[i].Clear;
92 memstreams[i].Write(data[0],Length(data));
93 memstreams[i].Seek(0,soFromBeginning);
94 END;
95 actualimg:=254;
96 Form5.timer.Interval:=Floor(loop_speed*(1/60)*1000);
97 Form5.timer.Enabled:=False;
98 Form5.btn_startstopClick(Form5);
99 Form5.panel_buttons.Visible:=True;
100 END;
101
102PROCEDURE TForm5.ShowPreview(fileid:LongWord);
103 BEGIN
104 _fileid:=fileid;
105 Form5.timer.Enabled:=False;
106 Form5.panel_buttons.Visible:=False;
107 Form5.Caption:='Preview '+dat_files[_fileid].FileName;
108 IF dat_files[fileid].Extension='TXAN' THEN PreviewTXAN;
109 IF dat_files[fileid].Extension='TXMB' THEN PreviewTXMB;
110 IF dat_files[fileid].Extension='TXMP' THEN PreviewTXMP;
111 END;
112
113PROCEDURE TForm5.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
114 BEGIN
115 CanClose:=False;
116 Form5.Visible:=False;
117 END;
118
119PROCEDURE TForm5.FormCreate(Sender: TObject);
120 BEGIN
121 SetLength(memstreams,1);
122 memstreams[0]:=TMemoryStream.Create;
123 Form5.Width:=170;
124 Form5.Height:=200;
125 END;
126
127PROCEDURE TForm5.timerTimer(Sender: TObject);
128 BEGIN
129 Inc(actualimg);
130 IF actualimg>=Length(memstreams) THEN actualimg:=0;
131 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
132 memstreams[actualimg].Seek(0,soFromBeginning);
133 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
134 END;
135
136PROCEDURE TForm5.panel_buttonsResize(Sender: TObject);
137 BEGIN
138 btn_startstop.Width:=panel_buttons.Width-45;
139 btn_inc.Left:=panel_buttons.Width-23;
140 END;
141
142PROCEDURE TForm5.btn_startstopClick(Sender: TObject);
143 BEGIN
144 Form5.timer.Enabled:=NOT Form5.timer.Enabled;
145 Form5.btn_dec.Enabled:=NOT Form5.timer.Enabled;
146 Form5.btn_inc.Enabled:=NOT Form5.timer.Enabled;
147 IF Form5.timer.Enabled THEN
148 Form5.btn_startstop.Caption:='Stop automatic'
149 ELSE
150 Form5.btn_startstop.Caption:='Start automatic';
151 END;
152
153PROCEDURE TForm5.FormResize(Sender: TObject);
154 BEGIN
155 IF Form5.Width>=150 THEN BEGIN
156 END ELSE Form5.Width:=150;
157 IF Form5.Height>=150 THEN BEGIN
158 END ELSE Form5.Height:=150;
159 END;
160
161PROCEDURE TForm5.btn_decClick(Sender: TObject);
162 BEGIN
163 IF actualimg>0 THEN
164 Dec(actualimg)
165 ELSE
166 actualimg:=High(memstreams);
167 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
168 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
169 memstreams[actualimg].Seek(0,soFromBeginning);
170 END;
171
172PROCEDURE TForm5.btn_incClick(Sender: TObject);
173 BEGIN
174 IF actualimg<High(memstreams) THEN
175 Inc(actualimg)
176 ELSE
177 actualimg:=0;
178 Form5.Caption:='Preview '+dat_files[_fileid].FileName+' ('+IntToStr(actualimg+1)+'/'+IntToStr(Length(memstreams))+')';
179 Form5.img.Picture.Bitmap.LoadFromStream(memstreams[actualimg]);
180 memstreams[actualimg].Seek(0,soFromBeginning);
181 END;
182
183END.
Note: See TracBrowser for help on using the repository browser.