LoveFrames/objects/frame.lua

1156 lines
30 KiB
Lua
Raw Normal View History

2012-05-06 00:24:42 +00:00
--[[------------------------------------------------
-- Love Frames - A GUI library for LOVE --
2014-01-14 11:29:11 +00:00
-- Copyright (c) 2012-2014 Kenny Shields --
2012-05-06 00:24:42 +00:00
--]]------------------------------------------------
-- get the current require path
local path = string.sub(..., 1, string.len(...) - string.len(".objects.frame"))
local loveframes = require(path .. ".libraries.common")
2013-11-25 13:06:41 +00:00
-- frame object
local newobject = loveframes.NewObject("frame", "loveframes_object_frame", true)
2012-05-06 00:24:42 +00:00
--[[---------------------------------------------------------
- func: initialize()
- desc: initializes the object
--]]---------------------------------------------------------
function newobject:initialize()
2012-05-06 00:24:42 +00:00
self.type = "frame"
self.name = "Frame"
self.width = 300
self.height = 150
self.clickx = 0
self.clicky = 0
self.dockx = 0
self.docky = 0
self.dockzonesize = 10
2014-01-08 00:06:03 +00:00
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
self.parentlocked = false
self.dragging = false
self.modal = false
self.modalbackground = false
self.showclose = true
self.dockedtop = false
self.dockedbottom = false
self.dockedleft = false
self.dockedright = false
self.topdockobject = false
self.bottomdockobject = false
self.leftdockobject = false
self.rightdockobject = false
self.dockable = false
2014-01-08 00:06:03 +00:00
self.resizing = false
self.canresize = false
self.alwaysontop = false
self.internals = {}
self.children = {}
self.icon = nil
self.OnClose = nil
self.OnDock = nil
2014-01-08 00:06:03 +00:00
self.OnResize = nil
-- create docking zones
2014-01-08 00:06:03 +00:00
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},
right = {x = 0, y = 0, width = 0, height = 0}
}
-- create the close button for the frame
local close = loveframes.objects["closebutton"]:new()
2012-05-06 00:24:42 +00:00
close.parent = self
close.OnClick = function(x, y, object)
local onclose = object.parent.OnClose
if onclose then
local ret = onclose(object.parent)
if ret ~= false then
object.parent:Remove()
end
else
object.parent:Remove()
2012-05-06 00:24:42 +00:00
end
end
table.insert(self.internals, close)
end
--[[---------------------------------------------------------
- func: update(deltatime)
- desc: updates the element
--]]---------------------------------------------------------
function newobject:update(dt)
2012-05-06 00:24:42 +00:00
local state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
local alwaysupdate = self.alwaysupdate
2012-05-06 00:24:42 +00:00
if not visible then
if not alwaysupdate then
2012-05-06 00:24:42 +00:00
return
end
end
local mx, my = love.mouse.getPosition()
local showclose = self.showclose
local close = self.internals[1]
local dragging = self.dragging
local screenlocked = self.screenlocked
local parentlocked = self.parentlocked
local modal = self.modal
local base = loveframes.base
local basechildren = base.children
local numbasechildren = #basechildren
local draworder = self.draworder
local dockedtop = self.dockedtop
local dockedbottom = self.dockedbottom
local dockedleft = self.dockedleft
local dockedright = self.dockedright
local dockable = self.dockable
local dockzonesize = self.dockzonesize
local children = self.children
local internals = self.internals
local parent = self.parent
local update = self.Update
2012-05-06 00:24:42 +00:00
self:CheckHover()
-- update dockzones
self.dockzones.top = {x = self.x, y = self.y - dockzonesize, width = self.width, height = dockzonesize}
self.dockzones.bottom = {x = self.x, y = self.y + self.height, width = self.width, height = dockzonesize}
self.dockzones.left = {x = self.x - dockzonesize, y = self.y, width = dockzonesize, height = self.height}
self.dockzones.right = {x = self.x + self.width, y = self.y, width = dockzonesize, height = self.height}
2012-05-06 00:24:42 +00:00
-- dragging check
if dragging then
if parent == base then
2014-01-08 00:06:03 +00:00
local width = self.width
local height = self.height
if not dockedtop and not dockedbottom then
self.y = my - self.clicky
end
if not dockedleft and not dockedright then
self.x = mx - self.clickx
end
local basechildren = loveframes.base.children
-- check for frames to dock with
if dockable then
local ondock = self.OnDock
for k, v in ipairs(basechildren) do
if v.type == "frame" then
local topcol = loveframes.util.RectangleCollisionCheck(self.dockzones.bottom, v.dockzones.top)
local botcol = loveframes.util.RectangleCollisionCheck(self.dockzones.top, v.dockzones.bottom)
local leftcol = loveframes.util.RectangleCollisionCheck(self.dockzones.right, v.dockzones.left)
local rightcol = loveframes.util.RectangleCollisionCheck(self.dockzones.left, v.dockzones.right)
local candockobject = v.dockable
if candockobject then
if topcol and not dockedtop then
self.y = v.y - self.height
self.docky = my
self.dockedtop = true
self.topdockobject = v
if ondock then
ondock(object, v)
end
elseif botcol and not dockedbottom then
self.y = v.y + v.height
self.docky = my
self.dockedbottom = true
self.bottomdockobject = v
if ondock then
ondock(object, v)
end
elseif leftcol and not dockedleft then
self.x = v.x - self.width
self.dockx = mx
self.dockedleft = true
self.leftdockobject = v
if ondock then
ondock(object, v)
end
elseif rightcol and not dockedright then
self.x = v.x + v.width
self.dockx = mx
self.dockedright = true
self.rightdockobject = v
if ondock then
ondock(object, v)
end
end
end
end
end
end
local dockx = self.dockx
local docky = self.docky
local x = self.x
local y = self.y
-- check to see if the frame should be undocked
if dockedtop then
local topdockobject = self.topdockobject
local tdox = topdockobject.x
local tdowidth = topdockobject.width
if my > (docky + 20) or my < (docky - 20) or (x + width) < tdox or x > (tdox + tdowidth) then
self.dockedtop = false
self.docky = 0
end
end
if dockedbottom then
local bottomdockobject = self.bottomdockobject
local bdox = bottomdockobject.x
local bdowidth = bottomdockobject.width
if my > (docky + 20) or my < (docky - 20) or (x + width) < bdox or x > (bdox + bdowidth) then
self.dockedbottom = false
self.docky = 0
end
end
if dockedleft then
local leftdockobject = self.leftdockobject
local ldoy = leftdockobject.y
local ldoheight = leftdockobject.height
if mx > (dockx + 20) or mx < (dockx - 20) or (y + height) < ldoy or y > (ldoy + ldoheight) then
self.dockedleft = false
self.dockx = 0
end
end
if dockedright then
local rightdockobject = self.rightdockobject
local rdoy = rightdockobject.y
local rdoheight = rightdockobject.height
if mx > (dockx + 20) or mx < (dockx - 20) or (y + height) < rdoy or y > (rdoy + rdoheight) then
self.dockedright = false
self.dockx = 0
end
end
else
self.staticx = mx - self.clickx
self.staticy = my - self.clicky
end
2014-01-08 00:06:03 +00:00
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
2012-05-06 00:24:42 +00:00
end
-- if screenlocked then keep within screen
if screenlocked then
2014-01-08 00:06:03 +00:00
local width = self.width
local height = self.height
local screenwidth = love.graphics.getWidth()
local screenheight = love.graphics.getHeight()
local x = self.x
local y = self.y
if x < 0 then
2012-05-06 00:24:42 +00:00
self.x = 0
end
if x + width > screenwidth then
self.x = screenwidth - width
2012-05-06 00:24:42 +00:00
end
if y < 0 then
2012-05-06 00:24:42 +00:00
self.y = 0
end
if y + height > screenheight then
self.y = screenheight - height
2012-05-06 00:24:42 +00:00
end
end
-- keep the frame within its parent's boundaries if parentlocked
if parentlocked then
2014-01-08 00:06:03 +00:00
local width = self.width
local height = self.height
local parentwidth = self.parent.width
local parentheight = self.parent.height
local staticx = self.staticx
local staticy = self.staticy
if staticx < 0 then
self.staticx = 0
end
if staticx + width > parentwidth then
self.staticx = parentwidth - width
end
if staticy < 0 then
self.staticy = 0
end
if staticy + height > parentheight then
self.staticy = parentheight - height
end
end
if parent == base and self.alwaysontop and not self:IsTopChild() then
self:MakeTop()
end
if modal then
local tip = false
local key = 0
for k, v in ipairs(basechildren) do
if v.type == "tooltip" and v.show then
tip = v
key = k
end
end
if tip then
self:Remove()
self.modalbackground:Remove()
table.insert(basechildren, key - 2, self.modalbackground)
table.insert(basechildren, key - 1, self)
end
if self.modalbackground.draworder > self.draworder then
self:MakeTop()
end
2014-03-29 16:07:26 +00:00
if self.modalbackground.state ~= self.state then
self.modalbackground:SetState(self.state)
end
end
if parent ~= base then
self.x = self.parent.x + self.staticx
self.y = self.parent.y + self.staticy
end
for k, v in ipairs(internals) do
2012-05-06 00:24:42 +00:00
v:update(dt)
end
for k, v in ipairs(children) do
2012-05-06 00:24:42 +00:00
v:update(dt)
end
if update then
update(self, dt)
2012-05-06 00:24:42 +00:00
end
end
--[[---------------------------------------------------------
- func: draw()
- desc: draws the object
--]]---------------------------------------------------------
function newobject:draw()
2012-05-06 00:24:42 +00:00
local state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local children = self.children
local internals = self.internals
local skins = loveframes.skins.available
local skinindex = loveframes.config["ACTIVESKIN"]
local defaultskin = loveframes.config["DEFAULTSKIN"]
local selfskin = self.skin
local skin = skins[selfskin] or skins[skinindex]
local drawfunc = skin.DrawFrame or skins[defaultskin].DrawFrame
local draw = self.Draw
local drawcount = loveframes.drawcount
-- set the object's draw order
self:SetDrawOrder()
2012-05-06 00:24:42 +00:00
if draw then
draw(self)
2012-05-06 00:24:42 +00:00
else
drawfunc(self)
2012-05-06 00:24:42 +00:00
end
for k, v in ipairs(internals) do
2012-05-06 00:24:42 +00:00
v:draw()
end
-- loop through the object's children and draw them
for k, v in ipairs(children) do
2012-05-06 00:24:42 +00:00
v:draw()
end
end
--[[---------------------------------------------------------
- func: mousepressed(x, y, button)
- desc: called when the player presses a mouse button
--]]---------------------------------------------------------
function newobject:mousepressed(x, y, button)
local state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
return
end
local width = self.width
local height = self.height
local internals = self.internals
local children = self.children
local dragging = self.dragging
local parent = self.parent
local base = loveframes.base
2012-05-06 00:24:42 +00:00
2014-01-08 00:06:03 +00:00
if button == "l" then
2012-05-06 00:24:42 +00:00
-- initiate dragging if not currently dragging
if not dragging and self.hover and self.draggable then
local topcol
if self.canresize then
topcol = loveframes.util.BoundingBox(x, self.x + 2, y, self.y + 2, 1, self.width - 4, 1, 21)
else
topcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, 25)
end
if topcol then
if parent == base then
self.clickx = x - self.x
self.clicky = y - self.y
else
self.clickx = x - self.staticx
self.clicky = y - self.staticy
end
2012-05-06 00:24:42 +00:00
self.dragging = true
end
end
if not self.resizing and self.canresize and loveframes.hoverobject == self then
2014-01-08 00:06:03 +00:00
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
2013-11-22 17:00:06 +00:00
if self.hover and button == "l" then
2012-05-06 00:24:42 +00:00
self:MakeTop()
end
end
for k, v in ipairs(internals) do
2012-05-06 00:24:42 +00:00
v:mousepressed(x, y, button)
end
for k, v in ipairs(children) do
2012-05-06 00:24:42 +00:00
v:mousepressed(x, y, button)
end
end
--[[---------------------------------------------------------
- func: mousereleased(x, y, button)
- desc: called when the player releases a mouse button
--]]---------------------------------------------------------
function newobject:mousereleased(x, y, button)
2012-05-06 00:24:42 +00:00
local state = loveframes.state
local selfstate = self.state
if state ~= selfstate then
return
end
local visible = self.visible
if not visible then
2012-05-06 00:24:42 +00:00
return
end
local children = self.children
local internals = self.internals
2014-01-08 00:06:03 +00:00
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
2012-05-06 00:24:42 +00:00
end
for k, v in ipairs(internals) do
2012-05-06 00:24:42 +00:00
v:mousereleased(x, y, button)
end
for k, v in ipairs(children) do
2012-05-06 00:24:42 +00:00
v:mousereleased(x, y, button)
end
end
--[[---------------------------------------------------------
- func: SetName(name)
2013-11-25 13:06:41 +00:00
- desc: sets the object's name
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:SetName(name)
2012-05-06 00:24:42 +00:00
self.name = name
2014-02-11 12:34:07 +00:00
return self
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: GetName()
2013-11-25 13:06:41 +00:00
- desc: gets the object's name
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:GetName()
2012-05-06 00:24:42 +00:00
return self.name
end
--[[---------------------------------------------------------
- func: SetDraggable(true/false)
2013-11-25 13:06:41 +00:00
- desc: sets whether the object can be dragged or not
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:SetDraggable(bool)
2012-05-06 00:24:42 +00:00
self.draggable = bool
2014-02-11 12:34:07 +00:00
return self
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: GetDraggable()
2013-11-25 13:06:41 +00:00
- desc: gets whether the object can be dragged ot not
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:GetDraggable()
2012-05-06 00:24:42 +00:00
return self.draggable
end
--[[---------------------------------------------------------
- func: SetScreenLocked(bool)
2013-11-25 13:06:41 +00:00
- desc: sets whether the object can be moved passed the
2012-05-06 00:24:42 +00:00
boundaries of the window or not
--]]---------------------------------------------------------
function newobject:SetScreenLocked(bool)
2012-05-06 00:24:42 +00:00
self.screenlocked = bool
2014-02-11 12:34:07 +00:00
return self
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: GetScreenLocked()
2013-11-25 13:06:41 +00:00
- desc: gets whether the object can be moved passed the
2012-05-06 00:24:42 +00:00
boundaries of window or not
--]]---------------------------------------------------------
function newobject:GetScreenLocked()
2012-05-06 00:24:42 +00:00
return self.screenlocked
end
--[[---------------------------------------------------------
- func: ShowCloseButton(bool)
2013-11-25 13:06:41 +00:00
- desc: sets whether the object's close button should
be drawn
2012-05-06 00:24:42 +00:00
--]]---------------------------------------------------------
function newobject:ShowCloseButton(bool)
2012-05-06 00:24:42 +00:00
local close = self.internals[1]
close.visible = bool
self.showclose = bool
2014-02-11 12:34:07 +00:00
return self
2012-05-06 00:24:42 +00:00
end
--[[---------------------------------------------------------
- func: MakeTop()
- desc: makes the object the top object in the drawing
order
--]]---------------------------------------------------------
function newobject:MakeTop()
2012-05-06 00:24:42 +00:00
local key = 0
local base = loveframes.base
local basechildren = base.children
local numbasechildren = #basechildren
2012-05-06 00:24:42 +00:00
-- check to see if the object's parent is not the base object
if self.parent ~= base then
local baseparent = self:GetBaseParent()
if baseparent.type == "frame" then
baseparent:MakeTop()
end
return self
end
-- check to see if the object is the only child of the base object
if numbasechildren == 1 then
return self
2012-05-06 00:24:42 +00:00
end
-- check to see if the object is already at the top
if basechildren[numbasechildren] == self then
return self
2012-05-06 00:24:42 +00:00
end
-- make this the top object
for k, v in ipairs(basechildren) do
2012-05-06 00:24:42 +00:00
if v == self then
table.remove(basechildren, k)
table.insert(basechildren, self)
2012-05-06 00:24:42 +00:00
key = k
break
end
end
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: SetModal(bool)
2013-11-25 13:06:41 +00:00
- desc: sets whether or not the object is in a modal
state
--]]---------------------------------------------------------
function newobject:SetModal(bool)
local modalobject = loveframes.modalobject
local mbackground = self.modalbackground
local parent = self.parent
local base = loveframes.base
if parent ~= base then
return
end
self.modal = bool
if bool then
if modalobject then
modalobject:SetModal(false)
end
loveframes.modalobject = self
if not mbackground then
self.modalbackground = loveframes.objects["modalbackground"]:new(self)
self.modal = true
end
else
if modalobject == self then
loveframes.modalobject = false
if mbackground then
self.modalbackground:Remove()
self.modalbackground = false
self.modal = false
end
end
end
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetModal()
- desc: gets whether or not the object is in a modal
state
--]]---------------------------------------------------------
function newobject:GetModal()
return self.modal
end
--[[---------------------------------------------------------
- func: SetVisible(bool)
- desc: set's whether the object is visible or not
--]]---------------------------------------------------------
function newobject:SetVisible(bool)
local children = self.children
local internals = self.internals
local closebutton = internals[1]
self.visible = bool
for k, v in ipairs(children) do
v:SetVisible(bool)
end
if self.showclose then
closebutton.visible = bool
end
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: SetParentLocked(bool)
2013-11-25 13:06:41 +00:00
- desc: sets whether the object can be moved passed the
boundaries of its parent or not
--]]---------------------------------------------------------
function newobject:SetParentLocked(bool)
self.parentlocked = bool
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetParentLocked(bool)
2013-11-25 13:06:41 +00:00
- desc: gets whether the object can be moved passed the
boundaries of its parent or not
--]]---------------------------------------------------------
function newobject:GetParentLocked()
return self.parentlocked
end
--[[---------------------------------------------------------
- func: SetIcon(icon)
- desc: sets the object's icon
--]]---------------------------------------------------------
function newobject:SetIcon(icon)
if type(icon) == "string" then
self.icon = love.graphics.newImage(icon)
else
self.icon = icon
end
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetIcon()
- desc: gets the object's icon
--]]---------------------------------------------------------
function newobject:GetIcon()
local icon = self.icon
if icon then
return icon
end
return false
end
--[[---------------------------------------------------------
- func: SetDockable(dockable)
- desc: sets whether or not the object can dock onto
2013-11-25 13:06:41 +00:00
another object of its type or be docked
by another object of its type
--]]---------------------------------------------------------
function newobject:SetDockable(dockable)
self.dockable = dockable
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetDockable()
- desc: gets whether or not the object can dock onto
2013-11-25 13:06:41 +00:00
another object of its type or be docked
by another object of its type
--]]---------------------------------------------------------
function newobject:GetDockable()
return self.dockable
end
--[[---------------------------------------------------------
- func: SetDockZoneSize(size)
- desc: sets the size of the object's docking zone
--]]---------------------------------------------------------
function newobject:SetDockZoneSize(size)
self.dockzonesize = size
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetDockZoneSize(size)
- desc: gets the size of the object's docking zone
--]]---------------------------------------------------------
function newobject:GetDockZoneSize()
return self.dockzonesize
end
--[[---------------------------------------------------------
- func: SetResizable(bool)
- desc: sets whether or not the object can be resized
--]]---------------------------------------------------------
function newobject:SetResizable(bool)
self.canresize = bool
2014-02-11 12:34:07 +00:00
return self
end
--[[---------------------------------------------------------
- func: GetResizable()
- desc: gets whether or not the object can be resized
--]]---------------------------------------------------------
function newobject:GetResizable()
return self.canresize
2014-01-08 01:06:51 +00:00
end
--[[---------------------------------------------------------
- func: SetMinWidth(width)
- desc: sets the object's minimum width
--]]---------------------------------------------------------
function newobject:SetMinWidth(width)
self.minwidth = width
2014-02-11 12:34:07 +00:00
return self
2014-01-08 01:06:51 +00:00
end
--[[---------------------------------------------------------
- func: GetMinWidth()
- desc: gets the object's minimum width
--]]---------------------------------------------------------
function newobject:GetMinWidth()
return self.minwidth
end
--[[---------------------------------------------------------
- func: SetMaxWidth(width)
- desc: sets the object's maximum width
--]]---------------------------------------------------------
function newobject:SetMaxWidth(width)
self.maxwidth = width
2014-02-11 12:34:07 +00:00
return self
2014-01-08 01:06:51 +00:00
end
--[[---------------------------------------------------------
- func: GetMaxWidth()
- desc: gets the object's maximum width
--]]---------------------------------------------------------
function newobject:GetMaxWidth()
return self.maxwidth
end
--[[---------------------------------------------------------
- func: SetMinHeight(height)
- desc: sets the object's minimum height
--]]---------------------------------------------------------
function newobject:SetMinHeight(height)
self.minheight = height
2014-02-11 12:34:07 +00:00
return self
2014-01-08 01:06:51 +00:00
end
--[[---------------------------------------------------------
- func: GetMinHeight()
- desc: gets the object's minimum height
--]]---------------------------------------------------------
function newobject:GetMinHeight()
return self.minheight
end
--[[---------------------------------------------------------
- func: SetMaxHeight(height)
- desc: sets the object's maximum height
--]]---------------------------------------------------------
function newobject:SetMaxHeight(height)
self.maxheight = height
2014-02-11 12:34:07 +00:00
return self
2014-01-08 01:06:51 +00:00
end
--[[---------------------------------------------------------
- func: GetMaxHeight()
- desc: gets the object's maximum height
--]]---------------------------------------------------------
function newobject:GetMaxHeight()
return self.maxheight
end
--[[---------------------------------------------------------
- func: SetMinSize(width, height)
- desc: sets the object's minimum size
--]]---------------------------------------------------------
function newobject:SetMinSize(width, height)
self.minwidth = width
self.minheight = height
return self
end
--[[---------------------------------------------------------
- func: GetMinSize()
- desc: gets the object's minimum size
--]]---------------------------------------------------------
function newobject:GetMinSize()
return self.minwidth, self.maxwidth
end
--[[---------------------------------------------------------
- func: SetMaxSize(width, height)
- desc: sets the object's maximum size
--]]---------------------------------------------------------
function newobject:SetMaxSize(width, height)
self.maxwidth = width
self.maxheight = height
return self
end
--[[---------------------------------------------------------
- func: GetMaxSize()
- desc: gets the object's maximum size
--]]---------------------------------------------------------
function newobject:GetMaxSize()
return self.maxwidth, self.maxheight
end
--[[---------------------------------------------------------
- func: SetAlwaysOnTop(bool)
- desc: sets whether or not a frame should always be
drawn on top of other objects
--]]---------------------------------------------------------
function newobject:SetAlwaysOnTop(bool)
self.alwaysontop = bool
return self
end
--[[---------------------------------------------------------
- func: GetAlwaysOnTop()
- desc: gets whether or not a frame should always be
drawn on top of other objects
--]]---------------------------------------------------------
function newobject:GetAlwaysOnTop()
return self.alwaysontop
end