test
This commit is contained in:
parent
dce78866ca
commit
7976727dc9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
*multi
|
||||
main.lua
|
||||
conf.lua
|
||||
*.ttf
|
||||
|
||||
86
gui/init.lua
86
gui/init.lua
@ -180,6 +180,7 @@ end
|
||||
-- Base Library
|
||||
function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
local c = {}
|
||||
local buildBackBetter
|
||||
local centerX = false
|
||||
local centerY = false
|
||||
local centering = false
|
||||
@ -216,6 +217,7 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
c.OnMoved = multi:newConnection()
|
||||
|
||||
-- Mouse event thread
|
||||
buildBackBetter = function()
|
||||
c:newThread(function()
|
||||
local dragging = false
|
||||
local waiting = {}
|
||||
@ -225,11 +227,51 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
local entered = false
|
||||
local moved = false
|
||||
local mx, my
|
||||
local movedFunc = thread:newFunction(function(self,ref,mx,my)
|
||||
self:Pause()
|
||||
thread.hold(function()
|
||||
return ref:canPress(mx,my)
|
||||
end)
|
||||
ref.OnExit(ref,mx,my)
|
||||
entered = false
|
||||
self:Resume()
|
||||
end)
|
||||
local dragFunc = thread:newFunction(function(self, ref, mx, my)
|
||||
self:Pause()
|
||||
thread.hold(function() return not(love.mouse.isDown(dragbutton)) end)
|
||||
if dragging then
|
||||
global_drag = nil
|
||||
dragging = false
|
||||
ref.OnDragEnd:Fire(ref,mx,my)
|
||||
end
|
||||
self:Resume()
|
||||
end)
|
||||
local releaseFunc = thread:newFunction(function(self, ref, mx, my, i)
|
||||
self:Pause()
|
||||
thread.hold(function() return not(love.mouse.isDown(i)) end)
|
||||
if pressed[i] then
|
||||
pressed[i] = false
|
||||
waiting[i] = false
|
||||
ref.OnReleased:Fire(ref, i, mx, my)
|
||||
end
|
||||
self:Resume()
|
||||
end)
|
||||
while true do
|
||||
thread.hold(function() -- Only Progress thread if events are subscribed to!
|
||||
return c.active and (draggable or c.OnEnter:hasConnections() or c.OnExit:hasConnections() or c.WhilePressing:hasConnections() or c.OnPressed:hasConnections() or c.OnReleased:hasConnections() or c.OnDragStart:hasConnections() or c.OnDragging:hasConnections() or c.OnDragEnd:hasConnections())
|
||||
end)
|
||||
thread.sleep(.001) -- Limits the potiential speed for events to 1/200. So 200 fps max, to be fair pressing mouse click 200 times by hand in a second is probably not possible
|
||||
thread.sleep(.01) -- Limits the potiential speed for events to 1/200. So 200 fps max, to be fair pressing mouse click 200 times by hand in a second is probably not possible
|
||||
if not love.mouse.isDown(1,2,3,4,5) then
|
||||
dragging = false
|
||||
waiting = {}
|
||||
pressed = {}
|
||||
ox, oy = 0, 0
|
||||
mox, moy = 0, 0
|
||||
entered = false
|
||||
moved = false
|
||||
mx, my = nil, nil
|
||||
global_drag = nil
|
||||
end
|
||||
local x, y, w, h = c:getAbsolutes()
|
||||
mx, my = love.mouse.getPosition()
|
||||
-- mouse moved
|
||||
@ -242,13 +284,7 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
if moved and not entered and c:canPress(mx,my) then
|
||||
entered = true
|
||||
c.OnEnter:Fire(c,mx,my)
|
||||
c:newThread(function()
|
||||
thread.hold(function()
|
||||
return not c:canPress(mx,my)
|
||||
end)
|
||||
c.OnExit:Fire(c,mx,my)
|
||||
entered = false
|
||||
end)
|
||||
movedFunc(movedFunc, c, mx, my)
|
||||
end
|
||||
|
||||
-- pressed/released/drag events
|
||||
@ -265,43 +301,27 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
global_drag = c
|
||||
c.OnDragStart:Fire(c, mx, my)
|
||||
ox, oy = mx, my
|
||||
c:newThread(function()
|
||||
thread.hold(function() return not(love.mouse.isDown(dragbutton)) end)
|
||||
if dragging then
|
||||
global_drag = nil
|
||||
dragging = false
|
||||
c.OnDragEnd:Fire(c,mx,my)
|
||||
end
|
||||
end).OnError(function()
|
||||
global_drag = nil
|
||||
dragging = false
|
||||
end)
|
||||
dragFunc(dragFunc, c, mx, my)
|
||||
end
|
||||
dragging = true
|
||||
end
|
||||
c:newThread(function()
|
||||
c.OnPressed:Fire(c, i, mx, my)
|
||||
end)
|
||||
end
|
||||
pressed[i] = true
|
||||
-- Only process when the drag button turn is active
|
||||
c.WhilePressing:Fire(c, i, mx, my)
|
||||
if not waiting[i] then
|
||||
waiting[i] = true
|
||||
c:newThread(function()
|
||||
thread.hold(function() return not(love.mouse.isDown(i)) end)
|
||||
if pressed[i] then
|
||||
pressed[i] = false
|
||||
waiting[i] = false
|
||||
c.OnReleased:Fire(c, i, mx, my)
|
||||
releaseFunc(releaseFunc, c, mx, my, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end).OnError(function()
|
||||
buildBackBetter()
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end).OnError(print)
|
||||
|
||||
buildBackBetter()
|
||||
function c:OnUpdate(func) -- Not crazy about this approach, will probably rework this
|
||||
if type(self)=="function" then func = self end
|
||||
mainupdater(function()
|
||||
@ -310,7 +330,7 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
|
||||
local function centerthread()
|
||||
c:newThread("Object_Centering",function()
|
||||
c:newThread(function()
|
||||
while true do
|
||||
thread.hold(function()
|
||||
return centerX or centerY -- If the condition is true it acts like a yield
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user