mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-18 16:04:22 +00:00
Rework custom cursor code
This commit is contained in:
parent
49dc7ec8ca
commit
83e2dc1adb
87
init.lua
87
init.lua
@ -126,27 +126,82 @@ function loveframes.update(dt)
|
||||
|
||||
if version == "0.9.0" then
|
||||
local hoverobject = loveframes.hoverobject
|
||||
local arrow = love.mouse.getSystemCursor("arrow")
|
||||
local curcursor = love.mouse.getCursor()
|
||||
if hoverobject then
|
||||
if not input_cursor_set then
|
||||
if hoverobject.type == "textinput" then
|
||||
local curcursor = love.mouse.getCursor()
|
||||
local newcursor = love.mouse.getSystemCursor("ibeam")
|
||||
love.mouse.setCursor(newcursor)
|
||||
loveframes.prevcursor = curcursor
|
||||
loveframes.input_cursor_set = true
|
||||
local ibeam = love.mouse.getSystemCursor("ibeam")
|
||||
local mx, my = love.mouse.getPosition()
|
||||
if hoverobject.type == "textinput" and not loveframes.resizeobject then
|
||||
if curcursor ~= ibeam then
|
||||
love.mouse.setCursor(ibeam)
|
||||
end
|
||||
else
|
||||
if hoverobject.type ~= "textinput" then
|
||||
local prevcursor = loveframes.prevcursor
|
||||
love.mouse.setCursor(prevcursor)
|
||||
loveframes.input_cursor_set = false
|
||||
elseif hoverobject.type == "frame" then
|
||||
if not hoverobject.dragging and hoverobject.canresize then
|
||||
if loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y, my, 5, 1, 5, 1) then
|
||||
local sizenwse = love.mouse.getSystemCursor("sizenwse")
|
||||
if curcursor ~= sizenwse then
|
||||
love.mouse.setCursor(sizenwse)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
|
||||
local sizenwse = love.mouse.getSystemCursor("sizenwse")
|
||||
if curcursor ~= sizenwse then
|
||||
love.mouse.setCursor(sizenwse)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 5, mx, hoverobject.y, my, 5, 1, 5, 1) then
|
||||
local sizenesw = love.mouse.getSystemCursor("sizenesw")
|
||||
if curcursor ~= sizenesw then
|
||||
love.mouse.setCursor(sizenesw)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + hoverobject.height - 5, my, 5, 1, 5, 1) then
|
||||
local sizenesw = love.mouse.getSystemCursor("sizenesw")
|
||||
if curcursor ~= sizenesw then
|
||||
love.mouse.setCursor(sizenesw)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y, my, hoverobject.width - 10, 1, 2, 1) then
|
||||
local sizens = love.mouse.getSystemCursor("sizens")
|
||||
if curcursor ~= sizens then
|
||||
love.mouse.setCursor(sizens)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x + 5, mx, hoverobject.y + hoverobject.height - 2, my, hoverobject.width - 10, 1, 2, 1) then
|
||||
local sizens = love.mouse.getSystemCursor("sizens")
|
||||
if curcursor ~= sizens then
|
||||
love.mouse.setCursor(sizens)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
|
||||
local sizewe = love.mouse.getSystemCursor("sizewe")
|
||||
if curcursor ~= sizewe then
|
||||
love.mouse.setCursor(sizewe)
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(hoverobject.x + hoverobject.width - 2, mx, hoverobject.y + 5, my, 2, 1, hoverobject.height - 10, 1) then
|
||||
local sizewe = love.mouse.getSystemCursor("sizewe")
|
||||
if curcursor ~= sizewe then
|
||||
love.mouse.setCursor(sizewe)
|
||||
end
|
||||
else
|
||||
if not loveframes.resizeobject then
|
||||
local arrow = love.mouse.getSystemCursor("arrow")
|
||||
if curcursor ~= arrow then
|
||||
love.mouse.setCursor(arrow)
|
||||
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
|
||||
if curcursor ~= arrow 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)
|
||||
end
|
||||
end
|
||||
else
|
||||
if input_cursor_set then
|
||||
local prevcursor = loveframes.prevcursor
|
||||
love.mouse.setCursor(prevcursor)
|
||||
loveframes.input_cursor_set = false
|
||||
if curcursor ~= arrow and not loveframes.resizeobject then
|
||||
love.mouse.setCursor(arrow)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,8 +32,8 @@ function newobject:initialize()
|
||||
self.linkcolor = {0, 102, 255, 255}
|
||||
self.linkhovercolor = {0, 0, 255, 255}
|
||||
self.ignorenewlines = false
|
||||
self.linkcursorset = false
|
||||
self.shadow = false
|
||||
self.linkcol = false
|
||||
self.internal = false
|
||||
self.linksenabled = false
|
||||
self.detectlinks = false
|
||||
@ -95,7 +95,7 @@ function newobject:update(dt)
|
||||
local version = love._version
|
||||
local linkcol = false
|
||||
|
||||
if hover and linksenabled then
|
||||
if hover and linksenabled and not loveframes.resizeobject then
|
||||
local formattedtext = self.formattedtext
|
||||
local x = self.x
|
||||
local y = self.y
|
||||
@ -112,17 +112,12 @@ function newobject:update(dt)
|
||||
local col = loveframes.util.BoundingBox(x + linkx, mx, y + linky, my, twidth, 1, theight, 1)
|
||||
v.hover = false
|
||||
if col then
|
||||
local linkcursorset = self.linkcursorset
|
||||
v.hover = true
|
||||
if not linkcursorset and version == "0.9.0" then
|
||||
local newcursor = love.mouse.getSystemCursor("hand")
|
||||
love.mouse.setCursor(newcursor)
|
||||
self.linkcursorset = true
|
||||
end
|
||||
linkcol = true
|
||||
end
|
||||
end
|
||||
end
|
||||
self.linkcol = linkcol
|
||||
end
|
||||
|
||||
-- move to parent if there is a parent
|
||||
@ -131,13 +126,6 @@ function newobject:update(dt)
|
||||
self.y = self.parent.y + self.staticy
|
||||
end
|
||||
|
||||
local linkcursorset = self.linkcursorset
|
||||
|
||||
if not linkcol and linkcursorset and version == "0.9.0" then
|
||||
self.linkcursorset = false
|
||||
love.mouse.setCursor()
|
||||
end
|
||||
|
||||
if update then
|
||||
update(self, dt)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user