Hello, I'm looking to anchor tooltips to mouse.
I want them to anchor to the mouse cursor at their bottom-right corner.
Exactly like this, pretty much:
The addon TipTac can do what I want, but it has lots and lots of other features that I really don't want (along with some stuff that just causes issues in general), so I'm trying to extract the code responsible for re-anchoring the tooltips, so I can have an addon that -only- re-anchors the tooltips, and nothing else.
Looking at TipTac's code, I've found that those are the functions for it:
Code:
-- Function to loop through tips to modify and hook
function tt:HookTips()
-- Need to be called as late as possible during load, as we want to try and be the last addon to hook "OnTooltipSetUnit" so we always have a "completed" tip to work on
gtt:HookScript("OnShow",GTTHook_OnShow);
gtt:HookScript("OnUpdate",GTTHook_OnUpdate);
gtt:HookScript("OnTooltipSetUnit",GTTHook_OnTooltipSetUnit);
gtt:HookScript("OnTooltipCleared",GTTHook_OnTooltipCleared);
-- HOOK: OnHide & OnTooltipSetItem Scripts
for index, tipName in ipairs(TT_TipsToModify) do
local tip = (_G[tipName] or false); -- don't want to nil out an entry
-- Here we make sure not to add duplicate items. This can happen for thing like AtlasLoot, which sets AtlasLootTooltip = GameTooltip
if (tip) then
for i = 1, index - 1 do
if (tip == TT_TipsToModify[i]) then
tip = false;
break;
end
end
end
-- Set string index to table or false
TT_TipsToModify[index] = tip;
if (type(tip) == "table") and (type(tip.GetObjectType) == "function") then
tip:HookScript("OnHide",TipHook_OnHide);
end
end
-- Replace GameTooltip_SetDefaultAnchor (For Re-Anchoring) -- Patch 3.2 made this function secure for some reason
hooksecurefunc("GameTooltip_SetDefaultAnchor",function(tooltip,parent)
-- Return if no tooltip or parent
if (not tooltip or not parent) then
return;
end
-- Position Tip to Normal, Mouse or Parent anchor
gtt_anchorType, gtt_anchorPoint = GetAnchorPosition();
tooltip:SetOwner(parent,"ANCHOR_NONE");
tooltip:ClearAllPoints();
if (gtt_anchorType == "mouse") then
tt:AnchorFrameToMouse(tooltip);
elseif (gtt_anchorType == "parent") then
tooltip:SetPoint(TT_MirrorAnchorsSmart[gtt_anchorPoint] or TT_MirrorAnchors[gtt_anchorPoint],parent,gtt_anchorPoint);
else
tooltip:SetPoint(gtt_anchorPoint,tt);
end
tooltip.default = 1;
end);
-- Clear this function as it's not needed anymore
self.HookTips = nil;
end
Code:
-- Anchor any given frame to mouse position
function tt:AnchorFrameToMouse(frame)
local x, y = GetCursorPosition();
local effScale = frame:GetEffectiveScale();
frame:ClearAllPoints();
frame:SetPoint(gtt_anchorPoint,UIParent,"BOTTOMLEFT",(x / effScale + cfg.mouseOffsetX),(y / effScale + cfg.mouseOffsetY));
end
I've pruned out the stuff I didn't need, and came up with this:
Code:
local function AnchorFrameToMouse(frame)
local x, y = GetCursorPosition()
local effScale = frame:GetEffectiveScale()
frame:ClearAllPoints()
frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMLEFT", (x / effScale), (y / effScale))
end
hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip, parent)
tooltip:SetOwner(parent, "ANCHOR_CURSOR")
tooltip:ClearAllPoints()
AnchorFrameToMouse(tooltip)
tooltip.default = 1
end)
Actually works surprisingly well, I'm somehow not getting that bug where tooltips appear for a split second at their previous location before jumping over to my mouse (was always struggling with that every time I tried to anchor tooltip to mouse).
The tooltips show up at my cursor's location when I mouse over something and they instantly hide when I move it away, which is good because I don't want any fadeout timer stuff, I want it to disappear right away when I mouse away.
There's one problem, though. When I move my cursor around, the tooltip follows my cursor on the X-axis, but its Y positioning doesn't update, and I really have no idea why it does that.
https://gfycat.com/SoggyDenseFlamingo
I feel like I must be missing something really obvious, but what?
Any help would be appreciated. :s
Edit: I just figured out that if I set the anchor to just "BOTTOM" instead of "BOTTOMRIGHT", things work as expected, except of course my cursor is at the bottom-center of my tooltip instead of bottom-right like I want it.