View Single Post
06-09-18, 01:34 PM   #5
Theroxis
A Fallenroot Satyr
Join Date: Jun 2018
Posts: 24
Here's what I have that's almost perfect:

Code:
--This function handles actually moving the GameTooltip frame
local function MouseAnchor(frame,parent)

	--Preserve Auction House Tooltip Behavior
	if AuctionFrame and AuctionFrame:IsShown() then
		return
	end

	--Set the Tooltip position, if we're on WorldFrame, anchor to the mouse; if we're on a UnitFrame anchor to that.
	local mouseFocus=GetMouseFocus()
	if mouseFocus==WorldFrame then
		local x, y = GetCursorPosition()
		local scale = frame:GetEffectiveScale()
		frame:ClearAllPoints()
		frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", (x/scale + 20), (y/scale - 20))
	else
		frame:ClearAllPoints()
		frame:SetPoint("BOTTOM",mouseFocus,"TOP",0,10)
	end
end

--Set the position once during SetDefaultAnchor or we get weird graphical stuff
hooksecurefunc("GameTooltip_SetDefaultAnchor",function(tooltip, parent) MouseAnchor(tooltip) end)

--Move it with the mouse updates, but not too often so we don't waste CPU
local Tooltip_interval=0.1
GameTooltip.TimeSinceLastUpdate=0

local function mouset_OnUpdate(self, elapsed)
	self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed
	if (self.TimeSinceLastUpdate > Tooltip_interval) then
		if (self.default) then
			MouseAnchor(self)
		end
	end
end

--Run the above function on every update.
GameTooltip:HookScript("OnUpdate", mouset_OnUpdate)
This no longer has the strange resize clamp behavior I was experiencing before. This was fixed by setting the position once during SetDefaultAnchor, as pointed out by Ammako. I've added a conditional to NOT do any movement of the tooltip if we're on the AuctionFrame, which makes the tooltip behave stock there. I also stole the Deftooltip UnitFrame clamp behavior, as it kind of makes sense. Finally, I made it so we aren't updating every frame of mouse movement, as that's kind of a lot of CPU to use. At 0.1s interval the movement is still quite smooth.

The last things on the agenda for me:
1.) Get rid of the fadeout (a hot topic, apparently from Google) on Worldframe items.
2.) If you mouseover a PLAYER and then a Doodad (the sign for a shop, for example) the tooltip size is incorrect, I'm not sure how to approach that.
  Reply With Quote