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
);
60 (* !!! copypaste from f_addresource_texture.CreateBitMap *)
63 if not LoadImageFromMemory(TextureData
, ImageSize
, img
) then
72 BitMap
:= TBitMap
.Create();
73 BitMap
.PixelFormat
:= pf24bit
;
75 BitMap
.Width
:= Width
;
76 BitMap
.Height
:= Height
;
79 ii
:= BitMap
.RawImage
.Data
;
80 for y
:= 0 to height
-1 do
82 for x
:= 0 to width
-1 do
84 clr
:= GetPixel32(img
, x
, y
);
85 // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so
86 // mix color with checkered background. Also, can't really read
87 // CHECKERS.tga from here. FUCK!
88 if UseCheckerboard
then
90 if (((x
shr 3) and 1) = 0) xor (((y
shr 3) and 1) = 0) then
97 bgc
.r
:= GetRValue(PreviewColor
);
98 bgc
.g
:= GetGValue(PreviewColor
);
99 bgc
.b
:= GetBValue(PreviewColor
);
101 clr
.r
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.r
+ clr
.a
* clr
.r
) div 255);
102 clr
.g
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.g
+ clr
.a
* clr
.g
) div 255);
103 clr
.b
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.b
+ clr
.a
* clr
.b
) div 255);
104 // TODO: check for RGB/BGR somehow?
105 ii
^ := clr
.b
; Inc(ii
);
106 ii
^ := clr
.g
; Inc(ii
);
107 ii
^ := clr
.r
; Inc(ii
);
109 (* Why this works in linux? *)
110 {$IFNDEF WINDOWS}Inc(ii
){$ENDIF}
113 FreeMem(TextureData
);
118 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
125 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
132 if lbResourcesList
.ItemIndex
= -1 then
134 if FResourceName
= '' then
137 Texture
:= ShowTGATexture(FFullResourceName
);
138 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
139 if Texture
= nil then
141 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
145 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
149 ResourceName
: String;
155 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
157 // Уже есть выбранный ресурс:
158 if FSetResource
<> '' then
160 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
162 if FileName
= '' then
163 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
164 if SectionName
= '' then
168 a
:= cbWADList
.Items
.IndexOf(FileName
);
171 cbWADList
.ItemIndex
:= a
;
172 cbWADList
.OnChange(nil);
176 a
:= cbSectionsList
.Items
.IndexOf(SectionName
);
179 cbSectionsList
.ItemIndex
:= a
;
180 cbSectionsList
.OnChange(nil);
184 a
:= lbResourcesList
.Items
.IndexOf(ResourceName
);
187 lbResourcesList
.ItemIndex
:= a
;
188 lbResourcesList
.OnClick(nil);