示例#1
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float scale = pen.Width == 0 ? 1 : size / (pen.Width * 2);

            if (scale <= 0)
            {
                scale = 1e-3f;
            }

            var hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            hPath.AddPolygon(new PointF[] {
                new PointF(1, -1),
                new PointF(1, 1),
                new PointF(-1, 1),
                new PointF(-1, -1),
            });
            var clone = new CustomLineCap(hPath, null, LineCap.Flat, 0)
            {
                WidthScale = scale
            }; // we set the stroke path only

            return(clone);
        }
示例#2
0
        private void CreateObjects()
        {
            brSolid  = new SolidBrushPlus(Color.CornflowerBlue);
            penSolid = new PenPlus(Color.Red, 10);
            penSolid.SetEndCap(LineCap.LineCapRound);
            penSolid.SetStartCap(LineCap.LineCapArrowAnchor);

            brHatch = new HatchBrush(HatchStyle.HatchStyle25Percent,
                                     Color.Black, Color.White);
            penHatch = new PenPlus(brHatch, 10);

            penSolidTrans = new PenPlus(Color.FromArgb(-0x5f7f7f7f), 10);

            penSolidCustomCap = new PenPlus(Color.Black, 20);
            GraphicsPath path = new GraphicsPath(FillMode.FillModeAlternate);

            path.AddEllipse(-0.5f, -1.5f, 1, 3);
            CustomLineCap cap = new CustomLineCap(null, path, LineCap.LineCapFlat, 0);

            penSolidCustomCap.SetCustomEndCap(cap);

            penDash = new PenPlus(Color.Black, 5);
            penDash.SetDashStyle(DashStyle.DashStyleDot);

            brGrad = new LinearGradientBrush(
                new GpPointF(0, 0), new GpPointF(100, 100),
                Color.Black, Color.White);
            penGradient = new PenPlus(brGrad, 30);
        }
 [Category("NotWorking")]          // not supported by libgdiplus
 public void CustomStartCap_Default()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         CustomLineCap clc = default_pen.CustomStartCap;
     });
 }
示例#4
0
        /// <summary>
        /// Overrides, when click on, handles color selection.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            // Check cursor, if on one of the buttons - hot track it
            for (int recIndex = 0; recIndex < buttons.Length; recIndex++)
            {
                if (buttons[recIndex].Contains(e.Location))
                {
                    mCurrentSelected = recIndex;


                    //if a custom cap is choosen we need to set the CustomLineCap
                    if (CustomCaps.SelectableLineCaps[recIndex] == ConnectionCap.Generalization)
                    {
                        mCustomLineCap = generalizationCap;
                    }
                    else
                    {
                        mCustomLineCap = null;
                    }

                    LineCap = CustomCaps.SelectableLineCaps[recIndex];
                    lineWidthTip.SetToolTip(this, CustomCaps.SelectableLineCaps[recIndex].ToString());

                    if (mContextForm != null)
                    {
                        mContextForm.Hide();
                    }
                    mContextForm = null;
                }
            }
            this.Refresh();
        }
示例#5
0
        private void LineCapToLineCap2(LineCap2 cap2, out LineCap capResult, out CustomLineCap customCapResult)
        {
            switch (cap2)
            {
            case LineCap2.Flat:
                capResult       = LineCap.Flat;
                customCapResult = null;
                break;

            case LineCap2.Arrow:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, false);
                break;

            case LineCap2.ArrowFilled:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5.0f * this.capScale, 5.0f * this.capScale, true);
                break;

            case LineCap2.Rounded:
                capResult       = LineCap.Round;
                customCapResult = null;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
示例#6
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float endPoint;

            endPoint = pen.Width == 0 ? 1 : size / (pen.Width);
            if (endPoint <= 0)
            {
                endPoint = 1e-3f;
            }

            float c = 0.8660254f; //  0.5 / Math.Tan(30°);

            float r = 1;          // 0.5/Math.Sin(30°);

            var hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            hPath.AddPolygon(new PointF[] {
                new PointF(0, -endPoint * 0.866f + r),
                new PointF(endPoint / 2 - c, -0.5f),
                new PointF(-endPoint / 2 + c, -0.5f),
            });
            var clone = new CustomLineCap(null, hPath, LineCap.Flat, endPoint * 0.866f - r); // we set the stroke path only

            clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
            return(clone);
        }
示例#7
0
        /// <summary>
        /// Deletes all tools based on the given CapStyle.
        /// </summary>
        private static void NotifyCapStyleChanged(ICapStyle capStyle)
        {
            Debug.Assert(capStyle != null);

            // Collect affected PenKeys
            List <PenKey> penKeys = new List <PenKey>();

            foreach (KeyValuePair <PenKey, Pen> item in _penCache)
            {
                if (item.Key.StartCapStyle != null && item.Key.StartCapStyle == capStyle)
                {
                    penKeys.Add(item.Key);
                }
                else if (item.Key.EndCapStyle != null && item.Key.EndCapStyle == capStyle)
                {
                    penKeys.Add(item.Key);
                }
            }
            // Delete affected Pens
            foreach (PenKey penKey in penKeys)
            {
                Pen pen = _penCache[penKey];
                _penCache.Remove(penKey);
                pen.Dispose();
                pen = null;
            }
            penKeys.Clear();

            // Collect affected CustomLineCaps
            List <CapKey> capKeys = new List <CapKey>();

            foreach (KeyValuePair <CapKey, CustomLineCap> item in _capCache)
            {
                if (item.Key.CapStyle == capStyle)
                {
                    capKeys.Add(item.Key);
                }
            }

            // Delete affected CustomLineCaps
            foreach (CapKey capKey in capKeys)
            {
                CustomLineCap cap = _capCache[capKey];
                _capCache.Remove(capKey);
                cap.Dispose();
                cap = null;
            }
            // Delete affected GraphicsPaths
            foreach (CapKey capKey in capKeys)
            {
                if (_capPathCache.ContainsKey(capKey))
                {
                    GraphicsPath path = _capPathCache[capKey];
                    _capPathCache.Remove(capKey);
                    path.Dispose();
                    path = null;
                }
            }
            capKeys.Clear();
        }
示例#8
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float scale = pen.Width == 0 ? 1 : size / (2 * pen.Width);

            if (scale <= 0)
            {
                scale = 1e-3f;
            }

            var hPath = new GraphicsPath();

            hPath.AddPolygon(new PointF[] {
                new PointF(0, 0),
                new PointF(-1, -1),
                new PointF(1, -1),
            });

            // Construct the hook-shaped end cap.
            var clone = new CustomLineCap(hPath, null, LineCap.Flat, 1)
            {
                WidthScale = scale
            };

            return(clone);
        }
示例#9
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float endPoint;

            endPoint = pen.Width == 0 ? 1 : size / (pen.Width * 2) - 0.5f;

            if (endPoint < 0)
            {
                endPoint = 1e-3f;
            }

            var hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            hPath.AddPolygon(new PointF[] {
                new PointF(endPoint, -endPoint),
                new PointF(endPoint, endPoint),
                new PointF(-endPoint, endPoint),
                new PointF(-endPoint, -endPoint),
            });
            var clone = new CustomLineCap(null, hPath, LineCap.Flat, endPoint); // we set the stroke path only

            clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
            return(clone);
        }
示例#10
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float endPoint;

            endPoint  = pen.Width == 0 ? 1 : size / pen.Width;
            endPoint /= 2;
            if (endPoint <= 0)
            {
                endPoint = 1e-3f;
            }

            var hPath = new GraphicsPath();

            var r = endPoint / (2 * Math.Sin(_designAngle * (Math.PI / 180)));
            var b = r - r * Math.Cos(_designAngle * (Math.PI / 180));
            var h = endPoint / 2;

            // Create the outline for our custom end cap.

            hPath.AddArc(
                (float)(-r - h), (float)(-b),
                (float)(2 * r), (float)(2 * r),
                (float)(-90 - _designAngle), (float)(2 * _designAngle));

            hPath.AddArc(
                (float)(h - r), (float)(b - 1.999999 * r),
                (float)(2 * r), (float)(2 * r),
                (float)(90 + _designAngle), (float)(-2 * _designAngle));

            var clone = new CustomLineCap(null, hPath); // we set the stroke path only

            clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
            return(clone);
        }
示例#11
0
        private static void LineCapToLineCap2(LineCap2 cap2, out LineCap capResult, out CustomLineCap customCapResult)
        {
            switch (cap2)
            {
            case LineCap2.Flat:
                capResult       = LineCap.Flat;
                customCapResult = null;
                return;

            case LineCap2.Arrow:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5f, 5f, false);
                return;

            case LineCap2.ArrowFilled:
                capResult       = LineCap.ArrowAnchor;
                customCapResult = new AdjustableArrowCap(5f, 5f, true);
                return;

            case LineCap2.Rounded:
                capResult       = LineCap.Round;
                customCapResult = null;
                return;
            }
            throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(cap2, "cap2");
        }
示例#12
0
        private CustomLineCap GetClone(Pen pen, float size)
        {
            float scale = pen.Width == 0 ? 1 : size / pen.Width;

            if (scale <= 0)
            {
                scale = 1e-3f;
            }

            var hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            // Create the outline for our custom end cap.
            hPath.AddPolygon(new PointF[] {
                new PointF(0, -0.866f),
                new PointF(0.5f, 0),
                new PointF(-0.5f, 0),
            });
            var clone = new CustomLineCap(hPath, null, LineCap.Flat, 0)
            {
                WidthScale = scale
            };

            return(clone);
        }
示例#13
0
        protected override Pen CreatePen(Color borderColor, int borderSize)
        {
            using (GraphicsPath gp = new GraphicsPath())
            {
                int arrowWidth = 2, arrowHeight = 6, arrowCurve = 1;
                gp.AddLine(new Point(0, 0), new Point(-arrowWidth, -arrowHeight));
                gp.AddCurve(new Point[] { new Point(-arrowWidth, -arrowHeight), new Point(0, -arrowHeight + arrowCurve), new Point(arrowWidth, -arrowHeight) });
                gp.CloseFigure();

                CustomLineCap lineCap = new CustomLineCap(gp, null)
                {
                    BaseInset = arrowHeight - arrowCurve
                };

                Pen pen = new Pen(borderColor, borderSize);
                pen.CustomEndCap = lineCap;

                if (ArrowHeadsBothSide)
                {
                    pen.CustomStartCap = lineCap;
                }

                pen.LineJoin = LineJoin.Round;
                return(pen);
            }
        }
示例#14
0
        private void DrawDropMark(Graphics gr)
        {
            if (_dropPosition.Position == NodePosition.Inside)
            {
                return;
            }

            if (_markPen == null)
            {
                GraphicsPath path = new GraphicsPath();
                path.AddLines(new Point[] { new Point(0, 0), new Point(1, 1), new Point(-1, 1), new Point(0, 0) });
                CustomLineCap cap = new CustomLineCap(null, path);
                cap.WidthScale = 0.5f;

                _markPen = new Pen(_dragDropMarkColor, _dragDropMarkWidth)
                {
                    CustomStartCap = cap,
                    CustomEndCap   = cap
                };
            }

            Rectangle rect  = GetNodeBounds(_dropPosition.Node);
            int       right = DisplayRectangle.Right - LeftMargin + OffsetX;
            int       y     = rect.Y;

            if (_dropPosition.Position == NodePosition.After)
            {
                y = rect.Bottom;
            }
            gr.DrawLine(_markPen, rect.X, y, right, y);
        }
示例#15
0
        protected override Pen CreatePen(Color borderColor, int borderSize, BorderStyle borderStyle)
        {
            using (GraphicsPath gp = new GraphicsPath())
            {
                int arrowWidth = 2, arrowHeight = 6, arrowCurve = 1;
                gp.AddLine(new Point(0, 0), new Point(-arrowWidth, -arrowHeight));
                gp.AddCurve(new Point[] { new Point(-arrowWidth, -arrowHeight), new Point(0, -arrowHeight + arrowCurve), new Point(arrowWidth, -arrowHeight) });
                gp.CloseFigure();

                CustomLineCap lineCap = new CustomLineCap(gp, null)
                {
                    BaseInset = arrowHeight - arrowCurve
                };

                Pen pen = new Pen(borderColor, borderSize);

                if (ArrowHeadDirection == ArrowHeadDirection.Both && MathHelpers.Distance(Points[0], Points[Points.Length - 1]) > arrowHeight * borderSize * 2)
                {
                    pen.CustomEndCap = pen.CustomStartCap = lineCap;
                }
                else if (ArrowHeadDirection == ArrowHeadDirection.Start)
                {
                    pen.CustomStartCap = lineCap;
                }
                else
                {
                    pen.CustomEndCap = lineCap;
                }

                pen.LineJoin  = LineJoin.Round;
                pen.DashStyle = (DashStyle)borderStyle;
                return(pen);
            }
        }
示例#16
0
        protected CustomLineCap GetClone(Pen pen, float size, bool startCap)
        {
            float endPoint;

            if (pen.Width * _designWidth < size)
            {
                endPoint = pen.Width == 0 ? 1 : size / pen.Width;
            }
            else
            {
                endPoint = _designWidth;
            }

            if (startCap)
            {
                endPoint = -endPoint;
            }

            GraphicsPath hPath = new GraphicsPath();

            // Create the outline for our custom end cap.
            hPath.AddLine(new PointF(endPoint < 0 ? 0.5f : -0.5f, 0), new PointF(endPoint / 2, 0));
            CustomLineCap clone = new CustomLineCap(null, hPath); // we set the stroke path only

            clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
            return(clone);
        }
示例#17
0
        private static CustomLineCap GenerateLineCap(ArrowStyle style)
        {
            CustomLineCap clc = null;

            using (GraphicsPath gp = new GraphicsPath())
                switch (style)
                {
                case ArrowStyle.PointyArrow:
                    gp.AddPolygon(new PointF[] { new PointF(0f, -0f), new PointF(.1f, -.2f),
                                                 new PointF(0f, -.15f),
                                                 new PointF(-.10f, -.2f) });
                    clc            = new CustomLineCap(gp, null);
                    clc.WidthScale = 30;
                    clc.BaseInset  = .15f;
                    break;

                case ArrowStyle.HollowArrow:
                    gp.AddPolygon(new PointF[] { new PointF(0, -1f), new PointF(2f, -4f),
                                                 new PointF(-2f, -4f) });
                    clc           = new CustomLineCap(null, gp);
                    clc.BaseInset = 5.0f;
                    break;

                case ArrowStyle.BigArrow:
                    gp.AddPolygon(new PointF[] { new PointF(0, 0f), new PointF(.25f, -.4f),
                                                 new PointF(-.25f, -.4f) });
                    clc            = new CustomLineCap(gp, null);
                    clc.BaseInset  = .4f;
                    clc.WidthScale = 15;
                    break;

                case ArrowStyle.LineArrow:
                    gp.AddLine(new PointF(0, 0), new PointF(2.5f, -4f));
                    gp.AddLine(new PointF(0, 0), new PointF(-2.5f, -4f));
                    clc           = new CustomLineCap(null, gp);
                    clc.BaseInset = 3f;
                    break;

                case ArrowStyle.TinyArrow:
                    gp.AddPolygon(new PointF[] { new PointF(0, 0f), new PointF(.25f, -.4f),
                                                 new PointF(-.25f, -.4f) });
                    clc            = new CustomLineCap(gp, null);
                    clc.BaseInset  = .4f;
                    clc.WidthScale = 5;
                    break;

                case ArrowStyle.LittleArrow:
                    gp.AddPolygon(new PointF[] { new PointF(0, 0f), new PointF(.25f, -.4f),
                                                 new PointF(-.25f, -.4f) });
                    clc            = new CustomLineCap(gp, null);
                    clc.BaseInset  = .4f;
                    clc.WidthScale = 10;
                    break;

                default:
                    throw new Exception("Unexpected arrow type");
                }
            return(clc);
        }
示例#18
0
 public void WidthScale_SetThenGet_Success(float value)
 {
     using (GraphicsPath strokePath = new GraphicsPath())
         using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
         {
             customLineCap.WidthScale = value;
             Assert.Equal(value, customLineCap.WidthScale);
         }
 }
示例#19
0
 public void BaseInset_SetThenGet_Success(float value)
 {
     using (GraphicsPath strokePath = new GraphicsPath())
         using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
         {
             customLineCap.BaseInset = value;
             Assert.Equal(value, customLineCap.BaseInset);
         }
 }
示例#20
0
 public void BaseCap_Set_InvalidLineCap_ThrowsArgumentException(LineCap baseCap)
 {
     using (GraphicsPath strokePath = new GraphicsPath())
         using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
         {
             AssertExtensions.Throws <ArgumentException>(null, () => customLineCap.BaseCap = baseCap);
             Assert.Equal(LineCap.Flat, customLineCap.BaseCap);
         }
 }
示例#21
0
 public void BaseCap_SetThenGet_Success(LineCap baseCap)
 {
     using (GraphicsPath strokePath = new GraphicsPath())
         using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
         {
             customLineCap.BaseCap = baseCap;
             Assert.Equal(baseCap, customLineCap.BaseCap);
         }
 }
示例#22
0
 public void StrokeJoin_SetThenGet_Success(LineJoin lineJoin)
 {
     using (GraphicsPath strokePath = new GraphicsPath())
         using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
         {
             customLineCap.StrokeJoin = lineJoin;
             Assert.Equal(lineJoin, customLineCap.StrokeJoin);
         }
 }
示例#23
0
 public void Ctor_InvalidLineCap_ReturnsFlat(LineCap baseCap)
 {
     using (GraphicsPath fillPath = new GraphicsPath())
         using (GraphicsPath strokePath = new GraphicsPath())
             using (CustomLineCap customLineCap = new CustomLineCap(fillPath, strokePath, baseCap, 0f))
             {
                 Assert.Equal(LineCap.Flat, customLineCap.BaseCap);
             }
 }
示例#24
0
 public static ArrowStyle GetLineCap(CustomLineCap custom)
 {
     //This should return the actual kind of arrow;
     //however, apparently this information isn't
     //available via the CustomLineCap; this means
     //that GraphicsProxy needs to be re-thought out
     //and that endcaps need to be passed separately,
     //not as part of the Pen
     return(ArrowStyle.TinyArrow);
 }
示例#25
0
        /// <summary>
        /// Initializes the <see cref="T:LinePenStyle"/> class.
        /// </summary>
        static LinePenStyle()
        {
            Point[] ps = new Point[3] {
                new Point(-2, 0), new Point(0, 4), new Point(2, 0)
            };
            GraphicsPath gpath = new GraphicsPath();

            gpath.AddPolygon(ps);
            gpath.CloseAllFigures();
            mGeneralizationCap = new CustomLineCap(null, gpath);
        }
		private void CreateMarkPen()
		{
			GraphicsPath path = new GraphicsPath();
			path.AddLines(new Point[] { new Point(0, 0), new Point(1, 1), new Point(-1, 1), new Point(0, 0) });
			CustomLineCap cap = new CustomLineCap(null, path);
			cap.WidthScale = 1.0f;

			_markPen = new Pen(_dragDropMarkColor, _dragDropMarkWidth);
			_markPen.CustomStartCap = cap;
			_markPen.CustomEndCap = cap;
		}
示例#27
0
 public LinkLine(Font font, DashStyle lineStyle, string startText, string middleText, string endText, CustomLineCap startCap, CustomLineCap endCap)
 {
     this.LineColor = Color.DarkGray;
     LineStyle      = lineStyle;
     Font           = font;
     //StartText = startText;
     //EndText = endText;
     MiddleText = middleText;
     StartCap   = startCap;
     EndCap     = endCap;
     this.Font  = new Font(this.Font.FontFamily.Name, 7F);
 }
        public void Draw(Graphics gr)
        {
            CustomLineCap e = EndLineCap.GetCustomLineCap();

            Pen pen = new Pen(Color.Black);

            pen.CustomEndCap = e;

            //gr.DrawLine(pen, Start.Location, End.Location);

            e.Dispose();
        }
示例#29
0
        public void SetThenGetStrokeCaps_Success(LineCap startCap, LineCap endCap)
        {
            using (GraphicsPath strokePath = new GraphicsPath())
                using (CustomLineCap customLineCap = new CustomLineCap(null, strokePath))
                {
                    customLineCap.SetStrokeCaps(startCap, endCap);
                    customLineCap.GetStrokeCaps(out LineCap retrievedStartCap, out LineCap retrievedEndCap);

                    Assert.Equal(startCap, retrievedStartCap);
                    Assert.Equal(endCap, retrievedEndCap);
                }
        }
示例#30
0
 public void Ctor_Path_Path_LineCap_Float(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset, LineCap expectedCap)
 {
     using (fillPath)
         using (strokePath)
             using (CustomLineCap customLineCap = new CustomLineCap(fillPath, strokePath, baseCap, baseInset))
             {
                 Assert.Equal(expectedCap, customLineCap.BaseCap);
                 Assert.Equal(baseInset, customLineCap.BaseInset);
                 Assert.Equal(LineJoin.Miter, customLineCap.StrokeJoin);
                 Assert.Equal(1f, customLineCap.WidthScale);
             }
 }