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