From 0b5cdb66977ecd8afb70d445eb392bf7c47f98ec Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Mon, 10 Jun 2013 12:34:01 -0400 Subject: [PATCH] Version 0.9.5.12 - Alpha (see changelog.txt) --- changelog.txt | 22 ++++ init.lua | 10 +- objects/base.lua | 3 + objects/columnlist.lua | 116 +++++++++++++++++- objects/internal/columnlist/columnlistrow.lua | 56 ++++++++- objects/list.lua | 6 +- skins/Blue/skin.lua | 34 ++++- skins/Orange/skin.lua | 34 ++++- util.lua | 27 +++- 9 files changed, 286 insertions(+), 22 deletions(-) diff --git a/changelog.txt b/changelog.txt index a06931c..f75f3c8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,25 @@ +================================================ +Version 0.9.5.12 - Alpha (June 10 - 2013) +================================================ +[ADDED] a new columnlist method: SelectRow(row, ctrl) +[ADDED] a new columnlist method: DeselectRow(row) +[ADDED] a new columnlist method: GetSelectedRows() +[ADDED] a new columnlist method: SetSelectionEnabled(bool) +[ADDED] a new columnlist method: GetSelectionEnabled() +[ADDED] a new columnlist method: SetMultiselectEnabled(bool) +[ADDED] a new columnlist method: GetMultiselectEnabled() +[ADDED] a new columnlistrow method: SetSelected(bool) +[ADDED] a new columnlistrow method: GetSelected() +[ADDED] a new columnlistrow method: SetColumnData(data) +[ADDED] a new columnlist event callback: OnRowRightClicked(parent, row, data) +[ADDED] a new columnlist event callback: OnRowSelected(parent, row, data) +[ADDED] a new util library function: GetCollisionCount() +[ADDED] a new util library function: GetHover() + +[CHANGED] the default mousewheel scroll-amount value for the list object +[CHANGED] the list object no longer uses delta time for scrolling by default +[CHANGED] some of the columnlistrow object's colors in the default skins + ================================================ Version 0.9.5.11 - Alpha (May 15 - 2013) ================================================ diff --git a/init.lua b/init.lua index 4ca009b..fbddbed 100644 --- a/init.lua +++ b/init.lua @@ -3,7 +3,6 @@ -- Copyright (c) 2013 Kenny Shields -- --]]------------------------------------------------ --- local path = ... -- central library table @@ -12,7 +11,7 @@ loveframes = {} -- library info loveframes.info = {} loveframes.info.author = "Kenny Shields" -loveframes.info.version = "0.9.5.11" +loveframes.info.version = "0.9.5.12" loveframes.info.stage = "Alpha" -- library configurations @@ -26,9 +25,11 @@ loveframes.config["DEBUG"] = false -- misc library vars loveframes.state = "none" loveframes.drawcount = 0 +loveframes.collisioncount = 0 loveframes.hoverobject = false loveframes.modalobject = false loveframes.inputobject = false +loveframes.hover = false loveframes.basicfont = love.graphics.newFont(12) loveframes.basicfontsmall = love.graphics.newFont(10) loveframes.objects = {} @@ -92,6 +93,9 @@ end function loveframes.update(dt) local base = loveframes.base + + loveframes.collisioncount = 0 + loveframes.hover = false base:update(dt) end @@ -239,7 +243,7 @@ function loveframes.Create(data, parent) -- to the current object for i, j in pairs(v) do if i ~= "children" and i ~= "func" then - if child == true then + if child then if i == "x" then object["staticx"] = j elseif i == "y" then diff --git a/objects/base.lua b/objects/base.lua index 76e4414..f5a8e19 100644 --- a/objects/base.lua +++ b/objects/base.lua @@ -732,10 +732,12 @@ function newobject:CheckHover() local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local hoverobject = loveframes.hoverobject local modalobject = loveframes.modalobject + local collisioncount = loveframes.collisioncount local clickbounds = self.clickbounds -- is the mouse inside the object? if selfcol then + loveframes.collisioncount = collisioncount + 1 local top = self:IsTopCollision() if top then if not hoverobject then @@ -773,6 +775,7 @@ function newobject:CheckHover() -- this chunk of code handles mouse enter and exit if self.hover then + loveframes.hover = true if not self.calledmousefunc then if self.OnMouseEnter then self.OnMouseEnter(self) diff --git a/objects/columnlist.lua b/objects/columnlist.lua index 6e22b54..7dfcabd 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -21,9 +21,13 @@ function newobject:initialize() self.autoscroll = false self.dtscrolling = true self.internal = false + self.selectionenabled = true + self.multiselect = false self.children = {} self.internals = {} self.OnRowClicked = nil + self.OnRowRightClicked = nil + self.OnRowSelected = nil self.OnScroll = nil local list = loveframes.objects["columnlistarea"]:new(self) @@ -159,7 +163,7 @@ function newobject:mousepressed(x, y, button) baseparent:MakeTop() end end - + for k, v in ipairs(internals) do v:mousepressed(x, y, button) end @@ -478,4 +482,114 @@ function newobject:GetDTScrolling() return self.dtscrolling +end + +--[[--------------------------------------------------------- + - func: SelectRow(row, ctrl) + - desc: selects the specfied row in the object's list + of rows +--]]--------------------------------------------------------- +function newobject:SelectRow(row, ctrl) + + local selectionenabled = self.selectionenabled + + if not selectionenabled then + return + end + + local list = self.internals[1] + local children = list.children + local multiselect = self.multiselect + local onrowselected = self.OnRowSelected + + for k, v in ipairs(children) do + if v == row then + if v.selected and ctrl then + v.selected = false + else + v.selected = true + if onrowselected then + onrowselected(self, row, row:GetColumnData()) + end + end + elseif v ~= row and not multiselect and not ctrl then + v.selected = false + end + end + +end + +--[[--------------------------------------------------------- + - func: DeselectRow(row) + - desc: deselects the specfied row in the object's list + of rows +--]]--------------------------------------------------------- +function newobject:DeselectRow(row) + + row.selected = false + +end + +--[[--------------------------------------------------------- + - func: GetSelectedRows() + - desc: gets the object's selected rows +--]]--------------------------------------------------------- +function newobject:GetSelectedRows() + + local rows = {} + local list = self.internals[1] + local children = list.children + + for k, v in ipairs(children) do + if v.selected then + table.insert(rows, v) + end + end + + return v + +end + +--[[--------------------------------------------------------- + - func: SetSelectionEnabled(bool) + - desc: sets whether or not the object's rows can be + selected +--]]--------------------------------------------------------- +function newobject:SetSelectionEnabled(bool) + + self.selectionenabled = bool + +end + +--[[--------------------------------------------------------- + - func: GetSelectionEnabled() + - desc: gets whether or not the object's rows can be + selected +--]]--------------------------------------------------------- +function newobject:GetSelectionEnabled() + + return self.selectionenabled + +end + +--[[--------------------------------------------------------- + - func: SetMultiselectEnabled(bool) + - desc: sets whether or not the object can have more + than one row selected +--]]--------------------------------------------------------- +function newobject:SetMultiselectEnabled(bool) + + self.multiselect = bool + +end + +--[[--------------------------------------------------------- + - func: GetMultiselectEnabled() + - desc: gets whether or not the object can have more + than one row selected +--]]--------------------------------------------------------- +function newobject:GetMultiselectEnabled() + + return self.multiselect + end \ No newline at end of file diff --git a/objects/internal/columnlist/columnlistrow.lua b/objects/internal/columnlist/columnlistrow.lua index 39c8ebb..886ea0f 100644 --- a/objects/internal/columnlist/columnlistrow.lua +++ b/objects/internal/columnlist/columnlistrow.lua @@ -20,6 +20,7 @@ function newobject:initialize(parent, data) self.height = 25 self.textx = 5 self.texty = 5 + self.selected = false self.internal = true self.columndata = data @@ -69,7 +70,7 @@ function newobject:draw() local visible = self.visible - if visible == false then + if not visible then return end @@ -103,11 +104,17 @@ function newobject:mousepressed(x, y, button) return end - if self.hover and button == "l" then + local hover = self.hover + + if hover and button == "l" then local baseparent = self:GetBaseParent() if baseparent and baseparent.type == "frame" then baseparent:MakeTop() end + local parent1 = self:GetParent() + local parent2 = parent1:GetParent() + local ctrldown = love.keyboard.isDown("lctrl") + parent2:SelectRow(self, ctrldown) end end @@ -122,12 +129,19 @@ function newobject:mousereleased(x, y, button) return end - if self.hover and button == "l" then + if self.hover then local parent1 = self:GetParent() local parent2 = parent1:GetParent() - local onrowclicked = parent2.OnRowClicked - if onrowclicked then - onrowclicked(parent2, self, self.columndata) + if button == "l" then + local onrowclicked = parent2.OnRowClicked + if onrowclicked then + onrowclicked(parent2, self, self.columndata) + end + elseif button == "r" then + local onrowrightclicked = parent2.OnRowRightClicked + if onrowrightclicked then + onrowrightclicked(parent2, self, self.columndata) + end end end @@ -194,6 +208,16 @@ function newobject:GetColorIndex() end +--[[--------------------------------------------------------- + - func: SetColumnData(data) + - desc: sets the object's column data +--]]--------------------------------------------------------- +function newobject:SetColumnData(data) + + self.columndata = data + +end + --[[--------------------------------------------------------- - func: GetColumnData() - desc: gets the object's column data @@ -202,4 +226,24 @@ function newobject:GetColumnData() return self.columndata +end + +--[[--------------------------------------------------------- + - func: SetSelected(selected) + - desc: sets whether or not the object is selected +--]]--------------------------------------------------------- +function newobject:SetSelected(selected) + + self.selected = true + +end + +--[[--------------------------------------------------------- + - func: GetSelected() + - desc: gets whether or not the object is selected +--]]--------------------------------------------------------- +function newobject:GetSelected() + + return self.selected + end \ No newline at end of file diff --git a/objects/list.lua b/objects/list.lua index 6284bc3..b733b1c 100644 --- a/objects/list.lua +++ b/objects/list.lua @@ -24,14 +24,14 @@ function newobject:initialize() self.offsetx = 0 self.extrawidth = 0 self.extraheight = 0 - self.buttonscrollamount = 200 - self.mousewheelscrollamount = 1500 + self.buttonscrollamount = 0.10 + self.mousewheelscrollamount = 10 self.internal = false self.hbar = false self.vbar = false self.autoscroll = false self.horizontalstacking = false - self.dtscrolling = true + self.dtscrolling = false self.internals = {} self.children = {} self.OnScroll = nil diff --git a/skins/Blue/skin.lua b/skins/Blue/skin.lua index 987b724..bd1f54b 100644 --- a/skins/Blue/skin.lua +++ b/skins/Blue/skin.lua @@ -115,9 +115,13 @@ skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} skin.controls.columnlistheader_text_font = smallfont -- columnlistrow -skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} -skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_body1_color = {245, 245, 245, 255} +skin.controls.columnlistrow_body2_color = {255, 255, 255, 255} +skin.controls.columnlistrow_body_selected_color = {26, 198, 255, 255} +skin.controls.columnlistrow_body_hover_color = {102, 217, 255, 255} skin.controls.columnlistrow_text_color = {100, 100, 100, 255} +skin.controls.columnlistrow_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistrow_text_selected_color = {255, 255, 255, 255} -- modalbackground skin.controls.modalbackground_body_color = {255, 255, 255, 100} @@ -1395,13 +1399,29 @@ function skin.DrawColumnListRow(object) local parent = object:GetParent() local cwidth, cheight = parent:GetParent():GetColumnSize() local theight = font:getHeight("a") + local hover = object:GetHover() + local selected = object:GetSelected() local body1color = skin.controls.columnlistrow_body1_color local body2color = skin.controls.columnlistrow_body2_color + local bodyhovercolor = skin.controls.columnlistrow_body_hover_color + local bodyselectedcolor = skin.controls.columnlistrow_body_selected_color local textcolor = skin.controls.columnlistrow_text_color + local texthovercolor = skin.controls.columnlistrow_text_hover_color + local textselectedcolor = skin.controls.columnlistrow_text_selected_color object:SetTextPos(5, height/2 - theight/2) - if colorindex == 1 then + if selected then + love.graphics.setColor(bodyselectedcolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + elseif colorindex == 1 then love.graphics.setColor(body1color) love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) love.graphics.setColor(bordercolor) @@ -1415,7 +1435,13 @@ function skin.DrawColumnListRow(object) for k, v in ipairs(columndata) do love.graphics.setFont(font) - love.graphics.setColor(textcolor) + if selected then + love.graphics.setColor(textselectedcolor) + elseif hover then + love.graphics.setColor(texthovercolor) + else + love.graphics.setColor(textcolor) + end love.graphics.print(v, x + textx, y + texty) x = x + cwidth end diff --git a/skins/Orange/skin.lua b/skins/Orange/skin.lua index 0a7eb7d..aef546f 100644 --- a/skins/Orange/skin.lua +++ b/skins/Orange/skin.lua @@ -115,9 +115,13 @@ skin.controls.columnlistheader_text_hover_color = {255, 255, 255, 255} skin.controls.columnlistheader_text_font = smallfont -- columnlistrow -skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} -skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +skin.controls.columnlistrow_body1_color = {245, 245, 245, 255} +skin.controls.columnlistrow_body2_color = {255, 255, 255, 255} +skin.controls.columnlistrow_body_selected_color = {255, 153, 0, 255} +skin.controls.columnlistrow_body_hover_color = {255, 173, 51, 255} skin.controls.columnlistrow_text_color = {100, 100, 100, 255} +skin.controls.columnlistrow_text_hover_color = {255, 255, 255, 255} +skin.controls.columnlistrow_text_selected_color = {255, 255, 255, 255} -- modalbackground skin.controls.modalbackground_body_color = {255, 255, 255, 100} @@ -1395,13 +1399,29 @@ function skin.DrawColumnListRow(object) local parent = object:GetParent() local cwidth, cheight = parent:GetParent():GetColumnSize() local theight = font:getHeight("a") + local hover = object:GetHover() + local selected = object:GetSelected() local body1color = skin.controls.columnlistrow_body1_color local body2color = skin.controls.columnlistrow_body2_color + local bodyhovercolor = skin.controls.columnlistrow_body_hover_color + local bodyselectedcolor = skin.controls.columnlistrow_body_selected_color local textcolor = skin.controls.columnlistrow_text_color + local texthovercolor = skin.controls.columnlistrow_text_hover_color + local textselectedcolor = skin.controls.columnlistrow_text_selected_color object:SetTextPos(5, height/2 - theight/2) - if colorindex == 1 then + if selected then + love.graphics.setColor(bodyselectedcolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + elseif hover then + love.graphics.setColor(bodyhovercolor) + love.graphics.rectangle("fill", x, y, width, height) + love.graphics.setColor(bordercolor) + skin.OutlinedRectangle(x, y, width, height, true, false, true, true) + elseif colorindex == 1 then love.graphics.setColor(body1color) love.graphics.rectangle("fill", x + 1, y + 1, width - 2, height - 2) love.graphics.setColor(bordercolor) @@ -1415,7 +1435,13 @@ function skin.DrawColumnListRow(object) for k, v in ipairs(columndata) do love.graphics.setFont(font) - love.graphics.setColor(textcolor) + if selected then + love.graphics.setColor(textselectedcolor) + elseif hover then + love.graphics.setColor(texthovercolor) + else + love.graphics.setColor(textcolor) + end love.graphics.print(v, x + textx, y + texty) x = x + cwidth end diff --git a/util.lua b/util.lua index fcd34ba..ad43075 100644 --- a/util.lua +++ b/util.lua @@ -268,4 +268,29 @@ function loveframes.util.Error(message) error("[Love Frames] " ..message) -end \ No newline at end of file +end + +--[[--------------------------------------------------------- + - func: loveframes.util.GetCollisionCount() + - desc: gets the total number of objects colliding with + the mouse +--]]--------------------------------------------------------- +function loveframes.util.GetCollisionCount() + + local collisioncount = loveframes.collisioncount + return collisioncount + +end + +--[[--------------------------------------------------------- + - func: loveframes.util.GetHover() + - desc: returns loveframes.hover, can be used to check + if the mouse is colliding with a visible + Love Frames object +--]]--------------------------------------------------------- +function loveframes.util.GetHover() + + return loveframes.hover + +end + \ No newline at end of file