View Single Post
03-27-21, 01:55 AM   #1
MinguasBeef
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: May 2019
Posts: 51
Getting correct frame ui position.

Edit: Found the solution right after I posted. https://wowwiki-archive.fandom.com/w...CursorPosition

I needed to divide the cursor coordinates by UIParent:GetEffectiveScale(). Sorry about that!


I'm trying to figure out how I can get accurate screen coordinates for a frame.
In this example, I have my cursor at the bottom left corner of the red frame.



This is the script i'm using.

Code:
local f = CreateFrame("Frame", nil, UIParent)
f:SetWidth(400)
f:SetHeight(300)
f:SetPoint("CENTER")
f.texture = f:CreateTexture(nil, "BACKGROUND")
f.texture:SetColorTexture(0.43, 0.03, 0.03, 0.8)
f.texture:SetAllPoints(f)

f:SetScript("OnUpdate", function(self, elapsed) OnUpdateCallback(elapsed) end)
f:Show()

local dt = 0
function OnUpdateCallback(elapsed)
    dt = dt + elapsed
    if (dt < 0.1) then
        return nil
    end
    dt = 0

    local mouseX, mouseY = GetCursorPosition()
    print("Cursor: " .. mouseX .. ", " .. mouseY)

    local frameX, frameY = f:GetLeft(), f:GetBottom()
    print("Frame: " .. frameX .. ", " .. frameY)
end
Why am I getting different coordinates between the mouse and the bottom left of the frame?

Last edited by MinguasBeef : 03-27-21 at 01:58 AM.
  Reply With Quote