Thread Tools Display Modes
06-17-18, 09:08 AM   #1
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
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?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
06-17-18, 09:25 AM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
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.

Last edited by Vrul : 06-17-18 at 09:26 AM. Reason: Forgot :
  Reply With Quote
06-17-18, 09:32 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
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
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
06-17-18, 09:37 AM   #4
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
I wasted several hours on it myself before I found that method.
  Reply With Quote

WoWInterface » PTR » PTR General Discussion » WorldMap GetCursorPosition

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