tibia-client/modules/tooltip/tooltip.lua

53 lines
1.2 KiB
Lua
Raw Normal View History

2011-11-03 20:07:07 +01:00
ToolTip = {}
-- private variables
local currentToolTip
-- private functions
local function moveToolTip(tooltip)
local pos = getMouseCursorPos()
pos.y = pos.y + 1
local xdif = getScreenSize().width - (pos.x + tooltip:getWidth())
if xdif < 2 then
pos.x = pos.x - tooltip:getWidth() - 3
else
pos.x = pos.x + 10
end
tooltip:moveTo(pos)
end
2011-11-03 23:28:10 +01:00
local function onButtonHoverChange(button, hovered)
if hovered then
ToolTip.display(button:getStyle().tooltip)
else
ToolTip:hide()
end
end
2011-11-03 20:07:07 +01:00
-- public functions
function ToolTip.display(text)
ToolTip.hide()
if text then
2011-11-03 23:28:10 +01:00
currentToolTip = UI.loadAndDisplay('/tooltip/tooltip.otui', UI.root)
2011-11-03 20:07:07 +01:00
currentToolTip.onMouseMove = moveToolTip
local label = currentToolTip:getChildById('toolTipText')
label:setText(text)
label:resizeToText()
local size = label:getSize()
size.width = size.width + 4
size.height = size.height + 4
currentToolTip:setSize(size)
2011-11-03 20:32:50 +01:00
moveToolTip(currentToolTip)
2011-11-03 20:07:07 +01:00
end
end
function ToolTip.hide()
if currentToolTip then
currentToolTip:destroy()
currentToolTip = nil
end
end
2011-11-03 23:28:10 +01:00
-- hooks
connect(UIButton, { onHoverChange = onButtonHoverChange})