source: oup/current/Unit7_txmpreplace.pas@ 10

Last change on this file since 10 was 10, checked in by alloc, 18 years ago
  • Property svn:executable set to *
File size: 6.3 KB
RevLine 
[10]1UNIT Unit7_txmpreplace;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data, Unit6_imgfuncs;
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 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 FormClose(Sender: TObject; var Action: TCloseAction);
30 PROCEDURE btn_replaceClick(Sender: TObject);
31 PROCEDURE btn_loadClick(Sender: TObject);
32 PROCEDURE list_txmpClick(Sender: TObject);
33 PROCEDURE Recreatelist;
34 PRIVATE
35 OniImage_Old:TOniImage;
36 OniImage_New:TOniImage;
37 PUBLIC
38 END;
39
40VAR
41 Form7: TForm7;
42
43IMPLEMENTATION
44USES Unit1_main, Unit15_Classes;
45{$R *.dfm}
46
47PROCEDURE TForm7.Recreatelist;
48 VAR
49 files:TStringArray;
50 i:LongWord;
51 BEGIN
52 list_txmp.Items.Clear;
53 files:=OniDataConnection.GetFilesList('TXMP','',True);
54 IF Length(files)>0 THEN
55 FOR i:=0 TO High(files) DO
56 list_txmp.Items.Add(files[i]);
57 group_bmpselect.Enabled:=False;
58 check_transparency.Checked:=False;
59 check_fading.Checked:=False;
60 END;
61
62
63PROCEDURE TForm7.list_txmpClick(Sender: TObject);
64 VAR
65 id:LongWord;
66 data:Tdata;
67 mem:TMemoryStream;
68 fadingbyte,depthbyte,storebyte:Byte;
69 BEGIN
70 id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
71 OniDataConnection.LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
72 OniDataConnection.LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
73 OniDataConnection.LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
74 check_fading.Checked:=(fadingbyte AND $01)>0;
75 check_transparency.Checked:=(depthbyte AND $04)>0;
76
77 OniImage_Old.LoadFromTXMP(id);
78 data:=OniImage_Old.GetAsBMP;
79 mem:=TMemoryStream.Create;
80 mem.Write(data[0],Length(data));
81 mem.Seek(0,soFromBeginning);
82 image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
83 mem.Free;
84
85 group_bmpselect.Enabled:=True;
86 END;
87
88PROCEDURE TForm7.btn_loadClick(Sender: TObject);
89 VAR
90 mem:TMemoryStream;
91 tempd:Tdata;
92 BEGIN
93 IF opend.Execute THEN BEGIN
94 OniImage_New.LoadFromBMP(opend.FileName);
95 tempd:=OniImage_New.GetAsBMP;
96 mem:=TMemoryStream.Create;
97 mem.Write(tempd[0],Length(tempd));
98 mem.Seek(0,soFromBeginning);
99 image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
100 mem.Free;
101 group_options.Enabled:=True;
102 END;
103 END;
104
105PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
106 VAR
107 id:LongWord;
108
109 oldsize,newsize:LongWord;
110 old_rawaddr,new_rawaddr:LongWord;
111 oldfading:Byte;
112 tempd:Tdata;
113
114 datbyte:Word;
115 BEGIN
116 IF list_txmp.ItemIndex>=0 THEN BEGIN
117 id:=OniDataConnection.ExtractFileID(list_txmp.Items.Strings[list_txmp.ItemIndex]);
118 OniDataConnection.LoadDatFilePart(id,$88,1,@oldfading);
119 if OniDataConnection.OSisMac then
120 OniDataConnection.UpdateDatFilePart(id,$A0,4,@old_rawaddr)
121 else
122 OniDataConnection.LoadDatFilePart(id,$9C,4,@old_rawaddr);
123
124 IF (OniImage_Old.Width<>OniImage_New.Width) OR (OniImage_Old.Height<>OniImage_New.Height) THEN BEGIN
125 IF MessageBox(Self.Handle,
126 PChar('Current image and new image have different size'+CrLf+
127 '(Current: '+IntToStr(OniImage_Old.Width)+'x'+IntToStr(OniImage_Old.Height)+
128 ' - New: '+IntToStr(OniImage_New.Width)+'x'+IntToStr(OniImage_New.Height)+')'+CrLf+
129 'Replace anyways?'),
130 PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
131 MB_YESNO)=IDNO THEN Exit;
132 END;
133
134 oldsize:=OniImage_Old.GetImageDataSize((oldfading and $01)>0);
135
136 IF check_fading.Checked THEN
137 IF NOT OniImage_New.GetMipMappedImage(tempd) THEN
138 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
139 check_fading.Checked:=False
140 ELSE
141 Exit;
142
143 IF NOT check_fading.Checked THEN
144 tempd:=OniImage_New.GetAsData;
145
146 newsize:=OniImage_New.GetImageDataSize(check_fading.Checked);
147 ShowMessage(IntToStr(newsize));
148
149 IF (newsize>oldsize) AND (OniDataConnection.Backend=ODB_Dat) THEN
150 new_rawaddr:=OniDataConnection.AppendRawFile(OniDataConnection.OSisMac,Length(tempd),tempd)
151 ELSE BEGIN
152 new_rawaddr:=old_rawaddr;
153 OniDataConnection.UpdateRawFile(id,$9C,Length(tempd),tempd);
154 END;
155
156 datbyte:=$00;
157 IF check_fading.Checked THEN datbyte:=datbyte OR $01;
158 OniDataConnection.UpdateDatFilePart(id,$88,1,@datbyte);
159 datbyte:=$10;
160 IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
161 OniDataConnection.UpdateDatFilePart(id,$89,1,@datbyte);
162 OniDataConnection.UpdateDatFilePart(id,$8C,2,@OniImage_New.Width);
163 OniDataConnection.UpdateDatFilePart(id,$8E,2,@OniImage_New.Height);
164 datbyte:=$08;
165 OniDataConnection.UpdateDatFilePart(id,$90,1,@datbyte);
166 if OniDataConnection.OSisMac then
167 OniDataConnection.UpdateDatFilePart(id,$A0,4,@new_rawaddr)
168 else
169 OniDataConnection.UpdateDatFilePart(id,$9C,4,@new_rawaddr);
170
171 ShowMessage('TXMP-image replaced');
172 END;
173 END;
174
175PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
176 BEGIN
177 OniImage_Old.Free;
178 OniImage_New.Free;
179 Action:=caFree;
180 END;
181
182PROCEDURE TForm7.FormCreate(Sender: TObject);
183 BEGIN
184 OniImage_Old:=TOniImage.Create;
185 OniImage_New:=TOniImage.Create;
186 END;
187
188PROCEDURE TForm7.btn_saveClick(Sender: TObject);
189 BEGIN
190 IF saved.Execute THEN
191 OniImage_Old.WriteToBMP(saved.FileName);
192 END;
193
194END.
Note: See TracBrowser for help on using the repository browser.