Quantcast Strange GameTooltip behavior with SetPoint - WoWInterface
Thread Tools Display Modes
06-09-18, 02:02 AM   #1
Theroxis
A Murloc Raider
Join Date: Jun 2018
Posts: 4
Strange GameTooltip behavior with SetPoint

So basically, I'm trying to learn lua and AddOn development by adding the features and UI elements I like from big already done stuff, but by only manipulating stock blizzard frames. It's been a neat way to learn how both the stock Blizzard UI and AddOns in general work.
I really like having a tooltip underneath the mouse cursor when I'm hovering over players, and other things in the world. It helps bring attention to what my pointy thing is pointing at. So I wrote this:
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))
end)
While this does work, and moves the ToolTip frame 25 pixels to the right and 25 pixels below the cursor - I notice that as I rapidly mouse over things, the tooltip appears to draw in the bottom right of the screen at it's default position, then scale to the TOPLEFT position, followed by finally settling on the correct size and position. This results in a twitchy flashing tooltip as I move around. This only happens when the tooltip changes, that is to say if I hover over something and then move while hovered over the same thing it behaves normally, but if I changed the mousefocus to something else, the behavior becomes erratic.

What causes this, and how can I stop it?
I've tried also hooking OnShow and doing the same math there, but that doesn't seem to help.
  Reply With Quote
06-09-18, 06:03 AM   #2
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
You could add
Code:
print(elpased)
after
Code:
local x, y = GetCursorPosition()
to understand what happens.
I think you might want to use UPDATE_MOUSEOVER_UNIT event though.
  Reply With Quote
06-09-18, 09:39 AM   #3
JDoubleU00
A Rage Talon Dragon Guard
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 330
Have you looked at other ToolTip addons that place the tip at the cursor? Here is just one that does that:

https://www.wowinterface.com/downloa...fsTooltip.html
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
06-09-18, 11:38 AM   #4
Ammako
A Cobalt Mageweaver
 
Ammako's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 208
Have a look at my reply to your comment from last night. Just adjust the SetPoint coordinates to your liking.
__________________
█████████████
█████████████
█████████████
█████████████
  Reply With Quote
06-09-18, 01:34 PM   #5
Theroxis
A Murloc Raider
Join Date: Jun 2018
Posts: 4
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
06-09-18, 03:59 PM   #6
Ammako
A Cobalt Mageweaver
 
Ammako's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 208
1) Doesn't hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end) do the trick? I always had that fadeout issue back when I used TipTac, and they claimed it "wasn't fixable", but it has never been a problem with my code.
2) That doesn't happen on my end, and not sure why it occurs, so I can't help there. It has to be something your code does differently from mine, but I wouldn't be able to tell what exactly.
__________________
█████████████
█████████████
█████████████
█████████████
  Reply With Quote
06-09-18, 04:22 PM   #7
Theroxis
A Murloc Raider
Join Date: Jun 2018
Posts: 4
Originally Posted by Ammako View Post
1) Doesn't hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end) do the trick? I always had that fadeout issue back when I used TipTac, and they claimed it "wasn't fixable", but it has never been a problem with my code.
2) That doesn't happen on my end, and not sure why it occurs, so I can't help there. It has to be something your code does differently from mine, but I wouldn't be able to tell what exactly.
It was actually directly related to FadeOut. Once I got FadeOut disabled, the issue with moving from a Unit to a doodad went away. If I waited for it to Fade before mousing over a doodad, the issue didn't happen, so by making it fade instantly the issue is resolved.

Also, that hooksecurefunc line doesn't work for me; I resorted to hiding based on UIParent and WorldFrame mouseover shenanigans. Unfortunately that has its issues as well. PhanxTooltip has a large block for getting rid of the fade, I might just copy that.

Last edited by Theroxis : 06-09-18 at 04:27 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Strange GameTooltip behavior with SetPoint

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off