source: oup/_old_/Tools/Preview.pas@ 186

Last change on this file since 186 was 87, checked in by alloc, 18 years ago
File size: 5.4 KB
Line 
1unit Preview;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
6 OniDataClass, OniImgClass, Data, Menus, Buttons;
7
8type
9 TForm_Preview = class(TForm_ToolTemplate)
10 lbl_notpossible: TLabel;
11 panel_buttons: TPanel;
12 btn_dec: TButton;
13 btn_startstop: TButton;
14 btn_inc: TButton;
15 img: TImage;
16 timer: TTimer;
17 procedure FormCreate(Sender: TObject);
18 procedure NewFile(fileinfo: TFileInfo);
19
20 procedure PreviewImage;
21 procedure PreviewTXAN;
22 procedure btn_incClick(Sender: TObject);
23 procedure btn_decClick(Sender: TObject);
24 procedure btn_startstopClick(Sender: TObject);
25 procedure timerTimer(Sender: TObject);
26 procedure panel_buttonsResize(Sender: TObject);
27
28 procedure DrawImage(index: Integer);
29 procedure SetBitmapCount(Count: Integer);
30 procedure LoadImage(fileid, index: Integer);
31 private
32 bitmaps: array of TBitmap;
33 actualimg: Byte;
34 _fileid: Integer;
35 public
36 end;
37
38var
39 Form_Preview: TForm_Preview;
40
41implementation
42{$R *.dfm}
43
44
45procedure TForm_Preview.FormCreate(Sender: TObject);
46begin
47 inherited;
48 Self.OnNewFileSelected := NewFile;
49end;
50
51
52procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
53var
54 ext: String;
55begin
56 _fileid := fileinfo.ID;
57 if _fileid >= 0 then
58 begin
59 lbl_notpossible.Visible := False;
60 Self.img.Visible := True;
61 Self.timer.Enabled := False;
62 Self.panel_buttons.Visible := False;
63 ext := fileinfo.Extension;
64 if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
65 PreviewImage
66 else if ext = 'TXAN' then
67 PreviewTXAN
68 else
69 begin
70 Self.lbl_notpossible.Visible := True;
71 Self.img.Visible := False;
72 end;
73 end
74 else
75 begin
76 Self.img.Visible := False;
77 lbl_notpossible.Visible := False;
78 Self.timer.Enabled := False;
79 Self.panel_buttons.Visible := False;
80 end;
81end;
82
83
84procedure TForm_Preview.LoadImage(fileid, index: Integer);
85var
86 Data: Tdata;
87 memstream: TMemoryStream;
88 OniImage: TOniImage;
89
90begin
91 OniImage := TOniImage.Create;
92 OniImage.Load(Connection, fileid);
93 Data := OniImage.GetAsBMP;
94 OniImage.Free;
95
96 memstream := TMemoryStream.Create;
97 memstream.Write(Data[0], Length(Data));
98 memstream.Seek(0, soFromBeginning);
99 bitmaps[index].LoadFromStream(memstream);
100 memstream.Free;
101end;
102
103
104procedure TForm_Preview.DrawImage(index: Integer);
105begin
106 BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
107 bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
108 BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
109 bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
110 img.Invalidate;
111end;
112
113
114procedure TForm_Preview.SetBitmapCount(Count: Integer);
115var
116 i: Integer;
117begin
118 if Length(bitmaps) > Count then
119 begin
120 for i := Count to High(bitmaps) do
121 bitmaps[i].Free;
122 SetLength(bitmaps, Count);
123 end;
124 if Length(bitmaps) < Count then
125 begin
126 i := Length(bitmaps);
127 SetLength(bitmaps, Count);
128 for i := i to High(bitmaps) do
129 bitmaps[i] := TBitmap.Create;
130 end;
131end;
132
133
134procedure TForm_Preview.PreviewImage;
135begin
136 SetBitmapCount(1);
137 LoadImage(_fileid, 0);
138 DrawImage(0);
139end;
140
141
142procedure TForm_Preview.PreviewTXAN;
143var
144 loop_speed: Word;
145 linkcount: LongWord;
146 link: LongWord;
147 i: Byte;
148begin
149 Connection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
150 Connection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
151 SetBitmapCount(linkcount);
152 for i := 0 to linkcount - 1 do
153 begin
154 Connection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
155 link := link div 256;
156 if link = 0 then
157 link := _fileid - 1;
158 LoadImage(link, i);
159 end;
160 actualimg := 254;
161 Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
162 Self.timer.Enabled := False;
163 Self.btn_startstopClick(Self);
164 Self.panel_buttons.Visible := True;
165end;
166
167
168procedure TForm_Preview.timerTimer(Sender: TObject);
169begin
170 btn_incClick(Self);
171end;
172
173
174procedure TForm_Preview.btn_startstopClick(Sender: TObject);
175begin
176 Self.timer.Enabled := not Self.timer.Enabled;
177 Self.btn_dec.Enabled := not Self.timer.Enabled;
178 Self.btn_inc.Enabled := not Self.timer.Enabled;
179 if Self.timer.Enabled then
180 Self.btn_startstop.Caption := 'Stop automatic'
181 else
182 Self.btn_startstop.Caption := 'Start automatic';
183end;
184
185
186procedure TForm_Preview.btn_decClick(Sender: TObject);
187begin
188 if actualimg > 0 then
189 Dec(actualimg)
190 else
191 actualimg := High(bitmaps);
192 Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
193 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
194 DrawImage(actualimg);
195end;
196
197
198procedure TForm_Preview.btn_incClick(Sender: TObject);
199begin
200 if actualimg < High(bitmaps) then
201 Inc(actualimg)
202 else
203 actualimg := 0;
204 Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
205 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
206 DrawImage(actualimg);
207end;
208
209
210procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
211begin
212 btn_startstop.Width := panel_buttons.Width - 45;
213 btn_inc.Left := panel_buttons.Width - 23;
214end;
215
216
217begin
218 AddToolListEntry('preview', 'Preview-Window', '');
219end.
Note: See TracBrowser for help on using the repository browser.