1 unit f_addresource_sky
;
3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
, SysUtils
, Variants
, Classes
,
9 Graphics
, Controls
, Forms
, Dialogs
, f_addresource
,
10 ExtCtrls
, StdCtrls
, utils
, Imaging
, ImagingTypes
, ImagingUtility
;
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 function ShowTGATexture(ResourceStr
: String): TBitMap
;
59 // Загружаем ресурс текстуры из WAD:
60 g_ProcessResourceStr(ResourceStr
, WADName
, SectionName
, ResourceName
);
62 WAD
:= TWADEditor_1
.Create();
63 WAD
.ReadFile(WADName
);
65 WAD
.GetResource(SectionName
, ResourceName
, TextureData
, ImageSize
);
70 if not LoadImageFromMemory(TextureData
, ImageSize
, img
) then
76 ImageSize
:= Width
*Height
*(ColorDepth
div 8);
78 BitMap
:= TBitMap
.Create();
79 BitMap
.PixelFormat
:= pf24bit
;
81 BitMap
.Width
:= Width
;
82 BitMap
.Height
:= Height
;
85 ii
:= BitMap
.RawImage
.Data
;
86 for y
:= 0 to height
-1 do
88 for x
:= 0 to width
-1 do
90 clr
:= GetPixel32(img
, x
, y
);
91 // assuming sky has no alpha
92 // TODO: check for ARGB/RGBA/BGRA/ABGR somehow?
93 ii
^ := clr
.b
; Inc(ii
);
94 ii
^ := clr
.g
; Inc(ii
);
95 ii
^ := clr
.r
; Inc(ii
);
104 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
108 if not FResourceSelected
then
112 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
119 if lbResourcesList
.ItemIndex
= -1 then
121 if FResourceName
= '' then
124 Texture
:= ShowTGATexture(FFullResourceName
);
125 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
126 if Texture
= nil then
128 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
132 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
136 ResourceName
: String;
142 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
144 // Уже есть выбранный ресурс:
145 if FSetResource
<> '' then
147 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
149 if FileName
= '' then
150 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
151 if SectionName
= '' then
155 a
:= cbWADList
.Items
.IndexOf(win2utf(FileName
));
158 cbWADList
.ItemIndex
:= a
;
159 cbWADList
.OnChange(nil);
163 a
:= cbSectionsList
.Items
.IndexOf(win2utf(SectionName
));
166 cbSectionsList
.ItemIndex
:= a
;
167 cbSectionsList
.OnChange(nil);
171 a
:= lbResourcesList
.Items
.IndexOf(win2utf(ResourceName
));
174 lbResourcesList
.ItemIndex
:= a
;
175 lbResourcesList
.OnClick(nil);