Pop.Box/pop/elements/element.lua

122 lines
3.4 KiB
Lua
Raw Normal View History

2015-11-18 03:27:06 +00:00
local path = string.sub(..., 1, string.len(...) - string.len(".elements.element"))
local class = require(path .. ".lib.middleclass")
2015-11-20 11:30:40 +00:00
--TODO determine if these requires can break because of slashes / subdirectories
2015-11-18 03:27:06 +00:00
2015-11-20 11:30:40 +00:00
local element = class("pop.element")
2015-11-18 03:27:06 +00:00
function element:initialize(pop, parent)
2015-11-20 11:30:40 +00:00
self.ax = 0 -- absolute locations
self.ay = 0
self.rx = 0 -- relative to parent locations
self.ry = 0
2015-11-18 03:27:06 +00:00
self.sizeControl = "fromInner" -- fromInner, fromOuter, specified
self.outerWidth = 0
self.outerHeight = 0
self.innerWidth = 0
self.innerHeight = 0
2015-11-20 11:30:40 +00:00
self.skin = pop.skins[pop.currentSkin]
2015-11-18 03:27:06 +00:00
self.visible = true
self.parent = parent
self.child = {}
parent.child[self] = self -- add ourselves to the parent's children
end
2015-11-20 11:30:40 +00:00
--TODO completely redefine interface based on what we should expect users to do
-- REMEMBER the goal is minimal effort on their part
-- THEREFORE, we should reduce this interface, they should rely on skins for borderSize (and thus, differences in outer/inner sizes)
-- all calls should be based on sizing the outside, and update() should update inners (including children!) based on outers
function element:getSize()
return self.outerWidth, self.outerHeight
2015-11-18 03:27:06 +00:00
end
2015-11-20 11:30:40 +00:00
function element:setSize(width, height)
assert(width > 0, "width must be above 0")
assert(height > 0, "height must be above 0")
self.outerWidth = width
self.outerHeight = height
self.sizeControl = "specified"
2015-11-18 03:27:06 +00:00
end
function element:getOuterWidth()
return self.outerWidth
end
function element:setOuterWidth(width)
assert(width > 0, "width must be above 0")
self.outerWidth = width
2015-11-20 11:30:40 +00:00
self.sizeControl = "specified"
--TODO needs to update() to update inner size based on borderSize ???
2015-11-18 03:27:06 +00:00
end
function element:getOuterHeight()
return self.outerHeight()
end
function element:setOuterHeight(height)
assert(height > 0, "height must be above 0")
self.outerHeight = height
2015-11-20 11:30:40 +00:00
self.sizeControl = "specified"
--TODO needs to update() to update inner size based on borderSize ???
2015-11-18 03:27:06 +00:00
end
function element:getInnerWidth()
return self.innerWidth
end
function element:setInnerWidth(width)
assert(width > 0, "width must be above 0")
self.innerWidth = width
2015-11-20 11:30:40 +00:00
self.sizeControl = "specified"
--TODO needs to update outerWidth ???
2015-11-18 03:27:06 +00:00
end
function element:getInnerHeight()
return self.innerHeight
end
function element:setInnerHeight(height)
assert(height > 0, "height must be above 0")
self.innerHeight = height
2015-11-20 11:30:40 +00:00
self.sizeControl = "specified"
--TODO needs to update outerHeight ??
2015-11-18 03:27:06 +00:00
end
--[[ TODO determine how to write these better (consistency motherfucker)
function element:getStyle()
return self.style.name
end
function element:setStyle(style)
self.style = style
end
]]
function element:getVisible()
return self.visible
end
function element:setVisible(bool)
self.visible = bool
end
function element:getParent()
return self.parent
end
function element:setParent(parent)
self.parent.child[self] = nil
self.parent = parent
self.parent.child[self] = self
end
--TODO figure out how getting and setting children might work? or no??
function element:update()
--TODO a proper error message
print("update() not deifnenfei")
end
function element:draw()
--TODO figure out how to get class name
print("Attempting to use element, or did not overwrite element's :draw() method.")
end
return element