-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbase.gfx.gui.panel.bmx
executable file
·199 lines (148 loc) · 4.55 KB
/
base.gfx.gui.panel.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
Rem
===========================================================
GUI Panel
===========================================================
End Rem
SuperStrict
Import "base.gfx.gui.backgroundbox.bmx"
Import "base.gfx.gui.textbox.bmx"
Type TGUIPanel Extends TGUIObject
Field guiBackground:TGUIBackgroundBox = Null
Field guiTextBox:TGUITextBox
Field guiTextBoxAlignment:TVec2D
Field _defaultValueColor:TColor
Field useBackgroundPadding:int = True
Method GetClassName:String()
Return "tguiscrollablepanel"
End Method
Method Create:TGUIPanel(pos:TVec2D, dimension:TVec2D, limitState:String = "")
Super.CreateBase(pos, dimension, limitState)
GUIManager.Add(Self)
Return Self
End Method
Method Remove:int()
Super.Remove()
if guiBackground then guiBackground.Remove()
if guiTextBox then guiTextBox.Remove()
End Method
Method SetPadding:Int(pTop:Float, pLeft:Float, pBottom:Float, pRight:Float)
if guiBackground
useBackgroundPadding = False
endif
Super.SetPadding(pTop, pLeft, pBottom, pRight)
End Method
Method GetPadding:TRectangle()
'if no manual padding was setup - use sprite padding
if guiBackground and useBackgroundPadding then return guiBackground.GetPadding()
Return Super.GetPadding()
End Method
Method SetSize(w:Float = 0, h:Float = 0)
'resize self
If w <= 0 Then w = rect.GetW()
If h <= 0 Then h = rect.GetH()
Super.SetSize(w, h)
End Method
'override to also check children
Method IsAppearanceChanged:int()
if guiBackground and guiBackground.isAppearanceChanged() then return TRUE
if guiTextBox and guiTextBox.isAppearanceChanged() then return TRUE
return Super.isAppearanceChanged()
End Method
Method SetBackground(obj:TGUIBackgroundBox=Null)
'remove old background from children
if guiBackground then removeChild(guiBackground)
'reset to nothing?
If Not obj
If guiBackground
guiBackground.remove()
guiBackground = Null
EndIf
Else
guiBackground = obj
'set background to ignore parental padding (so it starts at 0,0)
guiBackground.SetOption(GUI_OBJECT_IGNORE_PARENTPADDING, True)
'never focus it (ignores "hover")
guiBackground.SetOption(GUI_OBJECT_CAN_GAIN_FOCUS, False)
'set background to to be on same level than parent
guiBackground.SetZIndex(-1)
'invalidate padding
onChangePadding()
'we manage it now, not the guimanager
addChild(obj)
EndIf
End Method
'override default to return textbox value
Method GetValue:String()
If guiTextBox Then Return guiTextBox.GetValue()
Return ""
End Method
'override default to set textbox value
Method SetValue(value:String="")
If value=""
If guiTextBox
RemoveChild(guiTextBox)
guiTextBox.remove()
guiTextBox = Null
EndIf
Else
if not guiTextBox
guiTextBox = New TGUITextBox.Create(new TVec2D.Init(0,0), new TVec2D.Init(50,50), value, "")
'we take care of the text box
AddChild(guiTextBox)
if not guiTextBoxAlignment then guiTextBoxAlignment = ALIGN_CENTER_CENTER
else
guiTextBox.SetValue(value)
endif
If _defaultValueColor
guiTextBox.SetValueColor(_defaultValueColor)
Else
guiTextBox.SetValueColor(TColor.clWhite)
EndIf
guiTextBox.SetValueAlignment( guiTextBoxAlignment )
guiTextBox.SetAutoAdjustHeight(True)
EndIf
'to resize textbox accordingly
SetSize(-1,-1)
End Method
Method disableBackground()
If guiBackground Then guiBackground.disable()
End Method
Method enableBackground()
If guiBackground Then guiBackground.enable()
End Method
Method DrawContent()
'
End Method
Method UpdateChildren:Int()
If Not _children Or _children.Count() = 0 Then Return False
If HasOption(GUI_OBJECT_STATIC_CHILDREN) Then Return False
'update added elements
For Local obj:TGUIobject = EachIn _children.ReverseEnumerator()
obj.update()
Next
End Method
Method Update:Int()
'as we do not call "super.Update()" - we handle this manually
'if appearance changed since last update tick: inform widget
If isAppearanceChanged()
onAppearanceChanged()
SetAppearanceChanged(false)
Endif
UpdateChildren()
End Method
Method UpdateLayout()
' Super.UpdateLayout()
'move textbox
If guiTextBox
'text box is aligned to padding - so can start at "0,0"
'-> no additional offset
guiTextBox.SetPosition(0,0)
'getContentScreenWidth takes GetPadding into consideration
'which considers guiBackground already - so no need to distinguish
guiTextBox.SetSize(GetContentScreenRect().GetW(), GetContentScreenRect().GetH())
EndIf
if guiBackground
guiBackground.SetSize(rect.GetW(), rect.GetH())
Endif
End Method
End Type