Quantcast
Download
(988 b)
Download
Updated: 08-15-18 02:48 PM
Pictures
File Info
Compatibility:
Battle for Azeroth (8.0.1)
Updated:08-15-18 02:48 PM
Created:03-02-18 10:15 PM
Downloads:931
Favorites:2
MD5:

Anchor Tooltip to Mouse

Version: 1.2
by: Ammako [More]

This changes the anchor point of world object tooltips to the cursor, following the mouse cursor around. Interface tooltips keep their default position.

Also makes tooltips disappear instantly when you mouse away rather than slowly fading away.


Includes a quick fix to the background color of tooltips sometimes screwing up a little bit (not sure how relevant this is nowadays, but it doesn't appear break anything so I'm leaving it in.)

2018/08/15
- Changed a thing to make Azerite items tooltip backdrop color behave better.

2018/07/25
- Changed an OnUpdate to OnShow, because it turns out it works just the same but is much more efficient.
Post A Reply Comment Options
Unread 06-09-18, 03:52 PM  
Ammako
A Frostmaul Preserver
AddOn Author - Click to view AddOns

Forum posts: 256
File comments: 25
Uploads: 8
I noticed strange behavior on world object tooltips where the tooltip appears at bottom-middle before immediately anchoring back over to bottom-right, I can fix that by also running that function OnShow once before letting OnUpdate take over.

lua Code:
  1. GameTooltip:HookScript("OnUpdate", function() GameTooltip:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b, 1) end)
  2. hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end)
  3.  
  4. local function AnchorFrameToMouse(frame)
  5.     local x, y = GetCursorPosition()
  6.     local effScale = frame:GetEffectiveScale()
  7.     frame:ClearAllPoints()
  8.     frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMLEFT", (x / effScale), (y / effScale))
  9. end
  10.  
  11. hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip, parent)
  12.     if GetMouseFocus() ~= WorldFrame then return end
  13.     tooltip:SetOwner(parent, "ANCHOR_CURSOR")
  14.     AnchorFrameToMouse(tooltip)
  15.     tooltip.default = 1
  16. end)
  17.  
  18. GameTooltip:HookScript("OnShow", function(self, elapsed)
  19.     if GetMouseFocus() ~= WorldFrame then return end
  20.     AnchorFrameToMouse(self)
  21. end)
  22.  
  23. GameTooltip:HookScript("OnUpdate", function(self, elapsed)
  24.     if GetMouseFocus() ~= WorldFrame then return end
  25.     AnchorFrameToMouse(self)
  26. end)
Report comment to moderator  
Reply With Quote
Unread 06-09-18, 02:07 AM  
Ammako
A Frostmaul Preserver
AddOn Author - Click to view AddOns

Forum posts: 256
File comments: 25
Uploads: 8
I really hate this, but it works:

lua Code:
  1. GameTooltip:HookScript("OnUpdate", function() GameTooltip:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b, 1) end)
  2. hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end)
  3.  
  4. local function AnchorFrameToMouse(frame)
  5.     local x, y = GetCursorPosition()
  6.     local effScale = frame:GetEffectiveScale()
  7.     frame:ClearAllPoints()
  8.     frame:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMLEFT", (x / effScale), (y / effScale))
  9. end
  10.  
  11. hooksecurefunc("GameTooltip_SetDefaultAnchor", function(tooltip, parent)
  12.     if GetMouseFocus() ~= WorldFrame then return end
  13.     tooltip:SetOwner(parent, "ANCHOR_CURSOR")
  14.     AnchorFrameToMouse(tooltip)
  15.     tooltip.default = 1
  16. end)
  17.  
  18. GameTooltip:HookScript("OnUpdate", function(self, elapsed)
  19.     if GetMouseFocus() ~= WorldFrame then return end
  20.     AnchorFrameToMouse(self)
  21. end)

For whatever reason it refuses to properly update X coordinate when anchoring at the bottom corners unless I force update it every frame, when it has absolutely no problems doing it when anchoring at the bottom.

Need to set the anchor once during GameTooltip_SetDefaultAnchor to avoid weird graphical issues, and then a hook keeps the same function running over and over again afterwards. I'm probably not going to release this as an update yet because OnUpdate is bad and there has to be a better solution, but if anybody wants this badly enough, the code is here.
Report comment to moderator  
Reply With Quote
Unread 06-09-18, 01:24 AM  
Theroxis
A Fallenroot Satyr

Forum posts: 24
File comments: 3
Uploads: 0
Bottom Right Anchor

To achieve this is quite simple:
Code:
GameTooltip:HookScript("OnUpdate", function(self, elpased)
		local x, y = GetCursorPosition()
		local effScale = self:GetEffectiveScale()
		self:ClearAllPoints()
		self:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", (x / effScale + 25), (y / effScale + -25))
This idea is completely stolen from the old addon "lolTip"


Anyways, basically you HookScript the "OnUpdate" function of the tooltip; since this is called every time the mouse moves on something that produces a tooltip, it mimics the same behavior as setting the anchor to the mouse. Then we grab the X and Y position of the cursor using the builtin, as well as the effective scale of the tooltip. This way the code works even if someone uses the UiScale to change the size of the UI. Finally we do some cheeky math to set the position of the tooltip frame to 25 pixels to the right, and 25 pixels below the cursor. There is some odd behavior in my edit to this I'm trying to figure out, but I'm trying to do slightly more complicated things.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: