ToolsOptionCore.DragFrame = {}
local drag = ToolsOptionCore.DragFrame
function drag:Create(dragframe, parent, always)
	local d = CreateFrame("FRAME", nil, UIParent)
	d:SetPoint("TOPLEFT", dragframe, "TOPLEFT", -4, 4)
	d:SetWidth(16)
	d:SetHeight(16)
	d:EnableMouse(true)
	d:RegisterForDrag("LeftButton")
	d:Hide()
	local t = d:CreateTexture(nil, "ARTWORK")
	t:SetTexture("Interface\\Minimap\\ObjectIcons")
	t:SetTexCoord(0.25,0.5,0,0.25)
	t:SetAllPoints(d)

	d:SetScript("OnDragStart", function() dragframe:StartMoving() end)
	return d, function(p)
			dragframe:StopMovingOrSizing()
			self:DragStop(dragframe, p, parent, always)
		end
end
function drag:DragStop(f, p, parent, a)
	local us = parent:GetEffectiveScale()
	local fs = f:GetEffectiveScale()
	local ucx,ucy = parent:GetCenter()
	local fcx,fcy = f:GetCenter()
	local left = (f:GetLeft() * fs) - (parent:GetLeft() * us)
	local bottom = (f:GetBottom() * fs) - (parent:GetBottom() * us)
	local top = (f:GetTop() * fs) - (parent:GetTop() * us)
	local right = (f:GetRight() * fs) - (parent:GetRight() * us)
	ucx, ucy = ucx * us, ucy * us
	fcx, fcy = fcx * fs, fcy * fs
	local x, y = fcx - ucx, fcy - ucy
	if not a then
		left = left / fs
		bottom = bottom / fs
		top = top / fs
		right = right / fs
		x = x / fs
		y = y / fs
	end
	if p == 1 or p == "BOTTOMLEFT" then
		self.x, self.y = left, bottom
	elseif p == 2 or p == "BOTTOM" then
		self.x, self.y = x, bottom
	elseif p == 3 or p == "BOTTOMRIGHT" then
		self.x, self.y = right, bottom
	elseif p == 4 or p == "LEFT" then
		self.x, self.y = left, y
	elseif p == 5 or p == "CENTER" then
		self.x, self.y = x, y
	elseif p == 6 or p == "RIGHT" then
		self.x, self.y = right, y
	elseif p == 7 or p == "TOPLEFT" then
		self.x, self.y = left, top
	elseif p == 8 or p == "TOP" then
		self.x, self.y = x, top
	elseif p == 9 or p == "TOPRIGHT" then
		self.x, self.y = right, top
	end
	--ChatFrame1:AddMessage(p.." "..self.x.." "..self.y)
end