source: oup/releases/0.11a/Unit5_preview.pas@ 36

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