source: oup/current/Tools/Preview.pas@ 46

Last change on this file since 46 was 46, checked in by alloc, 18 years ago
File size: 5.2 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: LongWord;
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 lbl_notpossible.Visible := False;
58 Self.img.Visible := True;
59 Self.timer.Enabled := False;
60 Self.panel_buttons.Visible := False;
61 ext := fileinfo.Extension;
62 if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
63 PreviewImage
64 else if ext = 'TXAN' then
65 PreviewTXAN
66 else
67 begin
68 Self.lbl_notpossible.Visible := True;
69 Self.img.Visible := False;
70 end;
71end;
72
73
74procedure TForm_Preview.LoadImage(fileid, index: Integer);
75var
76 Data: Tdata;
77 memstream: TMemoryStream;
78 OniImage: TOniImage;
79
80begin
81 OniImage := TOniImage.Create;
82 OniImage.Load(fileid);
83 Data := OniImage.GetAsBMP;
84 OniImage.Free;
85
86 memstream := TMemoryStream.Create;
87 memstream.Write(Data[0], Length(Data));
88 memstream.Seek(0, soFromBeginning);
89 bitmaps[index].LoadFromStream(memstream);
90 memstream.Free;
91end;
92
93
94procedure TForm_Preview.DrawImage(index: Integer);
95begin
96 BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
97 bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
98 BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
99 bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
100 img.Invalidate;
101end;
102
103
104procedure TForm_Preview.SetBitmapCount(Count: Integer);
105var
106 i: Integer;
107begin
108 if Length(bitmaps) > Count then
109 begin
110 for i := Count to High(bitmaps) do
111 bitmaps[i].Free;
112 SetLength(bitmaps, Count);
113 end;
114 if Length(bitmaps) < Count then
115 begin
116 i := Length(bitmaps);
117 SetLength(bitmaps, Count);
118 for i := i to High(bitmaps) do
119 bitmaps[i] := TBitmap.Create;
120 end;
121end;
122
123
124procedure TForm_Preview.PreviewImage;
125begin
126 SetBitmapCount(1);
127 LoadImage(_fileid, 0);
128 DrawImage(0);
129end;
130
131
132procedure TForm_Preview.PreviewTXAN;
133var
134 loop_speed: Word;
135 linkcount: LongWord;
136 link: LongWord;
137 i: Byte;
138begin
139 OniDataConnection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
140 OniDataConnection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
141 SetBitmapCount(linkcount);
142 for i := 0 to linkcount - 1 do
143 begin
144 OniDataConnection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
145 link := link div 256;
146 if link = 0 then
147 link := _fileid - 1;
148 LoadImage(link, i);
149 end;
150 actualimg := 254;
151 Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
152 Self.timer.Enabled := False;
153 Self.btn_startstopClick(Self);
154 Self.panel_buttons.Visible := True;
155end;
156
157
158procedure TForm_Preview.timerTimer(Sender: TObject);
159begin
160 btn_incClick(Self);
161end;
162
163
164procedure TForm_Preview.btn_startstopClick(Sender: TObject);
165begin
166 Self.timer.Enabled := not Self.timer.Enabled;
167 Self.btn_dec.Enabled := not Self.timer.Enabled;
168 Self.btn_inc.Enabled := not Self.timer.Enabled;
169 if Self.timer.Enabled then
170 Self.btn_startstop.Caption := 'Stop automatic'
171 else
172 Self.btn_startstop.Caption := 'Start automatic';
173end;
174
175
176procedure TForm_Preview.btn_decClick(Sender: TObject);
177begin
178 if actualimg > 0 then
179 Dec(actualimg)
180 else
181 actualimg := High(bitmaps);
182 Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
183 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
184 DrawImage(actualimg);
185end;
186
187
188procedure TForm_Preview.btn_incClick(Sender: TObject);
189begin
190 if actualimg < High(bitmaps) then
191 Inc(actualimg)
192 else
193 actualimg := 0;
194 Self.Caption := 'Preview ' + OniDataConnection.GetFileInfo(_fileid).FileName +
195 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
196 DrawImage(actualimg);
197end;
198
199
200procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
201begin
202 btn_startstop.Width := panel_buttons.Width - 45;
203 btn_inc.Left := panel_buttons.Width - 23;
204end;
205
206
207begin
208 AddToolListEntry('preview', 'Preview-Window', '');
209end.
Note: See TracBrowser for help on using the repository browser.