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 WADEDITOR
, f_main
, g_language
, g_resources
;
38 function ShowTGATexture(ResourceStr
: String): TBitMap
;
57 g_ProcessResourceStr(ResourceStr
, WADName
, SectionName
, ResourceName
);
58 g_ReadResource(WADName
, SectionName
, ResourceName
, TextureData
, ImageSize
);
61 if not LoadImageFromMemory(TextureData
, ImageSize
, img
) then
67 ImageSize
:= Width
*Height
*(ColorDepth
div 8);
69 BitMap
:= TBitMap
.Create();
70 BitMap
.PixelFormat
:= pf24bit
;
72 BitMap
.Width
:= Width
;
73 BitMap
.Height
:= Height
;
76 ii
:= BitMap
.RawImage
.Data
;
77 for y
:= 0 to height
-1 do
79 for x
:= 0 to width
-1 do
81 clr
:= GetPixel32(img
, x
, y
);
82 // assuming sky has no alpha
83 // TODO: check for ARGB/RGBA/BGRA/ABGR somehow?
84 ii
^ := clr
.b
; Inc(ii
);
85 ii
^ := clr
.g
; Inc(ii
);
86 ii
^ := clr
.r
; Inc(ii
);
95 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
99 if not FResourceSelected
then
103 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
110 if lbResourcesList
.ItemIndex
= -1 then
112 if FResourceName
= '' then
115 Texture
:= ShowTGATexture(FFullResourceName
);
116 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
117 if Texture
= nil then
119 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
123 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
127 ResourceName
: String;
133 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
135 // Уже есть выбранный ресурс:
136 if FSetResource
<> '' then
138 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
140 if FileName
= '' then
141 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
142 if SectionName
= '' then
146 a
:= cbWADList
.Items
.IndexOf(FileName
);
149 cbWADList
.ItemIndex
:= a
;
150 cbWADList
.OnChange(nil);
154 a
:= cbSectionsList
.Items
.IndexOf(SectionName
);
157 cbSectionsList
.ItemIndex
:= a
;
158 cbSectionsList
.OnChange(nil);
162 a
:= lbResourcesList
.Items
.IndexOf(ResourceName
);
165 lbResourcesList
.ItemIndex
:= a
;
166 lbResourcesList
.OnClick(nil);