forked from thisdp/dgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.lua
211 lines (196 loc) · 4.98 KB
/
event.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
207
208
209
210
211
local cos,sin,rad,atan2 = math.cos,math.sin,math.rad,math.atan2
local gsub,sub,len,find,format = string.gsub,string.sub,string.len,string.find,string.format
local insert = table.insert
dgs = exports[getResourceName(getThisResource())]
addEvent("onDgsMouseLeave",true)
addEvent("onDgsMouseEnter",true)
addEvent("onDgsMouseClick",true)
addEvent("onDgsMouseDoubleClick",true)
addEvent("onDgsWindowClose",true)
addEvent("onDgsPositionChange",true)
addEvent("onDgsSizeChange",true)
addEvent("onDgsTextChange",true)
addEvent("onDgsScrollBarScrollPositionChange",true)
addEvent("onDgsScrollPaneScroll",true)
addEvent("onDgsDestroy",true)
addEvent("onDgsGridListSelect",true)
addEvent("onDgsGridListItemDoubleClick",true)
addEvent("onDgsProgressBarChange",true)
addEvent("onDgsCreate",true)
addEvent("onDgsPreRender",true)
addEvent("onDgsRender",true)
addEvent("onDgsElementRender",true)
addEvent("onDgsElementRender",true)
addEvent("onDgsFocus",true)
addEvent("onDgsBlur",true)
addEvent("onDgsCursorMove",true)
addEvent("onDgsTabPanelTabSelect",true)
addEvent("onDgsRadioButtonChange",true)
addEvent("onDgsCheckBoxChange",true)
addEvent("onDgsComboBoxSelect",true)
addEvent("onDgsComboBoxStateChange",true)
addEvent("onDgsEditPreSwitch",true)
addEvent("onDgsEditSwitched",true)
addEvent("onDgsEditAccepted",true)
addEvent("onDgsStopMoving",true)
addEvent("onDgsStopSizing",true)
addEvent("onDgsStopAlphaing",true)
addEvent("onDgsStopAniming",true)
-------
addEvent("giveIPBack",true)
-------DEBUG
addCommandHandler("debugdgs",function()
DEBUG_MODE = not getElementData(localPlayer,"DGS-DEBUG")
setElementData(localPlayer,"DGS-DEBUG",DEBUG_MODE,false)
end)
DEBUG_MODE = getElementData(localPlayer,"DGS-DEBUG")
--------------------------------Table Utility
function table.find(tab,ke,num)
for k,v in pairs(tab) do
if num then
if v[num] == ke then
return k
end
else
if v == ke then
return k
end
end
end
return false
end
function table.count(tabl)
local cnt = 0
for k,v in pairs(tabl) do
cnt = cnt + 1
end
return cnt
end
function table.merger(...)
local tab = {...}
if #tab > 1 then
local result = {}
for k,v in ipairs(tab) do
if type(v) ~= "table" then
assert(false,"@table.merger argument "..k..",expect table got "..type(v))
return false
end
for _k,_v in pairs(v) do
result[_k] = _v
end
end
return result
else
return tab[1] or false
end
end
function table.complement(theall,...)
assert(type(theall) == "table","@table.complement argument 1,expect table got "..type(theall))
local remove = table.merger(...)
local newtable = {}
for k,v in pairs(theall) do
if not table.find(remove) then
table.insert(newtable,v)
end
end
return newtable
end
function table.deepcopy(obj)
local InTable = {}
local function Func(obj)
if type(obj) ~= "table" then
return obj
end
local NewTable = {}
InTable[obj] = NewTable
for k,v in pairs(obj) do
NewTable[Func(k)] = Func(v)
end
return setmetatable(NewTable, getmetatable(obj))
end
return Func(obj)
end
--------------------------------String Utility
function string.count(str)
local _,count = gsub(str,"[^\128-\193]","")
return count
end
function string.split(s, delim, mode)
if type(delim) ~= "string" or len(delim) <= 0 then
return
end
if mode then
local start = 1
local t = {}
local index = 1
while true do
local pos = find (s, delim, start, true)
if not pos then
break
end
t[index] = sub(s,start,pos-1)
start = pos + len(delim)
index = index+1
end
t[index] = sub(s,start)
return t
else
local start = 1
local t = {}
while true do
local pos = find (s, delim, start, true)
if not pos then
break
end
insert (t, sub (s, start, pos - 1))
start = pos + len (delim)
end
insert (t, sub (s, start))
return t
end
end
--------------------------------Math Utility
function findRotation(x1,y1,x2,y2)
local t = -math.deg(math.atan2(x2-x1,y2-y1))
return t<0 and t+360 or t
end
function math.restrict(n_min,n_max,value)
if value <= n_min then
return n_min
elseif value >= n_max then
return n_max
else
return value
end
end
function math.inRange(n_min,n_max,value)
if value >= n_min and value <= n_max then
return true
end
return false
end
--------------------------------Color Utility
function fromcolor(int,useMath)
local a,r,g,b
if useMath then
b,g,r,a = bitExtract(int,0,8),bitExtract(int,8,8),bitExtract(int,16,8),bitExtract(int,24,8)
else
a,r,g,b = getColorFromString(format("#%.8x",int))
end
return r,g,b,a
end
function getColorAlpha(color)
return bitExtract(color,24,8)
end
function setColorAlpha(color,alpha)
return bitReplace(color,alpha,24,8)
end
function applyColorAlpha(color,alpha)
return bitReplace(color,bitExtract(color,24,8)*alpha,24,8)
end
--------------------------------Other Utility
function dgsRunString(func,...)
local fnc = loadstring(func)
assert(type(fnc) == "function","[DGS]Can't Load Bad Function By dgsRunString")
return fnc(...)
end