[93] | 1 | unit Preview;
|
---|
| 2 | interface
|
---|
| 3 | uses
|
---|
| 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 |
|
---|
| 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);
|
---|
[194] | 31 | procedure Splitter1Moved(Sender: TObject);
|
---|
[93] | 32 | private
|
---|
[192] | 33 | bitmaps: array of TOniImage;
|
---|
[93] | 34 | actualimg: Byte;
|
---|
| 35 | _fileid: Integer;
|
---|
| 36 | public
|
---|
| 37 | end;
|
---|
| 38 |
|
---|
| 39 | var
|
---|
| 40 | Form_Preview: TForm_Preview;
|
---|
| 41 |
|
---|
| 42 | implementation
|
---|
| 43 | {$R *.dfm}
|
---|
[194] | 44 | uses Imaging, ImagingComponents, ImagingTypes, jpeg;
|
---|
[93] | 45 |
|
---|
| 46 |
|
---|
| 47 | procedure TForm_Preview.FormCreate(Sender: TObject);
|
---|
| 48 | begin
|
---|
| 49 | inherited;
|
---|
| 50 | Self.OnNewFileSelected := NewFile;
|
---|
[194] | 51 | SetBitmapCount(0);
|
---|
[93] | 52 | end;
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
|
---|
| 56 | var
|
---|
| 57 | ext: String;
|
---|
| 58 | begin
|
---|
| 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;
|
---|
| 85 | end;
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | procedure TForm_Preview.LoadImage(fileid, index: Integer);
|
---|
| 89 | begin
|
---|
[192] | 90 | bitmaps[index].Load(ConnectionID, fileid);
|
---|
[93] | 91 | end;
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | procedure TForm_Preview.DrawImage(index: Integer);
|
---|
| 95 | begin
|
---|
[193] | 96 | bitmaps[index].DrawOnCanvas(img.Canvas, 1);
|
---|
[93] | 97 | end;
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | procedure TForm_Preview.SetBitmapCount(Count: Integer);
|
---|
| 101 | var
|
---|
| 102 | i: Integer;
|
---|
| 103 | begin
|
---|
| 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;
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 |
|
---|
[194] | 120 | procedure TForm_Preview.Splitter1Moved(Sender: TObject);
|
---|
| 121 | begin
|
---|
| 122 | inherited;
|
---|
| 123 | img.Picture.Assign(nil);
|
---|
| 124 | if Length(bitmaps) > 0 then
|
---|
| 125 | DrawImage(0);
|
---|
| 126 | end;
|
---|
| 127 |
|
---|
[93] | 128 | procedure TForm_Preview.PreviewImage;
|
---|
| 129 | begin
|
---|
| 130 | SetBitmapCount(1);
|
---|
| 131 | LoadImage(_fileid, 0);
|
---|
| 132 | DrawImage(0);
|
---|
| 133 | end;
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | procedure TForm_Preview.PreviewTXAN;
|
---|
| 137 | var
|
---|
| 138 | loop_speed: Word;
|
---|
[111] | 139 | linkcount: Integer;
|
---|
| 140 | link: Integer;
|
---|
[93] | 141 | i: Byte;
|
---|
| 142 | begin
|
---|
[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;
|
---|
| 159 | end;
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | procedure TForm_Preview.timerTimer(Sender: TObject);
|
---|
| 163 | begin
|
---|
| 164 | btn_incClick(Self);
|
---|
| 165 | end;
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | procedure TForm_Preview.btn_startstopClick(Sender: TObject);
|
---|
| 169 | begin
|
---|
| 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';
|
---|
| 179 | end;
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | procedure TForm_Preview.btn_decClick(Sender: TObject);
|
---|
| 183 | begin
|
---|
| 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);
|
---|
| 191 | end;
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | procedure TForm_Preview.btn_incClick(Sender: TObject);
|
---|
| 195 | begin
|
---|
| 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);
|
---|
| 203 | end;
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
|
---|
| 207 | begin
|
---|
| 208 | btn_startstop.Width := panel_buttons.Width - 45;
|
---|
| 209 | btn_inc.Left := panel_buttons.Width - 23;
|
---|
| 210 | end;
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | begin
|
---|
| 214 | AddToolListEntry('preview', 'Preview-Window', '');
|
---|
[194] | 215 | end.
|
---|