source: oup/current/Tools/TxmpReplace.pas@ 156

Last change on this file since 156 was 111, checked in by alloc, 18 years ago
File size: 6.3 KB
RevLine 
[93]1unit TxmpReplace;
2interface
3uses
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, Template, StdCtrls, ExtCtrls,
[97]6 Functions, Data, OniImgClass, Menus, Buttons, TypeDefs;
[93]7
8type
9 TForm_TxmpReplace = class(TForm_ToolTemplate)
10 group_options: TGroupBox;
11 btn_replace: TButton;
12 check_transparency: TCheckBox;
13 check_fading: TCheckBox;
14 panel_txmppreview: TPanel;
15 btn_save: TButton;
16 image_txmppreview: TImage;
17 splitter_txmp: TSplitter;
18 group_bmpselect: TGroupBox;
19 image_bmppreview: TImage;
20 panel_load: TPanel;
21 btn_load: TButton;
22 opend: TOpenDialog;
23 saved: TSaveDialog;
24 procedure SelectFile(fileinfo: TFileInfo);
25 procedure FormCreate(Sender: TObject);
26 procedure FormClose(Sender: TObject; var Action: TCloseAction);
27 procedure btn_saveClick(Sender: TObject);
28 procedure btn_loadClick(Sender: TObject);
29 procedure btn_replaceClick(Sender: TObject);
30 private
31 OniImage_Old: TOniImage;
32 OniImage_New: TOniImage;
33 old_size: Integer;
34 fileid: Integer;
35 public
36 end;
37
38var
39 Form_TxmpReplace: TForm_TxmpReplace;
40
41implementation
42{$R *.dfm}
[97]43uses Main, ConnectionManager;
[93]44
45
46
47procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo);
48var
49 mem: TMemoryStream;
50 fadingbyte, depthbyte, storebyte: Byte;
51begin
52 fileid := fileinfo.ID;
[105]53 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
54 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
55 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
[93]56 check_fading.Checked := (fadingbyte and $01) > 0;
57 check_transparency.Checked := (depthbyte and $04) > 0;
58
[105]59 OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
[93]60 old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
61 mem := TMemoryStream.Create;
[105]62 OniImage_Old.GetAsBMP(TStream(mem));
[93]63 mem.Seek(0, soFromBeginning);
64 image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
65 mem.Free;
66
67 group_bmpselect.Enabled := True;
68end;
69
70
71procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject);
72var
73 mem: TMemoryStream;
74begin
75 if opend.Execute then
76 begin
77 OniImage_New.LoadFromBMP(opend.FileName);
78 mem := TMemoryStream.Create;
[105]79 OniImage_New.GetAsBMP(TStream(mem));
[93]80 mem.Seek(0, soFromBeginning);
81 image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
82 mem.Free;
83 group_options.Enabled := True;
84 end;
85end;
86
87
88
89
90procedure TForm_TxmpReplace.btn_replaceClick(Sender: TObject);
91var
[111]92 newsize: Integer;
93 old_rawaddr, new_rawaddr: Integer;
[93]94 oldfading: Byte;
95 datbyte: Word;
[105]96 mem: TMemoryStream;
[93]97begin
98 if filelist.ItemIndex >= 0 then
99 begin
[105]100 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, 1, @oldfading);
101 if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
102 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @old_rawaddr)
[93]103 else
[105]104 ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
[93]105
106 if (OniImage_Old.Width <> OniImage_New.Width) or
107 (OniImage_Old.Height <> OniImage_New.Height) then
108 begin
[105]109 if MessageBox(Self.Handle,
110 PChar(
111 'Current image and new image have different size' + CrLf +
112 '(Current: ' + IntToStr(OniImage_Old.Width) + 'x' +
113 IntToStr(OniImage_Old.Height) + ' - New: ' +
114 IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) +
115 ')' + CrLf + 'Replace anyway?'),
116 PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then
[93]117 Exit;
118 end;
119
[105]120 mem := TMemoryStream.Create;
121
[93]122 if check_fading.Checked then
[105]123 if not OniImage_New.GetMipMappedImage(TStream(mem)) then
[93]124 if MessageBox(Self.Handle,
[105]125 PChar('Can not create a MipMapped-image (probably because of a wrong dimension).' +
126 #13 + #10 + 'Do you want to continue without MipMapping?'), PChar('Warning'),
127 MB_YESNO) = ID_YES then
[93]128 check_fading.Checked := False
129 else
130 Exit;
131
132 if not check_fading.Checked then
[105]133 begin
134 mem.Clear;
135 OniImage_New.GetAsData(TStream(mem));
136 end;
[93]137
138 newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
139
[105]140 if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
141 new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
142 not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem.Size, mem)
[93]143 else
144 begin
145 new_rawaddr := old_rawaddr;
[105]146 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem);
[93]147 end;
148
149 datbyte := $00;
150 if check_fading.Checked then
151 datbyte := datbyte or $01;
[105]152 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
[93]153 datbyte := $10;
154 if check_transparency.Checked then
155 datbyte := datbyte or $04;
[105]156 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $89, 1, @datbyte);
157 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
158 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
[93]159 datbyte := $08;
[105]160 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte);
161 if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
162 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
[93]163 else
[105]164 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
[93]165
166 ShowMessage('TXMP-image replaced');
167 end;
168end;
169
170
171
172
173procedure TForm_TxmpReplace.FormClose(Sender: TObject; var Action: TCloseAction);
174begin
175 OniImage_Old.Free;
176 OniImage_New.Free;
177 inherited;
178end;
179
180
181
182
183procedure TForm_TxmpReplace.FormCreate(Sender: TObject);
184begin
185 inherited;
186 OniImage_Old := TOniImage.Create;
187 OniImage_New := TOniImage.Create;
188 Self.AllowedExts := 'TXMP';
189 Self.OnNewFileSelected := SelectFile;
190end;
191
192
193
194
195procedure TForm_TxmpReplace.btn_saveClick(Sender: TObject);
196begin
197 if saved.Execute then
198 OniImage_Old.WriteToBMP(saved.FileName);
199end;
200
201begin
202 AddToolListEntry('txmpreplace', 'TXMP Replacer', 'TXMP');
203end.
Note: See TracBrowser for help on using the repository browser.