Add functionality for selecting tree nodes

This commit is contained in:
Kenny Shields 2014-07-05 23:15:51 -04:00
parent 4710c44bb7
commit 53894a743c
3 changed files with 22 additions and 7 deletions

View File

@ -152,6 +152,10 @@ function newobject:mousepressed(x, y, button)
v:mousepressed(x, y, button) v:mousepressed(x, y, button)
end end
if self.hover and button == "l" then
self.tree.selectednode = self
end
end end
--[[--------------------------------------------------------- --[[---------------------------------------------------------

View File

@ -25,6 +25,7 @@ function newobject:initialize()
self.vbar = false self.vbar = false
self.hbar = false self.hbar = false
self.internal = false self.internal = false
self.selectednode = false
self.children = {} self.children = {}
self.internals = {} self.internals = {}

View File

@ -1783,15 +1783,25 @@ function skin.DrawTreeNode(object)
leftpadding = buttonimage:getWidth() + 5 leftpadding = buttonimage:getWidth() + 5
end end
local iconwidth
if icon then if icon then
local iconwidth = icon:getWidth() iconwidth = icon:getWidth()
end
local twidth = loveframes.basicfont:getWidth(object.text)
local theight = loveframes.basicfont:getHeight(object.text)
if object.tree.selectednode == object then
love.graphics.setColor(102, 140, 255, 255)
love.graphics.rectangle("fill", x + leftpadding + 2 + iconwidth, object.y + 2, twidth, theight)
end
width = width + iconwidth + loveframes.basicfont:getWidth(object.text) + leftpadding width = width + iconwidth + loveframes.basicfont:getWidth(object.text) + leftpadding
love.graphics.setColor(255, 255, 255, 255) love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(icon, x + leftpadding, object.y) love.graphics.draw(icon, x + leftpadding, object.y)
love.graphics.setFont(loveframes.basicfont) love.graphics.setFont(loveframes.basicfont)
love.graphics.setColor(0, 0, 0, 255) love.graphics.setColor(0, 0, 0, 255)
love.graphics.print(object.text, x + leftpadding + 2 + iconwidth, object.y + 2) love.graphics.print(object.text, x + leftpadding + 2 + iconwidth, object.y + 2)
end
object:SetWidth(width + 5) object:SetWidth(width + 5)