ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/Preview.pas
Revision: 192
Committed: Thu May 24 17:48:18 2007 UTC (18 years, 4 months ago) by alloc
Content type: text/x-pascal
File size: 5131 byte(s)
Log Message:

File Contents

# Content
1 unit Preview;
2 interface
3 uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, Template, ExtCtrls, Math, StrUtils,
6 ConnectionManager, OniImgClass, Data, TypeDefs, 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 TOniImage;
33 actualimg: Byte;
34 _fileid: Integer;
35 public
36 end;
37
38 var
39 Form_Preview: TForm_Preview;
40
41 implementation
42 {$R *.dfm}
43 uses Imaging, ImagingComponents, ImagingTypes;
44
45
46 procedure TForm_Preview.FormCreate(Sender: TObject);
47 begin
48 inherited;
49 Self.OnNewFileSelected := NewFile;
50 end;
51
52
53 procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
54 var
55 ext: String;
56 begin
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;
82 end;
83
84
85 procedure TForm_Preview.LoadImage(fileid, index: Integer);
86 begin
87 bitmaps[index].Load(ConnectionID, fileid);
88 end;
89
90
91 procedure TForm_Preview.DrawImage(index: Integer);
92 begin
93 bitmaps[index].DrawOnCanvas(img.Canvas, 0);
94 end;
95
96
97 procedure TForm_Preview.SetBitmapCount(Count: Integer);
98 var
99 i: Integer;
100 begin
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
112 bitmaps[i] := TOniImage.Create;
113 end;
114 end;
115
116
117 procedure TForm_Preview.PreviewImage;
118 begin
119 SetBitmapCount(1);
120 LoadImage(_fileid, 0);
121 DrawImage(0);
122 end;
123
124
125 procedure TForm_Preview.PreviewTXAN;
126 var
127 loop_speed: Word;
128 linkcount: Integer;
129 link: Integer;
130 i: Byte;
131 begin
132 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
133 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
134 SetBitmapCount(linkcount);
135 for i := 0 to linkcount - 1 do
136 begin
137 ConManager.Connection[ConnectionID].LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
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;
148 end;
149
150
151 procedure TForm_Preview.timerTimer(Sender: TObject);
152 begin
153 btn_incClick(Self);
154 end;
155
156
157 procedure TForm_Preview.btn_startstopClick(Sender: TObject);
158 begin
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';
166 end;
167
168
169 procedure TForm_Preview.btn_decClick(Sender: TObject);
170 begin
171 if actualimg > 0 then
172 Dec(actualimg)
173 else
174 actualimg := High(bitmaps);
175 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
176 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
177 DrawImage(actualimg);
178 end;
179
180
181 procedure TForm_Preview.btn_incClick(Sender: TObject);
182 begin
183 if actualimg < High(bitmaps) then
184 Inc(actualimg)
185 else
186 actualimg := 0;
187 Self.Caption := 'Preview ' + ConManager.Connection[ConnectionID].GetFileInfo(_fileid).Name +
188 ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
189 DrawImage(actualimg);
190 end;
191
192
193 procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
194 begin
195 btn_startstop.Width := panel_buttons.Width - 45;
196 btn_inc.Left := panel_buttons.Width - 23;
197 end;
198
199
200 begin
201 AddToolListEntry('preview', 'Preview-Window', '');
202 end.