-
Notifications
You must be signed in to change notification settings - Fork 7
/
base.gfx.gui.backgroundbox.bmx
executable file
·88 lines (63 loc) · 1.98 KB
/
base.gfx.gui.backgroundbox.bmx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Rem
===========================================================
GUI Backgroundbox
===========================================================
End Rem
SuperStrict
Import "base.gfx.gui.bmx"
Import "base.util.registry.spriteloader.bmx"
Type TGUIBackgroundBox Extends TGUIobject
Field sprite:TSprite
Field spriteAlpha:Float = 1.0
Field spriteBaseName:String = "gfx_gui_panel"
Field spriteTintColor:TColor
Method GetClassName:String()
Return "tguibackgroundbox"
End Method
Method Create:TGUIBackgroundBox(position:TVec2D, dimension:TVec2D, limitState:String="")
Super.CreateBase(position, dimension, limitState)
SetZindex(0)
SetOption(GUI_OBJECT_CLICKABLE, False) 'by default not clickable
GUIManager.Add(Self)
Return Self
End Method
Method GetPadding:TRectangle()
'if no manual padding was setup - use sprite padding
If Not _padding
Local s:TSprite = GetSprite()
if s and s.IsNinePatch()
Local r:sRect = GetSprite().GetNinePatchInformation().contentBorder
Return New TRectangle.Init(r.x, r.y, r.w, r.h)
endif
EndIf
Return Super.GetPadding()
End Method
'acts as cache
Method GetSprite:TSprite()
'refresh cache if not set or wrong sprite name
If Not sprite Or sprite.GetName() <> spriteBaseName
sprite = GetSpriteFromRegistry(spriteBaseName)
'new -non default- sprite: adjust appearance
If sprite.GetName() <> "defaultsprite"
SetAppearanceChanged(True)
EndIf
EndIf
Return sprite
End Method
Method DrawContent()
End Method
Method DrawBackground()
Local oldCol:SColor8; GetColor(oldCol)
Local oldColA:Float = GetAlpha()
'a local spriteAlpha means widget as "parent" can have alpha 1.0
'while the sprite is drawn with 0.3
SetAlpha oldColA * GetScreenAlpha() * spriteAlpha
If spriteTintColor Then spriteTintColor.SetRGB()
Local r:TRectangle = GetScreenRect()
GetSprite().DrawArea(r.GetX(), r.GetY(), r.GetW(), r.GetH())
SetColor(oldCol)
SetAlpha(oldColA)
End Method
Method UpdateLayout()
End Method
End Type