|
|
|
|
|
|
using System; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Experimental.UIElements; |
|
|
|
using UnityEngine.Experimental.UIElements.StyleSheets; |
|
|
|
#if UNITY_2018_1
|
|
|
|
using GeometryChangedEvent = UnityEngine.Experimental.UIElements.PostLayoutEvent; |
|
|
|
#endif
|
|
|
|
|
|
|
public class ResizeSideHandle : VisualElement |
|
|
|
{ |
|
|
|
VisualElement m_ResizeTarget; |
|
|
|
VisualElement m_Container; |
|
|
|
bool m_StayWithinParentBounds; |
|
|
|
|
|
|
|
public bool stayWithinParentBounds |
|
|
|
{ |
|
|
|
get { return m_StayWithinParentBounds; } |
|
|
|
set { m_StayWithinParentBounds = value; } |
|
|
|
} |
|
|
|
WindowDockingLayout m_WindowDockingLayout; |
|
|
|
|
|
|
|
bool m_MaintainAspectRatio; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Action OnResizeFinished; |
|
|
|
|
|
|
|
bool m_DockingLeft; |
|
|
|
bool m_DockingTop; |
|
|
|
float m_InitialAspectRatio; |
|
|
|
|
|
|
|
public ResizeSideHandle(VisualElement resizeTarget, ResizeHandleAnchor anchor) |
|
|
|
private GUIStyle m_StyleWidget; |
|
|
|
private GUIStyle m_StyleLabel; |
|
|
|
private Texture image { get; set; } |
|
|
|
|
|
|
|
public ResizeSideHandle(VisualElement resizeTarget, VisualElement container, ResizeHandleAnchor anchor) |
|
|
|
m_WindowDockingLayout = new WindowDockingLayout(); |
|
|
|
|
|
|
|
m_Container = container; |
|
|
|
|
|
|
|
AddToClassList("resize"); |
|
|
|
|
|
|
|
|
|
|
void InitialLayoutSetup(GeometryChangedEvent evt) |
|
|
|
{ |
|
|
|
m_ResizeTarget.UnregisterCallback<GeometryChangedEvent>(InitialLayoutSetup); |
|
|
|
m_InitialAspectRatio = m_ResizeTarget.layout.width / m_ResizeTarget.layout.height; |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 GetMinSize() |
|
|
|
{ |
|
|
|
Vector2 minSize = new Vector2(60f, 60f); |
|
|
|
|
|
|
|
if (!Mathf.Approximately(m_ResizeTarget.style.minWidth.value, 0f)) |
|
|
|
{ |
|
|
|
minSize.x = m_ResizeTarget.style.minWidth; |
|
|
|
} |
|
|
|
|
|
|
|
if (!Mathf.Approximately(m_ResizeTarget.style.minHeight.value, 0f)) |
|
|
|
{ |
|
|
|
minSize.y = m_ResizeTarget.style.minHeight.value; |
|
|
|
} |
|
|
|
|
|
|
|
return minSize; |
|
|
|
} |
|
|
|
|
|
|
|
float GetMaxHorizontalExpansion(bool expandingLeft) |
|
|
|
{ |
|
|
|
float maxHorizontalExpansion; |
|
|
|
|
|
|
|
if (expandingLeft) |
|
|
|
{ |
|
|
|
maxHorizontalExpansion = m_ResizeBeginLayout.x; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
maxHorizontalExpansion = m_ResizeTarget.parent.layout.width - m_ResizeBeginLayout.xMax; |
|
|
|
} |
|
|
|
|
|
|
|
if (maintainAspectRatio) |
|
|
|
{ |
|
|
|
if (!m_DockingTop) |
|
|
|
{ |
|
|
|
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeBeginLayout.y); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
maxHorizontalExpansion = Mathf.Min(maxHorizontalExpansion, m_ResizeTarget.parent.layout.height - m_ResizeBeginLayout.yMax); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return maxHorizontalExpansion; |
|
|
|
} |
|
|
|
|
|
|
|
float GetMaxVerticalExpansion(bool expandingUp) |
|
|
|
{ |
|
|
|
float maxVerticalExpansion; |
|
|
|
|
|
|
|
if (expandingUp) |
|
|
|
{ |
|
|
|
maxVerticalExpansion = m_ResizeBeginLayout.y; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
maxVerticalExpansion = m_ResizeTarget.parent.layout.height - m_ResizeBeginLayout.yMax; |
|
|
|
} |
|
|
|
|
|
|
|
if (maintainAspectRatio) |
|
|
|
{ |
|
|
|
if (!m_DockingLeft) |
|
|
|
{ |
|
|
|
maxVerticalExpansion = Mathf.Min(maxVerticalExpansion, m_ResizeBeginLayout.x); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
maxVerticalExpansion = Mathf.Min(maxVerticalExpansion, m_ResizeTarget.parent.layout.width - m_ResizeBeginLayout.xMax); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return maxVerticalExpansion; |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
|
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y); |
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginMousePosition.y - GetMaxVerticalExpansion(true)); |
|
|
|
} |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax); |
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); |
|
|
|
newLayout.yMin = m_ResizeBeginLayout.yMin + delta.y; |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
{ |
|
|
|
if (m_DockingLeft) |
|
|
|
{ |
|
|
|
newLayout.width = newLayout.height * m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newHeight); |
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
mouseMoveEvent.StopImmediatePropagation(); |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
|
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x); |
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y); |
|
|
|
|
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false)); |
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, 0f); |
|
|
|
} |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax); |
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN); |
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
|
|
|
|
newLayout.width += delta.x; |
|
|
|
newLayout.yMin += delta.y; |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); |
|
|
|
{ |
|
|
|
if (newLayout.width < newLayout.height * m_InitialAspectRatio) |
|
|
|
{ |
|
|
|
newLayout.yMin = Mathf.Min(newLayout.yMax - newLayout.width / m_InitialAspectRatio, newLayout.yMax - GetMinSize().y); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.width = newLayout.height * m_InitialAspectRatio; |
|
|
|
} |
|
|
|
} |
|
|
|
newWidth = newHeight = Mathf.Min(newWidth, newHeight); |
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x); |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN); |
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false)); |
|
|
|
} |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); |
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
|
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
|
|
|
|
newLayout.xMax = m_ResizeBeginLayout.xMax + delta.x; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
if (m_DockingTop) |
|
|
|
{ |
|
|
|
newLayout.height = newLayout.width / m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio); |
|
|
|
} |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newWidth); |
|
|
|
|
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
|
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginLayout.xMin + GetMinSize().x); |
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y); |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginMousePosition.x + GetMaxHorizontalExpansion(false)); |
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false)); |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
|
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(m_Container.layout.xMin); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(float.NaN); |
|
|
|
newLayout.size += delta; |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x); |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); |
|
|
|
{ |
|
|
|
if (newLayout.width < newLayout.height * m_InitialAspectRatio) |
|
|
|
{ |
|
|
|
newLayout.height = newLayout.width / m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.width = newLayout.height * m_InitialAspectRatio; |
|
|
|
} |
|
|
|
} |
|
|
|
newWidth = newHeight = Mathf.Min(newWidth, newHeight); |
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
|
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y); |
|
|
|
|
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false)); |
|
|
|
} |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN); |
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); |
|
|
|
newLayout.yMax = m_ResizeBeginLayout.yMax + delta.y; |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
{ |
|
|
|
if (m_DockingLeft) |
|
|
|
{ |
|
|
|
newLayout.width = newLayout.height * m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.xMin = newLayout.xMax - (newLayout.height * m_InitialAspectRatio); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newHeight); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x); |
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, m_ResizeBeginLayout.yMin + GetMinSize().y); |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(m_Container.layout.yMin); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax); |
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f); |
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginMousePosition.y + GetMaxVerticalExpansion(false)); |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
|
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
|
|
|
|
newLayout.xMin += delta.x; |
|
|
|
newLayout.height += delta.y; |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y); |
|
|
|
{ |
|
|
|
if (newLayout.width < newLayout.height * m_InitialAspectRatio) |
|
|
|
{ |
|
|
|
newLayout.height = newLayout.width / m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.xMin = Mathf.Min(newLayout.xMax - newLayout.height * m_InitialAspectRatio, newLayout.xMax - GetMinSize().x); |
|
|
|
} |
|
|
|
} |
|
|
|
newWidth = newHeight = Mathf.Min(newWidth, newHeight); |
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x); |
|
|
|
|
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, m_ResizeBeginMousePosition.x - GetMaxHorizontalExpansion(true)); |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax); |
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); |
|
|
|
newLayout.xMin = m_ResizeBeginLayout.xMin + delta.x; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
{ |
|
|
|
if (m_DockingTop) |
|
|
|
{ |
|
|
|
newLayout.height = newLayout.width / m_InitialAspectRatio; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.yMin = newLayout.yMax - (newLayout.width / m_InitialAspectRatio); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newWidth); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
if (!m_Dragging) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
Vector2 restrictedMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseMoveEvent.mousePosition); |
|
|
|
restrictedMousePosition.x = Mathf.Min(restrictedMousePosition.x, m_ResizeBeginLayout.xMax - GetMinSize().x); |
|
|
|
restrictedMousePosition.y = Mathf.Min(restrictedMousePosition.y, m_ResizeBeginLayout.yMax - GetMinSize().y); |
|
|
|
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition; |
|
|
|
if (stayWithinParentBounds) |
|
|
|
{ |
|
|
|
restrictedMousePosition.x = Mathf.Max(restrictedMousePosition.x, 0f); |
|
|
|
restrictedMousePosition.y = Mathf.Max(restrictedMousePosition.y, 0f); |
|
|
|
} |
|
|
|
// Set anchor points for positioning
|
|
|
|
m_Container.style.positionTop = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionBottom = StyleValue<float>.Create(m_Container.parent.layout.height - m_Container.layout.yMax); |
|
|
|
m_Container.style.positionLeft = StyleValue<float>.Create(float.NaN); |
|
|
|
m_Container.style.positionRight = StyleValue<float>.Create(m_Container.parent.layout.width - m_Container.layout.xMax); |
|
|
|
Vector2 delta = restrictedMousePosition - m_ResizeBeginMousePosition; |
|
|
|
|
|
|
|
Rect newLayout = m_ResizeBeginLayout; |
|
|
|
|
|
|
|
newLayout.xMin += delta.x; |
|
|
|
newLayout.yMin += delta.y; |
|
|
|
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x); |
|
|
|
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y); |
|
|
|
{ |
|
|
|
if (newLayout.width < newLayout.height * m_InitialAspectRatio) |
|
|
|
{ |
|
|
|
newLayout.yMin = Mathf.Min(newLayout.yMax - newLayout.width / m_InitialAspectRatio, newLayout.yMax - GetMinSize().y); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
newLayout.xMin = Mathf.Min(newLayout.xMax - newLayout.height * m_InitialAspectRatio, newLayout.xMax - GetMinSize().x); |
|
|
|
} |
|
|
|
} |
|
|
|
newWidth = newHeight = Mathf.Min(newWidth, newHeight); |
|
|
|
m_ResizeTarget.layout = newLayout; |
|
|
|
m_ResizeTarget.style.width = StyleValue<float>.Create(newWidth); |
|
|
|
m_ResizeTarget.style.height = StyleValue<float>.Create(newHeight); |
|
|
|
|
|
|
|
mouseMoveEvent.StopPropagation(); |
|
|
|
} |
|
|
|
|
|
|
m_Dragging = true; |
|
|
|
|
|
|
|
m_DockingLeft = m_ResizeTarget.layout.center.x / m_ResizeTarget.parent.layout.width < .5f; |
|
|
|
m_DockingTop = m_ResizeTarget.layout.center.y / m_ResizeTarget.parent.layout.height < .5f; |
|
|
|
// Get the docking settings for the window, as well as the
|
|
|
|
// layout and mouse position when resize begins.
|
|
|
|
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout); |
|
|
|
m_WindowDockingLayout.ApplyPosition(m_Container); |
|
|
|
m_ResizeBeginMousePosition = m_ResizeTarget.parent.WorldToLocal(mouseDownEvent.mousePosition); |
|
|
|
m_ResizeBeginMousePosition = mouseDownEvent.mousePosition; |
|
|
|
|
|
|
|
m_Dragging = true; |
|
|
|
this.TakeMouseCapture(); |
|
|
|
|
|
|
m_Dragging = false; |
|
|
|
|
|
|
|
if (this.HasMouseCapture()) |
|
|
|
this.ReleaseMouseCapture(); |
|
|
|
|
|
|
|
if (OnResizeFinished != null) |
|
|
|
OnResizeFinished(); |
|
|
|
|
|
|
|
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout); |
|
|
|
m_WindowDockingLayout.ApplyPosition(m_Container); |
|
|
|
} |
|
|
|
|
|
|
|
public override void DoRepaint() |
|
|
|
{ |
|
|
|
if (m_StyleWidget == null) |
|
|
|
this.ReleaseMouseCapture(); |
|
|
|
m_StyleWidget = new GUIStyle("WindowBottomResize") { fixedHeight = 0 }; |
|
|
|
image = m_StyleWidget.normal.background; |
|
|
|
if (OnResizeFinished != null) |
|
|
|
if (image == null) |
|
|
|
OnResizeFinished(); |
|
|
|
Debug.LogWarning("null texture passed to GUI.DrawTexture"); |
|
|
|
return; |
|
|
|
|
|
|
|
GUI.DrawTexture(contentRect, image, ScaleMode.ScaleAndCrop, true, 0, GUI.color, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |