This commit is contained in:
Stepets 2014-11-09 18:48:03 +03:00
commit 34a84f6823
2 changed files with 83 additions and 70 deletions

144
init.lua
View File

@ -23,6 +23,7 @@ loveframes.config["DEFAULTSKIN"] = "Blue"
loveframes.config["ACTIVESKIN"] = "Blue" loveframes.config["ACTIVESKIN"] = "Blue"
loveframes.config["INDEXSKINIMAGES"] = true loveframes.config["INDEXSKINIMAGES"] = true
loveframes.config["DEBUG"] = false loveframes.config["DEBUG"] = false
loveframes.config["ENABLE_SYSTEM_CURSORS"] = true
-- misc library vars -- misc library vars
loveframes.state = "none" loveframes.state = "none"
@ -34,6 +35,7 @@ loveframes.modalobject = false
loveframes.inputobject = false loveframes.inputobject = false
loveframes.downobject = false loveframes.downobject = false
loveframes.resizeobject = false loveframes.resizeobject = false
loveframes.dragobject = false
loveframes.hover = false loveframes.hover = false
loveframes.input_cursor_set = false loveframes.input_cursor_set = false
loveframes.prevcursor = nil loveframes.prevcursor = nil
@ -86,84 +88,86 @@ function loveframes.update(dt)
end end
end end
local hoverobject = loveframes.hoverobject if loveframes.config["ENABLE_SYSTEM_CURSORS"] then
local arrow = love.mouse.getSystemCursor("arrow") local hoverobject = loveframes.hoverobject
local curcursor = love.mouse.getCursor() local arrow = love.mouse.getSystemCursor("arrow")
if hoverobject then local curcursor = love.mouse.getCursor()
local ibeam = love.mouse.getSystemCursor("ibeam") if hoverobject then
local mx, my = love.mouse.getPosition() local ibeam = love.mouse.getSystemCursor("ibeam")
if hoverobject.type == "textinput" and not loveframes.resizeobject then local mx, my = love.mouse.getPosition()
if curcursor ~= ibeam then if hoverobject.type == "textinput" and not loveframes.resizeobject then
love.mouse.setCursor(ibeam) if curcursor ~= ibeam then
end love.mouse.setCursor(ibeam)
elseif hoverobject.type == "frame" then end
if not hoverobject.dragging and hoverobject.canresize then elseif hoverobject.type == "frame" then
if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then if not hoverobject.dragging and hoverobject.canresize then
local sizenwse = love.mouse.getSystemCursor("sizenwse") if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then
if curcursor ~= sizenwse then local sizenwse = love.mouse.getSystemCursor("sizenwse")
love.mouse.setCursor(sizenwse) if curcursor ~= sizenwse then
end love.mouse.setCursor(sizenwse)
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then end
local sizenwse = love.mouse.getSystemCursor("sizenwse") elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
if curcursor ~= sizenwse then local sizenwse = love.mouse.getSystemCursor("sizenwse")
love.mouse.setCursor(sizenwse) if curcursor ~= sizenwse then
end love.mouse.setCursor(sizenwse)
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then end
local sizenesw = love.mouse.getSystemCursor("sizenesw") elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then
if curcursor ~= sizenesw then local sizenesw = love.mouse.getSystemCursor("sizenesw")
love.mouse.setCursor(sizenesw) if curcursor ~= sizenesw then
end love.mouse.setCursor(sizenesw)
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then end
local sizenesw = love.mouse.getSystemCursor("sizenesw") elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
if curcursor ~= sizenesw then local sizenesw = love.mouse.getSystemCursor("sizenesw")
love.mouse.setCursor(sizenesw) if curcursor ~= sizenesw then
end love.mouse.setCursor(sizenesw)
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then end
local sizens = love.mouse.getSystemCursor("sizens") elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then
if curcursor ~= sizens then local sizens = love.mouse.getSystemCursor("sizens")
love.mouse.setCursor(sizens) if curcursor ~= sizens then
end love.mouse.setCursor(sizens)
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then end
local sizens = love.mouse.getSystemCursor("sizens") elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then
if curcursor ~= sizens then local sizens = love.mouse.getSystemCursor("sizens")
love.mouse.setCursor(sizens) if curcursor ~= sizens then
end love.mouse.setCursor(sizens)
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then end
local sizewe = love.mouse.getSystemCursor("sizewe") elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
if curcursor ~= sizewe then local sizewe = love.mouse.getSystemCursor("sizewe")
love.mouse.setCursor(sizewe) if curcursor ~= sizewe then
end love.mouse.setCursor(sizewe)
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then end
local sizewe = love.mouse.getSystemCursor("sizewe") elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
if curcursor ~= sizewe then local sizewe = love.mouse.getSystemCursor("sizewe")
love.mouse.setCursor(sizewe) if curcursor ~= sizewe then
end love.mouse.setCursor(sizewe)
else end
if not loveframes.resizeobject then else
local arrow = love.mouse.getSystemCursor("arrow") if not loveframes.resizeobject then
if curcursor ~= arrow then local arrow = love.mouse.getSystemCursor("arrow")
love.mouse.setCursor(arrow) if curcursor ~= arrow then
love.mouse.setCursor(arrow)
end
end end
end end
end end
elseif hoverobject.type == "text" and hoverobject.linkcol and not loveframes.resizeobject then
local hand = love.mouse.getSystemCursor("hand")
if curcursor ~= hand then
love.mouse.setCursor(hand)
end
end end
elseif hoverobject.type == "text" and hoverobject.linkcol and not loveframes.resizeobject then if curcursor ~= arrow then
local hand = love.mouse.getSystemCursor("hand") if hoverobject.type ~= "textinput" and hoverobject.type ~= "frame" and not hoverobject.linkcol and not loveframes.resizeobject then
if curcursor ~= hand then love.mouse.setCursor(arrow)
love.mouse.setCursor(hand) elseif hoverobject.type ~= "textinput" and curcursor == ibeam then
love.mouse.setCursor(arrow)
end
end end
end else
if curcursor ~= arrow then if curcursor ~= arrow and not loveframes.resizeobject then
if hoverobject.type ~= "textinput" and hoverobject.type ~= "frame" and not hoverobject.linkcol and not loveframes.resizeobject then
love.mouse.setCursor(arrow)
elseif hoverobject.type ~= "textinput" and curcursor == ibeam then
love.mouse.setCursor(arrow) love.mouse.setCursor(arrow)
end end
end end
else
if curcursor ~= arrow and not loveframes.resizeobject then
love.mouse.setCursor(arrow)
end
end end
loveframes.collisions = {} loveframes.collisions = {}

View File

@ -506,12 +506,14 @@ function newobject:mousepressed(x, y, button)
self.clicky = y - self.staticy self.clicky = y - self.staticy
end end
self.dragging = true self.dragging = true
loveframes.dragobject = self
end end
end end
if not self.resizing and self.canresize and loveframes.hoverobject == self then if not self.resizing and self.canresize and loveframes.hoverobject == self then
if loveframes.util.BoundingBox(self.x, x, self.y, y, 5, 1, 5, 1) then if loveframes.util.BoundingBox(self.x, x, self.y, y, 5, 1, 5, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "top_left" self.resize_mode = "top_left"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -541,6 +543,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x + self.width - 5, x, self.y, y, 5, 1, 5, 1) then elseif loveframes.util.BoundingBox(self.x + self.width - 5, x, self.y, y, 5, 1, 5, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "top_right" self.resize_mode = "top_right"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -556,6 +559,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x, x, self.y + self.height - 5, y, 5, 1, 5, 1) then elseif loveframes.util.BoundingBox(self.x, x, self.y + self.height - 5, y, 5, 1, 5, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "bottom_left" self.resize_mode = "bottom_left"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -571,6 +575,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x + 5, x, self.y, y, self.width - 10, 1, 2, 1) then elseif loveframes.util.BoundingBox(self.x + 5, x, self.y, y, self.width - 10, 1, 2, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "top" self.resize_mode = "top"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -583,6 +588,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x + 5, x, self.y + self.height - 2, y, self.width - 10, 1, 2, 1) then elseif loveframes.util.BoundingBox(self.x + 5, x, self.y + self.height - 2, y, self.width - 10, 1, 2, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "bottom" self.resize_mode = "bottom"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -595,6 +601,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x, x, self.y + 5, y, 2, 1, self.height - 10, 1) then elseif loveframes.util.BoundingBox(self.x, x, self.y + 5, y, 2, 1, self.height - 10, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "left" self.resize_mode = "left"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -607,6 +614,7 @@ function newobject:mousepressed(x, y, button)
elseif loveframes.util.BoundingBox(self.x + self.width - 2, x, self.y + 5, y, 2, 1, self.height - 10, 1) then elseif loveframes.util.BoundingBox(self.x + self.width - 2, x, self.y + 5, y, 2, 1, self.height - 10, 1) then
self.resizing = true self.resizing = true
self.dragging = false self.dragging = false
loveframes.dragobject = false
self.resize_mode = "right" self.resize_mode = "right"
self.resizex = x self.resizex = x
self.resizey = y self.resizey = y
@ -656,6 +664,7 @@ function newobject:mousereleased(x, y, button)
local internals = self.internals local internals = self.internals
self.dragging = false self.dragging = false
loveframes.dragobject = false
if self.resizing then if self.resizing then
self.resizex = 0 self.resizex = 0