I would suggest doing something like this if you want to use the cursor position:
Lua Code:
local frame = CreateFrame("Frame")
local GetCursorPosition, IsMouselooking = GetCursorPosition, IsMouselooking
local GetMouseFocus = GetMouseFocus
local UIParent, WorldFrame = UIParent, WorldFrame
frame.timer = 0
frame:SetScript("OnUpdate", function(self, elapsed)
self.timer = self.timer + elapsed
local x, y = GetCursorPosition()
if self.x ~= x or self.y ~= y then
UIParent:SetAlpha(UIParent:GetAlpha()+elapsed)
elseif not IsMouselooking() then
self.timer = 0
UIParent:SetAlpha(UIParent:GetAlpha()-elapsed)
end
if self.timer > 3 then
-- check mouse looking here since the cursor position is static while
-- holding down right mouse button, also check that you're not mousing
-- over a frame since that may not be desirable either
if not IsMouselooking() and GetMouseFocus() == WorldFrame then
self.x = x
self.y = y
end
self.timer = 0
end
end)
This will fade out the UIParent smoothly instead of hiding/showing it, which isn't something you can do without causing problems. A lot of secure frames, from addons and Blizzard alike, are children of UIParent, and this would break stuff if you were to insecurely attempt to hide the frame in combat.
The performance dent is negligible with localized shortcuts to the global functions used in this script and you're only operating on simple true/false statements anyway. You don't have to worry about performance with such a small script.