Fix #34: Add [is,any][Hit,Active,Hovered]()
This commit is contained in:
parent
1d6626e6f4
commit
c66bbe9065
2 changed files with 26 additions and 2 deletions
21
core.lua
21
core.lua
|
@ -48,15 +48,29 @@ function suit:wasHovered(id)
|
||||||
return id == self.hovered_last
|
return id == self.hovered_last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function suit:anyActive()
|
||||||
|
return self.active ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
function suit:isActive(id)
|
function suit:isActive(id)
|
||||||
return id == self.active
|
return id == self.active
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function suit:anyHit()
|
||||||
|
return self.hit ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function suit:isHit(id)
|
||||||
|
return id == self.hit
|
||||||
|
end
|
||||||
|
|
||||||
function suit:getStateName(id)
|
function suit:getStateName(id)
|
||||||
if self:isActive(id) then
|
if self:isActive(id) then
|
||||||
return "active"
|
return "active"
|
||||||
elseif self:isHovered(id) then
|
elseif self:isHovered(id) then
|
||||||
return "hovered"
|
return "hovered"
|
||||||
|
elseif self:isHit(id) then
|
||||||
|
return "hit"
|
||||||
end
|
end
|
||||||
return "normal"
|
return "normal"
|
||||||
end
|
end
|
||||||
|
@ -84,7 +98,11 @@ function suit:registerHitbox(id, x,y,w,h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function suit:mouseReleasedOn(id)
|
function suit:mouseReleasedOn(id)
|
||||||
return not self.mouse_button_down and self:isActive(id) and self:isHovered(id)
|
if not self.mouse_button_down and self:isActive(id) and self:isHovered(id) then
|
||||||
|
self.hit = id
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function suit:updateMouse(x, y, button_down)
|
function suit:updateMouse(x, y, button_down)
|
||||||
|
@ -145,6 +163,7 @@ function suit:enterFrame()
|
||||||
self:updateMouse(love.mouse.getX(), love.mouse.getY(), love.mouse.isDown(1))
|
self:updateMouse(love.mouse.getX(), love.mouse.getY(), love.mouse.isDown(1))
|
||||||
self.key_down, self.textchar = nil, ""
|
self.key_down, self.textchar = nil, ""
|
||||||
self:grabKeyboardFocus(NONE)
|
self:grabKeyboardFocus(NONE)
|
||||||
|
self.hit = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function suit:exitFrame()
|
function suit:exitFrame()
|
||||||
|
|
7
init.lua
7
init.lua
|
@ -5,6 +5,8 @@ local suit = require(BASE .. "core")
|
||||||
|
|
||||||
local instance = suit.new()
|
local instance = suit.new()
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
|
_instance = instance,
|
||||||
|
|
||||||
new = suit.new,
|
new = suit.new,
|
||||||
getOptionsAndSize = suit.getOptionsAndSize,
|
getOptionsAndSize = suit.getOptionsAndSize,
|
||||||
|
|
||||||
|
@ -12,7 +14,10 @@ return setmetatable({
|
||||||
anyHovered = function(...) return instance:anyHovered(...) end,
|
anyHovered = function(...) return instance:anyHovered(...) end,
|
||||||
isHovered = function(...) return instance:isHovered(...) end,
|
isHovered = function(...) return instance:isHovered(...) end,
|
||||||
wasHovered = function(...) return instance:wasHovered(...) end,
|
wasHovered = function(...) return instance:wasHovered(...) end,
|
||||||
|
anyActive = function(...) return instance:anyActive(...) end,
|
||||||
isActive = function(...) return instance:isActive(...) end,
|
isActive = function(...) return instance:isActive(...) end,
|
||||||
|
anyHit = function(...) return instance:anyHit(...) end,
|
||||||
|
isHit = function(...) return instance:isHit(...) end,
|
||||||
|
|
||||||
mouseInRect = function(...) return instance:mouseInRect(...) end,
|
mouseInRect = function(...) return instance:mouseInRect(...) end,
|
||||||
registerHitbox = function(...) return instance:registerHitbox(...) end,
|
registerHitbox = function(...) return instance:registerHitbox(...) end,
|
||||||
|
@ -49,7 +54,7 @@ return setmetatable({
|
||||||
if k == "theme" then
|
if k == "theme" then
|
||||||
instance.theme = v
|
instance.theme = v
|
||||||
else
|
else
|
||||||
rawset(t, k, v)
|
rawset(instance, k, v)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue