--[[
	Menu.lua
		Functions for the Bagnon right click options menu
--]]


--show the menu
function BagnonMenu_Show(frame)
	--BagnonMenu:SetParent(frame);
	
	BagnonMenu.onShow = 1;
	BagnonMenu.frame = frame;
	BagnonMenuText:SetText(frame:GetName() .. " Settings");
	
	--Set values
	BagnonMenuLocked:SetChecked(BagnonSets[frame:GetName()].locked);
	BagnonMenuOpaque:SetChecked(BagnonSets[frame:GetName()].bg);
	BagnonMenuColumns:SetValue(frame.cols);
	BagnonMenuSpacing:SetValue(frame.space);
	BagnonMenuScale:SetValue(frame:GetScale() * 100);
	BagnonMenuOpacity:SetValue(frame:GetAlpha() * 100);
	
	--a nifty thing I saw in meta map adapted for my usage
	--places the options menu at the cursor's position
	local x, y = GetCursorPosition();
	x = x / UIParent:GetScale();
	y = y / UIParent:GetScale();
	
	BagnonMenu:ClearAllPoints();
	Infield_Place(BagnonMenu, "TOPLEFT", UIParent, "BOTTOMLEFT", x, y);
	
	BagnonMenu:Show();
	BagnonMenu.onShow = nil;
end

--change <frame>'s transparency
function BagnonMenu_SetAlpha(frame, alpha)
	if(alpha ~= 1) then
		BagnonSets[frame:GetName()].alpha = alpha;
	else
		BagnonSets[frame:GetName()].alpha = nil
	end
	frame:SetAlpha(alpha);
end

--Set and scale <frame>
function BagnonMenu_SetScale(frame, scale)
	BagnonSets[frame:GetName()].scale = scale;
	
	Infield_Scale(frame, scale);
	BagnonCore_SavePosition(frame);
end

function BagnonMenu_ToggleBG(frame, checked)
	if( checked ) then
		BagnonMenu_SetBackground(frame, bgn_OPAQUE_BG);
	else
		BagnonMenu_SetBackground(frame, bgn_NORMAL_BG);
	end
end

--switch set the frame's background, currently only switches to/from a transparent background
function BagnonMenu_SetBackground(frame, background)
	if(background == NORMAL_BG) then
		BagnonSets[frame:GetName()].bg = nil;
	else
		BagnonSets[frame:GetName()].bg = 1;
	end
	frame:SetBackdrop({bgFile=background, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", tile=false, tileSize=16, edgeSize=16, insets={left=4, right=4, top=4, bottom=4}})
end

function BagnonMenu_ToggleLock(frame, checked)
	local frameName = frame:GetName();
	
	if(checked) then
		BagnonSets[frameName].locked = 1;
	else
		BagnonSets[frameName].locked = nil;
	end
end