mirror of
https://github.com/linux-man/LoveFrames.git
synced 2024-11-26 05:14:21 +00:00
Add frame resizing functionality
This commit is contained in:
parent
ca26c83414
commit
49dc7ec8ca
@ -28,6 +28,7 @@ Version 0.9.7 - Alpha (Release Date TBD)
|
||||
[ADDED] a new tooltip method: SetOffsetY(yoffset)
|
||||
[ADDED] a new tooltip method: GetText()
|
||||
[ADDED] a new text event callback: OnClickLink(object, text)
|
||||
[ADDED] a new frame event callback: OnResize(object, width, height)
|
||||
[ADDED] a new util library function: TableHasValue(table, value)
|
||||
[ADDED] a new util library function: GetHoverObject()
|
||||
[ADDED] a new callback: textinput(text)
|
||||
@ -40,6 +41,7 @@ Version 0.9.7 - Alpha (Release Date TBD)
|
||||
[ADDED] support for text object link processing
|
||||
[ADDED] loveframes.downobject
|
||||
[ADDED] skin directives for the text object
|
||||
[ADDED] functionality for resizing frames
|
||||
|
||||
[FIXED] error when pressing a function key while a textinput was focused
|
||||
[FIXED] the tooltip object not setting the state of its text object
|
||||
|
1
init.lua
1
init.lua
@ -30,6 +30,7 @@ loveframes.hoverobject = false
|
||||
loveframes.modalobject = false
|
||||
loveframes.inputobject = false
|
||||
loveframes.downobject = false
|
||||
loveframes.resizeobject = false
|
||||
loveframes.hover = false
|
||||
loveframes.input_cursor_set = false
|
||||
loveframes.prevcursor = nil
|
||||
|
@ -21,6 +21,16 @@ function newobject:initialize()
|
||||
self.dockx = 0
|
||||
self.docky = 0
|
||||
self.dockzonesize = 10
|
||||
self.resizex = 0
|
||||
self.resizey = 0
|
||||
self.resizexmod = 0
|
||||
self.resizeymod = 0
|
||||
self.resizewidth = 0
|
||||
self.resizeheight = 0
|
||||
self.minwidth = 100
|
||||
self.minheight = 30
|
||||
self.maxwidth = 500
|
||||
self.maxheight = 500
|
||||
self.internal = false
|
||||
self.draggable = true
|
||||
self.screenlocked = false
|
||||
@ -38,15 +48,17 @@ function newobject:initialize()
|
||||
self.leftdockobject = false
|
||||
self.rightdockobject = false
|
||||
self.dockable = false
|
||||
self.resizing = false
|
||||
self.canresize = false
|
||||
self.internals = {}
|
||||
self.children = {}
|
||||
self.icon = nil
|
||||
self.OnClose = nil
|
||||
self.OnDock = nil
|
||||
self.OnResize = nil
|
||||
|
||||
-- create docking zones
|
||||
self.dockzones =
|
||||
{
|
||||
self.dockzones = {
|
||||
top = {x = 0, y = 0, width = 0, height = 0},
|
||||
bottom = {x = 0, y = 0, width = 0, height = 0},
|
||||
left = {x = 0, y = 0, width = 0, height = 0},
|
||||
@ -91,8 +103,6 @@ function newobject:update(dt)
|
||||
end
|
||||
|
||||
local mx, my = love.mouse.getPosition()
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local showclose = self.showclose
|
||||
local close = self.internals[1]
|
||||
local dragging = self.dragging
|
||||
@ -125,6 +135,8 @@ function newobject:update(dt)
|
||||
-- dragging check
|
||||
if dragging then
|
||||
if parent == base then
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
if not dockedtop and not dockedbottom then
|
||||
self.y = my - self.clicky
|
||||
end
|
||||
@ -225,10 +237,84 @@ function newobject:update(dt)
|
||||
self.staticx = mx - self.clickx
|
||||
self.staticy = my - self.clicky
|
||||
end
|
||||
elseif self.resizing then
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
if self.resize_mode == "top_left" then
|
||||
local new_width = self.resizewidth + (self.resizex - mx)
|
||||
local new_height = self.resizeheight + (self.resizey - my)
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
self.x = mx - self.resizexmod
|
||||
end
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
self.y = my - self.resizeymod
|
||||
end
|
||||
elseif self.resize_mode == "bottom_right" then
|
||||
local new_width = (mx - self.x) + self.resizexmod
|
||||
local new_height = (my - self.y) + self.resizeymod
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
end
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
end
|
||||
elseif self.resize_mode == "top_right" then
|
||||
local new_width = (mx - self.x) + self.resizexmod
|
||||
local new_height = self.resizeheight + (self.resizey - my)
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
end
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
self.y = my - self.resizeymod
|
||||
end
|
||||
elseif self.resize_mode == "bottom_left" then
|
||||
local new_width = self.resizewidth + (self.resizex - mx)
|
||||
local new_height = (my - self.y) + self.resizeymod
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
self.x = mx - self.resizexmod
|
||||
end
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
end
|
||||
elseif self.resize_mode == "top" then
|
||||
local new_height = self.resizeheight + (self.resizey - my)
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
self.y = my - self.resizeymod
|
||||
end
|
||||
elseif self.resize_mode == "bottom" then
|
||||
local new_height = (my - self.y) + self.resizeymod
|
||||
if new_height >= self.minheight and new_height <= self.maxheight then
|
||||
self.height = new_height
|
||||
end
|
||||
elseif self.resize_mode == "left" then
|
||||
local new_width = self.resizewidth + (self.resizex - mx)
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
self.x = mx - self.resizexmod
|
||||
end
|
||||
elseif self.resize_mode == "right" then
|
||||
local new_width = (mx - self.x) + self.resizexmod
|
||||
if new_width >= self.minwidth and new_width <= self.maxwidth then
|
||||
self.width = new_width
|
||||
end
|
||||
end
|
||||
if self.width ~= width or self.height ~= height then
|
||||
local onresize = self.OnResize
|
||||
if onresize then
|
||||
onresize(self, self.width, self.height)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if screenlocked then keep within screen
|
||||
if screenlocked then
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local screenwidth = love.graphics.getWidth()
|
||||
local screenheight = love.graphics.getHeight()
|
||||
local x = self.x
|
||||
@ -249,6 +335,8 @@ function newobject:update(dt)
|
||||
|
||||
-- keep the frame within its parent's boundaries if parentlocked
|
||||
if parentlocked then
|
||||
local width = self.width
|
||||
local height = self.height
|
||||
local parentwidth = self.parent.width
|
||||
local parentheight = self.parent.height
|
||||
local staticx = self.staticx
|
||||
@ -384,9 +472,9 @@ function newobject:mousepressed(x, y, button)
|
||||
local parent = self.parent
|
||||
local base = loveframes.base
|
||||
|
||||
if selfcol then
|
||||
if button == "l" then
|
||||
-- initiate dragging if not currently dragging
|
||||
if not dragging and self.hover and button == "l" then
|
||||
if not dragging and self.hover then
|
||||
if y < self.y + 25 and self.draggable then
|
||||
if parent == base then
|
||||
self.clickx = x - self.x
|
||||
@ -398,6 +486,116 @@ function newobject:mousepressed(x, y, button)
|
||||
self.dragging = true
|
||||
end
|
||||
end
|
||||
if not self.resizing and self.canresize then
|
||||
if loveframes.util.BoundingBox(self.x, x, self.y, y, 5, 1, 5, 1) then
|
||||
self.resizing = true
|
||||
self.dragging = false
|
||||
self.resize_mode = "top_left"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x then
|
||||
self.resizexmod = x - self.x
|
||||
end
|
||||
if y ~= self.y then
|
||||
self.resizeymod = y - self.y
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(self.x + self.width - 5, x, self.y + self.height - 5, y, 5, 1, 5, 1) then
|
||||
self.resizing = true
|
||||
self.resize_mode = "bottom_right"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x + self.width then
|
||||
self.resizexmod = (self.x + self.width) - x
|
||||
end
|
||||
if y ~= self.y + self.height then
|
||||
self.resizeymod = (self.y + self.height) - y
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(self.x + self.width - 5, x, self.y, y, 5, 1, 5, 1) then
|
||||
self.resizing = true
|
||||
self.dragging = false
|
||||
self.resize_mode = "top_right"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x + self.width then
|
||||
self.resizexmod = (self.x + self.width) - x
|
||||
end
|
||||
if y ~= self.y then
|
||||
self.resizeymod = y - self.y
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(self.x, x, self.y + self.height - 5, y, 5, 1, 5, 1) then
|
||||
self.resizing = true
|
||||
self.dragging = false
|
||||
self.resize_mode = "bottom_left"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x then
|
||||
self.resizexmod = x - self.x
|
||||
end
|
||||
if y ~= self.y + self.height then
|
||||
self.resizeymod = (self.y + self.height) - y
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(self.x + 5, x, self.y, y, self.width - 10, 1, 2, 1) then
|
||||
self.resizing = true
|
||||
self.dragging = false
|
||||
self.resize_mode = "top"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if y ~= self.y then
|
||||
self.resizeymod = y - self.y
|
||||
end
|
||||
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.dragging = false
|
||||
self.resize_mode = "bottom"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if y ~= self.y then
|
||||
self.resizeymod = (self.y + self.height) - y
|
||||
end
|
||||
elseif loveframes.util.BoundingBox(self.x, x, self.y + 5, y, 2, 1, self.height - 10, 1) then
|
||||
self.resizing = true
|
||||
self.dragging = false
|
||||
self.resize_mode = "left"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x then
|
||||
self.resizexmod = x - self.x
|
||||
end
|
||||
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.dragging = false
|
||||
self.resize_mode = "right"
|
||||
self.resizex = x
|
||||
self.resizey = y
|
||||
self.resizewidth = self.width
|
||||
self.resizeheight = self.height
|
||||
loveframes.resizeobject = self
|
||||
if x ~= self.x + self.width then
|
||||
self.resizexmod = (self.x + self.width) - x
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.hover and button == "l" then
|
||||
self:MakeTop()
|
||||
end
|
||||
@ -432,13 +630,20 @@ function newobject:mousereleased(x, y, button)
|
||||
return
|
||||
end
|
||||
|
||||
local dragging = self.dragging
|
||||
local children = self.children
|
||||
local internals = self.internals
|
||||
|
||||
-- exit the dragging state
|
||||
if dragging then
|
||||
self.dragging = false
|
||||
self.dragging = false
|
||||
|
||||
if self.resizing then
|
||||
self.resizex = 0
|
||||
self.resizey = 0
|
||||
self.resizexmod = 0
|
||||
self.resizeymod = 0
|
||||
self.resizewidth = 0
|
||||
self.resizeheight = 0
|
||||
self.resizing = false
|
||||
loveframes.resizeobject = false
|
||||
end
|
||||
|
||||
for k, v in ipairs(internals) do
|
||||
|
Loading…
Reference in New Issue
Block a user