initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
class Draggable : MouseManipulator
|
||||
{
|
||||
Action<Vector2> m_Handler;
|
||||
|
||||
bool m_Active;
|
||||
|
||||
bool m_OutputDeltaMovement;
|
||||
|
||||
public Draggable(Action<Vector2> handler, bool outputDeltaMovement = false)
|
||||
{
|
||||
m_Handler = handler;
|
||||
m_Active = false;
|
||||
m_OutputDeltaMovement = outputDeltaMovement;
|
||||
activators.Add(new ManipulatorActivationFilter()
|
||||
{
|
||||
button = MouseButton.LeftMouse
|
||||
});
|
||||
}
|
||||
|
||||
protected override void RegisterCallbacksOnTarget()
|
||||
{
|
||||
target.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
|
||||
target.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
|
||||
target.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
|
||||
}
|
||||
|
||||
protected override void UnregisterCallbacksFromTarget()
|
||||
{
|
||||
target.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
|
||||
target.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
|
||||
target.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
|
||||
}
|
||||
|
||||
void OnMouseDown(MouseDownEvent evt)
|
||||
{
|
||||
target.CaptureMouse();
|
||||
m_Active = true;
|
||||
evt.StopPropagation();
|
||||
}
|
||||
|
||||
void OnMouseMove(MouseMoveEvent evt)
|
||||
{
|
||||
if (m_Active)
|
||||
{
|
||||
if (m_OutputDeltaMovement)
|
||||
{
|
||||
m_Handler(evt.mouseDelta);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Handler(evt.localMousePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseUp(MouseUpEvent evt)
|
||||
{
|
||||
m_Active = false;
|
||||
|
||||
if (target.HasMouseCapture())
|
||||
{
|
||||
target.ReleaseMouse();
|
||||
}
|
||||
|
||||
evt.StopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad4cd8fec883e80418e5427585b426db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,239 @@
|
|||
using System;
|
||||
using UnityEditor.ShaderGraph.Drawing.Interfaces;
|
||||
using UnityEditor.ShaderGraph.Drawing.Views;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
class ElementResizer : Manipulator
|
||||
{
|
||||
bool m_IsEnabled = true;
|
||||
public bool isEnabled
|
||||
{
|
||||
get => m_IsEnabled;
|
||||
set => m_IsEnabled = value;
|
||||
}
|
||||
|
||||
public readonly ResizableElement.Resizer direction;
|
||||
|
||||
public readonly VisualElement resizedElement;
|
||||
|
||||
public ElementResizer(VisualElement resizedElement, ResizableElement.Resizer direction)
|
||||
{
|
||||
this.direction = direction;
|
||||
this.resizedElement = resizedElement;
|
||||
}
|
||||
|
||||
protected override void RegisterCallbacksOnTarget()
|
||||
{
|
||||
target.RegisterCallback<MouseDownEvent>(OnMouseDown);
|
||||
target.RegisterCallback<MouseUpEvent>(OnMouseUp);
|
||||
}
|
||||
|
||||
protected override void UnregisterCallbacksFromTarget()
|
||||
{
|
||||
target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
|
||||
target.UnregisterCallback<MouseUpEvent>(OnMouseUp);
|
||||
}
|
||||
|
||||
Vector2 m_StartMouse;
|
||||
Vector2 m_StartSize;
|
||||
|
||||
Vector2 m_MinSize;
|
||||
Vector2 m_MaxSize;
|
||||
|
||||
Vector2 m_StartPosition;
|
||||
|
||||
bool m_DragStarted = false;
|
||||
|
||||
void OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (!isEnabled)
|
||||
return;
|
||||
|
||||
if (e.button == 0 && e.clickCount == 1)
|
||||
{
|
||||
VisualElement resizedTarget = resizedElement.parent;
|
||||
if (resizedTarget != null)
|
||||
{
|
||||
VisualElement resizedBase = resizedTarget.parent;
|
||||
if (resizedBase != null)
|
||||
{
|
||||
target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
|
||||
e.StopPropagation();
|
||||
target.CaptureMouse();
|
||||
m_StartMouse = resizedBase.WorldToLocal(e.mousePosition);
|
||||
m_StartSize = new Vector2(resizedTarget.resolvedStyle.width, resizedTarget.resolvedStyle.height);
|
||||
m_StartPosition = new Vector2(resizedTarget.resolvedStyle.left, resizedTarget.resolvedStyle.top);
|
||||
|
||||
bool minWidthDefined = resizedTarget.resolvedStyle.minWidth != StyleKeyword.Auto;
|
||||
bool maxWidthDefined = resizedTarget.resolvedStyle.maxWidth != StyleKeyword.None;
|
||||
bool minHeightDefined = resizedTarget.resolvedStyle.minHeight != StyleKeyword.Auto;
|
||||
bool maxHeightDefined = resizedTarget.resolvedStyle.maxHeight != StyleKeyword.None;
|
||||
m_MinSize = new Vector2(
|
||||
minWidthDefined ? resizedTarget.resolvedStyle.minWidth.value : Mathf.NegativeInfinity,
|
||||
minHeightDefined ? resizedTarget.resolvedStyle.minHeight.value : Mathf.NegativeInfinity);
|
||||
m_MaxSize = new Vector2(
|
||||
maxWidthDefined ? resizedTarget.resolvedStyle.maxWidth.value : Mathf.Infinity,
|
||||
maxHeightDefined ? resizedTarget.resolvedStyle.maxHeight.value : Mathf.Infinity);
|
||||
|
||||
m_DragStarted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (!isEnabled)
|
||||
return;
|
||||
|
||||
VisualElement resizedTarget = resizedElement.parent;
|
||||
VisualElement resizedBase = resizedTarget.parent;
|
||||
|
||||
// Top left position of the parent visual element
|
||||
var parentRootPosition = resizedBase.worldBound;
|
||||
// Top left of the target visual element for resizing
|
||||
var targetRootPosition = resizedTarget.worldBound;
|
||||
var canResizePastParentBounds = ((ISGResizable)resizedTarget).CanResizePastParentBounds();
|
||||
|
||||
Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition);
|
||||
|
||||
if (!m_DragStarted)
|
||||
{
|
||||
if (resizedTarget is ISGResizable resizable)
|
||||
resizable.OnStartResize();
|
||||
m_DragStarted = true;
|
||||
}
|
||||
|
||||
if ((direction & ResizableElement.Resizer.Right) != 0)
|
||||
{
|
||||
var newWidth = m_StartSize.x + mousePos.x - m_StartMouse.x;
|
||||
var parentRightBoundary = parentRootPosition.x + resizedBase.layout.width;
|
||||
// Also ensure resizing does not happen past edge of parent views boundaries if the target does not allow it
|
||||
if (!canResizePastParentBounds)
|
||||
{
|
||||
if ((targetRootPosition.x + newWidth) > parentRightBoundary)
|
||||
{
|
||||
var targetToRightBoundaryDelta = parentRightBoundary - targetRootPosition.x;
|
||||
newWidth = targetToRightBoundaryDelta;
|
||||
}
|
||||
var newLayoutLeft = targetRootPosition.x - parentRootPosition.x;
|
||||
// When resizing to right, make sure to calculate and set the target elements Style.left before resizing to ensure correct resizing behavior
|
||||
// If Style.left is NaNpx it results in scaling towards the left
|
||||
// This is due to how the WindowDockingLayout code affects GraphSubWindows
|
||||
resizedTarget.style.left = newLayoutLeft;
|
||||
}
|
||||
|
||||
resizedTarget.style.width = Mathf.Clamp(newWidth, m_MinSize.x, m_MaxSize.x);
|
||||
}
|
||||
else if ((direction & ResizableElement.Resizer.Left) != 0)
|
||||
{
|
||||
float delta = mousePos.x - m_StartMouse.x;
|
||||
|
||||
if (m_StartSize.x - delta < m_MinSize.x)
|
||||
{
|
||||
delta = -m_MinSize.x + m_StartSize.x;
|
||||
}
|
||||
else if (m_StartSize.x - delta > m_MaxSize.x)
|
||||
{
|
||||
delta = -m_MaxSize.x + m_StartSize.x;
|
||||
}
|
||||
|
||||
var newWidth = -delta + m_StartSize.x;
|
||||
var targetToLeftBoundaryDelta = delta + m_StartPosition.x;
|
||||
|
||||
if (!canResizePastParentBounds)
|
||||
{
|
||||
// This ensures that the left side of the resizing target never can get pushed past the parent boundary even if mouse is moving really fast
|
||||
targetToLeftBoundaryDelta = Mathf.Clamp(targetToLeftBoundaryDelta, 2.5f, targetToLeftBoundaryDelta);
|
||||
|
||||
// Clamps width to max out at left edge of parent window
|
||||
if (Mathf.Approximately(targetToLeftBoundaryDelta, 2.5f))
|
||||
newWidth = (m_StartPosition.x + m_StartSize.x);
|
||||
|
||||
newWidth = Mathf.Clamp(newWidth, m_MinSize.x, m_MaxSize.x);
|
||||
}
|
||||
|
||||
resizedTarget.style.left = targetToLeftBoundaryDelta;
|
||||
resizedTarget.style.width = newWidth;
|
||||
}
|
||||
|
||||
if ((direction & ResizableElement.Resizer.Bottom) != 0)
|
||||
{
|
||||
var delta = mousePos.y - m_StartMouse.y;
|
||||
var newHeight = m_StartSize.y + delta;
|
||||
|
||||
var parentBottomBoundary = parentRootPosition.y + resizedBase.layout.height;
|
||||
if (!canResizePastParentBounds)
|
||||
{
|
||||
if ((targetRootPosition.y + newHeight) > parentBottomBoundary)
|
||||
{
|
||||
var targetToBottomBoundaryDelta = parentBottomBoundary - targetRootPosition.y;
|
||||
newHeight = targetToBottomBoundaryDelta;
|
||||
}
|
||||
var targetToTopBoundaryDelta = targetRootPosition.y - parentRootPosition.y;
|
||||
// When resizing to bottom, make sure to calculate and set the target elements Style.top before resizing to ensure correct resizing behavior
|
||||
// If Style.top is NaNpx it results in scaling towards the bottom
|
||||
// This is due to how the WindowDockingLayout code affects GraphSubWindows
|
||||
resizedTarget.style.top = targetToTopBoundaryDelta;
|
||||
|
||||
newHeight = Mathf.Clamp(newHeight, m_MinSize.y, m_MaxSize.y);
|
||||
}
|
||||
|
||||
resizedTarget.style.height = newHeight;
|
||||
}
|
||||
else if ((direction & ResizableElement.Resizer.Top) != 0)
|
||||
{
|
||||
float delta = mousePos.y - m_StartMouse.y;
|
||||
|
||||
if (m_StartSize.y - delta < m_MinSize.y)
|
||||
{
|
||||
delta = -m_MinSize.y + m_StartSize.y;
|
||||
}
|
||||
else if (m_StartSize.y - delta > m_MaxSize.y)
|
||||
{
|
||||
delta = -m_MaxSize.y + m_StartSize.y;
|
||||
}
|
||||
|
||||
var newHeight = -delta + m_StartSize.y;
|
||||
var targetToTopBoundaryDelta = m_StartPosition.y + delta;
|
||||
if (!canResizePastParentBounds)
|
||||
{
|
||||
// This ensures that the top of the resizing target never can get pushed past the parent boundary even if mouse is moving really fast
|
||||
targetToTopBoundaryDelta = Mathf.Clamp(targetToTopBoundaryDelta, 2.5f, targetToTopBoundaryDelta);
|
||||
|
||||
// Clamps height to max out at top edge of parent window
|
||||
if (Mathf.Approximately(targetToTopBoundaryDelta, 2.5f))
|
||||
newHeight = (m_StartPosition.y + m_StartSize.y);
|
||||
|
||||
newHeight = Mathf.Clamp(newHeight, m_MinSize.y, m_MaxSize.y);
|
||||
}
|
||||
|
||||
resizedTarget.style.top = targetToTopBoundaryDelta;
|
||||
resizedTarget.style.height = newHeight;
|
||||
}
|
||||
e.StopPropagation();
|
||||
}
|
||||
|
||||
void OnMouseUp(MouseUpEvent e)
|
||||
{
|
||||
if (!isEnabled)
|
||||
return;
|
||||
|
||||
if (e.button == 0)
|
||||
{
|
||||
VisualElement resizedTarget = resizedElement.parent;
|
||||
if (resizedTarget.style.width != m_StartSize.x || resizedTarget.style.height != m_StartSize.y)
|
||||
{
|
||||
if (resizedTarget is ISGResizable resizable)
|
||||
resizable.OnResized();
|
||||
}
|
||||
target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);
|
||||
target.ReleaseMouse();
|
||||
e.StopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 115a3d6c38944c34a134edc915a90ebe
|
||||
timeCreated: 1605227560
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.ShaderGraph.Drawing;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
class ResizeBorderFrame : VisualElement
|
||||
{
|
||||
List<ResizeSideHandle> m_ResizeSideHandles;
|
||||
|
||||
bool m_MaintainApsectRatio;
|
||||
|
||||
public bool maintainAspectRatio
|
||||
{
|
||||
get { return m_MaintainApsectRatio; }
|
||||
set
|
||||
{
|
||||
m_MaintainApsectRatio = value;
|
||||
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
|
||||
{
|
||||
resizeHandle.maintainAspectRatio = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Action OnResizeFinished;
|
||||
|
||||
public ResizeBorderFrame(VisualElement target)
|
||||
{
|
||||
InitializeResizeBorderFrame(target, target);
|
||||
}
|
||||
|
||||
public ResizeBorderFrame(VisualElement target, VisualElement container)
|
||||
{
|
||||
InitializeResizeBorderFrame(target, container);
|
||||
}
|
||||
|
||||
void InitializeResizeBorderFrame(VisualElement target, VisualElement container)
|
||||
{
|
||||
pickingMode = PickingMode.Ignore;
|
||||
|
||||
AddToClassList("resizeBorderFrame");
|
||||
|
||||
m_ResizeSideHandles = new List<ResizeSideHandle>();
|
||||
|
||||
// Add resize handles along the border
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopLeft));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Top));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.TopRight));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Right));
|
||||
m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomRight));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Bottom));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.BottomLeft));
|
||||
// m_ResizeSideHandles.Add(new ResizeSideHandle(target, container, ResizeHandleAnchor.Left));
|
||||
|
||||
foreach (ResizeSideHandle resizeHandle in m_ResizeSideHandles)
|
||||
{
|
||||
resizeHandle.OnResizeFinished += HandleResizefinished;
|
||||
Add(resizeHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleResizefinished()
|
||||
{
|
||||
if (OnResizeFinished != null)
|
||||
{
|
||||
OnResizeFinished();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1128492b211994d46be4acd2ccac15fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,365 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.UIElements.StyleSheets;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
enum ResizeDirection
|
||||
{
|
||||
Any,
|
||||
Vertical,
|
||||
Horizontal
|
||||
}
|
||||
|
||||
enum ResizeHandleAnchor
|
||||
{
|
||||
Top,
|
||||
TopRight,
|
||||
Right,
|
||||
BottomRight,
|
||||
Bottom,
|
||||
BottomLeft,
|
||||
Left,
|
||||
TopLeft
|
||||
}
|
||||
|
||||
class ResizeSideHandle : ImmediateModeElement
|
||||
{
|
||||
VisualElement m_ResizeTarget;
|
||||
VisualElement m_Container;
|
||||
|
||||
WindowDockingLayout m_WindowDockingLayout;
|
||||
|
||||
bool m_MaintainAspectRatio;
|
||||
|
||||
public bool maintainAspectRatio
|
||||
{
|
||||
get { return m_MaintainAspectRatio; }
|
||||
set { m_MaintainAspectRatio = value; }
|
||||
}
|
||||
|
||||
public Action OnResizeFinished;
|
||||
|
||||
bool m_Dragging;
|
||||
|
||||
Rect m_ResizeBeginLayout;
|
||||
Vector2 m_ResizeBeginMousePosition;
|
||||
|
||||
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_ResizeTarget = resizeTarget;
|
||||
m_Container = container;
|
||||
|
||||
AddToClassList("resize");
|
||||
|
||||
switch (anchor)
|
||||
{
|
||||
case ResizeHandleAnchor.Top:
|
||||
{
|
||||
AddToClassList("vertical");
|
||||
AddToClassList("top");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromTop);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.TopRight:
|
||||
{
|
||||
AddToClassList("diagonal");
|
||||
AddToClassList("top-right");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromTopRight);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.Right:
|
||||
{
|
||||
AddToClassList("horizontal");
|
||||
AddToClassList("right");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromRight);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.BottomRight:
|
||||
{
|
||||
AddToClassList("diagonal");
|
||||
AddToClassList("bottom-right");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromBottomRight);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.Bottom:
|
||||
{
|
||||
AddToClassList("vertical");
|
||||
AddToClassList("bottom");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromBottom);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.BottomLeft:
|
||||
{
|
||||
AddToClassList("diagonal");
|
||||
AddToClassList("bottom-left");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromBottomLeft);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.Left:
|
||||
{
|
||||
AddToClassList("horizontal");
|
||||
AddToClassList("left");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromLeft);
|
||||
break;
|
||||
}
|
||||
case ResizeHandleAnchor.TopLeft:
|
||||
{
|
||||
AddToClassList("diagonal");
|
||||
AddToClassList("top-left");
|
||||
RegisterCallback<MouseMoveEvent>(HandleResizeFromTopLeft);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RegisterCallback<MouseDownEvent>(HandleMouseDown);
|
||||
RegisterCallback<MouseUpEvent>(HandleDraggableMouseUp);
|
||||
|
||||
m_ResizeTarget.RegisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
|
||||
}
|
||||
|
||||
void InitialLayoutSetup(GeometryChangedEvent evt)
|
||||
{
|
||||
m_ResizeTarget.UnregisterCallback<GeometryChangedEvent>(InitialLayoutSetup);
|
||||
}
|
||||
|
||||
void HandleResizeFromTop(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = float.NaN;
|
||||
m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax;
|
||||
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
|
||||
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
if (maintainAspectRatio)
|
||||
m_ResizeTarget.style.width = newHeight;
|
||||
|
||||
mouseMoveEvent.StopImmediatePropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromTopRight(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = float.NaN;
|
||||
m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax;
|
||||
m_Container.style.left = m_Container.layout.xMin;
|
||||
m_Container.style.right = float.NaN;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
|
||||
|
||||
if (maintainAspectRatio)
|
||||
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromRight(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.left = m_Container.layout.xMin;
|
||||
m_Container.style.right = float.NaN;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
|
||||
if (maintainAspectRatio)
|
||||
{
|
||||
m_ResizeTarget.style.height = newWidth;
|
||||
}
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromBottomRight(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = m_Container.layout.yMin;
|
||||
m_Container.style.bottom = float.NaN;
|
||||
m_Container.style.left = m_Container.layout.xMin;
|
||||
m_Container.style.right = float.NaN;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width + relativeMousePosition.x);
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
|
||||
|
||||
if (maintainAspectRatio)
|
||||
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromBottom(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = m_Container.layout.yMin;
|
||||
m_Container.style.bottom = float.NaN;
|
||||
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
|
||||
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
if (maintainAspectRatio)
|
||||
m_ResizeTarget.style.width = newHeight;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromBottomLeft(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = m_Container.layout.yMin;
|
||||
m_Container.style.bottom = float.NaN;
|
||||
m_Container.style.left = float.NaN;
|
||||
m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height + relativeMousePosition.y);
|
||||
|
||||
if (maintainAspectRatio)
|
||||
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromLeft(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.left = float.NaN;
|
||||
m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
|
||||
if (maintainAspectRatio)
|
||||
m_ResizeTarget.style.height = newWidth;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleResizeFromTopLeft(MouseMoveEvent mouseMoveEvent)
|
||||
{
|
||||
if (!m_Dragging)
|
||||
return;
|
||||
|
||||
Vector2 relativeMousePosition = mouseMoveEvent.mousePosition - m_ResizeBeginMousePosition;
|
||||
|
||||
// Set anchor points for positioning
|
||||
m_Container.style.top = float.NaN;
|
||||
m_Container.style.bottom = m_Container.parent.layout.height - m_Container.layout.yMax;
|
||||
m_Container.style.left = float.NaN;
|
||||
m_Container.style.right = m_Container.parent.layout.width - m_Container.layout.xMax;
|
||||
|
||||
float newWidth = Mathf.Max(0f, m_ResizeBeginLayout.width - relativeMousePosition.x);
|
||||
float newHeight = Mathf.Max(0f, m_ResizeBeginLayout.height - relativeMousePosition.y);
|
||||
|
||||
if (maintainAspectRatio)
|
||||
newWidth = newHeight = Mathf.Min(newWidth, newHeight);
|
||||
|
||||
m_ResizeTarget.style.width = newWidth;
|
||||
m_ResizeTarget.style.height = newHeight;
|
||||
|
||||
mouseMoveEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleMouseDown(MouseDownEvent mouseDownEvent)
|
||||
{
|
||||
// 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_ResizeBeginLayout = m_ResizeTarget.layout;
|
||||
m_ResizeBeginMousePosition = mouseDownEvent.mousePosition;
|
||||
|
||||
m_Dragging = true;
|
||||
this.CaptureMouse();
|
||||
mouseDownEvent.StopPropagation();
|
||||
}
|
||||
|
||||
void HandleDraggableMouseUp(MouseUpEvent mouseUpEvent)
|
||||
{
|
||||
m_Dragging = false;
|
||||
|
||||
if (this.HasMouseCapture())
|
||||
this.ReleaseMouse();
|
||||
|
||||
if (OnResizeFinished != null)
|
||||
OnResizeFinished();
|
||||
|
||||
m_WindowDockingLayout.CalculateDockingCornerAndOffset(m_Container.layout, m_Container.parent.layout);
|
||||
m_WindowDockingLayout.ApplyPosition(m_Container);
|
||||
}
|
||||
|
||||
protected override void ImmediateRepaint()
|
||||
{
|
||||
if (m_StyleWidget == null)
|
||||
{
|
||||
m_StyleWidget = new GUIStyle("WindowBottomResize") { fixedHeight = 0 };
|
||||
image = m_StyleWidget.normal.background;
|
||||
}
|
||||
|
||||
if (image == null)
|
||||
{
|
||||
Debug.LogWarning("null texture passed to GUI.DrawTexture");
|
||||
return;
|
||||
}
|
||||
|
||||
GUI.DrawTexture(contentRect, image, ScaleMode.ScaleAndCrop, true, 0, GUI.color, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b165bcb20989fa2428253e51bc4f440f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,32 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
class Scrollable : MouseManipulator
|
||||
{
|
||||
Action<float> m_Handler;
|
||||
|
||||
public Scrollable(Action<float> handler)
|
||||
{
|
||||
m_Handler = handler;
|
||||
}
|
||||
|
||||
protected override void RegisterCallbacksOnTarget()
|
||||
{
|
||||
target.RegisterCallback<WheelEvent>(HandleMouseWheelEvent);
|
||||
}
|
||||
|
||||
protected override void UnregisterCallbacksFromTarget()
|
||||
{
|
||||
target.UnregisterCallback<WheelEvent>(HandleMouseWheelEvent);
|
||||
}
|
||||
|
||||
void HandleMouseWheelEvent(WheelEvent evt)
|
||||
{
|
||||
m_Handler(evt.delta.y);
|
||||
evt.StopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ea23c5e75fdbea49824261efe5fc133
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,182 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.UIElements.StyleSheets;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
class WindowDraggable : MouseManipulator
|
||||
{
|
||||
bool m_Active;
|
||||
|
||||
WindowDockingLayout m_WindowDockingLayout;
|
||||
|
||||
Vector2 m_LocalMosueOffset;
|
||||
|
||||
VisualElement m_Handle;
|
||||
GraphView m_GraphView;
|
||||
|
||||
public Action OnDragFinished;
|
||||
|
||||
public WindowDraggable(VisualElement handle = null, VisualElement container = null)
|
||||
{
|
||||
m_Handle = handle;
|
||||
m_Active = false;
|
||||
m_WindowDockingLayout = new WindowDockingLayout();
|
||||
|
||||
if (container != null)
|
||||
container.RegisterCallback<GeometryChangedEvent>(OnParentGeometryChanged);
|
||||
}
|
||||
|
||||
protected override void RegisterCallbacksOnTarget()
|
||||
{
|
||||
if (m_Handle == null)
|
||||
m_Handle = target;
|
||||
m_Handle.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
|
||||
m_Handle.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
|
||||
m_Handle.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
|
||||
target.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
}
|
||||
|
||||
protected override void UnregisterCallbacksFromTarget()
|
||||
{
|
||||
m_Handle.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
|
||||
m_Handle.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
|
||||
m_Handle.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
|
||||
target.UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
if (m_GraphView != null)
|
||||
m_GraphView.UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
}
|
||||
|
||||
void OnMouseDown(MouseDownEvent evt)
|
||||
{
|
||||
m_Active = true;
|
||||
|
||||
VisualElement parent = target.parent;
|
||||
while (parent != null && !(parent is GraphView))
|
||||
parent = parent.parent;
|
||||
m_GraphView = parent as GraphView;
|
||||
|
||||
if (m_GraphView != null)
|
||||
m_GraphView.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
|
||||
// m_LocalMouseOffset is offset from the target element's (0, 0) to the
|
||||
// to the mouse position.
|
||||
m_LocalMosueOffset = m_Handle.WorldToLocal(evt.mousePosition);
|
||||
|
||||
m_Handle.CaptureMouse();
|
||||
evt.StopImmediatePropagation();
|
||||
}
|
||||
|
||||
void OnMouseMove(MouseMoveEvent evt)
|
||||
{
|
||||
if (m_Active)
|
||||
{
|
||||
// The mouse position of is corrected according to the offset within the target
|
||||
// element (m_LocalWorldOffset) to set the position relative to the mouse position
|
||||
// when the dragging started.
|
||||
Vector2 position = target.parent.WorldToLocal(evt.mousePosition) - m_LocalMosueOffset;
|
||||
|
||||
// Make sure that the object remains in the parent window
|
||||
position.x = Mathf.Clamp(position.x, 0f, target.parent.layout.width - target.layout.width);
|
||||
position.y = Mathf.Clamp(position.y, 0f, target.parent.layout.height - target.layout.height);
|
||||
|
||||
// While moving, use only the left and top position properties,
|
||||
// while keeping the others NaN to not affect layout.
|
||||
target.style.left = position.x;
|
||||
target.style.top = position.y;
|
||||
target.style.right = float.NaN;
|
||||
target.style.bottom = float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseUp(MouseUpEvent evt)
|
||||
{
|
||||
bool emitDragFinishedEvent = m_Active;
|
||||
|
||||
m_Active = false;
|
||||
|
||||
if (m_Handle.HasMouseCapture())
|
||||
{
|
||||
m_Handle.ReleaseMouse();
|
||||
}
|
||||
|
||||
evt.StopImmediatePropagation();
|
||||
|
||||
// Recalculate which corner to dock to
|
||||
m_WindowDockingLayout.CalculateDockingCornerAndOffset(target.layout, target.parent.layout);
|
||||
m_WindowDockingLayout.ClampToParentWindow();
|
||||
|
||||
// Use the docking results to figure which of left/right and top/bottom needs to be set.
|
||||
m_WindowDockingLayout.ApplyPosition(target);
|
||||
|
||||
// Signal that the dragging has finished.
|
||||
if (emitDragFinishedEvent && OnDragFinished != null)
|
||||
OnDragFinished();
|
||||
}
|
||||
|
||||
void OnGeometryChanged(GeometryChangedEvent geometryChangedEvent)
|
||||
{
|
||||
// Make the target clamp to the border of the window if the
|
||||
// parent window becomes too small to contain it.
|
||||
if (target.parent.layout.width < target.layout.width)
|
||||
{
|
||||
if (m_WindowDockingLayout.dockingLeft)
|
||||
{
|
||||
target.style.left = 0f;
|
||||
target.style.right = float.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.style.left = float.NaN;
|
||||
target.style.right = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
if (target.parent.layout.height < target.layout.height)
|
||||
{
|
||||
if (m_WindowDockingLayout.dockingTop)
|
||||
{
|
||||
target.style.top = 0f;
|
||||
target.style.bottom = float.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.style.top = float.NaN;
|
||||
target.style.bottom = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnParentGeometryChanged(GeometryChangedEvent geometryChangedEvent)
|
||||
{
|
||||
// Check if the parent window can no longer contain the target window.
|
||||
// If the window is out of bounds, make one edge clamp to the border of the
|
||||
// parent window.
|
||||
if (target.layout.xMin < 0f)
|
||||
{
|
||||
target.style.left = 0f;
|
||||
target.style.right = float.NaN;
|
||||
}
|
||||
|
||||
if (target.layout.xMax > geometryChangedEvent.newRect.width)
|
||||
{
|
||||
target.style.left = float.NaN;
|
||||
target.style.right = 0f;
|
||||
}
|
||||
|
||||
if (target.layout.yMax > geometryChangedEvent.newRect.height)
|
||||
{
|
||||
target.style.top = float.NaN;
|
||||
target.style.bottom = 0f;
|
||||
}
|
||||
|
||||
if (target.layout.yMin < 0f)
|
||||
{
|
||||
target.style.top = 0f;
|
||||
target.style.bottom = float.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 604681490aa779348a355368c95cfcf5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue