// ======================================== // 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); }
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); }
protected override GraphicsPathDescription CreatePath() { var ret = new GraphicsPathDescription(); ret.AddEllipse(new Rectangle(new Point(0, -2), new Size(4, 4))); return(ret); }
// ======================================== // method // ======================================== // === AbstractPathBoundingFigure ========== protected override GraphicsPathDescription CreatePath(Rectangle bounds) { var ret = new GraphicsPathDescription(); ret.AddRectangle(bounds); return(ret); }
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); }
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); }
protected override Mkamo.Common.Forms.Descriptions.GraphicsPathDescription CreatePath() { var ret = new GraphicsPathDescription(); ret.AddLine(Point.Empty, new Point(8, 4)); ret.AddLine(Point.Empty, new Point(8, -4)); return(ret); }
protected override GraphicsPathDescription CreatePath() { var ret = new GraphicsPathDescription(); ret.AddLine(Point.Empty, new Point(8, 4)); ret.AddLine(new Point(8, 4), new Point(8, -4)); ret.AddLine(new Point(8, -4), Point.Empty); return(ret); }
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); }
// ======================================== // method // ======================================== // === AbstractPathBoundingFigure ========== protected override GraphicsPathDescription CreatePath(Rectangle bounds) { var ret = new GraphicsPathDescription(); var triangleLeft = Math.Max(bounds.Right - bounds.Height / 2, bounds.Left + bounds.Width / 2); var pt1 = bounds.Location; var pt2 = new Point(triangleLeft, bounds.Top); var pt3 = new Point(bounds.Right, bounds.Top + bounds.Height / 2); var pt4 = new Point(triangleLeft, bounds.Bottom); var pt5 = new Point(bounds.Left, bounds.Bottom); ret.AddLine(pt1, pt2); ret.AddLine(pt2, pt3); ret.AddLine(pt3, pt4); ret.AddLine(pt4, pt5); ret.AddLine(pt5, pt1); return(ret); }
// ======================================== // 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); }
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); }
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); }
// ======================================== // constructor // ======================================== public AbstractPathEdgeDecoration() { _path = CreatePath(); }
// ------------------------------ // protected // ------------------------------ protected override GraphicsPathDescription CreatePath(Rectangle bounds) { var path = new GraphicsPathDescription(); var roundWidth = (int)Math.Round(bounds.Width * CornerRatio, MidpointRounding.AwayFromZero); var roundHeight = (int)Math.Round(bounds.Height * CornerRatio, MidpointRounding.AwayFromZero); var roundSize = Math.Min(roundWidth, roundHeight); if (roundSize < 1) { roundSize = 1; } path.AddLine( new Point(bounds.Left + roundSize, bounds.Top), new Point(bounds.Right - roundSize, bounds.Top) ); path.AddArc( new Rectangle( bounds.Right - roundSize, bounds.Top, roundSize, roundSize ), 270, 90 ); path.AddLine( new Point(bounds.Right, bounds.Top + roundSize), new Point(bounds.Right, bounds.Bottom - roundSize) ); path.AddArc( new Rectangle( bounds.Right - roundSize, bounds.Bottom - roundSize, roundSize, roundSize ), 0, 90 ); path.AddLine( new Point(bounds.Right - roundSize, bounds.Bottom), new Point(bounds.Left + roundSize, bounds.Bottom) ); path.AddArc( new Rectangle( bounds.Left, bounds.Bottom - roundSize, roundSize, roundSize ), 90, 90 ); path.AddLine( new Point(bounds.Left, bounds.Bottom - roundSize), new Point(bounds.Left, bounds.Top + roundSize) ); path.AddArc( new Rectangle(bounds.Left, bounds.Top, roundSize, roundSize), 180, 90 ); return(path); }
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); }
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); }
// ======================================== // constructor // ======================================== protected AbstractPathBoundingNode() : base() { _pathDesc = null; _drawPathDesc = null; _angle = 0; _isFlippedHorizontal = false; _isFlippedVertical = false; _ResourceCache.RegisterResourceCreator( PathResourceKey, () => { if (_pathDesc == null) { _pathDesc = CreatePath(GetBoundsForPathCreation()); } var ret = _pathDesc.CreateGraphicsPath(); var matrix = CreateMatrix(); if (matrix != null) { ret.Transform(matrix); matrix.Dispose(); } return(ret); }, ResourceDisposingPolicy.Explicit ); _ResourceCache.RegisterResourceCreator( DrawPathResourceKey, () => { if (_drawPathDesc == null) { _drawPathDesc = CreateDrawPath(GetBoundsForPathCreation()); } var ret = _drawPathDesc.CreateGraphicsPath(); var matrix = CreateMatrix(); if (matrix != null) { ret.Transform(matrix); matrix.Dispose(); } return(ret); }, ResourceDisposingPolicy.Explicit ); _ResourceCache.RegisterResourceCreator( OutlinePathResourceKey, () => { if (_pathDesc == null) { _pathDesc = CreatePath(GetBoundsForPathCreation()); } var ret = _pathDesc.CreateGraphicsPath(); var matrix = CreateMatrix(); if (matrix != null) { ret.Transform(matrix); matrix.Dispose(); } ret.Flatten(null, 0.50f); return(ret); }, ResourceDisposingPolicy.Explicit ); }
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); }