source: oup/releases/0.34b/Tools/Preview.pas@ 687

Last change on this file since 687 was 205, checked in by alloc, 18 years ago
File size: 5.3 KB
Line 
1unit Preview;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
6 ConnectionManager, OniImgClass, Data, TypeDefs, Menus, Buttons;
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 procedure Splitter1Moved(Sender: TObject);
32 private
33 bitmaps: array of TOniImage;
34 actualimg: Byte;
35 _fileid: Integer;
36 public
37 end;
38
39var
40 Form_Preview: TForm_Preview;
41
42implementation
43{$R *.dfm}
44uses Imaging, ImagingComponents, ImagingTypes, jpeg;
45
46
47procedure TForm_Preview.FormCreate(Sender: TObject);
48begin
49 inherited;
50 Self.OnNewFileSelected := NewFile;
51 SetBitmapCount(0);
52end;
53
54
55procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
56var
57 ext: String;
58begin
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;
85end;
86
87
88procedure TForm_Preview.LoadImage(fileid, index: Integer);
89begin
90 bitmaps[index].Load(ConnectionID, fileid);
91end;
92
93
94procedure TForm_Preview.DrawImage(index: Integer);
95begin
96 bitmaps[index].DrawOnCanvas(img.Canvas, 1);
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
115 bitmaps[i] := TOniImage.Create;
116 end;
117end;
118
119
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
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;
139 linkcount: Integer;
140 link: Integer;
141 i: Byte;
142begin
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;
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;
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';
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);
188 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
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;
200 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
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', '');
215end.
Note: See TracBrowser for help on using the repository browser.