-
Notifications
You must be signed in to change notification settings - Fork 7
/
base.gfx.gui.window.base.bmx
executable file
·223 lines (171 loc) · 6.8 KB
/
base.gfx.gui.window.base.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Rem
====================================================================
GUI Window
====================================================================
====================================================================
If not otherwise stated, the following code is available under the
following licence:
LICENCE: zlib/libpng
Copyright (C) 2015-now Ronny Otto, digidea.de
This software is provided 'as-is', without any express or
implied warranty. In no event will the authors be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
====================================================================
End Rem
SuperStrict
Import "base.gfx.gui.panel.bmx"
Type TGUIWindowBase Extends TGUIPanel
Field guiCaptionTextBox:TGUITextBox
Field guiCaptionArea:TRectangle
'this panel can contain additional content (buttons, panels....)
Field guiContent:TGUIPanel
Global defaultCaptionColor:TColor = null
Method Create:TGUIWindowBase(pos:SVec2I, dimension:SVec2I, limitState:String = "")
Return Create(new TVec2D.Init(pos.x, pos.y), new TVec2D.Init(dimension.x, dimension.y), limitState)
End Method
Method Create:TGUIWindowBase(pos:TVec2D, dimension:TVec2D, limitState:String = "")
Super.CreateBase(pos, dimension, limitState)
'create background, setup text etc.
InitWindow(dimension)
guiTextBoxAlignment = ALIGN_LEFT_TOP
GUIManager.Add(Self)
Return Self
End Method
'override to delete additional widgets too
Method Remove:Int() override
Super.Remove()
if guiCaptionTextBox then guiCaptionTextBox.Remove()
return True
End Method
Method InitWindow(dimension:TVec2D)
If Not guiBackground
SetBackground( new TGUIBackgroundBox.Create(null, null) )
Else
guiBackground.rect.position.SetXY(0,0)
guiBackground.SetSize(dimension.GetX(), dimension.GetY())
EndIf
'set another panel background
guiBackground.spriteBaseName = "gfx_gui_window"
SetCaption("Window")
guiCaptionTextBox.SetFont( GetBitmapFont("Default", 16, BOLDFONT) )
guiBackground.SetParent(self)
'background has same zindex like window
guiBackground.SetZIndex(-1)
'caption uses automatic zindex (+1 to parent)
guiCaptionTextBox.SetZIndex(0)
End Method
'returns the content panel to add content too
'content panel gets created if not done yet
Method GetGuiContent:TGUIPanel()
if not guiContent
guiContent = new TGUIPanel.Create(new TVec2D, new TVec2D.Init(GetContentScreenRect().GetW(), GetContentScreenRect().GetH()), "")
AddChild(guiContent)
endif
return guiContent
End Method
'override to add guiContent-resizing
'size 0, 0 is not possible (leads to autosize)
Method SetSize(w:Float = 0, h:Float = 0)
Super.SetSize(w, h)
End Method
'override
Method UpdateLayout()
Super.UpdateLayout()
'resize content (if exists) to use all available content space
If guiContent
local contentScreenRect:TRectangle = GetContentScreenRect()
'content element is aligned according to padding setup, so 0,0
'is ok
guiContent.SetPosition(0,0)
guiContent.SetSize(contentScreenRect.GetW(), contentScreenRect.GetH())
EndIf
if guiCaptionTextBox
Local rect:TRectangle = new TRectangle.Init(-1,-1,-1,-1)
'if an area was defined - use as much values of this as
'possible
If guiCaptionArea
if guiCaptionArea.position.x <> -1 then rect.position.x = guiCaptionArea.position.x
if guiCaptionArea.position.y <> -1 then rect.position.y = guiCaptionArea.position.y
if guiCaptionArea.dimension.x <> -1 then rect.dimension.x = guiCaptionArea.dimension.x
if guiCaptionArea.dimension.y <> -1 then rect.dimension.y = guiCaptionArea.dimension.y
EndIf
'calculation of undefined/automatic values
'vertical center the caption between 0 and the start of
'content but to make it visible in all cases use "max(...)".
if guiBackground
Local padding:SRect = guiBackground.GetSprite().GetNinePatchInformation().contentBorder
if rect.position.x = -1 then rect.position.x = padding.GetLeft()
if rect.position.y = -1 then rect.position.y = 0
if rect.dimension.x = -1 then rect.dimension.x = GetContentScreenRect().GetW()
if rect.dimension.y = -1 then rect.dimension.y = Max(25, padding.GetTop())
else
if rect.position.x = -1 then rect.position.x = 0
if rect.position.y = -1 then rect.position.y = 0
if rect.dimension.x = -1 then rect.dimension.x = GetContentScreenRect().GetW()
if rect.dimension.y = -1 then rect.dimension.y = 25
endif
'reposition in all cases
guiCaptionTextBox.rect.position.SetXY(rect.GetX(), rect.GetY())
guiCaptionTextBox.SetSize(rect.GetW(), rect.GetH())
endif
End Method
Method SetCaptionArea(area:TRectangle)
guiCaptionArea = area.copy()
End Method
Method SetCaption:Int(caption:String="")
If caption=""
If guiCaptionTextBox
guiCaptionTextBox.remove()
guiCaptionTextBox = Null
EndIf
Else
If Not guiCaptionTextBox
'create the caption container
guiCaptionTextBox = New TGUITextBox.Create(new TVec2D, new TVec2D, caption, "")
If defaultCaptionColor
guiCaptionTextBox.SetValueColor(defaultCaptionColor)
Else
guiCaptionTextBox.SetValueColor(TColor.clWhite)
EndIf
guiCaptionTextBox.SetValueAlignment( ALIGN_CENTER_CENTER )
guiCaptionTextBox.SetAutoAdjustHeight(False)
guiCaptionTextBox.SetZIndex(1)
'set to ignore parental padding (so it starts at 0,0)
guiCaptionTextBox.SetOption(GUI_OBJECT_IGNORE_PARENTPADDING, True)
'we handle it
addChild(guiCaptionTextBox)
EndIf
'assign new caption
guiCaptionTextBox.value = caption
'manually call reposition function
InvalidateLayout()
EndIf
End Method
Method SetCaptionAndValue:Int(caption:String="", value:String="")
Local oldTextboxHeight:Float = GetContentScreenRect().GetH()
SetCaption(caption)
SetValue(value)
'resize window
if guiTextBox
if guiTextBox.getHeight() - GetContentScreenRect().GetH() > 0
Self.SetSize(0, GetScreenRect().GetH() + Max(guiTextBox.GetScreenRect().GetH(), guiTextBox.getHeight()) - GetContentScreenRect().GetH())
else
Self.SetSize(0, GetScreenRect().GetH() + guiTextBox.getHeight() - GetContentScreenRect().GetH() + 4)
endif
else
Self.SetSize(0, rect.getH())
endif
Return True
End Method
End Type