-
Notifications
You must be signed in to change notification settings - Fork 2
/
guisystem.monkey
125 lines (106 loc) · 3.44 KB
/
guisystem.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
Import horizon.inputcontrollermouse
Import horizon.guibase
Import mojo
'Import horizon.blitzmaxfunctions
'
Class GuiSystem
Global topElement : GuiBase
Global selectedElement : GuiBase
Global activeElement : GuiBase
Global modalElement : GuiBase
Global widgets : List<GuiBase>
Global mouse : InputControllerMouse
Global SKIN_PATH:String = "gfx/gui/"
Function Init()
widgets = New List<GuiBase>
mouse = InputControllerMouse.GetInstance()
End Function
Function RenderAll(darkenBG:Bool = True)
For Local w : GuiBase = EachIn widgets
If w.visible And w.autoRender
If (darkenBG And w = modalElement)
SetAlpha(0.7)
SetColor(0,0,0)
DrawRect 0,0,Application.GetInstance().width, Application.GetInstance().height
SetColor(255,255,255)
SetAlpha(1)
w.Render()
Else
w.Render()
End
End
Next
End Function
Function ClearWidgets()
topElement = Null
selectedElement = Null
activeElement = Null
modalElement = Null
widgets.Clear()
End Function
Function HideAllWidgets()
For Local w:GuiBase = EachIn widgets
w.Hide()
Next
End Function
Function RemoveWidget(w:GuiBase)
For Local w:GuiBase = EachIn w.childs
RemoveWidget(w)
Next
widgets.Remove(w)
End Function
Function GetModalElement:GuiBase()
Local m:GuiBase
For Local w : GuiBase = EachIn widgets
If w.visible And w.isModal
m = w
End
Next
Return m
End Function
Function ProcessMessages()
Local oldTopElement : GuiBase = topElement
modalElement = GetModalElement()
topElement = Null
For Local w : GuiBase = EachIn widgets
If w.visible And w.IsChildOf(modalElement)
If (w.rect.IsInRect(mouse.GetX(), mouse.GetY()))
topElement = w
End
End
Next
For Local w : GuiBase = EachIn widgets
If w.visible
w.Update()
End
Next
' send onMouseOver / onMouseOut
If (topElement <> oldTopElement)
If (topElement) Then topElement.OnMouseOver()
If (oldTopElement) Then oldTopElement.OnMouseOut()
End
If (mouse.IsMouseHit(mouse.BUTTON_LEFT))
activeElement = Null
End
If (topElement)
If (mouse.IsMouseHit(mouse.BUTTON_LEFT))
topElement.OnMouseHit()
selectedElement = topElement
activeElement = topElement
activeElement.OnActivate()
End
If (mouse.IsMouseDown(mouse.BUTTON_LEFT))
topElement.OnMouseDown()
End
If (mouse.GetDX() <> 0 Or mouse.GetDY() <> 0)
topElement.OnMouseMove(mouse.GetDX(), mouse.GetDY())
End
End
If (selectedElement And mouse.IsMouseUp(mouse.BUTTON_LEFT))
selectedElement.OnMouseUp()
If (topElement = selectedElement) Then selectedElement.OnMouseClick()
selectedElement = Null
End
If (activeElement And Not activeElement.visible) Then activeElement = Null
End
End