source: oup/releases/0.31a/Unit7_txmpreplace.pas@ 871

Last change on this file since 871 was 34, checked in by alloc, 18 years ago
File size: 7.5 KB
Line 
1UNIT Unit7_txmpreplace;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data;
6
7TYPE
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 check_32bit: TCheckBox;
24 panel_txmppreview: TPanel;
25 btn_save: TButton;
26 image_txmppreview: TImage;
27 saved: TSaveDialog;
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 FormResize(Sender: TObject);
35 PROCEDURE Recreatelist;
36 PRIVATE
37 actual_bmpdata:Tdata;
38 PUBLIC
39 END;
40
41VAR
42 Form7: TForm7;
43
44IMPLEMENTATION
45USES Unit1_main, Unit6_imgfuncs, Unit15_Classes;
46{$R *.dfm}
47
48PROCEDURE 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
64PROCEDURE TForm7.FormResize(Sender: TObject);
65 BEGIN
66 IF Self.Width>=400 THEN BEGIN
67 END ELSE Self.Width:=400;
68 IF Self.Height>=350 THEN BEGIN
69 END ELSE Self.Height:=350;
70 END;
71
72PROCEDURE TForm7.list_txmpClick(Sender: TObject);
73 VAR
74 id:LongWord;
75 data:Tdata;
76 img:TImgPackage;
77 mem:TMemoryStream;
78 fadingbyte,depthbyte,storebyte:Byte;
79 BEGIN
80 id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
81
82 OniDataConnection.LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
83 OniDataConnection.LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
84 OniDataConnection.LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
85 check_fading.Checked:=(fadingbyte AND $01)>0;
86 check_transparency.Checked:=(depthbyte AND $04)>0;
87 check_32bit.Checked:=(storebyte=8);
88
89 img:=LoadImgData(id);
90 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
91
92 mem:=TMemoryStream.Create;
93 mem.Write(data[0],Length(data));
94 mem.Seek(0,soFromBeginning);
95 image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
96 mem.Free;
97
98 group_bmpselect.Enabled:=True;
99 END;
100
101PROCEDURE TForm7.btn_loadClick(Sender: TObject);
102 VAR
103 bmpfile:TFileStream;
104 mem:TMemoryStream;
105 BEGIN
106 IF opend.Execute THEN BEGIN
107 bmpfile:=TFileStream.Create(opend.FileName, fmOpenRead);
108 SetLength(actual_bmpdata,bmpfile.Size);
109 bmpfile.Read(actual_bmpdata[0],bmpfile.Size);
110 bmpfile.Free;
111
112 mem:=TMemoryStream.Create;
113 mem.Write(actual_bmpdata[0],Length(actual_bmpdata));
114 mem.Seek(0,soFromBeginning);
115 image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
116 mem.Free;
117
118 group_options.Enabled:=True;
119 END;
120 END;
121
122PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
123 VAR
124 id:LongWord;
125 imgpkg:TImgPackage;
126 old_rawaddr,new_rawaddr:LongWord;
127 oldwidth,oldheight:Word;
128 oldstore,olddepth,oldfading:Byte;
129 oldsize:LongWord;
130 newsize:LongWord;
131 datbyte:Word;
132 BEGIN
133 IF list_txmp.ItemIndex>=0 THEN BEGIN
134 imgpkg:=BmpToImgdata(actual_bmpdata,check_32bit.Checked);
135
136 id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
137 OniDataConnection.LoadDatFilePart(id,$8C,2,@oldwidth);
138 OniDataConnection.LoadDatFilePart(id,$8E,2,@oldheight);
139 OniDataConnection.LoadDatFilePart(id,$88,1,@oldfading);
140 OniDataConnection.LoadDatFilePart(id,$89,1,@olddepth);
141 OniDataConnection.LoadDatFilePart(id,$90,1,@oldstore);
142 OniDataConnection.LoadDatFilePart(id,$9C,4,@old_rawaddr);
143 IF (oldwidth<>imgpkg.imgx) OR (oldheight<>imgpkg.imgy) THEN BEGIN
144 IF MessageBox(Self.Handle,
145 PChar('Current image and new image have different size'+CrLf+
146 '(Current: '+IntToStr(oldwidth)+'x'+IntToStr(oldheight)+
147 ' - New: '+IntToStr(imgpkg.imgx)+'x'+IntToStr(imgpkg.imgy)+')'+CrLf+
148 'Replace anyways?'),
149 PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
150 MB_YESNO)=IDNO THEN Exit;
151 END;
152
153 CASE oldstore OF
154 9: oldsize:=GetImageDataSize(oldwidth,oldheight,8,(oldfading AND $01)>0);
155 0,1,2: oldsize:=GetImageDataSize(oldwidth,oldheight,16,(oldfading AND $01)>0);
156 8: oldsize:=GetImageDataSize(oldwidth,oldheight,32,(oldfading AND $01)>0);
157 ELSE
158 oldsize:=0;
159 END;
160
161 IF check_fading.Checked THEN
162 IF Not CreateFadedImage(imgpkg,imgpkg.imgdata) THEN
163 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
164 check_fading.Checked:=False
165 ELSE
166 Exit;
167
168 IF check_32bit.Checked THEN
169 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,32,check_fading.Checked)
170 ELSE
171 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,16,check_fading.Checked);
172
173 IF (newsize>oldsize) AND (OniDataConnection.Backend=ODB_Dat) THEN
174 new_rawaddr:=OniDataConnection.AppendRawFile(False,Length(imgpkg.imgdata),imgpkg.imgdata)
175 ELSE BEGIN
176 new_rawaddr:=old_rawaddr;
177 OniDataConnection.UpdateRawFile(id,$9C,Length(imgpkg.imgdata),imgpkg.imgdata);
178 END;
179
180 datbyte:=$00;
181 IF check_fading.Checked THEN datbyte:=datbyte OR $01;
182 OniDataConnection.UpdateDatFilePart(id,$88,1,@datbyte);
183 datbyte:=$10;
184 IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
185 OniDataConnection.UpdateDatFilePart(id,$89,1,@datbyte);
186 OniDataConnection.UpdateDatFilePart(id,$8C,2,@imgpkg.imgx);
187 OniDataConnection.UpdateDatFilePart(id,$8E,2,@imgpkg.imgy);
188 IF check_32bit.Checked THEN
189 datbyte:=$08
190 ELSE
191 datbyte:=$01;
192 OniDataConnection.UpdateDatFilePart(id,$90,1,@datbyte);
193 OniDataConnection.UpdateDatFilePart(id,$9C,4,@new_rawaddr);
194
195 ShowMessage('TXMP-image replaced');
196 END;
197 END;
198
199PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
200 BEGIN
201 Action:=caFree;
202 Form1.close_window(Self.Name);
203 END;
204
205PROCEDURE TForm7.FormActivate(Sender: TObject);
206 BEGIN
207 Form1.SetActiveWindow(Self.Name);
208 END;
209
210PROCEDURE TForm7.btn_saveClick(Sender: TObject);
211 VAR
212 filestream:TFileStream;
213 img:TImgPackage;
214 BEGIN
215 IF saved.Execute THEN BEGIN
216 img:=LoadImgData(OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]));
217 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
218 filestream:=TFileStream.Create(saved.FileName,fmCreate);
219 filestream.Write(img.imgdata[0],Length(img.imgdata));
220 filestream.Free;
221 END;
222 END;
223
224END.
Note: See TracBrowser for help on using the repository browser.