Quantcast
--[[ File
NAME: TitanMovable.lua
DESC: DragonFlight introduced an Edit Mode for the user to move various frames where they want them.
Titan no longer needs to do this work.

The only routine is an API call so other addons can determine where Titan Panel is on the UI based on user selection - top and bottom bars only.
:DESC

--]]
-- Globals

-- Locals
local _G = getfenv(0);
local InCombatLockdown = _G.InCombatLockdown;


--[[ API
NAME: TitanMovable_GetPanelYOffset
DESC: Get the Y axis offset Titan needs (1 or 2 bars) at the given position - top or bottom.
VAR: framePosition - TITAN_PANEL_PLACE_TOP or TITAN_PANEL_PLACE_BOTTOM
OUT: Y axis offset, in pixels
NOTE:
- As of DragonFlight this may not be as useful. Leaving to not break any addons.

- The preferred method to determine the Y offset needed to use TitanUtils_GetBarAnchors()
which provides anchors (frames) for an addon to use.
:NOTE
--]]
function TitanMovable_GetPanelYOffset(framePosition) -- used by other addons
	-- Both top & bottom are figured out but only the
	-- requested position is returned
	local barnum_top = 0
	local barnum_bot = 0
	-- If user has the top set then determine the top offset
	if TitanBarDataVars[TITAN_PANEL_DISPLAY_PREFIX.."Bar"].show then
--	if TitanPanelGetVar("Bar_Show") then
		barnum_top = 1
	end
	if TitanBarDataVars[TITAN_PANEL_DISPLAY_PREFIX.."Bar2"].show then
--	if TitanPanelGetVar("Bar2_Show") then
		barnum_top = 2
	end
	-- If user has the bottom set then determine the bottom offset
	if TitanBarDataVars[TITAN_PANEL_DISPLAY_PREFIX.."AuxBar"].show then
--	if TitanPanelGetVar("AuxBar_Show") then
		barnum_bot = 1
	end

	if TitanBarDataVars[TITAN_PANEL_DISPLAY_PREFIX.."AuxBar2"].show then
--	if TitanPanelGetVar("AuxBar2_Show") then
		barnum_bot = 2
	end

	local scale = TitanPanelGetVar("Scale")
	-- return the requested offset
	-- 0 will be returned if the user has no bars showing
	-- or the scale is not valid
	if scale and framePosition then
		if framePosition == TITAN_PANEL_PLACE_TOP and barnum_top > 0 then
			return (-TITAN_PANEL_BAR_HEIGHT * scale)*(barnum_top);
		elseif framePosition == TITAN_PANEL_PLACE_BOTTOM and barnum_bot > 0 then
			return (TITAN_PANEL_BAR_HEIGHT * scale)*(barnum_bot)
				-1 -- no idea why -1 is needed... seems anchoring to bottom is off a pixel
		end
	end
	return 0
end

--[[
	TitanDebug ("MoveFrame :"
		.." "..tostring(frame:GetName())
		.." point:"..tostring(point)
		.." relativeTo:"..tostring(relativeTo:GetName())
		.." relativePoint:"..tostring(relativePoint)
		.." xOfs:"..tostring(xOfs)
		.." y:"..tostring(y)
		.." adj:"..tostring(DoAdjust(top_bottom, force))
		.." tb:"..tostring(top_bottom)
		.." f:"..tostring(force)
		)
	end
--]]