protected InteractiveHeaderedItem PrepareGroup(string title, IDrawableRectangle content)
        {
            #region Prepare Group Container
            DrawableItemsStack headerPlus  = new DrawableItemsStack();
            DrawableItemsStack headerMinus = new DrawableItemsStack();

            headerPlus.OrientationAxis  = Axis.X;
            headerMinus.OrientationAxis = Axis.X;
            #endregion

            #region Create Header
            TextSegment titleSegment = new TextSegment(Graphics, title, GroupTitleFont, true);

            PlusShape plus = new PlusShape();
            plus.Border = 3;
            headerPlus.Add(plus);
            headerPlus.Add(titleSegment);

            MinusShape minus = new MinusShape();
            minus.Border = 3;
            headerMinus.Add(minus);
            headerMinus.Add(titleSegment);

            DrawableItemsStack headerCollapsed = new DrawableItemsStack();
            DrawableItemsStack headerExpanded  = new DrawableItemsStack();

            headerCollapsed.OrientationAxis = Axis.Z;
            headerExpanded.OrientationAxis  = Axis.Z;

            headerCollapsed.Add(new DrawableRectangle(InnerTitlesBackground, null));
            headerCollapsed.Add(headerPlus);

            headerExpanded.Add(new DrawableRectangle(InnerTitlesBackground, null));
            headerExpanded.Add(headerMinus);
            #endregion

            InteractiveHeaderedItem tg = new InteractiveHeaderedItem(headerCollapsed, headerExpanded, content);
            tg.HeaderClicked += delegate { tg.Collapsed = !tg.Collapsed; };
            IMouseInteractable interactive = content as IMouseInteractable;
            if (interactive != null)
            {
                tg.ContentClicked += delegate(object sender, PointF pos) { interactive.HandleMouseClick(pos); }
            }
            ;
            tg.RedrawNeeded += HandleRedraw;

            return(tg);
        }
Exemple #2
0
        private IMouseInteractable GetMouseInteractionSource(Vector2 mousePosition)
        {
            IMouseInteractable source = null;

            foreach (var socket in _canvas.GetSockets())
            {
                source = socket.Editor().IsMouseOver(mousePosition);
                if (source != null)
                {
                    return(source);
                }
            }
            foreach (Node node in _canvas.Graph.NodeList)
            {
                source = node.Editor().IsMouseOver(mousePosition);
                if (source != null)
                {
                    return(source);
                }
            }

            foreach (var edge in _canvas.Graph.Editor().Edges)
            {
                source = edge.Editor().IsMouseOver(mousePosition);
                if (source != null)
                {
                    return(source);
                }
            }

            foreach (var @group in _canvas.Graph.GroupList)
            {
                source = @group.Editor().IsMouseOver(mousePosition);
                if (source != null)
                {
                    return(source);
                }
            }

            return(null);
        }
Exemple #3
0
 private void SetMouseInteractionSource()
 {
     _interactionSource = GetMouseInteractionSource(_mousePosition);
 }
Exemple #4
0
        private void ProcessMouseEvents(Event currentEvent)
        {
            // set isInCanvas, mousePos
            SetupMouseInfo();

            if (!_isMouseInCanvas)
            {
                return;
            }


            switch (currentEvent.type)
            {
            // *********************************** Mouse Down
            case EventType.MouseDown:
                FollowMachineInspector.CloseAll();

                // get interaction source
                _interactionSource = GetMouseInteractionSource(_mousePosition);

                if (_interactionSource == null)
                {
                    if (currentEvent.button == 0)
                    {
                        _interactionSource = _canvas.BoxSelection;
                    }
                    else
                    {
                        _canvas.CreationMenu.Show(_mousePosition);
                    }
                }

                if (currentEvent.clickCount < 2)
                {
                    _interactionSource?.MouseDown(_mousePosition, currentEvent);
                }
                else
                {
                    _interactionSource?.DoubleClick(_mousePosition, currentEvent);
                }

                Event.current.Use();
                break;

            // *********************************** Mouse Drag
            case EventType.MouseDrag:
                _interactionSource?.MouseDrag(
                    currentEvent.delta / _canvas.Zoom,
                    _mousePosition,
                    currentEvent);
                break;

            // *********************************** Mouse Up
            case EventType.MouseUp:
                if (_interactionSource != null)
                {
                    _interactionSource.MouseUp(_mousePosition, currentEvent);
                    _interactionSource = null;
                }

                break;

            // *********************************** Mouse Move
            case EventType.MouseMove:
                // exit if mouse not in canvas
                if (!_isMouseInCanvas)
                {
                    return;
                }

                var source = GetMouseInteractionSource(_mousePosition);

                if (source != _interactionSource)
                {
                    source?.MouseEnter(_mousePosition, currentEvent);
                    _interactionSource?.MouseExit(_mousePosition, currentEvent);
                    _interactionSource = source;
                }

                source?.MouseMove(_mousePosition, currentEvent);

                break;

            // ******************************* Drag and drop
            case EventType.DragUpdated:
                if (_isMouseInCanvas)
                {
                    _canvas.DropNode.Update(_mousePosition);
                }
                break;

            case EventType.DragPerform:
                if (_isMouseInCanvas)
                {
                    _canvas.DropNode.Perform(_mousePosition);
                }
                break;
            }
        }