1 | unit Preview;
|
---|
2 | interface
|
---|
3 | uses
|
---|
4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
5 | Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
|
---|
6 | OniDataClass, OniImgClass, Data, 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: LongWord;
|
---|
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 | 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;
|
---|
71 | end;
|
---|
72 |
|
---|
73 |
|
---|
74 | procedure TForm_Preview.LoadImage(fileid, index: Integer);
|
---|
75 | var
|
---|
76 | Data: Tdata;
|
---|
77 | memstream: TMemoryStream;
|
---|
78 | OniImage: TOniImage;
|
---|
79 |
|
---|
80 | begin
|
---|
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;
|
---|
91 | end;
|
---|
92 |
|
---|
93 |
|
---|
94 | procedure TForm_Preview.DrawImage(index: Integer);
|
---|
95 | begin
|
---|
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;
|
---|
101 | end;
|
---|
102 |
|
---|
103 |
|
---|
104 | procedure TForm_Preview.SetBitmapCount(Count: Integer);
|
---|
105 | var
|
---|
106 | i: Integer;
|
---|
107 | begin
|
---|
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;
|
---|
121 | end;
|
---|
122 |
|
---|
123 |
|
---|
124 | procedure TForm_Preview.PreviewImage;
|
---|
125 | begin
|
---|
126 | SetBitmapCount(1);
|
---|
127 | LoadImage(_fileid, 0);
|
---|
128 | DrawImage(0);
|
---|
129 | end;
|
---|
130 |
|
---|
131 |
|
---|
132 | procedure TForm_Preview.PreviewTXAN;
|
---|
133 | var
|
---|
134 | loop_speed: Word;
|
---|
135 | linkcount: LongWord;
|
---|
136 | link: LongWord;
|
---|
137 | i: Byte;
|
---|
138 | begin
|
---|
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;
|
---|
155 | end;
|
---|
156 |
|
---|
157 |
|
---|
158 | procedure TForm_Preview.timerTimer(Sender: TObject);
|
---|
159 | begin
|
---|
160 | btn_incClick(Self);
|
---|
161 | end;
|
---|
162 |
|
---|
163 |
|
---|
164 | procedure TForm_Preview.btn_startstopClick(Sender: TObject);
|
---|
165 | begin
|
---|
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';
|
---|
173 | end;
|
---|
174 |
|
---|
175 |
|
---|
176 | procedure TForm_Preview.btn_decClick(Sender: TObject);
|
---|
177 | begin
|
---|
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);
|
---|
185 | end;
|
---|
186 |
|
---|
187 |
|
---|
188 | procedure TForm_Preview.btn_incClick(Sender: TObject);
|
---|
189 | begin
|
---|
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);
|
---|
197 | end;
|
---|
198 |
|
---|
199 |
|
---|
200 | procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
|
---|
201 | begin
|
---|
202 | btn_startstop.Width := panel_buttons.Width - 45;
|
---|
203 | btn_inc.Left := panel_buttons.Width - 23;
|
---|
204 | end;
|
---|
205 |
|
---|
206 |
|
---|
207 | begin
|
---|
208 | AddToolListEntry('preview', 'Preview-Window', '');
|
---|
209 | end.
|
---|