Ejemplo n.º 1
0
        void OnGenerateVisualContent(MeshGenerationContext mgc)
        {
            GraphView gView = GetFirstAncestorOfType <GraphView>();

            if (gView == null)
            {
                return;
            }

            VisualElement container = gView.contentViewContainer;

            foreach (Line2 line in lines)
            {
                Vector2 start  = container.ChangeCoordinatesTo(gView, line.start);
                Vector2 end    = container.ChangeCoordinatesTo(gView, line.end);
                float   x      = Math.Min(start.x, end.x);
                float   y      = Math.Min(start.y, end.y);
                float   width  = Math.Max(1, Math.Abs(start.x - end.x));
                float   height = Math.Max(1, Math.Abs(start.y - end.y));

                var rect = new Rect(x, y, width, height);

                mgc.Rectangle(MeshGenerationContextUtils.RectangleParams.MakeSolid(rect, s_SnappingLineColor, ContextType.Editor));
            }
        }
        public virtual void AdjustGeometry()
        {
            if (m_AnchoredControl != null && m_AnchoredControl.visible && parent != null && !float.IsNaN(layout.width) && !float.IsNaN(layout.height))
            {
                var pos = m_AnchoredControl.ChangeCoordinatesTo(parent, Vector2.zero);

                style.left  = pos.x;
                style.top   = pos.y + m_AnchoredControl.layout.height;
                style.width = Math.Max(k_PopupMaxWidth, m_AnchoredControl.resolvedStyle.width);
            }
        }
Ejemplo n.º 3
0
        protected virtual void OnDragUpdatedEvent(DragUpdatedEvent evt)
        {
            VisualElement visualElement = evt.currentTarget as VisualElement;
            TreeViewItem  tree          = null;

            if (visualElement != null)
            {
                var trees = this.Query().Where(v =>
                                               v is TreeViewItem item &&
                                               item.HitTest(
                                                   visualElement.ChangeCoordinatesTo(v, evt.localMousePosition))
                                               ).ToList();
                tree = trees.LastOrDefault() as TreeViewItem;
            }
            object dragData = DragAndDrop.GetGenericData("uNode");

            if (dragData == null && DragAndDrop.objectReferences.Length > 0)
            {
                dragData = DragAndDrop.objectReferences[0];
            }
            if (tree == null || dragData == null)
            {
                RemoveDragIndicator();
                DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                return;
            }
            var  mPos  = visualElement.ChangeCoordinatesTo(tree.titleContainer, evt.localMousePosition);
            bool isTop = mPos.y <= tree.titleContainer.layout.height / 2;

            if (!CanAcceptDrop(tree, dragData))
            {
                RemoveDragIndicator();
                DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                return;
            }
            SetDragIndicator(tree, isTop);
            if (!m_DragStarted)
            {
                // TODO: Do something on first DragUpdated event (initiate drag)
                m_DragStarted = true;
                AddToClassList("dropping");
            }
            else
            {
                // TODO: Do something on subsequent DragUpdated events
                DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
            }
        }
        public void RelayoutScheduledStackedNodes()
        {
            m_TempMovedModels.Clear();
            foreach (KeyValuePair <Node, Rect> pair in m_ScheduledItems)
            {
                VisualElement hierarchyParent = pair.Key.hierarchy.parent;
                if (hierarchyParent != null)
                {
                    Rect cur = hierarchyParent.ChangeCoordinatesTo(m_VseGraphView.contentViewContainer, pair.Key.layout);

                    Vector2 d = cur.position - pair.Value.position;
                    ProcessDependency(pair.Key.model, d, (graphElement, model, delta, _) =>
                    {
                        Vector2 prevPos  = model.DependentNode.Position;
                        Rect posRect     = graphElement.GetPosition();
                        posRect.position = prevPos + delta;
                        if (!model.DependentNode.IsStacked)
                        {
                            graphElement.SetPosition(posRect);
                        }
                        model.DependentNode.Position = posRect.position;
                    });
                }
            }

            m_ScheduledItems.Clear();
        }
Ejemplo n.º 5
0
//        public bool DragUpdated(DragUpdatedEvent evt, IEnumerable<ISelectable> selection, IDropTarget dropTarget)
        public EventPropagation DragUpdated(IMGUIEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget)
        {
            VisualElement sourceItem = null;

            foreach (ISelectable selectedElement in selection)
            {
                sourceItem = selectedElement as VisualElement;

                if (sourceItem == null)
                {
                    continue;
                }
            }

            if (!Contains(sourceItem))
            {
                SetDragIndicatorVisible(false);

                return(EventPropagation.Continue);
            }

            var target = evt.target as VisualElement;
//            Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.localMousePosition);
            Vector2 localPosition = target.ChangeCoordinatesTo(this, evt.imguiEvent.mousePosition);

            m_InsertIndex = InsertionIndex(localPosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY = 0;

                if (m_InsertIndex == childCount)
                {
                    VisualElement lastChild = this[childCount - 1];

                    indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.style.marginBottom)).y;
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.style.marginTop)).y;
                }

                SetDragIndicatorVisible(true);

                m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height);

                return(EventPropagation.Stop);
            }
            else
            {
                SetDragIndicatorVisible(false);

                m_InsertIndex = -1;

                return(EventPropagation.Continue);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get the screen mouse position from the element and its local mouse position.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="mousePosition"></param>
        /// <param name="window"></param>
        /// <returns></returns>
        public static Vector2 GetScreenMousePosition(this VisualElement element, Vector2 mousePosition, EditorWindow window)
        {
            Vector2 position = window.GetMousePositionForMenu(element.ChangeCoordinatesTo(
                                                                  window.rootVisualElement,
                                                                  mousePosition));

            return(position);
        }
Ejemplo n.º 7
0
 void OnGeometryChanged(GeometryChangedEvent evt)
 {
     if (settingButton != null)
     {
         var settingsButtonLayout = settingButton.ChangeCoordinatesTo(settingsContainer.parent, settingButton.layout);
         settingsContainer.style.top  = settingsButtonLayout.yMax - 18f;
         settingsContainer.style.left = settingsButtonLayout.xMin - 26f;
     }
 }
Ejemplo n.º 8
0
        void OnDragUpdatedEvent(DragUpdatedEvent e)
        {
            var selection = DragAndDrop.GetGenericData("DragSelection") as List<ISelectable>;

            if (selection == null)
            {
                SetDragIndicatorVisible(false);
                return;
            }

            if (selection.Any(t => !(t is VFXBlackboardCategory)))
            {
                SetDragIndicatorVisible(false);
                return;
            }

            Vector2 localPosition = e.localMousePosition;

            m_InsertIndex = InsertionIndex(localPosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY = 0;

                if (m_InsertIndex == childCount)
                {
                    if (childCount > 0)
                    {
                        VisualElement lastChild = this[childCount - 1];

                        indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.resolvedStyle.marginBottom)).y;
                    }
                    else
                    {
                        indicatorY = this.contentRect.height;
                    }
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.resolvedStyle.marginTop)).y;
                }

                SetDragIndicatorVisible(true);

                m_DragIndicator.style.top =  indicatorY - m_DragIndicator.resolvedStyle.height * 0.5f;

                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            }
            else
            {
                SetDragIndicatorVisible(false);
            }
            e.StopPropagation();
        }
        void OnGeometryChanged(GeometryChangedEvent evt)
        {
            // style.positionTop and style.positionLeft are in relation to the parent,
            // so we translate the layout of the settings button to be in the coordinate
            // space of the settings view's parent.

            var settingsButtonLayout = m_SettingsButton.ChangeCoordinatesTo(m_NodeSettingsView.parent, m_SettingsButton.layout);

            m_NodeSettingsView.style.top  = settingsButtonLayout.yMax - 18f;
            m_NodeSettingsView.style.left = settingsButtonLayout.xMin - 16f;
        }
Ejemplo n.º 10
0
 protected new void OnMouseMove(MouseMoveEvent e)
 {
     if (!base.target.HasMouseCapture())
     {
         this.m_PrevDropTarget = null;
         this.m_Active         = false;
     }
     if (this.m_Active)
     {
         if (this.m_GraphView != null)
         {
             VisualElement src      = (VisualElement)e.target;
             Vector2       mousePos = src.ChangeCoordinatesTo(this.m_GraphView.contentContainer, e.localMousePosition);
             this.m_PanDiff = this.GetEffectivePanSpeed(mousePos);
             if (this.m_PanDiff != Vector3.zero)
             {
                 this.m_PanSchedule.Resume();
             }
             else
             {
                 this.m_PanSchedule.Pause();
             }
             this.m_MouseDiff = this.m_originalMouse - e.mousePosition;
             foreach (KeyValuePair <GraphElement, Rect> current in this.m_OriginalPos)
             {
                 GraphElement key            = current.Key;
                 Matrix4x4    worldTransform = key.worldTransform;
                 Vector3      vector         = new Vector3(worldTransform.m00, worldTransform.m11, worldTransform.m22);
                 Rect         position       = key.GetPosition();
                 key.SetPosition(new Rect(current.Value.x - (this.m_MouseDiff.x - this.m_ItemPanDiff.x) * base.panSpeed.x / vector.x, current.Value.y - (this.m_MouseDiff.y - this.m_ItemPanDiff.y) * base.panSpeed.y / vector.y, position.width, position.height));
             }
             List <ISelectable> selection    = this.m_GraphView.selection;
             IDropTarget        dropTargetAt = this.GetDropTargetAt(e.localMousePosition);
             if (this.m_PrevDropTarget != dropTargetAt && this.m_PrevDropTarget != null)
             {
                 using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent))
                 {
                     pooled.imguiEvent.type = EventType.DragExited;
                     this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget);
                 }
             }
             using (IMGUIEvent pooled2 = IMGUIEvent.GetPooled(e.imguiEvent))
             {
                 pooled2.imguiEvent.type = EventType.DragUpdated;
                 this.SendDragAndDropEvent(pooled2, selection, dropTargetAt);
             }
             this.m_PrevDropTarget = dropTargetAt;
             this.selectedElement  = null;
             e.StopPropagation();
         }
     }
 }
Ejemplo n.º 11
0
        internal IEnumerable <NodeView> CaclulateSelectedNodes(Rect rect)
        {
            Rect localRect;

            foreach (var view in nodeTable.Values)
            {
                localRect = workspace.ChangeCoordinatesTo(view, rect);
                if (view.Overlaps(localRect))
                {
                    yield return(view);
                }
            }
        }
        public static Rect GetRelativeRectFromTargetElement(VisualElement target, VisualElement relativeTo)
        {
            var targetMarginTop    = target.resolvedStyle.marginTop;
            var targetMarginLeft   = target.resolvedStyle.marginLeft;
            var targetMarginRight  = target.resolvedStyle.marginRight;
            var targetMarginBottom = target.resolvedStyle.marginBottom;

            Rect targetRect = target.rect;

            targetRect.y     -= targetMarginTop;
            targetRect.x     -= targetMarginLeft;
            targetRect.width  = targetRect.width + (targetMarginLeft + targetMarginRight);
            targetRect.height = targetRect.height + (targetMarginTop + targetMarginBottom);

            var relativeRect = target.ChangeCoordinatesTo(relativeTo, targetRect);

            return(relativeRect);
        }
Ejemplo n.º 13
0
        void OnPick(MouseDownEvent evt)
        {
            // Do not prevent zoom and pan
            if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey)))
            {
                return;
            }

            var pickedElement = PickElement(evt.mousePosition);

            if (pickedElement != null)
            {
                m_Selection.Select(this, pickedElement);
                SetInnerSelection(pickedElement);

                if (evt.clickCount == 2)
                {
                    var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition);
                    BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport));
                }
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            if (evt.button == (int)MouseButton.RightMouse)
            {
                if (pickedElement != null && m_ContextMenuManipulator != null)
                {
                    pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement);
                    m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement);
                    m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement);
                    evt.StopPropagation();
                }
            }
            else
            {
                evt.StopPropagation();
            }
        }
        protected void OnDragUpdatedEvent(DragUpdatedEvent evt)
        {
            var draggedObjects = DragAndDrop.GetGenericData("DragSelection") as List <IGraphElementModel>;

            if (!CanAcceptDrop(draggedObjects))
            {
                HideDragIndicator();
                return;
            }

            m_InsertIndex = InsertionIndex(evt.localMousePosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY;

                if (m_InsertIndex == childCount)
                {
                    VisualElement lastChild = this[m_InsertIndex - 1];

                    indicatorY = lastChild.ChangeCoordinatesTo(this,
                                                               new Vector2(0, lastChild.layout.height + lastChild.resolvedStyle.marginBottom)).y;
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this,
                                                                        new Vector2(0, -childAtInsertIndex.resolvedStyle.marginTop)).y;
                }

                ShowDragIndicator(indicatorY);
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            }
            else
            {
                HideDragIndicator();
            }

            evt.StopPropagation();
        }
Ejemplo n.º 15
0
        protected void ResizeSelfFromTarget(Rect targetRect)
        {
            var targetMarginTop    = m_Target.resolvedStyle.marginTop;
            var targetMarginLeft   = m_Target.resolvedStyle.marginLeft;
            var targetMarginRight  = m_Target.resolvedStyle.marginRight;
            var targetMarginBottom = m_Target.resolvedStyle.marginBottom;

            targetRect.y     -= targetMarginTop;
            targetRect.x     -= targetMarginLeft;
            targetRect.width  = targetRect.width + (targetMarginLeft + targetMarginRight);
            targetRect.height = targetRect.height + (targetMarginTop + targetMarginBottom);

            var selfRect = m_Target.ChangeCoordinatesTo(this.hierarchy.parent, targetRect);

            var top    = selfRect.y;
            var left   = selfRect.x;
            var width  = selfRect.width;
            var height = selfRect.height;

            style.top    = top;
            style.left   = left;
            style.width  = width;
            style.height = height;
        }
Ejemplo n.º 16
0
        private void OnMouseDown(MouseDownEvent evt)
        {
            if (_active)
            {
                evt.StopImmediatePropagation();
                return;
            }

            if (!target.ContainsPoint(evt.localMousePosition) || !CanStartManipulation(evt))
            {
                return;
            }

            if (_moveTarget == null)
            {
                _moveTarget = target;
            }


            if (_snapCenterToMouse)
            {
                StartPosition = new Vector2(_moveTarget.layout.width * 0.5f, _moveTarget.layout.height * 0.5f);
                Vector2 position = _moveTarget.ChangeCoordinatesTo(_moveTarget.parent, target.ChangeCoordinatesTo(_moveTarget, evt.localMousePosition) - StartPosition);
                _moveTarget.style.left = position.x;
                _moveTarget.style.top  = position.y;
            }
            else
            {
                StartPosition = target.ChangeCoordinatesTo(_moveTarget, evt.localMousePosition);
            }

            _active = true;
            target.CaptureMouse();
            OnActivated?.Invoke(evt);
            evt.StopPropagation();
        }
        static Rect CalculateRectToFitElements(GraphView graphView, IReadOnlyList <GraphElement> graphElements)
        {
            Rect rectToFit = graphView.ContentViewContainer.layout;

            if (graphElements == null || graphElements.Count == 0)
            {
                return(rectToFit);
            }

            VisualElement graphElement = graphElements[0];

            if (graphElement != null)
            {
                // Edges don't have a size. Only their internal EdgeControl have a size.
                if (graphElement is Edge edge)
                {
                    graphElement = edge.EdgeControl;
                }

                rectToFit = graphElement.ChangeCoordinatesTo(graphView.ContentViewContainer, graphElement.GetRect());
            }

            rectToFit = graphElements.Aggregate(rectToFit, (current, currentGraphElement) =>
            {
                VisualElement currentElement = currentGraphElement;

                if (currentGraphElement is Edge edge)
                {
                    currentElement = edge.EdgeControl;
                }

                return(RectUtils.Encompass(current, currentElement.ChangeCoordinatesTo(graphView.ContentViewContainer, currentElement.GetRect())));
            });

            return(rectToFit);
        }
Ejemplo n.º 18
0
        public void UpdateGeometryFromContent()
        {
            if (panel == null || !m_Initialized || m_IsUpdatingGeometryFromContent || m_IsMovingElements)
            {
                return;
            }

            GraphView graphView = GetFirstAncestorOfType <GraphView>();

            if (graphView == null)
            {
                return;
            }

            m_IsUpdatingGeometryFromContent = true;

            VisualElement viewport = graphView.contentViewContainer;
            Rect          contentRectInViewportSpace = Rect.zero;

            // Compute the bounding box of the content of the group in viewport space (because nodes are not parented by the group that contains them)
            if (m_ContainedElements != null)
            {
                for (int i = 0; i < m_ContainedElements.Count; ++i)
                {
                    GraphElement subElement = m_ContainedElements[i];

                    if (subElement.panel != panel)
                    {
                        continue;
                    }

                    Rect boundingRect = new Rect(0, 0, subElement.GetPosition().width, subElement.GetPosition().height);

                    if (IsValidRect(boundingRect))
                    {
                        boundingRect = subElement.ChangeCoordinatesTo(viewport, boundingRect);

                        // Use the first element with a valid geometry as reference to compute the bounding box of contained elements
                        if (!IsValidRect(contentRectInViewportSpace))
                        {
                            contentRectInViewportSpace = boundingRect;
                        }
                        else
                        {
                            contentRectInViewportSpace = RectUtils.Encompass(contentRectInViewportSpace, boundingRect);
                        }
                    }
                }
            }

            if ((m_ContainedElements == null) || (m_ContainedElements.Count == 0))
            {
                float contentX = m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value;
                float contentY = m_HeaderItem.layout.height + m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value;

                contentRectInViewportSpace = this.ChangeCoordinatesTo(viewport, new Rect(contentX, contentY, 0, 0));
            }

            float titleItemImplicitWidth = k_TitleItemMinWidth;

            if (m_HeaderItem != null)
            {
                Vector2 implicitSize = m_TitleItem.DoMeasure(100, MeasureMode.Undefined, 100, MeasureMode.Undefined);

                if (IsValidSize(implicitSize))
                {
                    titleItemImplicitWidth = implicitSize.x + m_TitleItem.style.marginLeft.value + m_TitleItem.style.paddingLeft.value
                                             + m_TitleItem.style.paddingRight.value + m_TitleItem.style.marginRight.value;
                }
            }

            float headerItemImplicitWidth = titleItemImplicitWidth + m_HeaderItem.style.paddingLeft.value + m_HeaderItem.style.paddingRight.value;

            Vector2 contentRectSize = contentRectInViewportSpace.size;

            contentRectSize.x += m_ContentItem.style.borderLeftWidth.value + m_ContentItem.style.paddingLeft.value + m_ContentItem.style.paddingRight.value + m_ContentItem.style.borderRightWidth.value;
            contentRectSize.y += m_ContentItem.style.borderTopWidth.value + m_ContentItem.style.paddingTop.value + m_ContentItem.style.paddingBottom.value + m_ContentItem.style.borderBottomWidth.value;

            Rect groupGeometry = new Rect();

            groupGeometry.position = viewport.ChangeCoordinatesTo(parent, contentRectInViewportSpace.position);
            groupGeometry.width    = Math.Max(contentRectSize.x, headerItemImplicitWidth) + style.borderLeftWidth.value + style.borderRightWidth.value; // Ensure that the title is always visible
            groupGeometry.height   = contentRectSize.y + m_HeaderItem.layout.height + style.borderTopWidth.value + style.borderBottomWidth.value;

            groupGeometry.x -= m_ContentItem.style.paddingLeft.value + style.borderLeftWidth.value;
            groupGeometry.y -= m_ContentItem.style.paddingTop.value + m_HeaderItem.layout.height + style.borderTopWidth.value;

            SetPosition(groupGeometry);

            Vector2 newPosInCanvasSpace = this.ChangeCoordinatesTo(viewport, new Vector2(0, 0));

            mPreviousPosInCanvasSpace       = newPosInCanvasSpace;
            m_ContainedElementsRect         = viewport.ChangeCoordinatesTo(this, contentRectInViewportSpace);
            m_IsUpdatingGeometryFromContent = false;
        }
Ejemplo n.º 19
0
        EventPropagation Frame(FrameType frameType)
        {
            Rect    rectToFit        = contentViewContainer.layout;
            Vector3 frameTranslation = Vector3.zero;
            Vector3 frameScaling     = Vector3.one;

            if (frameType == FrameType.Selection &&
                (selection.Count == 0 || !selection.Any(e => e.IsSelectable() && !(e is Edge))))
            {
                frameType = FrameType.All;
            }

            if (frameType == FrameType.Selection)
            {
                VisualElement graphElement = selection[0] as GraphElement;
                if (graphElement != null)
                {
                    // Edges don't have a size. Only their internal EdgeControl have a size.
                    if (graphElement is Edge)
                    {
                        graphElement = (graphElement as Edge).EdgeControl;
                    }
                    rectToFit = graphElement.ChangeCoordinatesTo(contentViewContainer, graphElement.GetRect());
                }

                rectToFit = selection.Cast <GraphElement>()
                            .Aggregate(rectToFit, (current, currentGraphElement) =>
                {
                    VisualElement currentElement = currentGraphElement;
                    if (currentGraphElement is Edge)
                    {
                        currentElement = (currentGraphElement as Edge).EdgeControl;
                    }
                    return(RectUtils.Encompass(current, currentElement.ChangeCoordinatesTo(contentViewContainer, currentElement.GetRect())));
                });
                CalculateFrameTransform(rectToFit, layout, k_FrameBorder, out frameTranslation, out frameScaling);
            }
            else if (frameType == FrameType.All)
            {
                rectToFit = CalculateRectToFitAll(contentViewContainer);
                CalculateFrameTransform(rectToFit, layout, k_FrameBorder, out frameTranslation, out frameScaling);
            } // else keep going if (frameType == FrameType.Origin)

            if (m_FrameAnimate)
            {
                // TODO Animate framing
                // RMAnimation animation = new RMAnimation();
                // parent.Animate(parent)
                //       .Lerp(new string[] {"m_Scale", "m_Translation"},
                //             new object[] {parent.scale, parent.translation},
                //             new object[] {frameScaling, frameTranslation}, 0.08f);
            }
            else
            {
                Matrix4x4.TRS(frameTranslation, Quaternion.identity, frameScaling);

                UpdateViewTransform(frameTranslation, frameScaling);
            }

            contentViewContainer.MarkDirtyRepaint();

            UpdatePersistedViewTransform();

            return(EventPropagation.Stop);
        }
Ejemplo n.º 20
0
        private void OnDragUpdatedEvent(DragUpdatedEvent evt)
        {
            var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>;

            if (!CanAcceptDrop(selection))
            {
                SetDragIndicatorVisible(false);
                return;
            }

            VisualElement sourceItem = null;

            foreach (ISelectable selectedElement in selection)
            {
                sourceItem = selectedElement as VisualElement;

                if (sourceItem == null)
                {
                    continue;
                }
            }

            if (!Contains(sourceItem))
            {
                SetDragIndicatorVisible(false);
                return;
            }

            Vector2 localPosition = evt.localMousePosition;

            m_InsertIndex = InsertionIndex(localPosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY = 0;

                if (m_InsertIndex == childCount)
                {
                    VisualElement lastChild = this[childCount - 1];

                    indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.resolvedStyle.marginBottom)).y;
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.resolvedStyle.marginTop)).y;
                }

                SetDragIndicatorVisible(true);

                m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height);
            }
            else
            {
                SetDragIndicatorVisible(false);

                m_InsertIndex = -1;
            }

            if (m_InsertIndex != -1)
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
            }

            evt.StopPropagation();
        }
Ejemplo n.º 21
0
        private void OnDragUpdatedEvent(DragUpdatedEvent evt)
        {
            var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>;

            if (selection == null)
            {
                SetDragIndicatorVisible(false);
                return;
            }

            if (selection.Any(t => !(t is VFXBlackboardField)))
            {
                SetDragIndicatorVisible(false);
                return;
            }

            Vector2 localPosition = evt.localMousePosition;

            m_InsertIndex = InsertionIndex(localPosition);

            if (m_InsertIndex != -1)
            {
                float indicatorY = 0;

                if (m_InsertIndex == childCount)
                {
                    if (childCount > 0)
                    {
                        VisualElement lastChild = this[childCount - 1];

                        indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.style.marginBottom)).y;
                    }
                    else
                    {
                        indicatorY = this.contentRect.height;
                    }
                }
                else
                {
                    VisualElement childAtInsertIndex = this[m_InsertIndex];

                    indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.style.marginTop)).y;
                }

                SetDragIndicatorVisible(true);

                m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height);
            }
            else
            {
                SetDragIndicatorVisible(false);

                m_InsertIndex = -1;
            }

            if (m_InsertIndex != -1)
            {
                DragAndDrop.visualMode = evt.ctrlKey ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move;
            }

            evt.StopPropagation();
        }
Ejemplo n.º 22
0
 public void UpdateGeometryFromContent()
 {
     if (base.panel != null && this.m_Initialized && !this.m_IsUpdatingGeometryFromContent && !this.m_IsMovingElements)
     {
         GraphView firstAncestorOfType = base.GetFirstAncestorOfType <GraphView>();
         if (firstAncestorOfType != null)
         {
             this.m_IsUpdatingGeometryFromContent = true;
             VisualElement contentViewContainer = firstAncestorOfType.contentViewContainer;
             Rect          rect = Rect.zero;
             if (this.m_ContainedElements != null)
             {
                 for (int i = 0; i < this.m_ContainedElements.Count; i++)
                 {
                     GraphElement graphElement = this.m_ContainedElements[i];
                     if (graphElement.panel == base.panel)
                     {
                         Rect rect2 = new Rect(0f, 0f, graphElement.GetPosition().width, graphElement.GetPosition().height);
                         if (GroupNode.IsValidRect(rect2))
                         {
                             rect2 = graphElement.ChangeCoordinatesTo(contentViewContainer, rect2);
                             if (!GroupNode.IsValidRect(rect))
                             {
                                 rect = rect2;
                             }
                             else
                             {
                                 rect = RectUtils.Encompass(rect, rect2);
                             }
                         }
                     }
                 }
             }
             if (this.m_ContainedElements == null || this.m_ContainedElements.Count == 0)
             {
                 float x = this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value;
                 float y = this.m_HeaderItem.layout.height + this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value;
                 rect = this.ChangeCoordinatesTo(contentViewContainer, new Rect(x, y, 0f, 0f));
             }
             float num = 10f;
             if (this.m_HeaderItem != null)
             {
                 Vector2 size = this.m_TitleItem.DoMeasure(100f, VisualElement.MeasureMode.Undefined, 100f, VisualElement.MeasureMode.Undefined);
                 if (GroupNode.IsValidSize(size))
                 {
                     num = size.x + this.m_TitleItem.style.marginLeft.value + this.m_TitleItem.style.paddingLeft.value + this.m_TitleItem.style.paddingRight.value + this.m_TitleItem.style.marginRight.value;
                 }
             }
             float   val   = num + this.m_HeaderItem.style.paddingLeft.value + this.m_HeaderItem.style.paddingRight.value;
             Vector2 size2 = rect.size;
             size2.x += this.m_ContentItem.style.borderLeftWidth.value + this.m_ContentItem.style.paddingLeft.value + this.m_ContentItem.style.paddingRight.value + this.m_ContentItem.style.borderRightWidth.value;
             size2.y += this.m_ContentItem.style.borderTopWidth.value + this.m_ContentItem.style.paddingTop.value + this.m_ContentItem.style.paddingBottom.value + this.m_ContentItem.style.borderBottomWidth.value;
             Rect position = default(Rect);
             position.position = contentViewContainer.ChangeCoordinatesTo(base.parent, rect.position);
             position.width    = Math.Max(size2.x, val) + base.style.borderLeftWidth.value + base.style.borderRightWidth.value;
             position.height   = size2.y + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value + base.style.borderBottomWidth.value;
             position.x       -= this.m_ContentItem.style.paddingLeft.value + base.style.borderLeftWidth.value;
             position.y       -= this.m_ContentItem.style.paddingTop.value + this.m_HeaderItem.layout.height + base.style.borderTopWidth.value;
             this.SetPosition(position);
             Vector2 vector = this.ChangeCoordinatesTo(contentViewContainer, new Vector2(0f, 0f));
             this.mPreviousPosInCanvasSpace       = vector;
             this.m_ContainedElementsRect         = contentViewContainer.ChangeCoordinatesTo(this, rect);
             this.m_IsUpdatingGeometryFromContent = false;
         }
     }
 }
Ejemplo n.º 23
0
        void OnPick(MouseDownEvent evt)
        {
            // Do not prevent zoom and pan
            if (evt.button == 2 || (evt.ctrlKey && evt.altKey || (evt.button == (int)MouseButton.RightMouse && evt.altKey)))
            {
                return;
            }

            m_PickedElements.Clear();
            var pickedElement = PickElement(evt.mousePosition, m_PickedElements);

            if (pickedElement != null)
            {
                var timeSinceStartup  = EditorApplication.timeSinceStartup;
                var previousMouseRect = new Rect(
                    m_PreviousPickMousePosition.x - BuilderConstants.PickSelectionRepeatRectHalfSize,
                    m_PreviousPickMousePosition.y - BuilderConstants.PickSelectionRepeatRectHalfSize,
                    BuilderConstants.PickSelectionRepeatRectSize,
                    BuilderConstants.PickSelectionRepeatRectSize);
                if (timeSinceStartup - m_PreviousPickMouseTime > BuilderConstants.PickSelectionRepeatMinTimeDelay && previousMouseRect.Contains(evt.mousePosition))
                {
                    m_SameLocationPickCount++;
                    var offset = 0;

                    var index = m_PickedElements.IndexOf(pickedElement);
                    // For compound controls, we don't seem to have the actual field root element
                    // in the pickedElements list. So we get index == -1 here. We need to do
                    // some magic to select the proper parent element from the list then.
                    if (index < 0)
                    {
                        index  = m_PickedElements.IndexOf(pickedElement.parent);
                        offset = 1;
                    }

                    var maxIndex = m_PickedElements.Count - 1;
                    var newIndex = index + m_SameLocationPickCount - offset;
                    if (newIndex > maxIndex)
                    {
                        m_SameLocationPickCount = 0;
                    }
                    else
                    {
                        pickedElement = m_PickedElements[newIndex];
                    }
                }
                else
                {
                    m_SameLocationPickCount = 0;
                }
                m_PreviousPickMousePosition = evt.mousePosition;
                m_PreviousPickMouseTime     = EditorApplication.timeSinceStartup;

                m_Selection.Select(this, pickedElement);
                SetInnerSelection(pickedElement);

                if (evt.clickCount == 2)
                {
                    var posInViewport = m_PickOverlay.ChangeCoordinatesTo(this, evt.localMousePosition);
                    BuilderInPlaceTextEditingUtilities.OpenEditor(pickedElement, this.ChangeCoordinatesTo(pickedElement, posInViewport));
                }
            }
            else
            {
                ClearInnerSelection();
                m_Selection.ClearSelection(this);
            }

            if (evt.button == (int)MouseButton.RightMouse)
            {
                if (pickedElement != null && m_ContextMenuManipulator != null)
                {
                    pickedElement.SetProperty(BuilderConstants.ElementLinkedDocumentVisualElementVEPropertyName, pickedElement);
                    m_ContextMenuManipulator.RegisterCallbacksOnTarget(pickedElement);
                    m_ContextMenuManipulator.DisplayContextMenu(evt, pickedElement);
                    evt.StopPropagation();
                }
            }
            else
            {
                evt.StopPropagation();
            }
        }