-------------------------------
-- Map Marker Dragging Frame --
-------------------------------
local addon, ns = ...
local ss = ns.SS

local setmetatable = setmetatable
local CreateFrame, Minimap, GetCursorPosition, UIParent = CreateFrame, Minimap, GetCursorPosition, UIParent
local math = math

local mtDraggingFrame = {};

function mtDraggingFrame:New(parent)
  -- Add the dragingFrame
  local dragingFrame = CreateFrame("Button",ss._f.."MinimapButton_DraggingFrame",parent)
  dragingFrame:Hide()

  dragingFrame:SetScript("OnUpdate", function(self)
    local xpos,ypos = GetCursorPosition()
    local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()

    xpos = xmin-xpos/UIParent:GetScale()+70 -- get coordinates as differences from the center of the minimap
    ypos = ypos/UIParent:GetScale()-ymin-70

    local locationAngle = math.deg(math.atan2(ypos,xpos)) -- save the degrees we are relative to the minimap center

    ss.MapMarker.MapButton:Reposition(locationAngle)
  end)

  return dragingFrame
end

ss["MapMarkerDraggingFrame"] = setmetatable({}, { __index = mtDraggingFrame });
