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
;
56 g_ProcessResourceStr(ResourceStr
, WADName
, SectionName
, ResourceName
);
57 g_ReadResource(WADName
, SectionName
, ResourceName
, TextureData
, ImageSize
);
59 (* !!! copypaste from f_addresource_texture.CreateBitMap *)
62 if not LoadImageFromMemory(TextureData
, ImageSize
, img
) then
70 BitMap
:= TBitMap
.Create();
71 BitMap
.PixelFormat
:= pf24bit
;
72 BitMap
.Width
:= Width
;
73 BitMap
.Height
:= Height
;
74 for y
:= 0 to height
- 1 do
76 for x
:= 0 to width
- 1 do
78 clr
:= GetPixel32(img
, x
, y
);
79 // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so
80 // mix color with checkered background. Also, can't really read
81 // CHECKERS.tga from here. FUCK!
82 if UseCheckerboard
then
84 if (((x
shr 3) and 1) = 0) xor (((y
shr 3) and 1) = 0) then
91 bgc
.r
:= GetRValue(PreviewColor
);
92 bgc
.g
:= GetGValue(PreviewColor
);
93 bgc
.b
:= GetBValue(PreviewColor
)
95 clr
.r
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.r
+ clr
.a
* clr
.r
) div 255);
96 clr
.g
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.g
+ clr
.a
* clr
.g
) div 255);
97 clr
.b
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.b
+ clr
.a
* clr
.b
) div 255);
98 BitMap
.Canvas
.Pixels
[x
, y
] := RGBToColor(clr
.r
, clr
.g
, clr
.b
)
101 FreeMem(TextureData
);
106 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
113 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
120 if lbResourcesList
.ItemIndex
= -1 then
122 if FResourceName
= '' then
125 Texture
:= ShowTGATexture(FFullResourceName
);
126 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
127 if Texture
= nil then
129 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
133 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
137 ResourceName
: String;
143 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
145 // Уже есть выбранный ресурс:
146 if FSetResource
<> '' then
148 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
150 if FileName
= '' then
151 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
152 if SectionName
= '' then
156 a
:= cbWADList
.Items
.IndexOf(FileName
);
159 cbWADList
.ItemIndex
:= a
;
160 cbWADList
.OnChange(nil);
164 a
:= cbSectionsList
.Items
.IndexOf(SectionName
);
167 cbSectionsList
.ItemIndex
:= a
;
168 cbSectionsList
.OnChange(nil);
172 a
:= lbResourcesList
.Items
.IndexOf(ResourceName
);
175 lbResourcesList
.ItemIndex
:= a
;
176 lbResourcesList
.OnClick(nil);