Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
        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)));
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        // ========================================
        // method
        // ========================================
        // === AbstractPathBoundingFigure ==========
        protected override GraphicsPathDescription CreatePath(Rectangle bounds)
        {
            var ret = new GraphicsPathDescription();

            var center = RectUtil.GetCenter(bounds);

            var top   = new Point(center.X, bounds.Top);
            var left  = new Point(bounds.Left, bounds.Bottom);
            var right = new Point(bounds.Right, bounds.Bottom);

            var pts = new[] {
                top,
                right,
                left,
                top,
            };

            ret.AddPolygon(pts);

            return(ret);
        }
Esempio n. 8
0
        protected override GraphicsPathDescription CreatePath(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 margin = (int)(width * _marginRatio);
            var pts    = new [] {
                new Point(left + margin, top),
                new Point(right, top),
                new Point(right - margin, bottom),
                new Point(left, bottom),
            };

            path.AddPolygon(pts);

            return(path);
        }
Esempio n. 9
0
        public Point GetConnectionPoint(IAnchor anchor, INode node, Point location)
        {
            var outerFrame = node.OuterFrame;

            switch (_connectionMethod)
            {
            case ConnectionMethodKind.Intersect: {
                var nextLoc = anchor.Kind == ConnectionAnchorKind.Source?
                              FirstRef.Next.EdgePoint:
                              LastRef.Prev.EdgePoint;
                var line = new Line(location, nextLoc);
                if (outerFrame.IntersectsWith(line))
                {
                    return(outerFrame.GetIntersectionPoint(line));
                }
                else
                {
                    /// 交わってなければ仕方がないのでNearestを返しておく
                    return(outerFrame.GetNearestPoint(line.Start));
                }
            }

            case ConnectionMethodKind.UpperSideMidpoint: {
                var bounds = node.Bounds;
                var center = RectUtil.GetCenter(bounds);
                return(anchor.Kind == ConnectionAnchorKind.Source ?
                       outerFrame.GetNearestPoint(new Point(center.X, bounds.Top)):
                       outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom)));
            }

            case ConnectionMethodKind.LowerSideMidpoint: {
                var bounds = node.Bounds;
                var center = RectUtil.GetCenter(bounds);
                return(anchor.Kind == ConnectionAnchorKind.Source ?
                       outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom)):
                       outerFrame.GetNearestPoint(new Point(center.X, bounds.Top)));
            }

            case ConnectionMethodKind.LeftSideMidpoint: {
                var bounds = node.Bounds;
                var center = RectUtil.GetCenter(bounds);
                return(anchor.Kind == ConnectionAnchorKind.Source ?
                       outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y)):
                       outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y)));
            }

            case ConnectionMethodKind.RightSideMidpoint: {
                var bounds = node.Bounds;
                var center = RectUtil.GetCenter(bounds);
                return(anchor.Kind == ConnectionAnchorKind.Source ?
                       outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y)):
                       outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y)));
            }

            case ConnectionMethodKind.SideMidpointOfOpposite: {
                var oppositeLoc = anchor.Kind == ConnectionAnchorKind.Source?
                                  LastRef.EdgePoint:
                                  FirstRef.EdgePoint;
                var bounds = node.Bounds;
                var dir    = RectUtil.GetDirectionStraightlyFromCenter(bounds, oppositeLoc);
                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)));
                }
            }

            case ConnectionMethodKind.SideMidpointOfNearest: {
                //var nearestLoc = outerFrame.GetNearestPoint(location);
                var bounds = node.Bounds;
                //var dir = RectUtil.GetDirectionStraightlyFromCenter(bounds, nearestLoc);
                var dir    = RectUtil.GetNearestLineDirection(bounds, location);
                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)));
                }
            }

            case ConnectionMethodKind.Nearest:
                return(outerFrame.GetNearestPoint(location));

            case ConnectionMethodKind.Center:
                // todo: ちゃんと実装
                // とりあえずこれでもCentralRouterが設定されていればすぐルーティングされるので問題なく動く
                return(outerFrame.GetNearestPoint(location));

            case ConnectionMethodKind.Comment:
                if (anchor.Kind == ConnectionAnchorKind.Source)
                {
                    var leftMiddle = new Point(node.Left, node.Top + node.Height / 2);
                    return(outerFrame.GetNearestPoint(leftMiddle));
                    //return outerFrame.GetNearestPoint(location);
                }
                else
                {
                    var pt = node.GetConnectionPoint(_targetConnectionOption);
                    if (pt.HasValue)
                    {
                        return(pt.Value);
                    }
                    else
                    {
                        return(outerFrame.GetNearestPoint(location));
                    }
                }

            default:
                return(outerFrame.GetNearestPoint(location));
            }
        }
Esempio n. 10
0
        private void MoveOverlapped(IEditor editor, List <IEditor> moved)
        {
            moved.Add(editor);
            var bounds = editor.Figure.Bounds;

            foreach (var edi in Host.Root.Content.GetChildrenByPosition())
            {
                if (moved.Contains(edi))
                {
                    continue;
                }

                if (!(edi.Model is MemoText || edi.Model is MemoImage || edi.Model is MemoTable || edi.Model is MemoFile))
                {
                    continue;
                }

                var ediBounds = edi.Figure.Bounds;
                if (
                    (ediBounds.Left > bounds.Left || ediBounds.Top > bounds.Top) &&
                    ediBounds.IntersectsWith(bounds)
                    )
                {
                    var needMoveLower = false;
                    var needMoveRight = false;
                    if (bounds.Contains(ediBounds))
                    {
                        var center    = RectUtil.GetCenter(bounds);
                        var ediCenter = RectUtil.GetCenter(ediBounds);
                        var dir       = PointUtil.GetDirectionStraightly(center, ediCenter);
                        if (EnumUtil.HasAnyFlags((int)dir, (int)(Directions.Left | Directions.Down)))
                        {
                            needMoveLower = true;
                        }
                        else
                        {
                            needMoveRight = true;
                        }
                    }
                    else if (ediBounds.Left <= bounds.Left)
                    {
                        needMoveLower = true;
                    }
                    else if (ediBounds.Top <= bounds.Top)
                    {
                        needMoveRight = true;
                    }
                    else
                    {
                        var intersect = Rectangle.Intersect(bounds, ediBounds);
                        if (intersect.Width == ediBounds.Width)
                        {
                            /// LeftもRightもbounds内
                            needMoveLower = true;
                        }
                        else if (intersect.Height == ediBounds.Height)
                        {
                            /// TopもBottomもbounds内
                            needMoveRight = true;
                        }
                        else if (intersect.Width >= intersect.Height)
                        {
                            needMoveLower = true;
                        }
                        else
                        {
                            needMoveRight = true;
                        }
                    }

                    if (needMoveLower)
                    {
                        var newTop = bounds.Bottom + MemopadConsts.DefaultElementSpace;
                        edi.RequestMove(new Size(0, newTop - ediBounds.Top));
                        MoveOverlapped(edi, moved);
                    }
                    else if (needMoveRight)
                    {
                        var newLeft = bounds.Right + MemopadConsts.DefaultElementSpace;
                        edi.RequestMove(new Size(newLeft - ediBounds.Left, 0));
                        MoveOverlapped(edi, moved);
                    }
                }
            }
        }
Esempio n. 11
0
        protected override GraphicsPathDescription CreatePath(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;

            /// 上向き矢印で考えたときに横幅をshapeWidth,高さをshapeHeight,上下左右をtop,bottom,left,bottomとする
            var shapeWidth = _direction == Directions.Up || _direction == Directions.Down?
                             width:
                             height;
            var shapeHeight = _direction == Directions.Up || _direction == Directions.Down?
                              height:
                              width;

            var headLen    = (int)(shapeHeight * _headLengthRatio);
            var shaftLen   = shapeHeight - headLen;
            var shaftWidth = (int)(shapeWidth * _shaftWidthRatio);
            var headWidth  = shapeWidth;
            var widthDiff  = headWidth - shaftWidth;

            Point headTop, headRightside, headLeftside, shaftTopRight, shaftTopLeft, shaftBottomRight, shaftBottomLeft;

            switch (_direction)
            {
            case Directions.Left: {
                headTop          = new Point(left, center.Y);
                headRightside    = new Point(left + headLen, top);
                headLeftside     = new Point(left + headLen, bottom);
                shaftTopRight    = new Point(left + headLen, top + widthDiff / 2);
                shaftTopLeft     = new Point(left + headLen, bottom - widthDiff / 2);
                shaftBottomRight = new Point(right, top + widthDiff / 2);
                shaftBottomLeft  = new Point(right, bottom - widthDiff / 2);
                break;
            }

            case Directions.Right: {
                headTop          = new Point(right, center.Y);
                headRightside    = new Point(right - headLen, bottom);
                headLeftside     = new Point(right - headLen, top);
                shaftTopRight    = new Point(right - headLen, bottom - widthDiff / 2);
                shaftTopLeft     = new Point(right - headLen, top + widthDiff / 2);
                shaftBottomRight = new Point(left, bottom - widthDiff / 2);
                shaftBottomLeft  = new Point(left, top + widthDiff / 2);
                break;
            }

            case Directions.Up: {
                headTop          = new Point(center.X, top);
                headRightside    = new Point(right, top + headLen);
                headLeftside     = new Point(left, top + headLen);
                shaftTopRight    = new Point(right - widthDiff / 2, top + headLen);
                shaftTopLeft     = new Point(left + widthDiff / 2, top + headLen);
                shaftBottomRight = new Point(right - widthDiff / 2, bottom);
                shaftBottomLeft  = new Point(left + widthDiff / 2, bottom);
                break;
            }

            case Directions.Down: {
                headTop          = new Point(center.X, bottom);
                headRightside    = new Point(left, bottom - headLen);
                headLeftside     = new Point(right, bottom - headLen);
                shaftTopRight    = new Point(left + widthDiff / 2, bottom - headLen);
                shaftTopLeft     = new Point(right - widthDiff / 2, bottom - headLen);
                shaftBottomRight = new Point(left + widthDiff / 2, top);
                shaftBottomLeft  = new Point(right - widthDiff / 2, top);
                break;
            }

            default: {
                throw new InvalidOperationException();
            }
            }

            path.AddPolygon(
                new Point[] {
                headTop,
                headRightside,
                shaftTopRight,
                shaftBottomRight,
                shaftBottomLeft,
                shaftTopLeft,
                headLeftside,
                headTop,
            }
                );

            return(path);
        }
Esempio n. 12
0
        protected override GraphicsPathDescription CreatePath(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;

            /// 上下矢印で考えたときに横幅をwidth,高さをlength,上下左右をtop,bottom,left,bottomとする

            var shapeWidth  = _isVertical? width: height;
            var shapeHeight = _isVertical? height: width;

            var headLen    = (int)(shapeHeight * _headLengthRatio);
            var shaftLen   = shapeHeight - headLen;
            var shaftWidth = (int)(shapeWidth * _shaftWidthRatio);
            var headWidth  = shapeWidth;
            var widthDiff  = headWidth - shaftWidth;

            Point northHeadTop, northHeadRightside, northHeadLeftside;
            Point shaftTopRight, shaftTopLeft, shaftBottomRight, shaftBottomLeft;
            Point southHeadTop, southHeadRightside, southHeadLeftside;

            if (_isVertical)
            {
                northHeadTop       = new Point(center.X, top);
                northHeadRightside = new Point(right, top + headLen);
                northHeadLeftside  = new Point(left, top + headLen);

                southHeadTop       = new Point(center.X, bottom);
                southHeadRightside = new Point(right, bottom - headLen);
                southHeadLeftside  = new Point(left, bottom - headLen);

                shaftTopRight    = new Point(right - widthDiff / 2, top + headLen);
                shaftTopLeft     = new Point(left + widthDiff / 2, top + headLen);
                shaftBottomRight = new Point(right - widthDiff / 2, bottom - headLen);
                shaftBottomLeft  = new Point(left + widthDiff / 2, bottom - headLen);
            }
            else
            {
                northHeadTop       = new Point(left, center.Y);
                northHeadRightside = new Point(left + headLen, top);
                northHeadLeftside  = new Point(left + headLen, bottom);

                shaftTopRight    = new Point(left + headLen, top + widthDiff / 2);
                shaftTopLeft     = new Point(left + headLen, bottom - widthDiff / 2);
                shaftBottomRight = new Point(right - headLen, top + widthDiff / 2);
                shaftBottomLeft  = new Point(right - headLen, bottom - widthDiff / 2);

                southHeadTop       = new Point(right, center.Y);
                southHeadRightside = new Point(right - headLen, top);
                southHeadLeftside  = new Point(right - headLen, bottom);
            }

            path.AddPolygon(
                new Point[] {
                northHeadTop,
                northHeadRightside,

                shaftTopRight,
                shaftBottomRight,

                southHeadRightside,
                southHeadTop,
                southHeadLeftside,

                shaftBottomLeft,
                shaftTopLeft,

                northHeadLeftside,
                northHeadTop,
            }
                );

            return(path);
        }
        private void InitItems()
        {
            _remove        = new ToolStripMenuItem();
            _remove.Text   = "削除(&R)";
            _remove.Click += (sender, e) => {
                using (_owner.CommandExecutor.BeginChain()) {
                    var req  = new RemoveRequest();
                    var cmds = new CompositeCommand();

                    var parent = default(IEditor);
                    foreach (var editor in _owner.SelectionManager.SelectedEditors)
                    {
                        if (parent == null)
                        {
                            parent = editor.Parent;
                        }
                        if (editor.CanUnderstand(req))
                        {
                            cmds.Children.Add(editor.GetCommand(req));
                        }
                    }
                    _owner.CommandExecutor.Execute(cmds);
                    if (parent != null)
                    {
                        parent.RequestSelect(SelectKind.True, true);
                    }
                }
            };

            _clone        = new ToolStripMenuItem();
            _clone.Text   = "複製(&C)";
            _clone.Click += (sender, e) => {
                var cloning = new List <IEditor>(_owner.SelectionManager.SelectedEditors);
                var req     = new CloneRequest(cloning);
                req.MoveDelta = CloneMoveDelta;

                if (cloning.Any())
                {
                    var target = cloning.First().Parent;
                    var cmd    = target.PerformRequest(req) as CloneCommand;
                    if (cmd != null && cmd.ClonedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var cloned in cmd.ClonedEditors)
                        {
                            cloned.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };

            _cut        = new ToolStripMenuItem();
            _cut.Text   = "切り取り(&X)";
            _cut.Click += (sender, e) => {
                var cmd = GetCutCommand();
                _owner.CommandExecutor.Execute(cmd);
            };

            _copy        = new ToolStripMenuItem();
            _copy.Text   = "コピー(&C)";
            _copy.Click += (sender, e) => {
                var targets = _owner.SelectionManager.SelectedEditors;
                var req     = new CopyRequest(targets);
                var list    = new EditorBundle(targets);
                list.PerformGroupRequest(req, _owner.CommandExecutor);
            };

            _copyAsImage        = new ToolStripMenuItem();
            _copyAsImage.Text   = "画像としてコピー(&I)";
            _copyAsImage.Click += (sender, e) => {
                _owner.CopySelectedAsImage();
            };

            _paste        = new ToolStripMenuItem();
            _paste.Text   = "貼り付け(&P)";
            _paste.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    var cmd = found.RequestPaste(_currentEvent.Location, null) as PasteCommand;
                    if (cmd != null && cmd.PastedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var editor in cmd.PastedEditors)
                        {
                            editor.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };

            _pasteInBlock        = new ToolStripMenuItem();
            _pasteInBlock.Text   = "段落内に貼り付け(&P)";
            _pasteInBlock.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    var cmd = found.RequestPaste(
                        _currentEvent.Location, EditorConsts.InBlockPasteDescription
                        ) as PasteCommand;
                    if (cmd != null && cmd.PastedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var editor in cmd.PastedEditors)
                        {
                            editor.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };


            _front        = new ToolStripMenuItem();
            _front.Text   = "前面に移動(&F)";
            _front.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.Front);
                }
            };

            _frontMost        = new ToolStripMenuItem();
            _frontMost.Text   = "最前面に移動(&F)";
            _frontMost.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.FrontMost);
                }
            };

            _back        = new ToolStripMenuItem();
            _back.Text   = "背面に移動(&B)";
            _back.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.Back);
                }
            };

            _backMost        = new ToolStripMenuItem();
            _backMost.Text   = "最背面に移動(&B)";
            _backMost.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.BackMost);
                }
            };

            _arrangeHLeft        = new ToolStripMenuItem("左揃え(&L)");
            _arrangeHLeft.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = rect.Left;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeHCenter        = new ToolStripMenuItem("左右中央揃え(&C)");
            _arrangeHCenter.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                var center  = RectUtil.GetCenter(rect);
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = center.X - edi.Figure.Width / 2;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeHRight        = new ToolStripMenuItem("右揃え(&R)");
            _arrangeHRight.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = rect.Right - edi.Figure.Width;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeVTop        = new ToolStripMenuItem("上揃え(&T)");
            _arrangeVTop.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = rect.Top;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };

            _arrangeVMiddle        = new ToolStripMenuItem("上下中央揃え(&M)");
            _arrangeVMiddle.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                var center  = RectUtil.GetCenter(rect);
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = center.Y - edi.Figure.Height / 2;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };

            _arrangeVBottom        = new ToolStripMenuItem("下揃え(&B)");
            _arrangeVBottom.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = rect.Bottom - edi.Figure.Height;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };


            _detailForm        = new ToolStripMenuItem();
            _detailForm.Text   = "設定(&S)";
            _detailForm.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    if (found.Controller != null && found.Controller.UIProvider != null)
                    {
                        var ui   = found.Controller.UIProvider;
                        var form = new DetailSettingsForm();
                        try {
                            form.Size  = _detailFormSize;
                            form.Theme = _owner.Theme;
                            ui.ConfigureDetailForm(form);
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                var cmd = form.GetUpdateCommand();
                                if (cmd != null)
                                {
                                    _owner.CommandExecutor.Execute(cmd);
                                }
                            }
                        } finally {
                            form.Dispose();
                        }
                    }
                }
            };
        }
        protected override Point GetExpectedConnectLocationForConnectedAnchor(
            IAnchor anchor, Rectangle oldBounds, Rectangle newBounds
            )
        {
            if (oldBounds == newBounds)
            {
                return(anchor.Location);
            }

            var isMoveOnly = oldBounds.Size == newBounds.Size;

            if (isMoveOnly)
            {
                var locDelta = newBounds.Location - (Size)oldBounds.Location;
                return(anchor.Location + (Size)locDelta);
            }

            var leftDelta   = newBounds.Left - oldBounds.Left;
            var topDelta    = newBounds.Top - oldBounds.Top;
            var rightDelta  = newBounds.Right - oldBounds.Right;
            var bottomDelta = newBounds.Bottom - oldBounds.Bottom;

            var dir = RectUtil.GetDirectionFromCenter(oldBounds, anchor.Location);
            //var dir = RectUtil.GetDirectionStraightlyFromCenter(oldBounds, anchor.Location);
            var newCenter = RectUtil.GetCenter(newBounds);
            var newLoc    = anchor.Location;

            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Left))
            {
                newLoc.X = Math.Min(newLoc.X + leftDelta, newCenter.X);
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Right))
            {
                newLoc.X = Math.Max(newLoc.X + rightDelta, newCenter.X);
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Up))
            {
                newLoc.Y = Math.Min(newLoc.Y + topDelta, newCenter.Y);
            }
            if (EnumUtil.HasAllFlags((int)dir, (int)Directions.Down))
            {
                newLoc.Y = Math.Max(newLoc.Y + bottomDelta, newCenter.Y);
            }

            using (_ResourceCache.UseResource()) {
                var path       = _OutlinePathResouce;
                var pts        = path.PathPoints;
                var ptAndDists = new List <Tuple <Point, int> >();
                for (int i = 0, len = pts.Length; i < len; ++i)
                {
                    var pt1 = Point.Round(pts[i]);
                    var pt2 = Point.Round(i + 1 < len ? pts[i + 1] : pts[0]);
                    if (pt1 != pt2)
                    {
                        var pathPortion = new Line(pt1, pt2);
                        var npt         = pathPortion.GetNearestPointFrom(newLoc);
                        var dist        = pathPortion.GetDistance(newLoc);
                        ptAndDists.Add(Tuple.Create(npt, dist));
                    }
                }
                return(ptAndDists.Count == 0? Point.Empty: ptAndDists.FindMin(t => t.Item2).Item1);
            }
        }
Esempio n. 15
0
        protected override GraphicsPathDescription CreatePath(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 figWidth = (int)(Height * _widthRatio);
            var margin   = (int)(Height * _marginRatio);

            var northTop         = top + margin;
            var northBottom      = northTop + figWidth;
            var northTopLeft     = new Point(left, northTop);
            var northTopRight    = new Point(right, northTop);
            var northBottomLeft  = new Point(left, northBottom);
            var northBottomRight = new Point(right, northBottom);

            var southBottom      = bottom - margin;
            var southTop         = southBottom - figWidth;
            var southTopLeft     = new Point(left, southTop);
            var southTopRight    = new Point(right, southTop);
            var southBottomLeft  = new Point(left, southBottom);
            var southBottomRight = new Point(right, southBottom);

            if (_isNotEqual)
            {
                var sin = (height * _strikeMarginRatio) / figWidth;
                var r   = Math.Asin(sin);
                var strikeMarginHeight = (int)(height * _strikeMarginRatio);
                var h = height - strikeMarginHeight;
                var strikeMarginWidth = (int)((width - figWidth * Math.Cos(r) - (h * Math.Tan(r))) / 2);
                var cos = (int)(figWidth * Math.Cos(r));

                var strikeTopLeft     = new Point(right - cos - strikeMarginWidth, top);
                var strikeTopRight    = new Point(right - strikeMarginWidth, top + strikeMarginHeight);
                var strikeBottomLeft  = new Point(left + strikeMarginWidth, bottom - strikeMarginHeight);
                var strikeBottomRight = new Point(left + cos + strikeMarginWidth, bottom);

                var strikeLeft  = new Line(strikeBottomLeft, strikeTopLeft);
                var strikeRight = new Line(strikeBottomRight, strikeTopRight);
                var line1       = new Line(northTopLeft, northTopRight);
                var line2       = new Line(northBottomLeft, northBottomRight);
                var ptl1        = strikeLeft.GetIntersectionPoint(line1);
                var ptl2        = strikeLeft.GetIntersectionPoint(line2);
                var ptr1        = strikeRight.GetIntersectionPoint(line1);
                var ptr2        = strikeRight.GetIntersectionPoint(line2);

                var line3 = new Line(southTopLeft, southTopRight);
                var line4 = new Line(southBottomLeft, southBottomRight);
                var ptl3  = strikeLeft.GetIntersectionPoint(line3);
                var ptl4  = strikeLeft.GetIntersectionPoint(line4);
                var ptr3  = strikeRight.GetIntersectionPoint(line3);
                var ptr4  = strikeRight.GetIntersectionPoint(line4);

                path.AddPolygon(
                    new Point[] {
                    northTopLeft,
                    ptl1,
                    strikeTopLeft,
                    strikeTopRight,
                    ptr1,
                    northTopRight,
                    northBottomRight,
                    ptr2,
                    ptr3,
                    southTopRight,
                    southBottomRight,
                    ptr4,
                    strikeBottomRight,
                    strikeBottomLeft,
                    ptl4,
                    southBottomLeft,
                    southTopLeft,
                    ptl3,
                    ptl2,
                    northBottomLeft,
                    northTopLeft,
                }
                    );
            }
            else
            {
                path.AddPolygon(
                    new Point[] {
                    northTopLeft,
                    northTopRight,
                    northBottomRight,
                    northBottomLeft,
                    northTopLeft,
                }
                    );

                path.AddPolygon(
                    new Point[] {
                    southTopLeft,
                    southTopRight,
                    southBottomRight,
                    southBottomLeft,
                    southTopLeft,
                }
                    );
            }


            return(path);
        }
Esempio n. 16
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 r        = Math.Atan2(height, width);
            var sin      = (int)(figWidth * Math.Sin(r));
            var cos      = (int)(figWidth * Math.Cos(r));

            /// 左上
            var ptlt1 = new Point(left, top + cos);
            var ptlt2 = new Point(left + sin, top);

            /// 右上
            var ptrt1 = new Point(right - sin, top);
            var ptrt2 = new Point(right, top + cos);

            /// 左下
            var ptlb1 = new Point(left, bottom - cos);
            var ptlb2 = new Point(left + sin, bottom);

            /// 右下
            var ptrb1 = new Point(right - sin, bottom);
            var ptrb2 = new Point(right, bottom - cos);

            /// 左上から右下の上側
            var line1t = new Line(ptlt2, ptrb2);
            /// 左上から右下の下側
            var line1b = new Line(ptlt1, ptrb1);

            /// 右上から左下の上側
            var line2t = new Line(ptrt1, ptlb1);
            /// 右上から左下の下側
            var line2b = new Line(ptrt2, ptlb2);

            /// 上交点
            var ptt = line1t.GetIntersectionPoint(line2t);
            /// 下交点
            var ptb = line1b.GetIntersectionPoint(line2b);
            /// 左交点
            var ptl = line1b.GetIntersectionPoint(line2t);
            /// 右交点
            var ptr = line1t.GetIntersectionPoint(line2b);

            var pts = new[] {
                ptlt1,
                ptlt2,
                ptt,
                ptrt1,
                ptrt2,
                ptr,
                ptrb2,
                ptrb1,
                ptb,
                ptlb2,
                ptlb1,
                ptl,
            };

            ret.AddPolygon(pts);

            return(ret);
        }
Esempio n. 17
0
        // ========================================
        // field
        // ========================================

        // ========================================
        // constructor
        // ========================================

        // ========================================
        // property
        // ========================================

        // ========================================
        // method
        // ========================================
        public void Route(IEdge edge)
        {
            if (edge.Source == edge.Target)
            {
                if (edge.Source != null)
                {
                    /// 同じ図形に両端がつながっている場合はループ
                    var pts = EdgeUtil.GetLoopPoints(edge.Source.Bounds);
                    edge.SetEdgePoints(pts);
                }
                return;
            }

            if (edge.EdgePointCount == 2)
            {
                /// first,lastしか点がない

                if (edge.IsSourceConnected && edge.IsTargetConnected)
                {
                    /// Sourceの中心点とTargetの中心点を結ぶ

                    var src       = edge.Source as INode;
                    var tgt       = edge.Target as INode;
                    var srcCenter = RectUtil.GetCenter(src.Bounds);
                    var tgtCenter = RectUtil.GetCenter(tgt.Bounds);

                    var line = new Line(tgtCenter, srcCenter);
                    if (src.OuterFrame.IntersectsWith(line))
                    {
                        edge.First = src.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.First = srcCenter;
                    }

                    line = new Line(srcCenter, tgtCenter);
                    if (tgt.OuterFrame.IntersectsWith(line))
                    {
                        edge.Last = tgt.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.Last = tgtCenter;
                    }
                }
                else if (edge.IsSourceConnected)
                {
                    /// Sourceの中心点とLastを結ぶ

                    var src       = edge.Source as INode;
                    var srcCenter = RectUtil.GetCenter(src.Bounds);

                    var line = new Line(edge.Last, srcCenter);
                    if (src.OuterFrame.IntersectsWith(line))
                    {
                        edge.First = src.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.First = srcCenter;
                    }
                }
                else if (edge.IsTargetConnected)
                {
                    /// Targetの中心点とFirstを結ぶ

                    var tgt       = edge.Target as INode;
                    var tgtCenter = RectUtil.GetCenter(tgt.Bounds);

                    var line = new Line(edge.First, tgtCenter);
                    if (tgt.OuterFrame.IntersectsWith(line))
                    {
                        edge.Last = tgt.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.Last = tgtCenter;
                    }
                }
                else
                {
                    /// 何もしない
                }
            }
            else if (edge.EdgePointCount > 2)
            {
                if (edge.IsSourceConnected)
                {
                    /// SourceがつながっているのでFirstを調整

                    var src       = edge.Source as INode;
                    var srcCenter = RectUtil.GetCenter(src.Bounds);

                    var line = new Line(edge.FirstRef.Next.EdgePoint, srcCenter);
                    if (src.OuterFrame.IntersectsWith(line))
                    {
                        edge.First = src.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.First = srcCenter;
                    }
                }

                if (edge.IsTargetConnected)
                {
                    /// TargetがつながっているのでLastを調整

                    var tgt       = edge.Target as INode;
                    var tgtCenter = RectUtil.GetCenter(tgt.Bounds);

                    var line = new Line(edge.LastRef.Prev.EdgePoint, tgtCenter);
                    if (tgt.OuterFrame.IntersectsWith(line))
                    {
                        edge.Last = tgt.OuterFrame.GetIntersectionPoint(line);
                    }
                    else
                    {
                        edge.Last = tgtCenter;
                    }
                }
            }
        }