[93] | 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 TBitmap;
|
---|
| 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 |
|
---|
| 44 |
|
---|
| 45 | procedure TForm_Preview.FormCreate(Sender: TObject);
|
---|
| 46 | begin
|
---|
| 47 | inherited;
|
---|
| 48 | Self.OnNewFileSelected := NewFile;
|
---|
| 49 | end;
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | procedure TForm_Preview.NewFile(fileinfo: TFileInfo);
|
---|
| 53 | var
|
---|
| 54 | ext: String;
|
---|
| 55 | begin
|
---|
| 56 | _fileid := fileinfo.ID;
|
---|
| 57 | if _fileid >= 0 then
|
---|
| 58 | begin
|
---|
| 59 | lbl_notpossible.Visible := False;
|
---|
| 60 | Self.img.Visible := True;
|
---|
| 61 | Self.timer.Enabled := False;
|
---|
| 62 | Self.panel_buttons.Visible := False;
|
---|
| 63 | ext := fileinfo.Extension;
|
---|
| 64 | if (ext = 'PSpc') or (ext = 'TXMB') or (ext = 'TXMP') then
|
---|
| 65 | PreviewImage
|
---|
| 66 | else if ext = 'TXAN' then
|
---|
| 67 | PreviewTXAN
|
---|
| 68 | else
|
---|
| 69 | begin
|
---|
| 70 | Self.lbl_notpossible.Visible := True;
|
---|
| 71 | Self.img.Visible := False;
|
---|
| 72 | end;
|
---|
| 73 | end
|
---|
| 74 | else
|
---|
| 75 | begin
|
---|
| 76 | Self.img.Visible := False;
|
---|
| 77 | lbl_notpossible.Visible := False;
|
---|
| 78 | Self.timer.Enabled := False;
|
---|
| 79 | Self.panel_buttons.Visible := False;
|
---|
| 80 | end;
|
---|
| 81 | end;
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | procedure TForm_Preview.LoadImage(fileid, index: Integer);
|
---|
| 85 | var
|
---|
| 86 | Data: Tdata;
|
---|
| 87 | memstream: TMemoryStream;
|
---|
| 88 | OniImage: TOniImage;
|
---|
| 89 |
|
---|
| 90 | begin
|
---|
| 91 | OniImage := TOniImage.Create;
|
---|
| 92 | OniImage.Load(Connection, fileid);
|
---|
| 93 | Data := OniImage.GetAsBMP;
|
---|
| 94 | OniImage.Free;
|
---|
| 95 |
|
---|
| 96 | memstream := TMemoryStream.Create;
|
---|
| 97 | memstream.Write(Data[0], Length(Data));
|
---|
| 98 | memstream.Seek(0, soFromBeginning);
|
---|
| 99 | bitmaps[index].LoadFromStream(memstream);
|
---|
| 100 | memstream.Free;
|
---|
| 101 | end;
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | procedure TForm_Preview.DrawImage(index: Integer);
|
---|
| 105 | begin
|
---|
| 106 | BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
|
---|
| 107 | bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
|
---|
| 108 | BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
|
---|
| 109 | bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
|
---|
| 110 | img.Invalidate;
|
---|
| 111 | end;
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | procedure TForm_Preview.SetBitmapCount(Count: Integer);
|
---|
| 115 | var
|
---|
| 116 | i: Integer;
|
---|
| 117 | begin
|
---|
| 118 | if Length(bitmaps) > Count then
|
---|
| 119 | begin
|
---|
| 120 | for i := Count to High(bitmaps) do
|
---|
| 121 | bitmaps[i].Free;
|
---|
| 122 | SetLength(bitmaps, Count);
|
---|
| 123 | end;
|
---|
| 124 | if Length(bitmaps) < Count then
|
---|
| 125 | begin
|
---|
| 126 | i := Length(bitmaps);
|
---|
| 127 | SetLength(bitmaps, Count);
|
---|
| 128 | for i := i to High(bitmaps) do
|
---|
| 129 | bitmaps[i] := TBitmap.Create;
|
---|
| 130 | end;
|
---|
| 131 | end;
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | procedure TForm_Preview.PreviewImage;
|
---|
| 135 | begin
|
---|
| 136 | SetBitmapCount(1);
|
---|
| 137 | LoadImage(_fileid, 0);
|
---|
| 138 | DrawImage(0);
|
---|
| 139 | end;
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | procedure TForm_Preview.PreviewTXAN;
|
---|
| 143 | var
|
---|
| 144 | loop_speed: Word;
|
---|
| 145 | linkcount: LongWord;
|
---|
| 146 | link: LongWord;
|
---|
| 147 | i: Byte;
|
---|
| 148 | begin
|
---|
| 149 | Connection.LoadDatFilePart(_fileid, $14, SizeOf(loop_speed), @loop_speed);
|
---|
| 150 | Connection.LoadDatFilePart(_fileid, $1C, SizeOf(linkcount), @linkcount);
|
---|
| 151 | SetBitmapCount(linkcount);
|
---|
| 152 | for i := 0 to linkcount - 1 do
|
---|
| 153 | begin
|
---|
| 154 | Connection.LoadDatFilePart(_fileid, $20 + i * 4, SizeOf(link), @link);
|
---|
| 155 | link := link div 256;
|
---|
| 156 | if link = 0 then
|
---|
| 157 | link := _fileid - 1;
|
---|
| 158 | LoadImage(link, i);
|
---|
| 159 | end;
|
---|
| 160 | actualimg := 254;
|
---|
| 161 | Self.timer.Interval := Floor(loop_speed * (1 / 60) * 1000);
|
---|
| 162 | Self.timer.Enabled := False;
|
---|
| 163 | Self.btn_startstopClick(Self);
|
---|
| 164 | Self.panel_buttons.Visible := True;
|
---|
| 165 | end;
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | procedure TForm_Preview.timerTimer(Sender: TObject);
|
---|
| 169 | begin
|
---|
| 170 | btn_incClick(Self);
|
---|
| 171 | end;
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | procedure TForm_Preview.btn_startstopClick(Sender: TObject);
|
---|
| 175 | begin
|
---|
| 176 | Self.timer.Enabled := not Self.timer.Enabled;
|
---|
| 177 | Self.btn_dec.Enabled := not Self.timer.Enabled;
|
---|
| 178 | Self.btn_inc.Enabled := not Self.timer.Enabled;
|
---|
| 179 | if Self.timer.Enabled then
|
---|
| 180 | Self.btn_startstop.Caption := 'Stop automatic'
|
---|
| 181 | else
|
---|
| 182 | Self.btn_startstop.Caption := 'Start automatic';
|
---|
| 183 | end;
|
---|
| 184 |
|
---|
| 185 |
|
---|
| 186 | procedure TForm_Preview.btn_decClick(Sender: TObject);
|
---|
| 187 | begin
|
---|
| 188 | if actualimg > 0 then
|
---|
| 189 | Dec(actualimg)
|
---|
| 190 | else
|
---|
| 191 | actualimg := High(bitmaps);
|
---|
| 192 | Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
|
---|
| 193 | ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
|
---|
| 194 | DrawImage(actualimg);
|
---|
| 195 | end;
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | procedure TForm_Preview.btn_incClick(Sender: TObject);
|
---|
| 199 | begin
|
---|
| 200 | if actualimg < High(bitmaps) then
|
---|
| 201 | Inc(actualimg)
|
---|
| 202 | else
|
---|
| 203 | actualimg := 0;
|
---|
| 204 | Self.Caption := 'Preview ' + Connection.GetFileInfo(_fileid).FileName +
|
---|
| 205 | ' (' + IntToStr(actualimg + 1) + '/' + IntToStr(Length(bitmaps)) + ')';
|
---|
| 206 | DrawImage(actualimg);
|
---|
| 207 | end;
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | procedure TForm_Preview.panel_buttonsResize(Sender: TObject);
|
---|
| 211 | begin
|
---|
| 212 | btn_startstop.Width := panel_buttons.Width - 45;
|
---|
| 213 | btn_inc.Left := panel_buttons.Width - 23;
|
---|
| 214 | end;
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | begin
|
---|
| 218 | AddToolListEntry('preview', 'Preview-Window', '');
|
---|
| 219 | end.
|
---|