fb5bd5f1946d4528c06b58a64ddf7296069a4377
1 unit f_addresource_sky
;
8 LCLIntf
, LCLType
, LMessages
, SysUtils
, Variants
, Classes
,
9 Graphics
, Controls
, Forms
, Dialogs
, f_addresource
,
13 TAddSkyForm
= class (TAddResourceForm
)
14 PanelTexPreview
: TPanel
;
17 procedure bOKClick(Sender
: TObject
);
18 procedure lbResourcesListClick(Sender
: TObject
);
19 procedure FormActivate(Sender
: TObject
);
25 property SetResource
: String read FSetResource write FSetResource
;
29 AddSkyForm
: TAddSkyForm
;
34 BinEditor
, WADEDITOR
, f_main
, g_language
;
38 procedure SwapRGB(data
: Pointer; Size
: Integer);
53 function ShowTGATexture(ResourceStr
: String): TBitMap
;
55 TGAHeader
: packed record // Header type for TGA images
59 ColorMapSpec
: Array[0..4] of Byte;
60 OrigX
: Array [0..1] of Byte;
61 OrigY
: Array [0..1] of Byte;
62 Width
: Array [0..1] of Byte;
63 Height
: Array [0..1] of Byte;
67 image
: Pointer; {or PRGBTRIPLE}
84 // Загружаем ресурс текстуры из WAD:
85 g_ProcessResourceStr(ResourceStr
, WADName
, SectionName
, ResourceName
);
87 WAD
:= TWADEditor_1
.Create();
88 WAD
.ReadFile(WADName
);
90 WAD
.GetResource(SectionName
, ResourceName
, TextureData
, ImageSize
);
95 CopyMemory(@TGAHeader
, TextureData
, SizeOf(TGAHeader
));
97 if TGAHeader
.ImageType
<> 2 then
99 if TGAHeader
.ColorMapType
<> 0 then
101 if TGAHeader
.BPP
< 24 then
104 Width
:= TGAHeader
.Width
[0]+TGAHeader
.Width
[1]*256;
105 Height
:= TGAHeader
.Height
[0]+TGAHeader
.Height
[1]*256;
106 ColorDepth
:= TGAHeader
.BPP
;
107 ImageSize
:= Width
*Height
*(ColorDepth
div 8);
110 GetMem(Image
, ImageSize
);
112 CopyMemory(Image
, Pointer(Integer(TextureData
)+SizeOf(TGAHeader
)), ImageSize
);
114 BitMap
:= TBitMap
.Create();
116 if TGAHeader
.BPP
= 24 then
117 BitMap
.PixelFormat
:= pf24bit
119 BitMap
.PixelFormat
:= pf32bit
;
121 BitMap
.Width
:= Width
;
122 BitMap
.Height
:= Height
;
124 // Копируем изображение в BitMap:
125 for I
:= Height
-1 downto 0 do
126 CopyMemory(BitMap
.ScanLine
[Height
-1-I
],
127 Pointer(Integer(Image
)+(Width
*I
*(TGAHeader
.BPP
div 8))),
128 Width
*(TGAHeader
.BPP
div 8));
130 FreeMem(Image
, ImageSize
);
131 FreeMem(TextureData
);
135 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
139 if not FResourceSelected
then
143 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
150 if lbResourcesList
.ItemIndex
= -1 then
152 if FResourceName
= '' then
155 Texture
:= ShowTGATexture(FFullResourceName
);
156 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
157 if Texture
= nil then
159 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
163 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
167 ResourceName
: String;
173 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
175 // Уже есть выбранный ресурс:
176 if FSetResource
<> '' then
178 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
180 if FileName
= '' then
181 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
182 if SectionName
= '' then
186 a
:= cbWADList
.Items
.IndexOf(FileName
);
189 cbWADList
.ItemIndex
:= a
;
190 cbWADList
.OnChange(nil);
194 a
:= cbSectionsList
.Items
.IndexOf(SectionName
);
197 cbSectionsList
.ItemIndex
:= a
;
198 cbSectionsList
.OnChange(nil);
202 a
:= lbResourcesList
.Items
.IndexOf(ResourceName
);
205 lbResourcesList
.ItemIndex
:= a
;
206 lbResourcesList
.OnClick(nil);