Getting correct frame ui position. - WoWInterface
Thread Tools Display Modes
03-27-21, 01:55 AM   #1
A Cyclonian
AddOn Author - Click to view addons
Join Date: May 2019
Posts: 42
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.

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?

Last edited by MinguasBeef : 03-27-21 at 01:58 AM.
  Reply With Quote
03-28-21, 10:25 AM   #2
A Pyroguard Emberseer
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,361
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 ]
I think there are a few "modifiers" you can add if it's not exactly what you want.
Ahhhh, the vagueries of the aging mind. Wait.... What was I saying?

Carbonite <----- GitHub main module (Maps ONLY) download link. The other modules are also available on GitHub.
Carbonite-CLASSIC<----- GitHub link to Carbonite Classic. Thanks to ircdirk for this!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Getting correct frame ui position.

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