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)
end
if self.hover and button == "l" then
self.tree.selectednode = self
end
end
--[[---------------------------------------------------------

View File

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

View File

@ -1783,16 +1783,26 @@ function skin.DrawTreeNode(object)
leftpadding = buttonimage:getWidth() + 5
end
local iconwidth
if icon then
local iconwidth = icon:getWidth()
width = width + iconwidth + loveframes.basicfont:getWidth(object.text) + leftpadding
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(icon, x + leftpadding, object.y)
love.graphics.setFont(loveframes.basicfont)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print(object.text, x + leftpadding + 2 + iconwidth, object.y + 2)
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
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(icon, x + leftpadding, object.y)
love.graphics.setFont(loveframes.basicfont)
love.graphics.setColor(0, 0, 0, 255)
love.graphics.print(object.text, x + leftpadding + 2 + iconwidth, object.y + 2)
object:SetWidth(width + 5)
end