local imgui require imgui local vkeys require vkeys local wm require l

  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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
local imgui = require 'imgui'
local vkeys = require 'vkeys'
local wm = require 'lib.windows.message'
local module = {}
module._VERSION = "1.0.0"
module._SETTINGS = {
noKeysMessage = "No"
}
-- Spinner:
module.Spinner = function(label, radius, thickness, color)
local style = imgui.GetStyle()
local pos = imgui.GetCursorScreenPos()
local size = imgui.ImVec2(radius * 2, (radius + style.FramePadding.y) * 2)
imgui.Dummy(imgui.ImVec2(size.x + style.ItemSpacing.x, size.y))
local DrawList = imgui.GetWindowDrawList()
DrawList:PathClear()
local num_segments = 30
local start = math.abs(math.sin(imgui.GetTime() * 1.8) * (num_segments - 5))
local a_min = 3.14 * 2.0 * start / num_segments
local a_max = 3.14 * 2.0 * (num_segments - 3) / num_segments
local centre = imgui.ImVec2(pos.x + radius, pos.y + radius + style.FramePadding.y)
for i = 0, num_segments do
local a = a_min + (i / num_segments) * (a_max - a_min)
DrawList:PathLineTo(imgui.ImVec2(centre.x + math.cos(a + imgui.GetTime() * 8) * radius, centre.y + math.sin(a + imgui.GetTime() * 8) * radius))
end
DrawList:PathStroke(color, false, thickness)
return true
end
-- BufferingBar:
module.BufferingBar = function(label, value, size_arg, bg_col, fg_col)
local style = imgui.GetStyle()
local size = size_arg;
local DrawList = imgui.GetWindowDrawList()
size.x = size.x - (style.FramePadding.x * 2);
local pos = imgui.GetCursorScreenPos()
imgui.Dummy(imgui.ImVec2(size.x, size.y))
local circleStart = size.x * 0.85;
local circleEnd = size.x;
local circleWidth = circleEnd - circleStart;
DrawList:AddRectFilled(pos, imgui.ImVec2(pos.x + circleStart, pos.y + size.y), bg_col)
DrawList:AddRectFilled(pos, imgui.ImVec2(pos.x + circleStart * value, pos.y + size.y), fg_col)
local t = imgui.GetTime()
local r = size.y / 2;
local speed = 1.5;
local a = speed * 0;
local b = speed * 0.333;
local c = speed * 0.666;
local o1 = (circleWidth+r) * (t+a - speed * math.floor((t+a) / speed)) / speed;
local o2 = (circleWidth+r) * (t+b - speed * math.floor((t+b) / speed)) / speed;
local o3 = (circleWidth+r) * (t+c - speed * math.floor((t+c) / speed)) / speed;
DrawList:AddCircleFilled(imgui.ImVec2(pos.x + circleEnd - o1, pos.y + r), r, bg_col);
DrawList:AddCircleFilled(imgui.ImVec2(pos.x + circleEnd - o2, pos.y + r), r, bg_col);
DrawList:AddCircleFilled(imgui.ImVec2(pos.x + circleEnd - o3, pos.y + r), r, bg_col);
return true
end
-- HotKey:
local tBlockKeys = {[vkeys.VK_RETURN] = true, [vkeys.VK_T] = true, [vkeys.VK_F6] = true, [vkeys.VK_F8] = true}
local tBlockChar = {[116] = true, [84] = true}
local tModKeys = {[vkeys.VK_MENU] = true, [vkeys.VK_SHIFT] = true, [vkeys.VK_CONTROL] = true}
local tBlockNextDown = {}
local tHotKeyData = {
edit = nil,
save = {},
lastTick = os.clock(),
tickState = false
}
local tKeys = {}
module.HotKey = function(name, keys, lastkeys, width)
local width = width or 90
local name = tostring(name)
local lastkeys = lastkeys or {}
local keys, bool = keys or {}, false
lastkeys.v = keys.v
local sKeys = table.concat(module.getKeysName(keys.v), " + ")
if #tHotKeyData.save > 0 and tostring(tHotKeyData.save[1]) == name then
keys.v = tHotKeyData.save[2]
sKeys = table.concat(module.getKeysName(keys.v), " + ")
tHotKeyData.save = {}
bool = true
elseif tHotKeyData.edit ~= nil and tostring(tHotKeyData.edit) == name then
if #tKeys == 0 then
if os.clock() - tHotKeyData.lastTick > 0.5 then
tHotKeyData.lastTick = os.clock()
tHotKeyData.tickState = not tHotKeyData.tickState
end
sKeys = tHotKeyData.tickState and module._SETTINGS.noKeysMessage or " "
else
sKeys = table.concat(module.getKeysName(tKeys), " + ")
end
end
imgui.PushStyleColor(imgui.Col.Button, imgui.GetStyle().Colors[imgui.Col.FrameBg])
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.GetStyle().Colors[imgui.Col.FrameBgActive])
if imgui.Button((tostring(sKeys):len() == 0 and module._SETTINGS.noKeysMessage or sKeys) .. name, imgui.ImVec2(width, 0)) then
tHotKeyData.edit = name
end
imgui.PopStyleColor(3)
return bool
end
function module.getCurrentEdit()
return tHotKeyData.edit ~= nil
end
function module.getKeysList(bool)
local bool = bool or false
local tKeysList = {}
if bool then
for k, v in ipairs(tKeys) do
tKeysList[k] = vkeys.id_to_name(v)
end
else
tKeysList = tKeys
end
return tKeysList
end
function module.getKeysName(keys)
if type(keys) ~= "table" then
return false
else
local tKeysName = {}
for k, v in ipairs(keys) do
tKeysName[k] = vkeys.id_to_name(v)
end
return tKeysName
end
end
local function getKeyNumber(id)
for k, v in ipairs(tKeys) do
if v == id then
return k
end
end
return -1
end
local function reloadKeysList()
local tNewKeys = {}
for k, v in pairs(tKeys) do
tNewKeys[#tNewKeys + 1] = v
end
tKeys = tNewKeys
return true
end
-- Toggle Button:
module.ToggleButton = function(str_id, bool)
local rBool = false
if LastActiveTime == nil then
LastActiveTime = {}
end
if LastActive == nil then
LastActive = {}
end
local function ImSaturate(f)
return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
end
local p = imgui.GetCursorScreenPos()
local draw_list = imgui.GetWindowDrawList()
local height = imgui.GetTextLineHeightWithSpacing()
local width = height * 1.55
local radius = height * 0.50
local ANIM_SPEED = 0.15
if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
bool.v = not bool.v
rBool = true
LastActiveTime[tostring(str_id)] = os.clock()
LastActive[tostring(str_id)] = true
end
local t = bool.v and 1.0 or 0.0
if LastActive[tostring(str_id)] then
local time = os.clock() - LastActiveTime[tostring(str_id)]
if time <= ANIM_SPEED then
local t_anim = ImSaturate(time / ANIM_SPEED)
t = bool.v and t_anim or 1.0 - t_anim
else
LastActive[tostring(str_id)] = false
end
end
local col_bg
if bool.v then
col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
else
col_bg = imgui.ImColor(100, 100, 100, 180):GetU32()
end
draw_list:AddRectFilled(imgui.ImVec2(p.x, p.y + (height / 6)), imgui.ImVec2(p.x + width - 1.0, p.y + (height - (height / 6))), col_bg, 5.0)
draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 0.75, imgui.GetColorU32(bool.v and imgui.GetStyle().Colors[imgui.Col.ButtonActive] or imgui.ImColor(150, 150, 150, 255):GetVec4()))
return rBool
end
function module.isKeyModified(id)
if type(id) ~= "number" then
return false
end
return (tModKeys[id] or false) or (tBlockKeys[id] or false)
end
addEventHandler("onWindowMessage", function (msg, wparam, lparam)
if tHotKeyData.edit ~= nil and msg == wm.WM_CHAR then
if tBlockChar[wparam] then
consumeWindowMessage(true, true)
end
end
if msg == wm.WM_KEYDOWN or msg == wm.WM_SYSKEYDOWN then
if tHotKeyData.edit ~= nil and wparam == vkeys.VK_ESCAPE then
tKeys = {}
tHotKeyData.edit = nil
consumeWindowMessage(true, true)
end
if tHotKeyData.edit ~= nil and wparam == vkeys.VK_BACK then
tHotKeyData.save = {tHotKeyData.edit, {}}
tHotKeyData.edit = nil
consumeWindowMessage(true, true)
end
local num = getKeyNumber(wparam)
if num == -1 then
tKeys[#tKeys + 1] = wparam
if tHotKeyData.edit ~= nil then
if not module.isKeyModified(wparam) then
tHotKeyData.save = {tHotKeyData.edit, tKeys}
tHotKeyData.edit = nil
tKeys = {}
consumeWindowMessage(true, true)
end
end
end
reloadKeysList()
if tHotKeyData.edit ~= nil then
consumeWindowMessage(true, true)
end
elseif msg == wm.WM_KEYUP or msg == wm.WM_SYSKEYUP then
local num = getKeyNumber(wparam)
if num > -1 then
tKeys[num] = nil
end
reloadKeysList()
if tHotKeyData.edit ~= nil then
consumeWindowMessage(true, true)
end
end
end)
return module