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

Last change on this file since 193 was 193, checked in by alloc, 17 years ago
File size: 5.0 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
[192]32 bitmaps: array of TOniImage;
[93]33 actualimg: Byte;
34 _fileid: Integer;
35 public
36 end;
37
38var
39 Form_Preview: TForm_Preview;
40
41implementation
42{$R *.dfm}
[192]43uses Imaging, ImagingComponents, ImagingTypes;
[93]44
45
46procedure TForm_Preview.FormCreate(Sender: TObject);
47begin
48 inherited;
49 Self.OnNewFileSelected := NewFile;
50end;
51
52
53procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
54var
55 ext: String;
56begin
57 _fileid := fileinfo.ID;
58 if _fileid >= 0 then
59 begin
60 lbl_notpossible.Visible := False;
61 Self.img.Visible := True;
62 Self.timer.Enabled := False;
63 Self.panel_buttons.Visible := False;
64 ext := fileinfo.Extension;
65 if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
66 PreviewImage
67 else if ext = 'TXAN' then
68 PreviewTXAN
69 else
70 begin
71 Self.lbl_notpossible.Visible := True;
72 Self.img.Visible := False;
73 end;
74 end
75 else
76 begin
77 Self.img.Visible := False;
78 lbl_notpossible.Visible := False;
79 Self.timer.Enabled := False;
80 Self.panel_buttons.Visible := False;
81 end;
82end;
83
84
85procedure TForm_Preview.LoadImage(fileid, index: Integer);
86begin
[192]87 bitmaps[index].Load(ConnectionID, fileid);
[93]88end;
89
90
91procedure TForm_Preview.DrawImage(index: Integer);
92begin
[193]93 bitmaps[index].DrawOnCanvas(img.Canvas, 1);
[93]94end;
95
96
97procedure TForm_Preview.SetBitmapCount(Count: Integer);
98var
99 i: Integer;
100begin
101 if Length(bitmaps) > Count then
102 begin
103 for i := Count to High(bitmaps) do
104 bitmaps[i].Free;
105 SetLength(bitmaps, Count);
106 end;
107 if Length(bitmaps) < Count then
108 begin
109 i := Length(bitmaps);
110 SetLength(bitmaps, Count);
111 for i := i to High(bitmaps) do
[192]112 bitmaps[i] := TOniImage.Create;
[93]113 end;
114end;
115
116
117procedure TForm_Preview.PreviewImage;
118begin
119 SetBitmapCount(1);
120 LoadImage(_fileid, 0);
121 DrawImage(0);
122end;
123
124
125procedure TForm_Preview.PreviewTXAN;
126var
127 loop_speed: Word;
[111]128 linkcount: Integer;
129 link: Integer;
[93]130 i: Byte;
131begin
[97]132 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
133 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
[93]134 SetBitmapCount(linkcount);
135 for i := 0 to linkcount - 1 do
136 begin
[97]137 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
[93]138 link := link div 256;
139 if link = 0 then
140 link := _fileid - 1;
141 LoadImage(link, i);
142 end;
143 actualimg := 254;
144 Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
145 Self.timer.Enabled := False;
146 Self.btn_startstopClick(Self);
147 Self.panel_buttons.Visible := True;
148end;
149
150
151procedure TForm_Preview.timerTimer(Sender: TObject);
152begin
153 btn_incClick(Self);
154end;
155
156
157procedure TForm_Preview.btn_startstopClick(Sender: TObject);
158begin
159 Self.timer.Enabled := not Self.timer.Enabled;
160 Self.btn_dec.Enabled := not Self.timer.Enabled;
161 Self.btn_inc.Enabled := not Self.timer.Enabled;
162 if Self.timer.Enabled then
163 Self.btn_startstop.Caption := 'Stop automatic'
164 else
165 Self.btn_startstop.Caption := 'Start automatic';
166end;
167
168
169procedure TForm_Preview.btn_decClick(Sender: TObject);
170begin
171 if actualimg > 0 then
172 Dec(actualimg)
173 else
174 actualimg := High(bitmaps);
[97]175 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
[93]176 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
177 DrawImage(actualimg);
178end;
179
180
181procedure TForm_Preview.btn_incClick(Sender: TObject);
182begin
183 if actualimg < High(bitmaps) then
184 Inc(actualimg)
185 else
186 actualimg := 0;
[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.panel_buttonsResize(Sender: TObject);
194begin
195 btn_startstop.Width := panel_buttons.Width - 45;
196 btn_inc.Left := panel_buttons.Width - 23;
197end;
198
199
200begin
201 AddToolListEntry('preview', 'Preview-Window', '');
202end.
Note: See TracBrowser for help on using the repository browser.