WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Getting correct frame ui position. (https://www.wowinterface.com/forums/showthread.php?t=58651)

MinguasBeef 03-27-21 01:55 AM

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?

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:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI