2012-09-02 00:56:32 +00:00
|
|
|
--[[------------------------------------------------
|
2012-09-29 23:20:41 +00:00
|
|
|
-- Love Frames - A GUI library for LOVE --
|
|
|
|
-- Copyright (c) 2012 Kenny Shields --
|
2012-09-02 00:56:32 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
|
|
|
-- tooltip clas
|
2012-11-24 22:42:16 +00:00
|
|
|
local newobject = loveframes.NewObject("tooltip", "loveframes_object_tooltip", true)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:initialize(object, text, width)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
local width = width or 0
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
self.type = "tooltip"
|
|
|
|
self.parent = loveframes.base
|
|
|
|
self.object = object or nil
|
|
|
|
self.width = width or 0
|
|
|
|
self.height = 0
|
|
|
|
self.padding = 5
|
|
|
|
self.xoffset = 10
|
|
|
|
self.yoffset = -10
|
|
|
|
self.internal = true
|
|
|
|
self.show = false
|
|
|
|
self.followcursor = true
|
|
|
|
self.alwaysupdate = true
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.text = loveframes.Create("text")
|
|
|
|
self.text:Remove()
|
|
|
|
self.text.parent = self
|
|
|
|
self.text:SetText(text or "")
|
|
|
|
self.text:SetWidth(width or 0)
|
|
|
|
self.text:SetPos(0, 0)
|
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- apply template properties to the object
|
|
|
|
loveframes.templates.ApplyToObject(self)
|
|
|
|
|
2012-09-02 00:56:32 +00:00
|
|
|
table.insert(loveframes.base.internals, self)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:update(dt)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local visible = self.visible
|
2012-09-02 00:56:32 +00:00
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local text = self.text
|
|
|
|
local object = self.object
|
2012-09-02 00:56:32 +00:00
|
|
|
local draworder = self.draworder
|
2012-09-29 23:20:41 +00:00
|
|
|
local update = self.Update
|
|
|
|
|
|
|
|
self.width = text.width + self.padding * 2
|
|
|
|
self.height = text.height + self.padding * 2
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
if object then
|
|
|
|
|
|
|
|
if object == loveframes.base then
|
|
|
|
self:Remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local hover = object.hover
|
2012-09-02 00:56:32 +00:00
|
|
|
local odraworder = object.draworder
|
2012-09-29 23:20:41 +00:00
|
|
|
local ovisible = object.visible
|
|
|
|
local ohover = object.hover
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
self.show = ohover
|
|
|
|
self.visible = ovisible
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if ohover and ovisible then
|
2012-09-02 00:56:32 +00:00
|
|
|
local top = self:IsTopInternal()
|
2012-09-29 23:20:41 +00:00
|
|
|
if self.followcursor then
|
2012-09-02 00:56:32 +00:00
|
|
|
local x, y = love.mouse.getPosition()
|
|
|
|
self.x = x + self.xoffset
|
|
|
|
self.y = y - self.height + self.yoffset
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not top then
|
2012-09-02 00:56:32 +00:00
|
|
|
self:MoveToTop()
|
|
|
|
end
|
|
|
|
|
|
|
|
text:SetPos(self.padding, self.padding)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local baseparent = object:GetBaseParent()
|
|
|
|
|
|
|
|
if baseparent then
|
2012-09-29 23:20:41 +00:00
|
|
|
if baseparent.removed and baseparent.removed then
|
2012-09-02 00:56:32 +00:00
|
|
|
self:Remove()
|
|
|
|
end
|
|
|
|
elseif object.removed then
|
|
|
|
self:Remove()
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
text:update(dt)
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if update then
|
|
|
|
update(self, dt)
|
2012-09-02 00:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: draw()
|
|
|
|
- desc: draws the object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:draw()
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if not visible then
|
2012-09-02 00:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
local show = self.show
|
|
|
|
local text = self.text
|
|
|
|
local skins = loveframes.skins.available
|
|
|
|
local skinindex = loveframes.config["ACTIVESKIN"]
|
|
|
|
local defaultskin = loveframes.config["DEFAULTSKIN"]
|
|
|
|
local selfskin = self.skin
|
|
|
|
local skin = skins[selfskin] or skins[skinindex]
|
|
|
|
local drawfunc = skin.DrawToolTip or skins[defaultskin].DrawToolTip
|
|
|
|
local draw = self.Draw
|
|
|
|
local drawcount = loveframes.drawcount
|
|
|
|
|
2012-10-22 14:19:02 +00:00
|
|
|
-- set the object's draw order
|
|
|
|
self:SetDrawOrder()
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if show then
|
2012-09-02 00:56:32 +00:00
|
|
|
|
2012-09-29 23:20:41 +00:00
|
|
|
if draw then
|
|
|
|
draw(self)
|
2012-09-02 00:56:32 +00:00
|
|
|
else
|
|
|
|
drawfunc(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
text:draw()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFollowCursor(bool)
|
|
|
|
- desc: sets whether or not the tooltip should follow the
|
|
|
|
cursor
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetFollowCursor(bool)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.followcursor = bool
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetObject(object)
|
|
|
|
- desc: sets the tooltip's object
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetObject(object)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.object = object
|
2012-12-20 04:00:19 +00:00
|
|
|
self.x = object.x
|
|
|
|
self.y = object.y
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the tooltip's text
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetText(text)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.text:SetText(text)
|
|
|
|
self.text2 = text
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetTextMaxWidth(text)
|
|
|
|
- desc: sets the tooltip's text max width
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetTextMaxWidth(width)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.text:SetMaxWidth(width)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetOffsets(xoffset, yoffset)
|
|
|
|
- desc: sets the tooltip's x and y offset
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetOffsets(xoffset, yoffset)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.xoffset = xoffset
|
|
|
|
self.yoffset = yoffset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetPadding(padding)
|
|
|
|
- desc: sets the tooltip's padding
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetPadding(padding)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.padding = padding
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFont(font)
|
|
|
|
- desc: sets the tooltip's font
|
|
|
|
--]]---------------------------------------------------------
|
2012-11-24 22:42:16 +00:00
|
|
|
function newobject:SetFont(font)
|
2012-09-02 00:56:32 +00:00
|
|
|
|
|
|
|
self.text:SetFont(font)
|
|
|
|
|
2012-05-06 00:24:42 +00:00
|
|
|
end
|