WoWInterface (
-   Lua/XML Help (
-   -   Getting correct frame ui position. (

MinguasBeef 03-27-21 01:55 AM

Getting correct frame ui position.
Edit: Found the solution right after I posted.

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.


local f = CreateFrame("Frame", nil, UIParent)
f.texture = f:CreateTexture(nil, "BACKGROUND")
f.texture:SetColorTexture(0.43, 0.03, 0.03, 0.8)

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

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

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

    local frameX, frameY = f:GetLeft(), f:GetBottom()
    print("Frame: " .. frameX .. ", " .. frameY)

Why am I getting different coordinates between the mouse and the bottom left of the frame?

jeffy162 03-28-21 10:25 AM

Try creating your frame, then use "/framestack" to get your coordinates.
(OR - it might be \framestack [you can use fstack instead of framestack or you could anyway :o ]
I think there are a few "modifiers" you can add if it's not exactly what you want.

All times are GMT -6. The time now is 04:55 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI