c01815a23b2c37219354f41fc52c95c066378758
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
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 // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so
83 // mix color with checkered background. Also, can't really read
84 // CHECKERS.tga from here. FUCK!
85 if UseCheckerboard
then
87 if (((x
shr 3) and 1) = 0) xor (((y
shr 3) and 1) = 0) then
94 bgc
.r
:= GetRValue(PreviewColor
);
95 bgc
.g
:= GetGValue(PreviewColor
);
96 bgc
.b
:= GetBValue(PreviewColor
);
98 clr
.r
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.r
+ clr
.a
* clr
.r
) div 255);
99 clr
.g
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.g
+ clr
.a
* clr
.g
) div 255);
100 clr
.b
:= ClampToByte((Byte(255 - clr
.a
) * bgc
.b
+ clr
.a
* clr
.b
) div 255);
101 // TODO: check for RGB/BGR somehow?
102 ii
^ := clr
.b
; Inc(ii
);
103 ii
^ := clr
.g
; Inc(ii
);
104 ii
^ := clr
.r
; Inc(ii
);
106 (* Why this works in linux? *)
107 {$IFNDEF WINDOWS}Inc(ii
){$ENDIF}
110 FreeMem(TextureData
);
115 procedure TAddSkyForm
.bOKClick(Sender
: TObject
);
122 procedure TAddSkyForm
.lbResourcesListClick(Sender
: TObject
);
129 if lbResourcesList
.ItemIndex
= -1 then
131 if FResourceName
= '' then
134 Texture
:= ShowTGATexture(FFullResourceName
);
135 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
136 if Texture
= nil then
138 iPreview
.Canvas
.StretchDraw(iPreview
.Canvas
.ClipRect
, Texture
);
142 procedure TAddSkyForm
.FormActivate(Sender
: TObject
);
146 ResourceName
: String;
152 iPreview
.Canvas
.FillRect(iPreview
.Canvas
.ClipRect
);
154 // Уже есть выбранный ресурс:
155 if FSetResource
<> '' then
157 g_ProcessResourceStr(FSetResource
, FileName
, SectionName
, ResourceName
);
159 if FileName
= '' then
160 FileName
:= _lc
[I_WAD_SPECIAL_MAP
];
161 if SectionName
= '' then
165 a
:= cbWADList
.Items
.IndexOf(FileName
);
168 cbWADList
.ItemIndex
:= a
;
169 cbWADList
.OnChange(nil);
173 a
:= cbSectionsList
.Items
.IndexOf(SectionName
);
176 cbSectionsList
.ItemIndex
:= a
;
177 cbSectionsList
.OnChange(nil);
181 a
:= lbResourcesList
.Items
.IndexOf(ResourceName
);
184 lbResourcesList
.ItemIndex
:= a
;
185 lbResourcesList
.OnClick(nil);