1 | unit Preview;
|
---|
2 | interface
|
---|
3 | uses
|
---|
4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
5 | Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
|
---|
6 | ConnectionManager, OniImgClass, Data, TypeDefs, Menus, Buttons;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
38 | var
|
---|
39 | Form_Preview: TForm_Preview;
|
---|
40 |
|
---|
41 | implementation
|
---|
42 | {$R *.dfm}
|
---|
43 |
|
---|
44 |
|
---|
45 | procedure TForm_Preview.FormCreate(Sender: TObject);
|
---|
46 | begin
|
---|
47 | inherited;
|
---|
48 | Self.OnNewFileSelected := NewFile;
|
---|
49 | end;
|
---|
50 |
|
---|
51 |
|
---|
52 | procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
|
---|
53 | var
|
---|
54 | ext: String;
|
---|
55 | begin
|
---|
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;
|
---|
81 | end;
|
---|
82 |
|
---|
83 |
|
---|
84 | procedure TForm_Preview.LoadImage(fileid, index: Integer);
|
---|
85 | var
|
---|
86 | memstream: TMemoryStream;
|
---|
87 | OniImage: TOniImage;
|
---|
88 | begin
|
---|
89 | OniImage := TOniImage.Create;
|
---|
90 | OniImage.Load(ConnectionID, fileid);
|
---|
91 | memstream := TMemoryStream.Create;
|
---|
92 | OniImage.GetAsBMP(TStream(memstream));
|
---|
93 | OniImage.Free;
|
---|
94 | bitmaps[index].LoadFromStream(memstream);
|
---|
95 | memstream.Free;
|
---|
96 | end;
|
---|
97 |
|
---|
98 |
|
---|
99 | procedure TForm_Preview.DrawImage(index: Integer);
|
---|
100 | begin
|
---|
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;
|
---|
106 | end;
|
---|
107 |
|
---|
108 |
|
---|
109 | procedure TForm_Preview.SetBitmapCount(Count: Integer);
|
---|
110 | var
|
---|
111 | i: Integer;
|
---|
112 | begin
|
---|
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;
|
---|
126 | end;
|
---|
127 |
|
---|
128 |
|
---|
129 | procedure TForm_Preview.PreviewImage;
|
---|
130 | begin
|
---|
131 | SetBitmapCount(1);
|
---|
132 | LoadImage(_fileid, 0);
|
---|
133 | DrawImage(0);
|
---|
134 | end;
|
---|
135 |
|
---|
136 |
|
---|
137 | procedure TForm_Preview.PreviewTXAN;
|
---|
138 | var
|
---|
139 | loop_speed: Word;
|
---|
140 | linkcount: LongWord;
|
---|
141 | link: LongWord;
|
---|
142 | i: Byte;
|
---|
143 | begin
|
---|
144 | ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
|
---|
145 | ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
|
---|
146 | SetBitmapCount(linkcount);
|
---|
147 | for i := 0 to linkcount - 1 do
|
---|
148 | begin
|
---|
149 | ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
|
---|
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;
|
---|
160 | end;
|
---|
161 |
|
---|
162 |
|
---|
163 | procedure TForm_Preview.timerTimer(Sender: TObject);
|
---|
164 | begin
|
---|
165 | btn_incClick(Self);
|
---|
166 | end;
|
---|
167 |
|
---|
168 |
|
---|
169 | procedure TForm_Preview.btn_startstopClick(Sender: TObject);
|
---|
170 | begin
|
---|
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';
|
---|
178 | end;
|
---|
179 |
|
---|
180 |
|
---|
181 | procedure TForm_Preview.btn_decClick(Sender: TObject);
|
---|
182 | begin
|
---|
183 | if actualimg > 0 then
|
---|
184 | Dec(actualimg)
|
---|
185 | else
|
---|
186 | actualimg := High(bitmaps);
|
---|
187 | Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
|
---|
188 | ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
|
---|
189 | DrawImage(actualimg);
|
---|
190 | end;
|
---|
191 |
|
---|
192 |
|
---|
193 | procedure TForm_Preview.btn_incClick(Sender: TObject);
|
---|
194 | begin
|
---|
195 | if actualimg < High(bitmaps) then
|
---|
196 | Inc(actualimg)
|
---|
197 | else
|
---|
198 | actualimg := 0;
|
---|
199 | Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
|
---|
200 | ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
|
---|
201 | DrawImage(actualimg);
|
---|
202 | end;
|
---|
203 |
|
---|
204 |
|
---|
205 | procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
|
---|
206 | begin
|
---|
207 | btn_startstop.Width := panel_buttons.Width - 45;
|
---|
208 | btn_inc.Left := panel_buttons.Width - 23;
|
---|
209 | end;
|
---|
210 |
|
---|
211 |
|
---|
212 | begin
|
---|
213 | AddToolListEntry('preview', 'Preview-Window', '');
|
---|
214 | end.
|
---|