Dim info As String = "
Скрипт помещает свой контейнер между двумя другими
Версия 0.3 (12 октября 2015)
"

Dim cx1,cx2,cy1,cy2 As Container
Dim v1,v2 As Vertex
Dim pos1, pos2, sizeX, sizeY As Double
Dim minX, minY, maxX, maxY As Double
Dim commonPadding, paddingLeft, paddingRight, paddingTop, paddingBottom As Double
Dim modeAxis, modePadding As Integer

Dim buttonNames As Array[String]
buttonNames.Push("По ширине")
buttonNames.Push("По высоте")
buttonNames.Push("По ширине и высоте")

Dim paddingModes As Array[String]
paddingModes.Push("Общий зазор")
paddingModes.Push("Раздельный")

sub OnInitParameters()
	RegisterRadioButton("modeAxis", "Выбор осей слежения", 1, buttonNames)
	RegisterParameterDouble("minX", "Мин. размер по X", 0.0, 0, 999999)
	RegisterParameterDouble("maxX", "Макс. размер по X", 999999.0, 0, 999999)
	RegisterParameterContainer("cx1","Объект-граница СЛЕВА")
	RegisterParameterContainer("cx2","Объект-граница СПРАВА")
	RegisterParameterDouble("minY", "Мин. размер по Y", 0.0, 0, 999999)
	RegisterParameterDouble("maxY", "Макс. размер по Y", 999999.0, 0, 999999)
	RegisterParameterContainer("cy1","Объект-граница СВЕРХУ")
	RegisterParameterContainer("cy2","Объект-граница СНИЗУ")
	RegisterRadioButton("mode_padding", "Зазор", 0, paddingModes)
	RegisterParameterDouble("common_padding", "Общий зазор", 0.0, -9999, 9999)
	RegisterParameterDouble("padding_left", "Зазор слева", 0.0, -9999, 9999)
	RegisterParameterDouble("padding_right", "Зазор справа", 0.0, -9999, 9999)
	RegisterParameterDouble("padding_top", "Зазор сверху", 0.0, -9999, 9999)
	RegisterParameterDouble("padding_bottom", "Зазор снизу", 0.0, -9999, 9999)
end sub

sub OnInit()
	cx1 = GetParameterContainer("cx1")
	cx2 = GetParameterContainer("cx2")
	cy1 = GetParameterContainer("cy1")
	cy2 = GetParameterContainer("cy2")
	commonPadding = GetParameterDouble("common_padding")
end sub
sub OnParameterChanged(parameterName As String)
	OnInit()
	modeAxis = GetParameterInt("modeAxis")
	if modeAxis == 0 then
		SendGuiParameterShow("cx1", 1)
		SendGuiParameterShow("cx2", 1)
		SendGuiParameterShow("minX", 1)
		SendGuiParameterShow("maxX", 1)
		SendGuiParameterShow("cy1", 0)
		SendGuiParameterShow("cy2", 0)
		SendGuiParameterShow("minY", 0)
		SendGuiParameterShow("maxY", 0)
		if modePadding == 1 then
			SendGuiParameterShow("padding_top", 0)
			SendGuiParameterShow("padding_bottom", 0)
		end if
	elseif modeAxis == 1 then
		SendGuiParameterShow("cx1", 0)
		SendGuiParameterShow("cx2", 0)
		SendGuiParameterShow("minX", 0)
		SendGuiParameterShow("maxX", 0)
		SendGuiParameterShow("cy1", 1)
		SendGuiParameterShow("cy2", 1)
		SendGuiParameterShow("minY", 1)
		SendGuiParameterShow("maxY", 1)
		if modePadding == 1 then
			SendGuiParameterShow("padding_left", 0)
			SendGuiParameterShow("padding_right", 0)
		end if
	elseif modeAxis == 2 then
		SendGuiParameterShow("cx1", 1)
		SendGuiParameterShow("cx2", 1)
		SendGuiParameterShow("minX", 1)
		SendGuiParameterShow("maxX", 1)
		SendGuiParameterShow("cy1", 1)
		SendGuiParameterShow("cy2", 1)
		SendGuiParameterShow("minY", 1)
		SendGuiParameterShow("maxY", 1)
	end if
	
	modePadding = GetParameterInt("mode_padding")
	if modePadding == 0 then
		SendGuiParameterShow("common_padding", 1)
		SendGuiParameterShow("padding_left", 0)
		SendGuiParameterShow("padding_right", 0)
		SendGuiParameterShow("padding_top", 0)
		SendGuiParameterShow("padding_bottom", 0)
	else
		SendGuiParameterShow("common_padding", 0)
		if modeAxis == 0 OR modeAxis == 2 then
			SendGuiParameterShow("padding_left", 1)
			SendGuiParameterShow("padding_right", 1)
		end if
		if modeAxis == 1 OR modeAxis == 2 then
			SendGuiParameterShow("padding_top", 1)
			SendGuiParameterShow("padding_bottom", 1)
		end if
	end if
	
	commonPadding = GetParameterDouble("common_padding")
	paddingLeft = GetParameterDouble("padding_left")
	paddingRight = GetParameterDouble("padding_right")
	paddingTop = GetParameterDouble("padding_top")
	paddingBottom = GetParameterDouble("padding_bottom")
	minX = GetParameterDouble("minX")
	minY = GetParameterDouble("minY")
	maxX = GetParameterDouble("maxX")
	maxY = GetParameterDouble("maxY")
end sub

Function GetPadding(side As String) As Double
	if modePadding == 0 then
		GetPadding = commonPadding
		exit function
	else
		if side == "left" then
			GetPadding = paddingLeft
		elseif side == "right" then
			GetPadding = paddingRight
		elseif side == "top" then
			GetPadding = paddingTop
		elseif side == "bottom" then
			GetPadding = paddingBottom
		end if
	end if
End Function

sub OnExecPerField()
	'X по ширине
	if modeAxis == 2 OR modeAxis == 0 then
		if cx1 <> null AND cx2 <> null then
			cx1.GetTransformedBoundingBox(v1,v2)
			v1 = cx1.ParentContainer.LocalPosToWorldPos(v1)
			v2 = cx1.ParentContainer.LocalPosToWorldPos(v2)
			pos1 = v2.x + GetPadding("left")
			
			cx2.GetTransformedBoundingBox(v1,v2)
			v1 = cx2.ParentContainer.LocalPosToWorldPos(v1)
			v2 = cx2.ParentContainer.LocalPosToWorldPos(v2)
			pos2 = v1.x - GetPadding("right")
			sizeX = (pos2 - pos1)/100.0
			if sizeX < minX then sizeX = minX
			if sizeX > maxX then sizeX = maxX
			
			this.position.x = pos1
			this.scaling.x = sizeX
		end if
	end if
	
	
	'Y по высоте
	if modeAxis == 2 OR modeAxis == 1 then
		if cy1 <> null AND cy2 <> null then
			cy1.GetTransformedBoundingBox(v1,v2)
			v1 = cy1.ParentContainer.LocalPosToWorldPos(v1)
			v2 = cy1.ParentContainer.LocalPosToWorldPos(v2)
			pos1 = v1.y - GetPadding("top")
			
			cy2.GetTransformedBoundingBox(v1,v2)
			v1 = cy2.ParentContainer.LocalPosToWorldPos(v1)
			v2 = cy2.ParentContainer.LocalPosToWorldPos(v2)
			pos2 = v2.y + GetPadding("bottom")
			sizeY = (pos1 - pos2)/100.0
			if sizeY < minY then sizeY = minY
			if sizeY > maxY then sizeY = maxY
			
			this.position.y = pos1
			this.scaling.y = sizeY
		end if
	end if
end sub