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

Last change on this file since 807 was 244, checked in by alloc, 17 years ago
File size: 5.3 KB
RevLine 
[93]1unit Preview;
[220]2
[93]3interface
[220]4
[93]5uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
[220]7 Dialogs, _TemplateFileList, Menus, StdCtrls, ExtCtrls, Buttons,
[244]8 TypeDefs, OniImgClass, VirtualTrees, ComCtrls;
[93]9
10type
[220]11 TForm_Preview = class(TForm_TemplateFileList)
12 img: TImage;
[93]13 panel_buttons: TPanel;
14 btn_dec: TButton;
15 btn_startstop: TButton;
16 btn_inc: TButton;
17 timer: TTimer;
[220]18 lbl_notpossible: TLabel;
[93]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);
[194]33 procedure Splitter1Moved(Sender: TObject);
[93]34 private
[192]35 bitmaps: array of TOniImage;
[93]36 actualimg: Byte;
37 _fileid: Integer;
38 public
39 end;
40
41implementation
42{$R *.dfm}
[220]43uses
44 ConnectionManager, Math, _TemplateFile;
[93]45
46
47procedure TForm_Preview.FormCreate(Sender: TObject);
48begin
49 inherited;
50 Self.OnNewFileSelected := NewFile;
[194]51 SetBitmapCount(0);
[93]52end;
53
54
55procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
56var
57 ext: String;
58begin
59 _fileid := fileinfo.ID;
[194]60 SetBitmapCount(0);
[93]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;
85end;
86
87
88procedure TForm_Preview.LoadImage(fileid, index: Integer);
89begin
[192]90 bitmaps[index].Load(ConnectionID, fileid);
[93]91end;
92
93
94procedure TForm_Preview.DrawImage(index: Integer);
95begin
[193]96 bitmaps[index].DrawOnCanvas(img.Canvas, 1);
[93]97end;
98
99
100procedure TForm_Preview.SetBitmapCount(Count: Integer);
101var
102 i: Integer;
103begin
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
[192]115 bitmaps[i] := TOniImage.Create;
[93]116 end;
117end;
118
119
[194]120procedure TForm_Preview.Splitter1Moved(Sender: TObject);
121begin
122 inherited;
123 img.Picture.Assign(nil);
124 if Length(bitmaps) > 0 then
125 DrawImage(0);
126end;
127
[93]128procedure TForm_Preview.PreviewImage;
129begin
130 SetBitmapCount(1);
131 LoadImage(_fileid, 0);
132 DrawImage(0);
133end;
134
135
136procedure TForm_Preview.PreviewTXAN;
137var
138 loop_speed: Word;
[111]139 linkcount: Integer;
140 link: Integer;
[93]141 i: Byte;
142begin
[97]143 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
144 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
[93]145 SetBitmapCount(linkcount);
146 for i := 0 to linkcount - 1 do
147 begin
[97]148 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
[93]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;
159end;
160
161
162procedure TForm_Preview.timerTimer(Sender: TObject);
163begin
164 btn_incClick(Self);
165end;
166
167
168procedure TForm_Preview.btn_startstopClick(Sender: TObject);
169begin
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;
[194]173 if self.timer.Enabled then
174 timerTimer(Self);
[93]175 if Self.timer.Enabled then
176 Self.btn_startstop.Caption := 'Stop automatic'
177 else
178 Self.btn_startstop.Caption := 'Start automatic';
179end;
180
181
182procedure TForm_Preview.btn_decClick(Sender: TObject);
183begin
184 if actualimg > 0 then
185 Dec(actualimg)
186 else
187 actualimg := High(bitmaps);
[97]188 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
[93]189 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
190 DrawImage(actualimg);
191end;
192
193
194procedure TForm_Preview.btn_incClick(Sender: TObject);
195begin
196 if actualimg < High(bitmaps) then
197 Inc(actualimg)
198 else
199 actualimg := 0;
[97]200 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
[93]201 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
202 DrawImage(actualimg);
203end;
204
205
206procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
207begin
208 btn_startstop.Width := panel_buttons.Width - 45;
209 btn_inc.Left := panel_buttons.Width - 23;
210end;
211
212
213begin
214 AddToolListEntry('preview', 'Preview-Window', '');
[194]215end.
[220]216
Note: See TracBrowser for help on using the repository browser.