Example #1
0
        protected override GraphicsPathDescription CreatePath(Rectangle bounds)
        {
            var ret = new GraphicsPathDescription();

            var center = RectUtil.GetCenter(bounds);
            var left   = bounds.Left;
            var right  = bounds.Right;
            var top    = bounds.Top;
            var bottom = bounds.Bottom;
            var height = bounds.Height;
            var width  = bounds.Width;

            var figWidth  = (int)(Math.Min(width, height) * _widthRatio);
            var widthHalf = (int)((Math.Min(width, height) * _widthRatio) / 2);

            var leftTop     = new Point(left, center.Y - widthHalf);
            var rightTop    = new Point(right, center.Y - widthHalf);
            var leftBottom  = new Point(left, center.Y + widthHalf);
            var rightBottom = new Point(right, center.Y + widthHalf);

            var pts = new[] {
                leftTop,
                rightTop,
                rightBottom,
                leftBottom,
            };

            ret.AddPolygon(pts);

            return(ret);
        }
        private Point GetSideMidpoint(Point loc, INode node)
        {
            var outerFrame = node.OuterFrame;
            var bounds     = node.Bounds;
            var dir        = RectUtil.GetNearestLineDirection(bounds, loc);
            var center     = RectUtil.GetCenter(bounds);

            if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Left))
            {
                return(outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y)));
            }
            else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Right))
            {
                return(outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y)));
            }
            else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Up))
            {
                return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Top)));
            }
            else
            {
                /// } else if (EnumUtil.HasFlag((int) dir, (int) Mkamo.Common.DataType.Directions.Left)) {
                return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom)));
            }
        }
Example #3
0
        protected override GraphicsPathDescription CreateDrawPath(Rectangle bounds)
        {
            var path = new GraphicsPathDescription();

            var center = RectUtil.GetCenter(bounds);
            var left   = bounds.Left;
            var right  = bounds.Right;
            var top    = bounds.Top;
            var bottom = bounds.Bottom;
            var height = bounds.Height;
            var width  = bounds.Width;

            var ovalHeight     = (int)(height * _ovalRatio);
            var ovalHeightHalf = ovalHeight / 2;

            path.AddArc(new Rectangle(left, top, width, ovalHeight), 180, 180);
            path.AddLine(new Point(right, top + ovalHeightHalf), new Point(right, bottom - ovalHeightHalf));
            path.AddArc(new Rectangle(left, bottom - ovalHeight, width, ovalHeight), 0, 180);
            path.AddLine(new Point(left, bottom - ovalHeightHalf), new Point(left, top + ovalHeightHalf));

            path.AddArc(new Rectangle(left, top, width, ovalHeight), 180, 180);
            path.AddArc(new Rectangle(left, top, width, ovalHeight), 0, 180);

            path.FillMode = System.Drawing.Drawing2D.FillMode.Winding;
            return(path);
        }
Example #4
0
        // === AbstractConnectableNode ==========
        protected virtual Point GetExpectedConnectLocationForConnectedAnchor(
            IAnchor anchor, Rectangle oldBounds, Rectangle newBounds
            )
        {
            var locDelta = newBounds.Location - (Size)oldBounds.Location;

            var newAnchorX = anchor.Location.X + locDelta.X;

            newAnchorX = Math.Min(newAnchorX, newBounds.Right - 1);

            var newAnchorY = anchor.Location.Y + locDelta.Y;

            newAnchorY = Math.Min(newAnchorY, newBounds.Bottom - 1);

            var dir = RectUtil.GetNearestLineDirection(oldBounds, anchor.Location);

            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Left))
            {
                return(new Point(newBounds.Left, newAnchorY));
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Right))
            {
                return(new Point(newBounds.Right - 1, newAnchorY));
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Up))
            {
                return(new Point(newAnchorX, newBounds.Top));
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Down))
            {
                return(new Point(newAnchorX, newBounds.Bottom - 1));
            }

            throw new ArgumentException();
        }
Example #5
0
        // ========================================
        // method
        // ========================================
        // === AbstractPathBoundingFigure ==========
        protected override GraphicsPathDescription CreatePath(Rectangle bounds)
        {
            // todo: widthが大きくなると図形が崩れる,背景を塗りつぶさない,線だけでマウスクリックを拾う,edgeとの接続方法など未解決

            var ret = new GraphicsPathDescription();

            var triangleLeft = Math.Max(bounds.Right - bounds.Height / 2, bounds.Left + bounds.Width / 2);

            var center = RectUtil.GetCenter(bounds);
            var half   = new Size(bounds.Width / 2, bounds.Height / 2);

            var pt1 = new Point(center.X, bounds.Top + half.Width);
            var pt2 = new Point(center.X, center.Y - half.Width);
            var pt3 = new Point(center.X, center.Y + half.Width);
            var pt4 = new Point(center.X, bounds.Bottom - half.Width);

            var r1 = new Rectangle(center.X, bounds.Top, bounds.Width - 1, bounds.Width - 1);
            var r2 = new Rectangle(bounds.Left - half.Width, center.Y - bounds.Width, bounds.Width - 1, bounds.Width - 1);
            var r3 = new Rectangle(bounds.Left - half.Width, center.Y, bounds.Width - 1, bounds.Width - 1);
            var r4 = new Rectangle(center.X, bounds.Bottom - bounds.Width, bounds.Width - 1, bounds.Width - 1);

            ret.AddArc(r1, 270, -90);
            ret.AddLine(pt1, pt2);
            ret.AddArc(r2, 0, 90);
            ret.AddArc(r3, 270, 90);
            ret.AddLine(pt3, pt4);
            ret.AddArc(r4, 180, -90);

            return(ret);
        }
Example #6
0
        private void DrawNode(Node node)
        {
            NodeViewData viewData = this.GetViewDataForNode(node);
            Rect         nodeRect = this.GetNodeRect(node);

            if (this.IsNodeSelected(node))
            {
                Rect     expandedNodeRect  = RectUtil.Expand(nodeRect, kNodeSelectedLineWeight);
                GUIStyle nodeSelectedStyle = GUIStyleUtil.StyleWithTexture(GUI.skin.box, kNodeSelectedTexture);
                GUI.Box(expandedNodeRect, "", nodeSelectedStyle);
            }

            Rect nodeShadowRect = nodeRect;

            nodeShadowRect.position = nodeShadowRect.position + new Vector2(kNodeShadowOffset, kNodeShadowOffset);
            GUI.Box(nodeShadowRect, "", (GUIStyle)"NodeShadow");

            GUIStyle nodeStyle = (GUIStyle)"Node";

            if (this.TargetGraph.IsStartingNode(node))
            {
                nodeStyle = (GUIStyle)"StartingNode";
            }

            GUI.Box(nodeRect, viewData.name, nodeStyle);
        }
Example #7
0
        private Rect CalculateAssignedRC(PresentationSource source)
        {
            Rect rectElement = new Rect(m_elementAttachedTo.RenderSize);
            Rect rectRoot    = RectUtil.ElementToRoot(rectElement, m_elementAttachedTo, source);

            return(RectUtil.RootToClient(rectRoot, source));
        }
Example #8
0
        /// <summary>
        /// Create split from the source and the split up rectangles, spreading the neighbours
        /// of the split over its children
        /// </summary>
        /// <param name="source"></param>
        /// <param name="rectangles"></param>
        /// <returns></returns>
        public SplitRect[] CreateSplits(SplitRect source, RectInt[] rectangles)
        {
            var result = new SplitRect[rectangles.Length];

            for (var i = 0; i < rectangles.Length; ++i)
            {
                result[i] = new SplitRect()
                {
                    _rect      = rectangles[i],
                    Neighbours = new HashSet <SplitRect>(source.Neighbours.Where(
                                                             (neighbour) => !RectUtil.AreDisconnected(rectangles[i], neighbour._rect)))
                };

                foreach (var neighbour in result[i].Neighbours)
                {
                    neighbour.Neighbours.Add(result[i]);
                }
            }

            for (var i = 0; i < result.Length; ++i)
            {
                for (var j = i + 1; j < result.Length; ++j)
                {
                    result[i].Neighbours.Add(result[j]);
                    result[j].Neighbours.Add(result[i]);
                }
            }

            return(result);
        }
Example #9
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (_isDragStarted)
            {
                var oldRect = _rubberbandRect;

                _rubberbandRect = RectUtil.GetRectangleFromDiagonalPoints(_dragStartPoint, e.Location);

                var newRect = _rubberbandRect;

                oldRect.Inflate(8, 8);
                newRect.Inflate(8, 8);

                Invalidate(oldRect);
                Invalidate(newRect);
            }
            else if (_isDragPrepared)
            {
                if (!_dragStartRect.Contains(e.X, e.Y))
                {
                    _isDragStarted = true;
                }
            }
        }
Example #10
0
        private void ProcessClickCount(MouseEventArgs e)
        {
            var rect = RectUtil.GetArroundingRectangle(_prevMouseDownLocation, _doubleClickSize);
            var now  = DateTime.Now;

            if (rect.Contains(e.Location))
            {
                var span = now - _prevMouseDownTime;
                if (_clickCount < 4)
                {
                    if (span.TotalMilliseconds <= _doubleClickTime)
                    {
                        ++_clickCount;
                    }
                    else
                    {
                        _clickCount = 1;
                    }
                }
                else
                {
                    _clickCount = 1;
                }
            }
            else
            {
                _clickCount = 1;
            }

            _prevMouseDownTime     = now;
            _prevMouseDownLocation = e.Location;
        }
Example #11
0
        protected override GraphicsPathDescription CreateDrawPath(Rectangle bounds)
        {
            var path = new GraphicsPathDescription();

            var center = RectUtil.GetCenter(bounds);
            var left   = bounds.Left;
            var right  = bounds.Right;
            var top    = bounds.Top;
            var bottom = bounds.Bottom;
            var height = bounds.Height;
            var width  = bounds.Width;

            var fold = (int)(Math.Min(width, height) * _foldRatio);
            var pts  = new[] {
                new Point(left, top),
                new Point(right, top),
                new Point(right, bottom - fold),
                new Point(right - fold, bottom),
                new Point(left, bottom),
            };

            path.AddPolygon(pts);

            var foldTop = (int)(fold * 3 / 4);

            path.AddPolygon(
                new[] {
                new Point(right, bottom - fold),
                new Point(right - foldTop, bottom - foldTop),
                new Point(right - fold, bottom),
            }
                );

            return(path);
        }
Example #12
0
 protected virtual void HandleDragFinish(object sender, MouseEventArgs e)
 {
     _rubberbandRequest.Toggle = _toggle;
     _rubberbandRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, e.Location);
     Handle.Host.HideFeedback(_rubberbandRequest);
     Handle.Host.PerformRequest(_rubberbandRequest);
     Host.Site.EditorCanvas.Cursor = _oldCursor;
 }
 private void Awake()
 {
     grayout   = GameObject.FindGameObjectWithTag("Grayout").GetComponent <Grayout>();
     droppable = GetComponent <Droppable>();
     droppable.dropDelegate += OnDrop;
     rectUtil  = GetComponent <RectUtil>();
     boxSprite = box.sprite;
 }
Example #14
0
        protected override void OnFigureDragMove(MouseEventArgs e)
        {
            base.OnFigureDragMove(e);

            _rubberbandRequest.Toggle = _toggle;
            _rubberbandRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, e.Location);
            Host.ShowFeedback(_rubberbandRequest);
        }
Example #15
0
 public override bool HandleDragMove(MouseEventArgs e)
 {
     if (_target != null)
     {
         _request.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, e.Location);
         _target.ShowFeedback(_request);
     }
     return(true);
 }
    public void ShouldReturnFalseWhenCallingDisconnectedOnTheSameRect()
    {
        // trivial test two rects that are the same
        var r1 = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        var r2 = new RectInt(Vector2Int.zero, Vector2Int.one * 2);

        Assert.IsFalse(RectUtil.AreDisconnected(r1, r2));
        Assert.IsFalse(RectUtil.AreDisconnected(r1, r1));
        Assert.IsFalse(RectUtil.AreDisconnected(r2, r2));
    }
Example #17
0
        protected override void OnFigureDragFinish(MouseEventArgs e)
        {
            base.OnFigureDragFinish(e);

            _rubberbandRequest.Toggle = _toggle;
            _rubberbandRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, e.Location);
            Host.HideFeedback(_rubberbandRequest);
            Host.PerformRequest(_rubberbandRequest);
            Host.Site.EditorCanvas.Cursor = _oldCursor;
        }
Example #18
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (_isDragStarted)
            {
                _rubberbandRect = RectUtil.GetRectangleFromDiagonalPoints(_dragStartPoint, e.Location);
            }

            ClearDragState();
        }
    public void ShouldReturnFalseWhenRectsAreHalfTouching()
    {
        var r1 = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        var r2 = new RectInt(Vector2Int.right * 2 + Vector2Int.up, Vector2Int.one * 2);
        var r3 = new RectInt(Vector2Int.left * 2 + Vector2Int.down, Vector2Int.one * 2);
        var r4 = new RectInt(Vector2Int.up * 2 + Vector2Int.right, Vector2Int.one * 2);
        var r5 = new RectInt(Vector2Int.down * 2 + Vector2Int.left, Vector2Int.one * 2);

        Assert.IsFalse(RectUtil.AreDisconnected(r1, r2));
        Assert.IsFalse(RectUtil.AreDisconnected(r1, r3));
        Assert.IsFalse(RectUtil.AreDisconnected(r1, r4));
        Assert.IsFalse(RectUtil.AreDisconnected(r1, r5));
    }
    public void ShouldReturnTrueApart()
    {
        var r1 = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        var r2 = new RectInt(Vector2Int.left * 3, Vector2Int.one * 2);
        var r3 = new RectInt(Vector2Int.right * 3, Vector2Int.one * 2);
        var r4 = new RectInt(Vector2Int.up * 3, Vector2Int.one * 2);
        var r5 = new RectInt(Vector2Int.down * 3, Vector2Int.one * 2);

        Assert.IsTrue(RectUtil.AreDisconnected(r1, r2));
        Assert.IsTrue(RectUtil.AreDisconnected(r1, r3));
        Assert.IsTrue(RectUtil.AreDisconnected(r1, r4));
        Assert.IsTrue(RectUtil.AreDisconnected(r1, r5));
    }
Example #21
0
 public override bool HandleDragFinish(MouseEventArgs e)
 {
     if (_target != null)
     {
         var bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, e.Location);
         _request.Bounds = bounds;
         _target.HideFeedback(_request);
         CreateNode(_target, bounds);
         if (!KeyUtil.IsControlPressed())
         {
             _target.Site.EditorCanvas.Tool = _defaultTool;
         }
         _target = null;
     }
     return(true);
 }
Example #22
0
        public override bool IntersectsWith(Rectangle rect)
        {
            if (!IsValidEdge)
            {
                return(false);
            }

            for (int i = 0; i < _edgePoints.Count - 1; ++i)
            {
                if (RectUtil.IntersectsWith(rect, _edgePoints[i], _edgePoints[i + 1]))
                {
                    return(true);
                }
            }
            return(false);
        }
 private bool isPointContained(Rect rect, Vector2 point)
 {
     if (CheckX && CheckY)
     {
         return(rect.Contains(point));
     }
     if (CheckX)
     {
         return(RectUtil.ContainsHorizontal(rect, point));
     }
     if (CheckY)
     {
         return(RectUtil.ContainsVertical(rect, point));
     }
     return(false);
 }
Example #24
0
        protected override GraphicsPathDescription CreatePath(Rectangle bounds)
        {
            var ret = new GraphicsPathDescription();

            var center = RectUtil.GetCenter(bounds);
            var left   = bounds.Left;
            var right  = bounds.Right;
            var top    = bounds.Top;
            var bottom = bounds.Bottom;
            var height = bounds.Height;
            var width  = bounds.Width;

            var figWidth  = (int)(Math.Min(width, height) * _widthRatio);
            var widthHalf = (int)((Math.Min(width, height) * _widthRatio) / 2);

            var northLeft  = new Point(center.X - widthHalf, top);
            var northRight = new Point(center.X + widthHalf, top);

            var eastTop    = new Point(right, center.Y - widthHalf);
            var eastBottom = new Point(right, center.Y + widthHalf);

            var southLeft  = new Point(center.X - widthHalf, bottom);
            var southRight = new Point(center.X + widthHalf, bottom);

            var westTop    = new Point(left, center.Y - widthHalf);
            var westBottom = new Point(left, center.Y + widthHalf);

            var pts = new[] {
                northLeft,
                northRight,
                new Point(northRight.X, westTop.Y),
                eastTop,
                eastBottom,
                new Point(northRight.X, westBottom.Y),
                southRight,
                southLeft,
                new Point(northLeft.X, westBottom.Y),
                westBottom,
                westTop,
                new Point(northLeft.X, westTop.Y),
            };

            ret.AddPolygon(pts);

            return(ret);
        }
Example #25
0
 public override bool IntersectsWith(Rectangle rect)
 {
     if (_points.Count > 1)
     {
         var translated = new Rectangle(
             rect.Location - (Size)Location,
             rect.Size
             );
         for (int i = 0; i < _points.Count - 1; ++i)
         {
             if (RectUtil.IntersectsWith(translated, _points[i], _points[i + 1]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #26
0
        public override bool HandleDragMove(MouseEventArgs e)
        {
            using (_Host.RootEditor.Figure.DirtManager.BeginDirty()) {
                if (_targets != null)
                {
                    _targets.HideFeedback(_moveRequest);
                }

                var delta      = (Size)e.Location - (Size)_startPoint;
                var horizontal = Math.Abs(delta.Width) > Math.Abs(delta.Height);
                horizontal = Math.Abs(delta.Width) < 40 && Math.Abs(delta.Height) < 40 ? false: horizontal;

                var content = _Host.RootEditor.Content;
                if (horizontal)
                {
                    _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Left > _startPoint.X).ToArray();
                }
                else
                {
                    _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Top > _startPoint.Y).ToArray();
                }
                _targets = new EditorBundle(_moveRequest.MovingEditors);

                var moveDelta = horizontal ?
                                new Size(delta.Width, 0) :
                                new Size(0, delta.Height);
                _moveRequest.MoveDelta = moveDelta;
                _targets.ShowFeedback(_moveRequest);

                _spaceRequest.Horizontal = horizontal;
                if (horizontal)
                {
                    _spaceRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, new Point(e.X, _startPoint.Y + 20));
                }
                else
                {
                    _spaceRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, new Point(_startPoint.X + 20, e.Y));
                }
                _Host.RootEditor.Content.ShowFeedback(_spaceRequest);
            }

            return(true);
        }
    public void TestGetTouchPoints()
    {
        // right
        var r1          = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        var r2          = new RectInt(Vector2Int.right * 2, Vector2Int.one * 2);
        var touchPoints = RectUtil.GetIntersection(r1, r2);

        Assert.IsTrue(touchPoints[0].x == 2);
        Assert.IsTrue(touchPoints[1].x == 2);
        Assert.IsTrue(touchPoints[0].y == 0);
        Assert.IsTrue(touchPoints[1].y == 2);

        // right & down
        r1          = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        r2          = new RectInt(Vector2Int.right * 2 + Vector2Int.down, Vector2Int.one * 2);
        touchPoints = RectUtil.GetIntersection(r1, r2);

        Assert.IsTrue(touchPoints[0].x == 2);
        Assert.IsTrue(touchPoints[1].x == 2);
        Assert.IsTrue(touchPoints[0].y == 0);
        Assert.IsTrue(touchPoints[1].y == 1);

        // bottom & left
        r1          = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        r2          = new RectInt(Vector2Int.left + Vector2Int.down * 2, Vector2Int.one * 2);
        touchPoints = RectUtil.GetIntersection(r1, r2);

        Assert.IsTrue(touchPoints[0].x == 0);
        Assert.IsTrue(touchPoints[1].x == 1);
        Assert.IsTrue(touchPoints[0].y == 0);
        Assert.IsTrue(touchPoints[1].y == 0);

        // top
        r1          = new RectInt(Vector2Int.zero, Vector2Int.one * 2);
        r2          = new RectInt(Vector2Int.zero + Vector2Int.up * 2, Vector2Int.one * 2);
        touchPoints = RectUtil.GetIntersection(r1, r2);

        Assert.IsTrue(touchPoints[0].x == 0);
        Assert.IsTrue(touchPoints[1].x == 2);
        Assert.IsTrue(touchPoints[0].y == 2);
        Assert.IsTrue(touchPoints[1].y == 2);
    }
Example #28
0
        private void DrawTransitionFromPointToPoint(TransitionViewData transitionViewData, Vector2 point, Vector2 targetPoint, TransitionViewStyle style)
        {
            Color    transitionColor      = TransitionViewStyleUtil.GetColor(style);
            GUIStyle transitionArrowStyle = TransitionViewStyleUtil.GetArrowStyle(style);

            Vector2 offset = targetPoint - point;
            // ex. A ---> B    ==    Direction.RIGHT
            Direction offsetDirection = DirectionUtil.ConvertVector2(offset);

            // ex. (Direction.RIGHT).Vector2Value()   ==   Vector2(1.0f, 0.0f)
            Vector2 nodeTangent       = Vector2.Scale(offsetDirection.Vector2Value(), Vector2Util.Abs(offset) * kTransitionTangentMultiplier);
            Vector2 targetNodeTangent = -nodeTangent;

            Handles.DrawBezier(point,
                               targetPoint,
                               point + nodeTangent,
                               targetPoint + targetNodeTangent,
                               transitionColor,
                               null,
                               kTransitionLineWidth);

            Vector3[] bezierPoints = Handles.MakeBezierPoints(point,
                                                              targetPoint,
                                                              point + nodeTangent,
                                                              targetPoint + targetNodeTangent,
                                                              division: 40);

            int     midPointIndex   = Mathf.FloorToInt(bezierPoints.Length / 2.0f);
            Vector2 midPointTangent = bezierPoints[midPointIndex + 1] - bezierPoints[midPointIndex];

            Vector2 midPoint      = (point + targetPoint) / 2.0f;
            float   rotationAngle = Vector2.Angle(Vector2.right, midPointTangent);

            if (midPointTangent.y < 0.0f)
            {
                rotationAngle *= -1.0f;
            }

            GUIUtility.RotateAroundPivot(rotationAngle, midPoint);
            GUI.Box(RectUtil.MakeRect(midPoint, new Vector2(10.0f, 10.0f), pivot: new Vector2(0.5f, 0.5f)), "", transitionArrowStyle);
            GUIUtility.RotateAroundPivot(-rotationAngle, midPoint);
        }
Example #29
0
        private Point[] TargetConnected(IEdge edge)
        {
            var tgt    = edge.Target;
            var srcLoc = GetSourceLocation(edge); //edge.SourceAnchor.Location;
            var tgtLoc = GetTargetLocation(edge); // edge.TargetAnchor.Location;

            var tgtDir = RectUtil.GetNearestLineDirection(tgt.Bounds, tgtLoc);

            var bendPts = default(Point[]);

            if (EnumUtil.HasAllFlags((int)tgtDir, (int)Directions.Left))
            {
                var angle          = 180;
                var tgtTopLeft     = new Point(tgt.Right, tgt.Bottom);
                var tgtBottomRight = new Point(tgt.Left, tgt.Top);
                bendPts = SourceConnectedBase(tgtLoc, srcLoc, tgtTopLeft, tgtBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)tgtDir, (int)Directions.Right))
            {
                var angle          = 0;
                var tgtTopLeft     = tgt.Location;
                var tgtBottomRight = new Point(tgt.Right, tgt.Bottom);
                bendPts = SourceConnectedBase(tgtLoc, srcLoc, tgtTopLeft, tgtBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)tgtDir, (int)Directions.Up))
            {
                var angle          = 90;
                var tgtTopLeft     = new Point(tgt.Left, tgt.Bottom);
                var tgtBottomRight = new Point(tgt.Right, tgt.Top);
                bendPts = SourceConnectedBase(tgtLoc, srcLoc, tgtTopLeft, tgtBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)tgtDir, (int)Directions.Down))
            {
                var angle          = 270;
                var tgtTopLeft     = new Point(tgt.Right, tgt.Top);
                var tgtBottomRight = new Point(tgt.Left, tgt.Bottom);
                bendPts = SourceConnectedBase(tgtLoc, srcLoc, tgtTopLeft, tgtBottomRight, angle);
            }

            return(bendPts.Reverse().ToArray());
        }
Example #30
0
        private Point[] SourceConnected(IEdge edge)
        {
            var src    = edge.Source;
            var srcLoc = GetSourceLocation(edge); //edge.SourceAnchor.Location;
            var tgtLoc = GetTargetLocation(edge); // edge.TargetAnchor.Location;

            var srcDir = RectUtil.GetNearestLineDirection(src.Bounds, srcLoc);

            var bendPts = default(Point[]);

            if (EnumUtil.HasAllFlags((int)srcDir, (int)Directions.Left))
            {
                var angle          = 180;
                var srcTopLeft     = new Point(src.Right, src.Bottom);
                var srcBottomRight = new Point(src.Left, src.Top);
                bendPts = SourceConnectedBase(srcLoc, tgtLoc, srcTopLeft, srcBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)srcDir, (int)Directions.Right))
            {
                var angle          = 0;
                var srcTopLeft     = src.Location;
                var srcBottomRight = new Point(src.Right, src.Bottom);
                bendPts = SourceConnectedBase(srcLoc, tgtLoc, srcTopLeft, srcBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)srcDir, (int)Directions.Up))
            {
                var angle          = 90;
                var srcTopLeft     = new Point(src.Left, src.Bottom);
                var srcBottomRight = new Point(src.Right, src.Top);
                bendPts = SourceConnectedBase(srcLoc, tgtLoc, srcTopLeft, srcBottomRight, angle);
            }
            else if (EnumUtil.HasAllFlags((int)srcDir, (int)Directions.Down))
            {
                var angle          = 270;
                var srcTopLeft     = new Point(src.Right, src.Top);
                var srcBottomRight = new Point(src.Left, src.Bottom);
                bendPts = SourceConnectedBase(srcLoc, tgtLoc, srcTopLeft, srcBottomRight, angle);
            }

            return(bendPts);
        }