[35] | 1 | UNIT Unit7_txmpreplace;
|
---|
| 2 | INTERFACE
|
---|
| 3 | USES
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 5 | Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data, Unit6_imgfuncs;
|
---|
| 6 |
|
---|
| 7 | TYPE
|
---|
| 8 | TForm7 = Class(TForm)
|
---|
| 9 | panel_12: TPanel;
|
---|
| 10 | group_txmpselect: TGroupBox;
|
---|
| 11 | splitter_txmp: TSplitter;
|
---|
| 12 | list_txmp: TListBox;
|
---|
| 13 | Splitter1: TSplitter;
|
---|
| 14 | group_bmpselect: TGroupBox;
|
---|
| 15 | panel_load: TPanel;
|
---|
| 16 | btn_load: TButton;
|
---|
| 17 | image_bmppreview: TImage;
|
---|
| 18 | opend: TOpenDialog;
|
---|
| 19 | group_options: TGroupBox;
|
---|
| 20 | btn_replace: TButton;
|
---|
| 21 | check_transparency: TCheckBox;
|
---|
| 22 | check_fading: TCheckBox;
|
---|
| 23 | panel_txmppreview: TPanel;
|
---|
| 24 | btn_save: TButton;
|
---|
| 25 | image_txmppreview: TImage;
|
---|
| 26 | saved: TSaveDialog;
|
---|
| 27 | procedure FormCreate(Sender: TObject);
|
---|
| 28 | PROCEDURE btn_saveClick(Sender: TObject);
|
---|
| 29 | PROCEDURE FormActivate(Sender: TObject);
|
---|
| 30 | PROCEDURE FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 31 | PROCEDURE btn_replaceClick(Sender: TObject);
|
---|
| 32 | PROCEDURE btn_loadClick(Sender: TObject);
|
---|
| 33 | PROCEDURE list_txmpClick(Sender: TObject);
|
---|
| 34 | PROCEDURE Recreatelist;
|
---|
| 35 | PRIVATE
|
---|
| 36 | OniImage_Old:TOniImage;
|
---|
| 37 | OniImage_New:TOniImage;
|
---|
| 38 | PUBLIC
|
---|
| 39 | END;
|
---|
| 40 |
|
---|
| 41 | VAR
|
---|
| 42 | Form7: TForm7;
|
---|
| 43 |
|
---|
| 44 | IMPLEMENTATION
|
---|
| 45 | USES Unit1_main, Unit15_Classes;
|
---|
| 46 | {$R *.dfm}
|
---|
| 47 |
|
---|
| 48 | PROCEDURE TForm7.Recreatelist;
|
---|
| 49 | VAR
|
---|
| 50 | files:TStringArray;
|
---|
| 51 | i:LongWord;
|
---|
| 52 | BEGIN
|
---|
| 53 | list_txmp.Items.Clear;
|
---|
| 54 | files:=OniDataConnection.GetFilesList('TXMP','',True);
|
---|
| 55 | IF Length(files)>0 THEN
|
---|
| 56 | FOR i:=0 TO High(files) DO
|
---|
| 57 | list_txmp.Items.Add(files[i]);
|
---|
| 58 | group_bmpselect.Enabled:=False;
|
---|
| 59 | check_transparency.Checked:=False;
|
---|
| 60 | check_fading.Checked:=False;
|
---|
| 61 | END;
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | PROCEDURE TForm7.list_txmpClick(Sender: TObject);
|
---|
| 65 | VAR
|
---|
| 66 | id:LongWord;
|
---|
| 67 | data:Tdata;
|
---|
| 68 | mem:TMemoryStream;
|
---|
| 69 | fadingbyte,depthbyte,storebyte:Byte;
|
---|
| 70 | BEGIN
|
---|
| 71 | id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
|
---|
| 72 | OniDataConnection.LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
|
---|
| 73 | OniDataConnection.LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
|
---|
| 74 | OniDataConnection.LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
|
---|
| 75 | check_fading.Checked:=(fadingbyte AND $01)>0;
|
---|
| 76 | check_transparency.Checked:=(depthbyte AND $04)>0;
|
---|
| 77 |
|
---|
| 78 | OniImage_Old.LoadFromTXMP(id);
|
---|
| 79 | data:=OniImage_Old.GetAsBMP;
|
---|
| 80 | mem:=TMemoryStream.Create;
|
---|
| 81 | mem.Write(data[0],Length(data));
|
---|
| 82 | mem.Seek(0,soFromBeginning);
|
---|
| 83 | image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
|
---|
| 84 | mem.Free;
|
---|
| 85 |
|
---|
| 86 | group_bmpselect.Enabled:=True;
|
---|
| 87 | END;
|
---|
| 88 |
|
---|
| 89 | PROCEDURE TForm7.btn_loadClick(Sender: TObject);
|
---|
| 90 | VAR
|
---|
| 91 | mem:TMemoryStream;
|
---|
| 92 | tempd:Tdata;
|
---|
| 93 | BEGIN
|
---|
| 94 | IF opend.Execute THEN BEGIN
|
---|
| 95 | OniImage_New.LoadFromBMP(opend.FileName);
|
---|
| 96 | tempd:=OniImage_New.GetAsBMP;
|
---|
| 97 | mem:=TMemoryStream.Create;
|
---|
| 98 | mem.Write(tempd[0],Length(tempd));
|
---|
| 99 | mem.Seek(0,soFromBeginning);
|
---|
| 100 | image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
|
---|
| 101 | mem.Free;
|
---|
| 102 | group_options.Enabled:=True;
|
---|
| 103 | END;
|
---|
| 104 | END;
|
---|
| 105 |
|
---|
| 106 | PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
|
---|
| 107 | VAR
|
---|
| 108 | id:LongWord;
|
---|
| 109 |
|
---|
| 110 | oldsize,newsize:LongWord;
|
---|
| 111 | old_rawaddr,new_rawaddr:LongWord;
|
---|
| 112 | oldfading:Byte;
|
---|
| 113 | tempd:Tdata;
|
---|
| 114 |
|
---|
| 115 | datbyte:Word;
|
---|
| 116 | BEGIN
|
---|
| 117 | IF list_txmp.ItemIndex>=0 THEN BEGIN
|
---|
| 118 | id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
|
---|
| 119 | OniDataConnection.LoadDatFilePart(id,$88,1,@oldfading);
|
---|
| 120 | if OniDataConnection.OSisMac then
|
---|
| 121 | OniDataConnection.UpdateDatFilePart(id,$A0,4,@old_rawaddr)
|
---|
| 122 | else
|
---|
| 123 | OniDataConnection.LoadDatFilePart(id,$9C,4,@old_rawaddr);
|
---|
| 124 |
|
---|
| 125 | IF (OniImage_Old.Width<>OniImage_New.Width) OR (OniImage_Old.Height<>OniImage_New.Height) THEN BEGIN
|
---|
| 126 | IF MessageBox(Self.Handle,
|
---|
| 127 | PChar('Current image and new image have different size'+CrLf+
|
---|
| 128 | '(Current: '+IntToStr(OniImage_Old.Width)+'x'+IntToStr(OniImage_Old.Height)+
|
---|
| 129 | ' - New: '+IntToStr(OniImage_New.Width)+'x'+IntToStr(OniImage_New.Height)+')'+CrLf+
|
---|
| 130 | 'Replace anyways?'),
|
---|
| 131 | PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
|
---|
| 132 | MB_YESNO)=IDNO THEN Exit;
|
---|
| 133 | END;
|
---|
| 134 |
|
---|
| 135 | oldsize:=OniImage_Old.GetImageDataSize((oldfading and $01)>0);
|
---|
| 136 |
|
---|
| 137 | IF check_fading.Checked THEN
|
---|
| 138 | IF NOT OniImage_New.GetMipMappedImage(tempd) THEN
|
---|
| 139 | IF MessageBox(Self.Handle, PChar('Can not create a MipMapped-image (probably because of a wrong dimension).'+#13+#10+'Do you want to continue without MipMapping?'), PChar('Warning'), MB_YESNO)=ID_YES THEN
|
---|
| 140 | check_fading.Checked:=False
|
---|
| 141 | ELSE
|
---|
| 142 | Exit;
|
---|
| 143 |
|
---|
| 144 | IF NOT check_fading.Checked THEN
|
---|
| 145 | tempd:=OniImage_New.GetAsData;
|
---|
| 146 |
|
---|
| 147 | newsize:=OniImage_New.GetImageDataSize(check_fading.Checked);
|
---|
| 148 | ShowMessage(IntToStr(newsize));
|
---|
| 149 |
|
---|
| 150 | IF (newsize>oldsize) AND (OniDataConnection.Backend=ODB_Dat) THEN
|
---|
| 151 | new_rawaddr:=OniDataConnection.AppendRawFile(OniDataConnection.OSisMac,Length(tempd),tempd)
|
---|
| 152 | ELSE BEGIN
|
---|
| 153 | new_rawaddr:=old_rawaddr;
|
---|
| 154 | OniDataConnection.UpdateRawFile(id,$9C,Length(tempd),tempd);
|
---|
| 155 | END;
|
---|
| 156 |
|
---|
| 157 | datbyte:=$00;
|
---|
| 158 | IF check_fading.Checked THEN datbyte:=datbyte OR $01;
|
---|
| 159 | OniDataConnection.UpdateDatFilePart(id,$88,1,@datbyte);
|
---|
| 160 | datbyte:=$10;
|
---|
| 161 | IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
|
---|
| 162 | OniDataConnection.UpdateDatFilePart(id,$89,1,@datbyte);
|
---|
| 163 | OniDataConnection.UpdateDatFilePart(id,$8C,2,@OniImage_New.Width);
|
---|
| 164 | OniDataConnection.UpdateDatFilePart(id,$8E,2,@OniImage_New.Height);
|
---|
| 165 | datbyte:=$08;
|
---|
| 166 | OniDataConnection.UpdateDatFilePart(id,$90,1,@datbyte);
|
---|
| 167 | if OniDataConnection.OSisMac then
|
---|
| 168 | OniDataConnection.UpdateDatFilePart(id,$A0,4,@new_rawaddr)
|
---|
| 169 | else
|
---|
| 170 | OniDataConnection.UpdateDatFilePart(id,$9C,4,@new_rawaddr);
|
---|
| 171 |
|
---|
| 172 | ShowMessage('TXMP-image replaced');
|
---|
| 173 | END;
|
---|
| 174 | END;
|
---|
| 175 |
|
---|
| 176 | PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 177 | BEGIN
|
---|
| 178 | OniImage_Old.Free;
|
---|
| 179 | OniImage_New.Free;
|
---|
| 180 | Action:=caFree;
|
---|
| 181 | Form1.close_window(Self.Name);
|
---|
| 182 | END;
|
---|
| 183 |
|
---|
| 184 | PROCEDURE TForm7.FormCreate(Sender: TObject);
|
---|
| 185 | BEGIN
|
---|
| 186 | OniImage_Old:=TOniImage.Create;
|
---|
| 187 | OniImage_New:=TOniImage.Create;
|
---|
| 188 | END;
|
---|
| 189 |
|
---|
| 190 | PROCEDURE TForm7.FormActivate(Sender: TObject);
|
---|
| 191 | BEGIN
|
---|
| 192 | Form1.SetActiveWindow(Self.Name);
|
---|
| 193 | END;
|
---|
| 194 |
|
---|
| 195 | PROCEDURE TForm7.btn_saveClick(Sender: TObject);
|
---|
| 196 | BEGIN
|
---|
| 197 | IF saved.Execute THEN
|
---|
| 198 | OniImage_Old.WriteToBMP(saved.FileName);
|
---|
| 199 | END;
|
---|
| 200 |
|
---|
| 201 | END.
|
---|