-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiwidget.monkey
175 lines (140 loc) · 3.8 KB
/
guiwidget.monkey
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
Import horizon.guisystem
Import horizon.guibase
Import horizon.rect
Import horizon.color
Class GuiWidget Extends GuiBase
Global idCounter : Int
Const NOTHING : Int = 0
Const HOVER : Int = 1
Const DOWN : Int = 2
Field widgetState : Int
Field id : Int
Field parent : GuiWidget
Field color : Color
Field clicked : Bool
Field entered:Bool
Method IsChildOf:Bool(element:GuiBase)
If (Not element) Then Return True
If (parent)
If (parent = element) Then Return True
Return parent.IsChildOf(element)
End If
Return False
End Method
'dirty helper method because of time pressure, sorry
Method IsMouseEntered:Bool()
Local ret:Bool = entered
entered = False
Return (ret)
End Method
Method New()
Super.New()
idCounter += 1
id = idCounter
visible = True
childs = New List<GuiBase>
rect = New Rect(0, 0, 100, 100)
color = New Color(255, 255, 255)
GuiSystem.widgets.AddLast(Self)
End Method
Method ToFront()
Local root:GuiBase = GetRootParent(Self.parent)
If root
GuiWidget(root).ChildsToFront()
Else
ChildsToFront()
EndIf
End Method
Function GetRootParent:GuiBase(widget:GuiBase)
If widget
Local root:GuiBase
While widget
root = widget
widget = GuiWidget(root).parent
Wend
Return root
EndIf
Return Null
End Function
Method ChildsToFront()
GuiSystem.widgets.Remove(Self)
GuiSystem.widgets.AddLast(Self)
For Local c : GuiBase = EachIn childs
If GuiWidget(c) Then GuiWidget(c).ChildsToFront()
Next
End Method
Method ToBack()
GuiSystem.widgets.Remove(Self)
For Local c : GuiBase = EachIn childs
c.ToBack()
Next
GuiSystem.widgets.AddFirst(Self)
End Method
Method OnActivate()
ToFront()
End Method
Method Render()
End Method
Method AddChild(w : GuiWidget)
If (w.parent) Then w.parent.RemoveChild(w)
childs.AddLast(w)
w.parent = Self
End Method
Method RemoveChild(w : GuiWidget)
childs.Remove(w)
w.parent = Null
End Method
Method Update()
clicked = False
#if TARGET="flash" or TARGET="html5"
If (Not TouchDown(1))
If GuiSystem.topElement <> Self Then widgetState = NOTHING Else widgetState = HOVER
End If
#else
If (Not TouchDown(0))
widgetState = NOTHING
End If
#end
End Method
Method GetWidgetState : Int()
Return widgetState
End Method
Method OnMouseHit()
clicked = True
widgetState = DOWN
End Method
Method OnMouseUp()
widgetState = NOTHING
If (GuiSystem.topElement = Self) Then widgetState = HOVER
End Method
Method IsClicked : Bool()
Return clicked
End Method
Method OnMouseOut()
If (widgetState = HOVER) Then widgetState = NOTHING
entered = False
End Method
Method OnMouseOver()
If (widgetState = NOTHING) Then widgetState = HOVER
entered = True
End Method
Method OnMouseMove(dx : Int, dy : Int)
End Method
Method OnMouseDown()
End Method
Method OnRMouseDown()
End Method
Method OnMouseClick()
End Method
Method OnMove()
rect.Move(-InputControllerMouse.GetInstance().GetDX(), -InputControllerMouse.GetInstance().GetDY())
End Method
Method OnRMouseHit()
End Method
Method OnRMouseUp()
End Method
Method Hide()
Super.Hide()
clicked = False
End Method
End