예제 #1
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {//TODO: Only reset selected if Not over node.
            base.OnMouseLeftButtonDown(e);
            if (InserterOpen)
            {
                var r = _inserter.PerformClick(e.GetPosition(this));
                if (r.Item1)
                {
                    if (r.Item2 != null)
                    {
                        nodes.Add(r.Item2);
                    }
                    InserterOpen = false;
                }


                InvalidateVisual();
                return;
            } //Inserter Handling

            if (nodeForAction != null && nodeForAction.HoveredHandle.HandleType == HandleType.Output)
            {
                _draggingConnection = true;
                nodeForAction.BeginDrag();
                InvalidateVisual();
                return;
            }

            leftMouseDown = true;
            selctedNodes  = new List <Node>();
            Node tempNode = null;

            if (controlDown)
            {
                dragFrom = e.GetPosition(this);

                return;
            }
            foreach (var node in nodes)
            {
                if (node.getRect(offset).Contains(e.MouseDevice.GetPosition(this)))
                {
                    tempNode = node;
                }
            }

            if (tempNode != null)
            {
                selctedNodes.Add(tempNode);
            }
        }
예제 #2
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            //SortingNodes
            if (selctedNodes != null && selctedNodes.Count > 0)
            {
                foreach (var node in selctedNodes)
                {
                    nodes = nodes.MoveToFront(node);
                }
            }

            //Drawing BG;
            brush.Color = ColorIdentifier.Background.get();
            drawingContext.DrawRectangle(brush, null, new Rect(0, 0, ActualWidth, ActualHeight));

            //Draw Grid;
            SolidColorBrush b        = (SolidColorBrush)ColorIdentifier.Line1.get().toBrush();
            Pen             pen      = new Pen(b, DoubleIdentifier.GridThickness.get());
            int             gridSize = 20;

            DrawGrid(drawingContext, pen, gridSize, ActualWidth, ActualHeight);

            gridSize     *= 2;
            pen.Thickness = 0.8;
            b.Color       = ColorIdentifier.Line2.get();
            DrawGrid(drawingContext, pen, gridSize, ActualWidth, ActualHeight);


            //DrawContent
            //Draw Connections
            foreach (var node in nodes)
            {
                node.DrawConnections(drawingContext);
            }
            //Draw Nodes
            if (!_draggingConnection)
            {
                nodeForAction = null;
            }
            else
            {
                draggingTo = null;
            }
            foreach (var node in nodes)
            {
                if (node.Draw(drawingContext, this, mousePos, offset,
                              selctedNodes?.Contains(node) ?? false))
                {
                    if (!_draggingConnection)
                    {
                        nodeForAction = node;
                    }
                    else
                    {
                        draggingTo = node;
                    }
                }
            }


            //Draw Inserter
            if (InserterOpen)
            {
                if (_inserter.Perform(drawingContext, this, mousePos))
                {
                    InserterOpen = false;
                }
            }

            //Draw Selection
            if (controlDown && leftMouseDown && dragFrom != null)
            {
                Brush s = ColorIdentifier.Bounding.get().toBrush();
                var   p = new Pen(s, 3);
                p.DashStyle = DashStyles.Dash;
                p.DashCap   = PenLineCap.Square;

                drawingContext.DrawRectangle(null, p, new Rect(dragFrom, mousePos));
            }
            //Drawing Bounding;
            drawingContext.DrawRectangle(null, new Pen(ColorIdentifier.Bounding.get().toBrush(), DoubleIdentifier.WindowBoundingThickness.get()), new Rect(0, 0, ActualWidth, ActualHeight));
        }