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:
local x, y = GetCursorPosition()
x = x / WorldMapButton:GetEffectiveScale()
y = y / WorldMapButton:GetEffectiveScale()
local centerX, centerY = WorldMapButton:GetCenter()
local width = WorldMapButton:GetWidth()
local height = WorldMapButton:GetHeight()
local adjustedY = addon['round']((centerY + (height/2) - y) / height * 100,1)
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:
local map = WorldMapFrame.ScrollContainer
local x, y = map:GetCursorPosition()
-- x = x / map:GetEffectiveScale()
-- y = y / map:GetEffectiveScale()
local centerX, centerY = map:GetCenter()
local width = map:GetWidth()
local height = map:GetHeight()
local adjustedY = addon['round']((centerY + (height/2) - y) / height * 100,1)
local adjustedX = addon['round']((x - (centerX - (width/2))) / width * 100,1)
Can someone point me in the right direction?