Code cleanup

This commit is contained in:
Kenny Shields 2014-08-23 04:36:47 -04:00
parent ac5818b102
commit e4c518e2f0
3 changed files with 78 additions and 134 deletions

View File

@ -45,31 +45,26 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:update(dt) function newobject:update(dt)
local visible = self.visible if not self.visible then
local alwaysupdate = self.alwaysupdate if not self.alwaysupdate then
if not visible then
if not alwaysupdate then
return return
end end
end end
local cwidth, cheight = self.parent:GetColumnSize() local cwidth, cheight = self.parent:GetColumnSize()
local parent = self.parent local parent = self.parent
local base = loveframes.base
local update = self.Update local update = self.Update
local internals = self.internals local internals = self.internals
local children = self.children
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= loveframes.base then
self.x = parent.x + self.staticx self.x = parent.x + self.staticx
self.y = parent.y + self.staticy self.y = parent.y + self.staticy
end end
for k, v in ipairs(children) do for k, v in ipairs(self.children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height) local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, self.width, v.width, self.height, v.height)
if col then if col then
v:update(dt) v:update(dt)
@ -95,9 +90,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:draw() function newobject:draw()
local visible = self.visible if not self.visible then
if not visible then
return return
end end
@ -113,10 +106,6 @@ function newobject:draw()
local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea local drawfunc = skin.DrawColumnListArea or skins[defaultskin].DrawColumnListArea
local drawoverfunc = skin.DrawOverColumnListArea or skins[defaultskin].DrawOverColumnListArea local drawoverfunc = skin.DrawOverColumnListArea or skins[defaultskin].DrawOverColumnListArea
local draw = self.Draw local draw = self.Draw
local drawcount = loveframes.drawcount
local internals = self.internals
local children = self.children
local swidth = width local swidth = width
local sheight = height local sheight = height
@ -141,7 +130,7 @@ function newobject:draw()
love.graphics.setStencil(stencilfunc) love.graphics.setStencil(stencilfunc)
for k, v in ipairs(children) do for k, v in ipairs(self.children) do
local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, width, v.width, height, v.height) local col = loveframes.util.BoundingBox(self.x, v.x, self.y, v.y, width, v.width, height, v.height)
if col then if col then
v:draw() v:draw()
@ -150,7 +139,7 @@ function newobject:draw()
love.graphics.setStencil() love.graphics.setStencil()
for k, v in ipairs(internals) do for k, v in ipairs(self.internals) do
v:draw() v:draw()
end end
@ -166,10 +155,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:mousepressed(x, y, button) function newobject:mousepressed(x, y, button)
local toplist = self:IsTopList()
local scrollamount = self.mousewheelscrollamount local scrollamount = self.mousewheelscrollamount
local internals = self.internals
local children = self.children
if self.hover and button == "l" then if self.hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
@ -178,10 +164,9 @@ function newobject:mousepressed(x, y, button)
end end
end end
if self.bar and toplist then if self.bar and self:IsTopList() then
local bar = self:GetScrollBar() local bar = self:GetScrollBar()
local dtscrolling = self.dtscrolling if self.dtscrolling then
if dtscrolling then
local dt = love.timer.getDelta() local dt = love.timer.getDelta()
if button == "wu" then if button == "wu" then
bar:Scroll(-scrollamount * dt) bar:Scroll(-scrollamount * dt)
@ -197,11 +182,11 @@ function newobject:mousepressed(x, y, button)
end end
end end
for k, v in ipairs(internals) do for k, v in ipairs(self.internals) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
for k, v in ipairs(children) do for k, v in ipairs(self.children) do
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
@ -232,21 +217,17 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:CalculateSize() function newobject:CalculateSize()
local columnheight = self.parent.columnheight
local numitems = #self.children
local height = self.height local height = self.height
local width = self.width local width = self.width
local itemheight = columnheight local parent = self.parent
local itemwidth = 0 local itemheight = parent.columnheight
local bar = self.bar
local children = self.children
for k, v in ipairs(children) do for k, v in ipairs(self.children) do
itemheight = itemheight + v.height itemheight = itemheight + v.height
end end
self.itemheight = itemheight self.itemheight = itemheight
self.itemwidth = self.parent:GetTotalColumnWidth() self.itemwidth = parent:GetTotalColumnWidth()
local hbarheight = 0 local hbarheight = 0
local hbar = self:GetHorizontalScrollBar() local hbar = self:GetHorizontalScrollBar()
@ -262,7 +243,7 @@ function newobject:CalculateSize()
if not self.vbar then if not self.vbar then
table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "vertical")) table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "vertical"))
self.vbar = true self.vbar = true
self:GetVerticalScrollBar().autoscroll = self.parent.autoscroll self:GetVerticalScrollBar().autoscroll = parent.autoscroll
end end
else else
if self.vbar then if self.vbar then
@ -278,15 +259,15 @@ function newobject:CalculateSize()
vbarwidth = vbar.width vbarwidth = vbar.width
end end
if self.itemwidth > (self.width - vbarwidth) then if self.itemwidth > (width - vbarwidth) then
if vbar then if vbar then
self.itemwidth = self.itemwidth + vbarwidth self.itemwidth = self.itemwidth + vbarwidth
end end
self.extrawidth = self.itemwidth - self.width self.extrawidth = self.itemwidth - width
if not self.hbar then if not self.hbar then
table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "horizontal")) table.insert(self.internals, loveframes.objects["scrollbody"]:new(self, "horizontal"))
self.hbar = true self.hbar = true
self:GetHorizontalScrollBar().autoscroll = self.parent.autoscroll self:GetHorizontalScrollBar().autoscroll = parent.autoscroll
end end
else else
if self.hbar then if self.hbar then
@ -304,51 +285,38 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:RedoLayout() function newobject:RedoLayout()
local children = self.children
local starty = 0 local starty = 0
local startx = 0 self.rowcolorindex = 1
local bar = self.bar
local display = self.display
if #children > 0 then for k, v in ipairs(self.children) do
self.rowcolorindex = 1 v:SetWidth(self.parent:GetTotalColumnWidth())
for k, v in ipairs(children) do v.staticx = 0
v:SetWidth(self.parent:GetTotalColumnWidth()) v.staticy = starty
local height = v.height if self.vbar then
v.staticx = startx local vbar = self:GetVerticalScrollBar()
v.staticy = starty vbar.staticx = self.width - vbar.width
if self.vbar then
local vbar = self:GetVerticalScrollBar()
--v:SetWidth(self.width - vbar.width)
vbar.staticx = self.width - vbar.width
if self.hbar then
vbar.height = self.height - self:GetHorizontalScrollBar().height
else
vbar.height = self.height
end
else
--v:SetWidth(self.width)
end
if self.hbar then if self.hbar then
local hbar = self:GetHorizontalScrollBar() vbar.height = self.height - self:GetHorizontalScrollBar().height
--self:SetHeight(self.parent.height - hbar.height)
if self.vbar then
hbar.width = self.width - self:GetVerticalScrollBar().width
else
hbar.width = self.width
end
else else
--self:SetHeight(self.parent.height) vbar.height = self.height
end end
starty = starty + v.height end
v.lastheight = v.height if self.hbar then
v.colorindex = self.rowcolorindex local hbar = self:GetHorizontalScrollBar()
if self.rowcolorindex == self.rowcolorindexmax then if self.vbar then
self.rowcolorindex = 1 hbar.width = self.width - self:GetVerticalScrollBar().width
else else
self.rowcolorindex = self.rowcolorindex + 1 hbar.width = self.width
end end
end end
starty = starty + v.height
v.lastheight = v.height
v.colorindex = self.rowcolorindex
if self.rowcolorindex == self.rowcolorindexmax then
self.rowcolorindex = 1
else
self.rowcolorindex = self.rowcolorindex + 1
end
end end
end end
@ -359,17 +327,15 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:AddRow(data) function newobject:AddRow(data)
local row = loveframes.objects["columnlistrow"]:new(self, data)
local colorindex = self.rowcolorindex local colorindex = self.rowcolorindex
local colorindexmax = self.rowcolorindexmax
if colorindex == colorindexmax then if colorindex == self.rowcolorindexmax then
self.rowcolorindex = 1 self.rowcolorindex = 1
else else
self.rowcolorindex = colorindex + 1 self.rowcolorindex = colorindex + 1
end end
table.insert(self.children, row) table.insert(self.children, loveframes.objects["columnlistrow"]:new(self, data))
self:CalculateSize() self:CalculateSize()
self:RedoLayout() self:RedoLayout()
self.parent:AdjustColumns() self.parent:AdjustColumns()
@ -381,14 +347,9 @@ end
- desc: gets the object's scroll bar - desc: gets the object's scroll bar
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:GetScrollBar() function newobject:GetScrollBar()
local internals = self.internals
if self.bar then if self.bar then
local scrollbody = internals[1] return self.internals[1].internals[1].internals[1]
local scrollarea = scrollbody.internals[1]
local scrollbar = scrollarea.internals[1]
return scrollbar
else else
return false return false
end end
@ -401,10 +362,8 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:Sort(column, desc) function newobject:Sort(column, desc)
self.rowcolorindex = 1
local colorindexmax = self.rowcolorindexmax
local children = self.children local children = self.children
self.rowcolorindex = 1
table.sort(children, function(a, b) table.sort(children, function(a, b)
if desc then if desc then
@ -417,7 +376,7 @@ function newobject:Sort(column, desc)
for k, v in ipairs(children) do for k, v in ipairs(children) do
local colorindex = self.rowcolorindex local colorindex = self.rowcolorindex
v.colorindex = colorindex v.colorindex = colorindex
if colorindex == colorindexmax then if colorindex == self.rowcolorindexmax then
self.rowcolorindex = 1 self.rowcolorindex = 1
else else
self.rowcolorindex = colorindex + 1 self.rowcolorindex = colorindex + 1

View File

@ -17,7 +17,7 @@ function newobject:initialize(name, parent)
self.name = name self.name = name
self.state = parent.state self.state = parent.state
self.width = 80 self.width = 80
self.height = self.parent.columnheight self.height = parent.columnheight
self.columnid = 0 self.columnid = 0
self.hover = false self.hover = false
self.down = false self.down = false
@ -61,20 +61,15 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:update(dt) function newobject:update(dt)
local visible = self.visible if not self.visible then
local alwaysupdate = self.alwaysupdate if not self.alwaysupdate then
if not visible then
if not alwaysupdate then
return return
end end
end end
local parent = self.parent
local base = loveframes.base
local update = self.Update local update = self.Update
local parent = self.parent
local list = self.parent.internals[1] local list = parent.internals[1]
local vbar = list:GetVerticalScrollBar() local vbar = list:GetVerticalScrollBar()
local width = list.width local width = list.width
if vbar then if vbar then
@ -93,23 +88,26 @@ function newobject:update(dt)
end end
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= loveframes.base then
self.x = (parent.x + self.staticx) - self.parent.internals[1].offsetx self.x = (parent.x + self.staticx) - parent.internals[1].offsetx
self.y = parent.y + self.staticy self.y = parent.y + self.staticy
end end
if self.parent.resizecolumn and self.parent.resizecolumn == self then local resizecolumn = parent.resizecolumn
if resizecolumn and resizecolumn == self then
local x, y = love.mouse.getPosition() local x, y = love.mouse.getPosition()
local start = false local start = false
self.width = x - self.x self.width = x - self.x
if self.width < 20 then if self.width < 20 then
self.width = 20 self.width = 20
end end
self.parent.startadjustment = true parent.startadjustment = true
self.parent.internals[1]:CalculateSize() parent.internals[1]:CalculateSize()
self.parent.internals[1]:RedoLayout() parent.internals[1]:RedoLayout()
elseif self.parent.resizecolumn and self.parent.startadjustment then elseif resizecolumn and parent.startadjustment then
self.staticx = self.parent.children[self.columnid - 1].staticx + self.parent.children[self.columnid - 1].width local header = parent.children[self.columnid - 1]
self.staticx = header.staticx + header.width
end end
self.resizebox = {x = self.x + (self.width - 2), y = self.y, width = 4, height = self.height} self.resizebox = {x = self.x + (self.width - 2), y = self.y, width = 4, height = self.height}
@ -126,9 +124,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:draw() function newobject:draw()
local visible = self.visible if not self.visible then
if not visible then
return return
end end
@ -200,7 +196,8 @@ function newobject:mousereleased(x, y, button)
end end
end end
if self.parent.resizecolumn and self.parent.resizecolumn == self then local resizecolumn = self.parent.resizecolumn
if resizecolumn and resizecolumn == self then
self.parent.resizecolumn = nil self.parent.resizecolumn = nil
end end

View File

@ -40,23 +40,19 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:update(dt) function newobject:update(dt)
local visible = self.visible if not self.visible then
local alwaysupdate = self.alwaysupdate if not self.alwaysupdate then
if not visible then
if not alwaysupdate then
return return
end end
end end
local parent = self.parent local parent = self.parent
local base = loveframes.base
local update = self.Update local update = self.Update
self:CheckHover() self:CheckHover()
-- move to parent if there is a parent -- move to parent if there is a parent
if parent ~= base then if parent ~= loveframes.base then
self.x = parent.x + self.staticx self.x = parent.x + self.staticx
self.y = parent.y + self.staticy self.y = parent.y + self.staticy
end end
@ -73,9 +69,7 @@ end
--]]--------------------------------------------------------- --]]---------------------------------------------------------
function newobject:draw() function newobject:draw()
local visible = self.visible if not self.visible then
if not visible then
return return
end end
@ -109,17 +103,12 @@ function newobject:mousepressed(x, y, button)
return return
end end
local hover = self.hover if self.hover and button == "l" then
if hover and button == "l" then
local baseparent = self:GetBaseParent() local baseparent = self:GetBaseParent()
if baseparent and baseparent.type == "frame" then if baseparent and baseparent.type == "frame" then
baseparent:MakeTop() baseparent:MakeTop()
end end
local parent1 = self:GetParent() self:GetParent():GetParent():SelectRow(self, loveframes.util.IsCtrlDown())
local parent2 = parent1:GetParent()
local ctrldown = loveframes.util.IsCtrlDown()
parent2:SelectRow(self, ctrldown)
end end
end end
@ -135,17 +124,16 @@ function newobject:mousereleased(x, y, button)
end end
if self.hover then if self.hover then
local parent1 = self:GetParent() local parent = self:GetParent():GetParent()
local parent2 = parent1:GetParent()
if button == "l" then if button == "l" then
local onrowclicked = parent2.OnRowClicked local onrowclicked = parent.OnRowClicked
if onrowclicked then if onrowclicked then
onrowclicked(parent2, self, self.columndata) onrowclicked(parent, self, self.columndata)
end end
elseif button == "r" then elseif button == "r" then
local onrowrightclicked = parent2.OnRowRightClicked local onrowrightclicked = parent.OnRowRightClicked
if onrowrightclicked then if onrowrightclicked then
onrowrightclicked(parent2, self, self.columndata) onrowrightclicked(parent, self, self.columndata)
end end
end end
end end