WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   PTR General Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=172)
-   -   WorldMap GetCursorPosition (https://www.wowinterface.com/forums/showthread.php?t=56293)

Rilgamon 06-17-18 09:08 AM

WorldMap GetCursorPosition
 
In the process of updating for BfA I ran into a problem I dont find the right math (I'm not good at math ;) ).
The old way to translate Mouse position to Map coords in my zz_coords addon
Lua Code:
  1. local x, y = GetCursorPosition()
  2. x = x / WorldMapButton:GetEffectiveScale()
  3. y = y / WorldMapButton:GetEffectiveScale()
  4.  
  5. local centerX, centerY = WorldMapButton:GetCenter()
  6. local width = WorldMapButton:GetWidth()
  7. local height = WorldMapButton:GetHeight()
  8. local adjustedY = addon['round']((centerY + (height/2) - y) / height * 100,1)
  9. local adjustedX = addon['round']((x - (centerX - (width/2))) / width * 100,1)

For BfA I found that WorldMapFrame.ScrollContainer provides the GetCursorPosition-Function.
But it seems I cant use that frame as a replacement to get the effective scale/width/height.
When I remove the 2 lines that adjust x and y to the scale in BfA I get the right coords only when fully zoomed out.
Lua Code:
  1. local map = WorldMapFrame.ScrollContainer
  2. local x, y = map:GetCursorPosition()
  3. --  x = x / map:GetEffectiveScale()
  4. --  y = y / map:GetEffectiveScale()
  5. local centerX, centerY = map:GetCenter()
  6. local width = map:GetWidth()
  7. local height = map:GetHeight()
  8. local adjustedY = addon['round']((centerY + (height/2) - y) / height * 100,1)
  9. local adjustedX = addon['round']((x - (centerX - (width/2))) / width * 100,1)
Can someone point me in the right direction?

Vrul 06-17-18 09:25 AM

Blizzard actually did all the work:
Code:

local x, y = WorldMapFrame.ScrollContainer:GetNormalizedCursorPosition()
That will return the x, y coordinates taking into account map zoom, pan, etc...

Just multiply x and y by 100 and it should work like you want.

Rilgamon 06-17-18 09:32 AM

Argh ... I already played with it but still tried to keep width and height in the formula.
Thank you!!! Should have asked earlier :) I have spent the whole day digging through the new worldmap functions :D

Vrul 06-17-18 09:37 AM

I wasted several hours on it myself before I found that method.


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

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