2013-02-11 21:15:40 +00:00
|
|
|
--[[------------------------------------------------
|
|
|
|
-- Love Frames - A GUI library for LOVE --
|
2014-01-14 11:29:11 +00:00
|
|
|
-- Copyright (c) 2012-2014 Kenny Shields --
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]------------------------------------------------
|
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
return function(loveframes)
|
|
|
|
---------- module start ----------
|
2014-10-23 22:36:16 +00:00
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
-- tooltip clas
|
|
|
|
local newobject = loveframes.NewObject("tooltip", "loveframes_object_tooltip", true)
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: initialize()
|
|
|
|
- desc: initializes the object
|
|
|
|
--]]---------------------------------------------------------
|
2013-09-14 15:37:01 +00:00
|
|
|
function newobject:initialize(object, text)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
self.type = "tooltip"
|
|
|
|
self.parent = loveframes.base
|
|
|
|
self.object = object or nil
|
2013-09-14 15:37:01 +00:00
|
|
|
self.width = 0
|
2013-02-11 21:15:40 +00:00
|
|
|
self.height = 0
|
|
|
|
self.padding = 5
|
|
|
|
self.xoffset = 10
|
|
|
|
self.yoffset = -10
|
|
|
|
self.internal = true
|
|
|
|
self.followcursor = true
|
|
|
|
self.followobject = false
|
|
|
|
self.alwaysupdate = true
|
2013-09-14 15:37:01 +00:00
|
|
|
self.internals = {}
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- create the object's text
|
2013-09-14 15:37:01 +00:00
|
|
|
local textobject = loveframes.Create("text")
|
|
|
|
textobject:Remove()
|
|
|
|
textobject.parent = self
|
|
|
|
textobject:SetText(text or "")
|
|
|
|
textobject:SetPos(0, 0)
|
|
|
|
table.insert(self.internals, textobject)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
-- apply template properties to the object
|
2019-03-06 23:19:58 +00:00
|
|
|
loveframes.ApplyTemplatesToObject(self)
|
2013-02-11 21:15:40 +00:00
|
|
|
table.insert(loveframes.base.internals, self)
|
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
self:SetDrawFunc()
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: update(deltatime)
|
|
|
|
- desc: updates the object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:update(dt)
|
|
|
|
|
|
|
|
local state = loveframes.state
|
|
|
|
local selfstate = self.state
|
|
|
|
|
|
|
|
if state ~= selfstate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local visible = self.visible
|
|
|
|
local alwaysupdate = self.alwaysupdate
|
|
|
|
|
|
|
|
if not visible then
|
|
|
|
if not alwaysupdate then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
local padding = self.padding
|
2013-02-11 21:15:40 +00:00
|
|
|
local object = self.object
|
|
|
|
local draworder = self.draworder
|
|
|
|
local update = self.Update
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
self.width = textobject.width + padding * 2
|
|
|
|
self.height = textobject.height + padding * 2
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
if object then
|
|
|
|
if object == loveframes.base then
|
|
|
|
self:Remove()
|
|
|
|
return
|
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
--local ovisible = object.visible
|
2013-02-11 21:15:40 +00:00
|
|
|
local ohover = object.hover
|
|
|
|
local ostate = object.state
|
|
|
|
if ostate ~= state then
|
|
|
|
self.visible = false
|
|
|
|
return
|
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
self.visible = ohover
|
|
|
|
if ohover then
|
2013-02-11 21:15:40 +00:00
|
|
|
local top = self:IsTopInternal()
|
|
|
|
local followcursor = self.followcursor
|
|
|
|
local followobject = self.followobject
|
2013-09-14 15:37:01 +00:00
|
|
|
local xoffset = self.xoffset
|
|
|
|
local yoffset = self.yoffset
|
2013-02-11 21:15:40 +00:00
|
|
|
if followcursor then
|
2013-09-14 15:37:01 +00:00
|
|
|
local height = self.height
|
|
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
self.x = mx + xoffset
|
|
|
|
self.y = my - height + yoffset
|
2013-02-11 21:15:40 +00:00
|
|
|
elseif followobject then
|
2013-09-14 15:37:01 +00:00
|
|
|
local ox = object.x
|
|
|
|
local oy = object.y
|
|
|
|
self.x = ox + xoffset
|
|
|
|
self.y = oy + yoffset
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
if not top then
|
|
|
|
self:MoveToTop()
|
|
|
|
end
|
2013-09-14 15:37:01 +00:00
|
|
|
textobject:SetPos(padding, padding)
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-06 23:19:58 +00:00
|
|
|
--textobject:SetVisible(self.show)
|
2013-09-14 15:37:01 +00:00
|
|
|
textobject:SetState(selfstate)
|
|
|
|
textobject:update(dt)
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
if update then
|
|
|
|
update(self, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFollowCursor(bool)
|
|
|
|
- desc: sets whether or not the tooltip should follow the
|
|
|
|
cursor
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetFollowCursor(bool)
|
|
|
|
|
|
|
|
self.followcursor = bool
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-01-15 15:21:25 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFollowCursor()
|
|
|
|
- desc: gets whether or not the tooltip should follow the
|
|
|
|
cursor
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetFollowCursor()
|
|
|
|
|
|
|
|
return self.followcursor
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetObject(object)
|
|
|
|
- desc: sets the tooltip's object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetObject(object)
|
|
|
|
|
|
|
|
self.object = object
|
|
|
|
self.x = object.x
|
|
|
|
self.y = object.y
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
2014-01-15 15:27:33 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetObject()
|
|
|
|
- desc: gets the tooltip's object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetObject()
|
|
|
|
|
|
|
|
return self.object
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetText(text)
|
|
|
|
- desc: sets the tooltip's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetText(text)
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
|
|
|
|
textobject:SetText(text)
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-09-14 15:37:01 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetText()
|
|
|
|
- desc: gets the tooltip's text
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetText()
|
|
|
|
|
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
local text = textobject:GetText()
|
|
|
|
|
|
|
|
return text
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetTextMaxWidth(text)
|
|
|
|
- desc: sets the tooltip's text max width
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetTextMaxWidth(width)
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
|
|
|
|
textobject:SetMaxWidth(width)
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-09-14 15:37:01 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetOffsetX(xoffset)
|
|
|
|
- desc: sets the tooltip's x offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetOffsetX(xoffset)
|
|
|
|
|
|
|
|
self.xoffset = xoffset
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-09-14 15:37:01 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-01-14 11:17:23 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetOffsetX()
|
|
|
|
- desc: gets the tooltip's x offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetOffsetX()
|
|
|
|
|
|
|
|
return self.xoffset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetOffsetY(yoffset)
|
|
|
|
- desc: sets the tooltip's y offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetOffsetY(yoffset)
|
|
|
|
|
|
|
|
self.yoffset = yoffset
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-01-14 11:17:23 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetOffsetY()
|
|
|
|
- desc: gets the tooltip's y offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetOffsetY()
|
|
|
|
|
|
|
|
return self.yoffset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetOffsets(xoffset, yoffset)
|
|
|
|
- desc: sets the tooltip's x and y offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetOffsets(xoffset, yoffset)
|
|
|
|
|
|
|
|
self.xoffset = xoffset
|
|
|
|
self.yoffset = yoffset
|
|
|
|
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
end
|
|
|
|
|
2014-01-14 11:19:51 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetOffsets()
|
|
|
|
- desc: gets the tooltip's x and y offset
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetOffsets()
|
|
|
|
|
|
|
|
return self.xoffset, self.yoffset
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetPadding(padding)
|
|
|
|
- desc: sets the tooltip's padding
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetPadding(padding)
|
|
|
|
|
|
|
|
self.padding = padding
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-02-11 12:35:00 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetPadding()
|
|
|
|
- desc: gets the tooltip's padding
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetPadding()
|
|
|
|
|
|
|
|
return self.padding
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFont(font)
|
|
|
|
- desc: sets the tooltip's font
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetFont(font)
|
|
|
|
|
2013-09-14 15:37:01 +00:00
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
|
|
|
|
textobject:SetFont(font)
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-01-15 15:35:30 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFont()
|
|
|
|
- desc: gets the tooltip's font
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetFont()
|
|
|
|
|
|
|
|
local internals = self.internals
|
|
|
|
local textobject = internals[1]
|
|
|
|
|
|
|
|
return textobject:GetFont()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-02-11 21:15:40 +00:00
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: SetFollowObject(bool)
|
|
|
|
- desc: sets whether or not the tooltip should follow
|
2013-03-23 19:50:44 +00:00
|
|
|
its assigned object
|
2013-02-11 21:15:40 +00:00
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:SetFollowObject(bool)
|
|
|
|
|
|
|
|
self.followobject = bool
|
2014-02-11 12:34:07 +00:00
|
|
|
return self
|
2013-02-11 21:15:40 +00:00
|
|
|
|
2014-01-15 15:53:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
--[[---------------------------------------------------------
|
|
|
|
- func: GetFollowObject()
|
|
|
|
- desc: gets whether or not the tooltip should follow
|
|
|
|
its assigned object
|
|
|
|
--]]---------------------------------------------------------
|
|
|
|
function newobject:GetFollowObject()
|
|
|
|
|
|
|
|
return self.followobject
|
|
|
|
|
2014-11-09 21:24:10 +00:00
|
|
|
end
|
2019-03-06 23:19:58 +00:00
|
|
|
|
|
|
|
---------- module end ----------
|
|
|
|
end
|