浏览代码

Implement aspect ratio maintaining for vertical resize handles

/main
Jens Holm 7 年前
当前提交
40d78c85
共有 1 个文件被更改,包括 37 次插入85 次删除
  1. 122
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs

122
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/ResizeSideHandle.cs


if (expandingUp)
{
maxVerticalExpansion = m_ResizeTarget.layout.x;
maxVerticalExpansion = m_ResizeTarget.layout.y;
maxVerticalExpansion = m_ResizeTarget.parent.layout.width - m_ResizeTarget.layout.xMax;
maxVerticalExpansion = m_ResizeTarget.parent.layout.height - m_ResizeTarget.layout.yMax;
}
if (maintainAspectRatio)

void OnResizeFromHorizontal(Vector2 resizeDelta, ResizeHandleAnchor anchor)
{
float resizeAmount = resizeDelta.x / 2f;
float aspectRatio = m_ResizeTarget.layout.width / m_ResizeTarget.layout.height;
Vector2 minSize = GetMinSize();
Rect newLayout = m_ResizeTarget.layout;

{
resizeAmount = Mathf.Clamp(resizeAmount, GetMaxContraction(), GetMaxHorizontalExpansion(resizeLeft));
if (resizeLeft)
{
resizeAmount = Mathf.Clamp(resizeAmount, -GetMaxHorizontalExpansion(resizeLeft), GetMaxContraction());
}
else
{
resizeAmount = Mathf.Clamp(resizeAmount, -GetMaxContraction(), GetMaxHorizontalExpansion(resizeLeft));
}
}
if (resizeLeft)

void OnResizeFromVertical(Vector2 resizeDelta, ResizeHandleAnchor anchor)
{
}
float resizeAmount = resizeDelta.y / 2f;
void OnResizeFromCorner(Vector2 resizeDelta, ResizeHandleAnchor anchor)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
Vector2 minSize = GetMinSize();
}
Rect newLayout = m_ResizeTarget.layout;
void OnResize(Vector2 resizeDelta, ResizeDirection direction, ResizeHandleAnchor anchor)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
bool resizeUp = anchor == ResizeHandleAnchor.Top;
Vector2 minSize = new Vector2(60f, 60f);
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f))
if (stayWithinParentBounds)
minSize.x = m_ResizeTarget.style.minWidth;
if (resizeUp)
{
resizeAmount = Mathf.Clamp(resizeAmount, -GetMaxVerticalExpansion(resizeUp), GetMaxContraction());
}
else
{
resizeAmount = Mathf.Clamp(resizeAmount, -GetMaxContraction(), GetMaxVerticalExpansion(resizeUp));
}
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f))
{
minSize.y = m_ResizeTarget.style.minHeight.value;
}
if (direction == ResizeDirection.Vertical)
if (resizeUp)
normalizedResizeDelta.x = 0f;
newLayout.yMin += resizeAmount;
else if (direction == ResizeDirection.Horizontal)
else
normalizedResizeDelta.y = 0f;
newLayout.yMax += resizeAmount;
Rect newLayout = m_ResizeTarget.layout;
bool dominantResizeAlongX = Mathf.Abs(normalizedResizeDelta.x) >= Mathf.Abs(normalizedResizeDelta.y);
float aspectRatio = m_ResizeTarget.layout.width / m_ResizeTarget.layout.height;
bool expanding;
if (dominantResizeAlongX)
{
expanding = (IsAnchorLeft(anchor) && normalizedResizeDelta.x < 0f) || (!IsAnchorLeft(anchor) && normalizedResizeDelta.x > 0f);
}
else
if (!resizeUp)
expanding = (IsAnchorTop(anchor) && normalizedResizeDelta.y < 0f) || (!IsAnchorTop(anchor) && normalizedResizeDelta.y > 0f);
resizeAmount = -resizeAmount;
if (dominantResizeAlongX)
if (!m_DockingLeft)
normalizedResizeDelta.y = 0f;
float changeAlongY = Mathf.Abs(normalizedResizeDelta.x) / aspectRatio * .5f;
changeAlongY = expanding ? changeAlongY : -changeAlongY;
newLayout.yMin -= changeAlongY;
newLayout.yMax += changeAlongY;
newLayout.xMin += resizeAmount;
normalizedResizeDelta.x = 0f;
float changeAlongX = Mathf.Abs(normalizedResizeDelta.y) * aspectRatio * .5f;
changeAlongX = expanding ? changeAlongX : -changeAlongX;
newLayout.xMin -= changeAlongX;
newLayout.xMax += changeAlongX;
newLayout.xMax -= resizeAmount;
if (IsAnchorLeft(anchor))
{
newLayout.xMin = Mathf.Min(newLayout.xMin + normalizedResizeDelta.x, newLayout.xMax - minSize.x);
}
else
{
newLayout.xMax = Mathf.Max(newLayout.xMax + normalizedResizeDelta.x, newLayout.xMin + minSize.x);
}
if (IsAnchorTop(anchor))
{
newLayout.yMin = Mathf.Min(newLayout.yMin + normalizedResizeDelta.y, newLayout.yMax - minSize.y);
}
else
{
newLayout.yMax = Mathf.Max(newLayout.yMax + normalizedResizeDelta.y, newLayout.yMin + minSize.y);
}
m_ResizeTarget.layout = newLayout;
}
if (stayWithinParentBounds)
{
newLayout.xMin = Mathf.Max(newLayout.xMin, 0f);
newLayout.yMin = Mathf.Max(newLayout.yMin, 0f);
newLayout.xMax = Mathf.Min(newLayout.xMax, m_ResizeTarget.parent.layout.width);
newLayout.yMax = Mathf.Min(newLayout.yMax, m_ResizeTarget.parent.layout.height);
}
m_ResizeTarget.layout = newLayout;
void OnResizeFromCorner(Vector2 resizeDelta, ResizeHandleAnchor anchor)
{
Vector2 normalizedResizeDelta = resizeDelta / 2f;
Vector2 minSize = GetMinSize();
}
void HandleMouseDown(MouseDownEvent evt)

Debug.Log("docking left: " + m_DockingLeft + " docking top: " + m_DockingTop);
}
void HandleDraggableMouseUp(MouseUpEvent evt)

正在加载...
取消
保存