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
|
||||
end
|
||||
|
||||
function suit:anyActive()
|
||||
return self.active ~= nil
|
||||
end
|
||||
|
||||
function suit:isActive(id)
|
||||
return id == self.active
|
||||
end
|
||||
|
||||
function suit:anyHit()
|
||||
return self.hit ~= nil
|
||||
end
|
||||
|
||||
function suit:isHit(id)
|
||||
return id == self.hit
|
||||
end
|
||||
|
||||
function suit:getStateName(id)
|
||||
if self:isActive(id) then
|
||||
return "active"
|
||||
elseif self:isHovered(id) then
|
||||
return "hovered"
|
||||
elseif self:isHit(id) then
|
||||
return "hit"
|
||||
end
|
||||
return "normal"
|
||||
end
|
||||
|
@ -84,7 +98,11 @@ function suit:registerHitbox(id, x,y,w,h)
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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.key_down, self.textchar = nil, ""
|
||||
self:grabKeyboardFocus(NONE)
|
||||
self.hit = nil
|
||||
end
|
||||
|
||||
function suit:exitFrame()
|
||||
|
|
7
init.lua
7
init.lua
|
@ -5,6 +5,8 @@ local suit = require(BASE .. "core")
|
|||
|
||||
local instance = suit.new()
|
||||
return setmetatable({
|
||||
_instance = instance,
|
||||
|
||||
new = suit.new,
|
||||
getOptionsAndSize = suit.getOptionsAndSize,
|
||||
|
||||
|
@ -12,7 +14,10 @@ return setmetatable({
|
|||
anyHovered = function(...) return instance:anyHovered(...) end,
|
||||
isHovered = function(...) return instance:isHovered(...) end,
|
||||
wasHovered = function(...) return instance:wasHovered(...) end,
|
||||
anyActive = function(...) return instance:anyActive(...) 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,
|
||||
registerHitbox = function(...) return instance:registerHitbox(...) end,
|
||||
|
@ -49,7 +54,7 @@ return setmetatable({
|
|||
if k == "theme" then
|
||||
instance.theme = v
|
||||
else
|
||||
rawset(t, k, v)
|
||||
rawset(instance, k, v)
|
||||
end
|
||||
end,
|
||||
__index = function(t, k)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue