Example #1
0
        private void StartSingleDrag(BonsaiInputEvent startEvent)
        {
            BonsaiNode node   = startEvent.node;
            Vector2    offset = EditorSingleDrag.StartDrag(node, startEvent.canvasMousePostion);

            MotionAction = (CanvasTransform t) => EditorSingleDrag.Drag(node, BonsaiInput.MousePosition(t), offset);
        }
Example #2
0
 private void MouseUp(object sender, BonsaiInputEvent inputEvent)
 {
     if (CanApplyAction == null || CanApplyAction(inputEvent))
     {
         ApplyAction?.Invoke(inputEvent);
     }
     ClearActions();
 }
        private void MouseUp(object sender, BonsaiInputEvent inputEvent)
        {
            ApplyAction?.Invoke(inputEvent);
            ClearActions();

            // Update selection caused by changing connections or clicks.
            UpdateAbortableSelection();
        }
Example #4
0
 private void Clicked(object sender, BonsaiInputEvent inputEvent)
 {
     // Quickly clicked a node when in multi-selection.
     // Select the single node.
     if (!Event.current.control && inputEvent.node != null && NodeSelection.IsMultiSelection)
     {
         NodeSelection.SetSingleSelection(inputEvent.node);
     }
 }
 private void DoubleClicked(object sender, BonsaiInputEvent inputEvent)
 {
     if (inputEvent.node != null)
     {
         // Open sub-tree
         var include = inputEvent.node.Behaviour as Standard.Include;
         if (include)
         {
             OpenIncludedSubTree(include);
         }
     }
 }
Example #6
0
        private void MouseDown(object sender, BonsaiInputEvent inputEvent)
        {
            // Busy, action is active.
            if (MotionAction != null)
            {
                return;
            }

            if (inputEvent.IsPortFocused())
            {
                StartConnection(inputEvent);
            }

            else if (inputEvent.IsNodeFocused())
            {
                // Apply node linking.
                if (!NodeSelection.IsEmpty && Event.current.shift)
                {
                    BonsaiNode sourceLink = NodeSelection.FirstNodeSelected;
                    BonsaiNode nodeToLink = inputEvent.node;
                    if (EditorNodeLinking.ApplyLink(sourceLink.Behaviour, nodeToLink.Behaviour))
                    {
                        NodeSelection.SetReferenced(sourceLink.Behaviour);
                    }
                }

                // Extended selection mode.
                else if (Event.current.control)
                {
                    NodeSelection.ToggleSelecion(inputEvent.node);
                }

                else if (!NodeSelection.IsNodeSelected(inputEvent.node))
                {
                    // This condition is necessary, so multi-dragging works when clicking on a node under multi-select.
                    NodeSelection.SetSingleSelection(inputEvent.node);
                }

                StartDrag(inputEvent);
            }

            else
            {
                NodeSelection.SetTreeSelection(Canvas.Tree);
                // Canvas was clicked on.
                StartAreaSelection(inputEvent);
            }
        }
Example #7
0
        private void StartDrag(BonsaiInputEvent e)
        {
            // Dragging is only only allowed in edit mode.
            if (IsEditMode)
            {
                if (NodeSelection.IsSingleSelection)
                {
                    StartSingleDrag(e);
                }

                else if (NodeSelection.IsMultiSelection)
                {
                    StartMultiDrag(e);
                }
            }
        }
        private void HandleClickActions(CanvasTransform t, IReadOnlyList <BonsaiNode> nodes, Event e)
        {
            if (IsClickAction(e))
            {
                if (quickClicksCount == 0)
                {
                    doubleClickTimer.Start();
                }

                clickTimer.Start();
                MouseDown?.Invoke(this, CreateInputEvent(t, nodes));
            }

            else if (IsUnlickAction(e))
            {
                BonsaiInputEvent inputEvent = CreateInputEvent(t, nodes);

                // A node click is registered if below a time threshold.
                if (clickTimer.Enabled)
                {
                    Click?.Invoke(this, inputEvent);
                }

                // Collect quick, consecutive clicks.
                if (doubleClickTimer.Enabled)
                {
                    quickClicksCount++;
                }

                // Double click event occured.
                if (quickClicksCount >= 2)
                {
                    DoubleClick?.Invoke(this, inputEvent);
                    doubleClickTimer.Stop();
                    quickClicksCount = 0;
                }

                clickTimer.Stop();
                MouseUp?.Invoke(this, inputEvent);
            }
        }
Example #9
0
        private void StartConnection(BonsaiInputEvent startEvent)
        {
            BonsaiNode parent = startEvent.isOutputFocused
        ? startEvent.node
        : EditorNodeConnecting.StartConnection(startEvent.node);

            if (parent != null)
            {
                ApplyAction = (BonsaiInputEvent applyEvent)
                              => EditorNodeConnecting.FinishConnection(Canvas, parent, applyEvent.node);

                CanApplyAction = (BonsaiInputEvent checkEvent) => checkEvent.node != null;

                Viewer.CustomDraw = (CanvasTransform t) =>
                {
                    var start = t.CanvasToScreenSpace(parent.OutputRect.center);
                    var end   = Event.current.mousePosition;
                    Drawer.DrawRectConnectionScreenSpace(start, end, Color.white);
                    OnCanvasChanged();
                };
            }
        }
Example #10
0
        private void StartAreaSelection(BonsaiInputEvent startEvent)
        {
            Vector2 startScreenSpace = Event.current.mousePosition;
            Vector2 start            = startEvent.canvasMousePostion;

            ApplyAction = (BonsaiInputEvent applyEvent) =>
            {
                Vector2 end           = applyEvent.canvasMousePostion;
                var     areaSelection = EditorAreaSelect.NodesUnderArea(Canvas.Nodes, start, end);
                NodeSelection.SetMultiSelection(areaSelection.ToList());
            };

            Viewer.CustomOverlayDraw = () =>
            {
                // Construct and display the rect.
                Vector2 endScreenSpace = Event.current.mousePosition;
                Rect    selectionRect  = EditorAreaSelect.SelectionArea(startScreenSpace, endScreenSpace);
                Color   selectionColor = new Color(0f, 0.5f, 1f, 0.1f);
                Handles.DrawSolidRectangleWithOutline(selectionRect, selectionColor, Color.blue);
                OnCanvasChanged();
            };
        }
        private void HandleClickActions(CanvasTransform t, IReadOnlyList <BonsaiNode> nodes, Event e)
        {
            if (IsClickAction(e))
            {
                clickTimer.Start();
                MouseDown?.Invoke(this, CreateInputEvent(t, nodes));
            }

            else if (IsUnlickAction(e))
            {
                BonsaiInputEvent inputEvent = CreateInputEvent(t, nodes);

                // A node click is registered if below a time threshold.
                if (clickTimer.Enabled)
                {
                    Click?.Invoke(this, inputEvent);
                }

                // Reset for next click.
                clickTimer.Stop();
                MouseUp?.Invoke(this, inputEvent);
            }
        }
        private void StartConnection(BonsaiInputEvent startEvent)
        {
            bool isOutputFocused = startEvent.isOutputFocused;

            BonsaiNode parent = isOutputFocused
        ? startEvent.node
        : EditorNodeConnecting.StartConnection(startEvent.node);

            if (parent != null)
            {
                ApplyAction = (BonsaiInputEvent applyEvent) =>
                {
                    if (applyEvent.node != null)
                    {
                        EditorNodeConnecting.FinishConnection(Canvas, parent, applyEvent.node);
                    }

                    // Connection dropped on canvas. Show create menu to make a new connected node.
                    // Only do this for connections started from the output port.
                    else if (isOutputFocused)
                    {
                        // We have to cache the parent because GenericMenu's callback upong selecting an item is deferred,
                        // and cannot handle node connection in this scope.
                        pendingParentConnection = parent;
                        Input.ShowCreateNodeMenu();
                    }
                };

                Viewer.CustomDraw = (CanvasTransform t) =>
                {
                    var start = t.CanvasToScreenSpace(parent.OutputRect.center);
                    var end   = Event.current.mousePosition;
                    Drawer.DrawRectConnectionScreenSpace(start, end, Color.white);
                    OnCanvasChanged();
                };
            }
        }
Example #13
0
        private void StartMultiDrag(BonsaiInputEvent startEvent)
        {
            var nodes = EditorMultiDrag.StartDrag(NodeSelection.SelectedNodes, startEvent.canvasMousePostion);

            MotionAction = (CanvasTransform t) => EditorMultiDrag.Drag(BonsaiInput.MousePosition(t), nodes);
        }