forked from thisdp/dgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParentManager.lua
206 lines (191 loc) · 6.82 KB
/
ParentManager.lua
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
BottomFatherTable = {} --Store Bottom Father Element
CenterFatherTable = {} --Store Center Father Element (Default)
TopFatherTable = {} --Store Top Father Element
dx3DInterfaceTable = {}
FatherTable = {} --Store Father Element
ChildrenTable = {} --Store Children Element
LayerCastTable = {center=CenterFatherTable,top=TopFatherTable,bottom=BottomFatherTable}
function dgsSetLayer(dgsGUI,layer,forceDetatch)
assert(dgsIsDxElement(dgsGUI),"Bad argument @dgsSetLayer at argument 1, expect a dgs-dxgui element got "..dgsGetType(dgsGUI))
if dgsElementType[dgsGUI] == "dgs-dxtab" then return false end
assert(layer == "center" or layer == "top" or layer == "bottom","Bad argument @dgsSetLayer at argument 2, expect a string(top/center/bottom) got "..dgsGetType(layer))
local hasParent = isElement(FatherTable[dgsGUI])
if hasParent and not forceDetatch then return false end
if hasParent then
local id = table.find(ChildrenTable[FatherTable[dgsGUI]],dgsGUI)
if id then
table.remove(ChildrenTable[FatherTable[dgsGUI]],id)
end
FatherTable[dgsGUI] = nil
end
local oldLayer = dgsElementData[dgsGUI].alwaysOn or "center"
if oldLayer == layer then return false end
local id = table.find(LayerCastTable[oldLayer],dgsGUI)
if id then
table.remove(LayerCastTable[oldLayer],id)
end
dgsSetData(dgsGUI,"alwaysOn",layer == "center" and false or layer)
table.insert(LayerCastTable[layer],dgsGUI)
return true
end
function dgsGetLayer(dgsGUI)
assert(dgsIsDxElement(dgsGUI),"Bad argument @dgsGetLayer at argument 1, expect a dgs-dxgui element got "..dgsGetType(dgsGUI))
return dgsElementData[dgsGUI].alwaysOn or "center"
end
function dgsSetCurrentLayerIndex(dgsGUI,index)
assert(dgsIsDxElement(dgsGUI),"Bad argument @dgsSetCurrentLayerIndex at argument 1, expect a dgs-dxgui element got "..dgsGetType(dgsGUI))
assert(type(index) == "number" ,"Bad argument @dgsSetCurrentLayerIndex at argument 2, expect a number got "..dgsGetType(index))
local layer = dgsElementData[dgsGUI].alwaysOn or "center"
local hasParent = isElement(FatherTable[dgsGUI])
local theTable = hasParent and ChildrenTable[FatherTable[dgsGUI]] or LayerCastTable[layer]
local index = math.restrict(1,#theTable+1,index)
local id = table.find(theTable,dgsGUI)
if id then
table.remove(theTable,id)
end
table.insert(theTable,index,dgsGUI)
return true
end
function dgsGetCurrentLayerIndex(dgsGUI)
assert(dgsIsDxElement(dgsGUI),"Bad argument @dgsGetCurrentLayerIndex at argument 1, expect a dgs-dxgui element got "..dgsGetType(dgsGUI))
local layer = dgsElementData[dgsGUI].alwaysOn or "center"
local hasParent = isElement(FatherTable[dgsGUI])
local theTable = hasParent and ChildrenTable[FatherTable[dgsGUI]] or LayerCastTable[layer]
return table.find(theTable,dgsGUI) or false
end
function dgsGetLayerElements(layer)
assert(layer == "center" or layer == "top" or layer == "bottom","Bad argument @dgsGetLayerElements at argument 1, expect a string(top/center/bottom) got "..dgsGetType(layer))
return #LayerCastTable[layer] or false
end
function dgsGetChild(parent,id)
return ChildrenTable[parent][id] or false
end
function dgsGetChildren(parent)
return ChildrenTable[parent] or {}
end
function dgsGetParent(child)
return FatherTable[child] or false
end
function dgsGetDxGUIFromResource(res)
local res = res or sourceResource
if res then
return resourceDxGUI[res] or {}
end
end
function dgsGetDxGUINoParent(alwaysBottom)
return alwaysBottom and BottomFatherTable or CenterFatherTable
end
function dgsSetParent(child,parent,nocheckfather)
if isElement(child) then
local _parent = FatherTable[child]
local parentTable = isElement(_parent) and ChildrenTable[_parent] or CenterFatherTable
if isElement(parent) then
if not dgsIsDxElement(parent) then return end
if not nocheckfather then
local id = table.find(parentTable,child)
if id then
table.remove(parentTable,id)
end
end
FatherTable[child] = parent
ChildrenTable[parent] = ChildrenTable[parent] or {}
table.insert(ChildrenTable[parent],child)
else
local id = table.find(parentTable,child)
if id then
table.remove(parentTable,id)
end
FatherTable[id] = nil
table.insert(CenterFatherTable,child)
end
return true
end
return false
end
function blurEditMemo()
local gui = guiCreateLabel(0,0,0,0,"",false)
guiBringToFront(gui)
destroyElement(gui)
end
lastFront = false
function dgsBringToFront(dxgui,mouse,dontMoveParent,dontChangeData)
assert(dgsIsDxElement(dxgui),"Bad argument @dgsBringToFront at argument 1, expect a dgs-dxgui element got "..dgsGetType(dxgui))
local parent = FatherTable[dxgui] --Get Parent
--local mouse = mouse or "left"
if not dontChangeData then
local oldShow = MouseData.nowShow
MouseData.nowShow = dxgui
if dgsGetType(dxgui) == "dgs-dxedit" then
MouseData.editCursor = true
resetTimer(MouseData.EditTimer)
local edit = dgsElementData[dxgui].edit
guiBringToFront(edit)
elseif dgsElementType[dxgui] == "dgs-dxmemo" then
MouseData.editCursor = true
resetTimer(MouseData.MemoTimer)
local memo = dgsElementData[dxgui].memo
guiBringToFront(memo)
elseif dxgui ~= oldShow then
local dgsType = dgsGetType(oldShow)
if dgsType == "dgs-dxedit" or dgsType == "dgs-dxmemo" then
blurEditMemo()
end
end
if isElement(oldShow) and dgsElementData[oldShow].clearSelection then
dgsSetData(oldShow,"selectfrom",dgsElementData[oldShow].cursorpos)
end
end
if not isElement(parent) then
local id = table.find(CenterFatherTable,dxgui)
if id then
table.remove(CenterFatherTable,id)
table.insert(CenterFatherTable,dxgui)
end
else
local parents = dxgui
while true do
local uparents = FatherTable[parents] --Get Parent
if isElement(uparents) then
local children = ChildrenTable[uparents]
local id = table.find(children,parents)
if id then
table.remove(children,id)
table.insert(children,parents)
if dgsElementType[parents] == "dgs-dxscrollpane" then
local scrollbar = dgsElementData[parents].scrollbars
dgsBringToFront(scrollbar[1],"left",_,true)
dgsBringToFront(scrollbar[2],"left",_,true)
end
end
parents = uparents
else
local id = table.find(CenterFatherTable,parents)
if id then
table.remove(CenterFatherTable,id)
table.insert(CenterFatherTable,parents)
if dgsElementType[parents] == "dgs-dxscrollpane" then
local scrollbar = dgsElementData[parents].scrollbars
dgsBringToFront(scrollbar[1],"left",_,true)
dgsBringToFront(scrollbar[2],"left",_,true)
end
end
break
end
if dontMoveParent then
break
end
end
end
if isElement(lastFront) and lastFront ~= dxgui then
triggerEvent("onDgsBlur",lastFront,dxgui)
end
triggerEvent("onDgsFocus",dxgui,lastFront)
lastFront = dxgui
if mouse == "left" then
MouseData.clickl = dxgui
MouseData.clickData = nil
elseif mouse == "right" then
MouseData.clickr = dxgui
end
return true
end