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

Last change on this file since 125 was 111, checked in by alloc, 18 years ago
File size: 5.4 KB
RevLine 
[93]1unit Preview;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
[97]6 ConnectionManager, OniImgClass, Data, TypeDefs, Menus, Buttons;
[93]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 memstream: TMemoryStream;
87 OniImage: TOniImage;
88begin
89 OniImage := TOniImage.Create;
[97]90 OniImage.Load(ConnectionID, fileid);
[101]91 memstream := TMemoryStream.Create;
92 OniImage.GetAsBMP(TStream(memstream));
[93]93 OniImage.Free;
94 bitmaps[index].LoadFromStream(memstream);
95 memstream.Free;
96end;
97
98
99procedure TForm_Preview.DrawImage(index: Integer);
100begin
101 BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
102 bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
103 BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
104 bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
105 img.Invalidate;
106end;
107
108
109procedure TForm_Preview.SetBitmapCount(Count: Integer);
110var
111 i: Integer;
112begin
113 if Length(bitmaps) > Count then
114 begin
115 for i := Count to High(bitmaps) do
116 bitmaps[i].Free;
117 SetLength(bitmaps, Count);
118 end;
119 if Length(bitmaps) < Count then
120 begin
121 i := Length(bitmaps);
122 SetLength(bitmaps, Count);
123 for i := i to High(bitmaps) do
124 bitmaps[i] := TBitmap.Create;
125 end;
126end;
127
128
129procedure TForm_Preview.PreviewImage;
130begin
131 SetBitmapCount(1);
132 LoadImage(_fileid, 0);
133 DrawImage(0);
134end;
135
136
137procedure TForm_Preview.PreviewTXAN;
138var
139 loop_speed: Word;
[111]140 linkcount: Integer;
141 link: Integer;
[93]142 i: Byte;
143begin
[97]144 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
145 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
[93]146 SetBitmapCount(linkcount);
147 for i := 0 to linkcount - 1 do
148 begin
[97]149 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
[93]150 link := link div 256;
151 if link = 0 then
152 link := _fileid - 1;
153 LoadImage(link, i);
154 end;
155 actualimg := 254;
156 Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
157 Self.timer.Enabled := False;
158 Self.btn_startstopClick(Self);
159 Self.panel_buttons.Visible := True;
160end;
161
162
163procedure TForm_Preview.timerTimer(Sender: TObject);
164begin
165 btn_incClick(Self);
166end;
167
168
169procedure TForm_Preview.btn_startstopClick(Sender: TObject);
170begin
171 Self.timer.Enabled := not Self.timer.Enabled;
172 Self.btn_dec.Enabled := not Self.timer.Enabled;
173 Self.btn_inc.Enabled := not Self.timer.Enabled;
174 if Self.timer.Enabled then
175 Self.btn_startstop.Caption := 'Stop automatic'
176 else
177 Self.btn_startstop.Caption := 'Start automatic';
178end;
179
180
181procedure TForm_Preview.btn_decClick(Sender: TObject);
182begin
183 if actualimg > 0 then
184 Dec(actualimg)
185 else
186 actualimg := High(bitmaps);
[97]187 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
[93]188 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
189 DrawImage(actualimg);
190end;
191
192
193procedure TForm_Preview.btn_incClick(Sender: TObject);
194begin
195 if actualimg < High(bitmaps) then
196 Inc(actualimg)
197 else
198 actualimg := 0;
[97]199 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
[93]200 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
201 DrawImage(actualimg);
202end;
203
204
205procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
206begin
207 btn_startstop.Width := panel_buttons.Width - 45;
208 btn_inc.Left := panel_buttons.Width - 23;
209end;
210
211
212begin
213 AddToolListEntry('preview', 'Preview-Window', '');
214end.
Note: See TracBrowser for help on using the repository browser.