View Single Post
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