Example #1
0
 public PenCapProvider()
 {
     mMultiCap = null;
     mAggrCap = null;
     mInhCap = null;
     mSingleCap = null;
 }
Example #2
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;

			GraphicsPath 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));

			CustomLineCap clone = new CustomLineCap(null, hPath); // we set the stroke path only
			clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
			return clone;
		}
 /// <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);
 }
Example #4
0
        public object Clone()
        {
            IntPtr cloneCap = IntPtr.Zero;

            int status = SafeNativeMethods.Gdip.GdipCloneCustomLineCap(new HandleRef(this, nativeCap), out cloneCap);

            if (status != SafeNativeMethods.Gdip.Ok)
                throw SafeNativeMethods.Gdip.StatusException(status);
            
            return CustomLineCap.CreateCustomLineCapObject(cloneCap);
       }
Example #5
0
        void IView.Draw(System.Drawing.Graphics g)
        {
            Pen          p  = new Pen(color, width);
            GraphicsPath gp = new GraphicsPath();

            gp.AddLines(new Point[] { new Point(-2, -5), new Point(0, 0), new Point(2, -5) });
            CustomLineCap clp = new System.Drawing.Drawing2D.CustomLineCap(null, gp);

            clp.SetStrokeCaps(LineCap.Square, LineCap.Square);
            clp.WidthScale   = 1;
            p.CustomStartCap = clp;


            Point T = new Point(point1.X, point1.Y);

            if (point1 != point2)
            {
                double ab = Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y));
                double r  = ab / Math.Sqrt(2);
                double b  = Math.PI / 4 - Math.Atan2(point2.X - Point1.X, point2.Y - Point1.Y);
                Point  O  = new Point((int)(point1.X + r * Math.Cos(b) - r), (int)(point1.Y + r * Math.Sin(b) - r));
                int    sa = (int)(180 + b * 180 / Math.PI);



                int a = 90 - (int)((Math.Acos((2 * r * r - radius * radius) / (2 * r * r)) * 180 / Math.PI) * 1.3);
                if ((int)r * 2 > 0)
                {
                    g.DrawArc(p, O.X, O.Y, (int)r * 2, (int)r * 2, sa - a, a);
                }



                T.X += (int)(r * 0.7 * Math.Cos(b + 70 * Math.PI / 180));
                T.Y += (int)(r * 0.7 * Math.Sin(b + 70 * Math.PI / 180)) - 15;
            }
            else
            {
                g.DrawArc(p, point1.X - 60, point1.Y - 30, 60, 60, 40, 280);
                T.X -= 40;
            }

            SolidBrush Sel = new SolidBrush(Color.Silver);

            if (isOver)
            {
                Sel.Color = Color.DarkTurquoise;
            }

            g.DrawString(Val, new Font("Roboto Condensed", 18, FontStyle.Bold), Sel, T.X, T.Y, VertexView.stringFormat);

            valR.Size     = g.MeasureString(Val, new Font("Roboto Condensed", 18, FontStyle.Bold));
            valR.Location = new Point(T.X - (int)valR.Size.Width / 2, T.Y - (int)valR.Size.Height / 2);
        }
		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;
		}
Example #7
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);
 }
Example #8
0
		private CustomLineCap GetClone(Pen pen, float size)
		{
			float endPoint;

			endPoint = pen.Width == 0 ? 1 : size / pen.Width;

			GraphicsPath hPath = new GraphicsPath();
			// Create the outline for our custom end cap.
			hPath.AddLine(new PointF(-endPoint / 2, 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;
		}
    public ArrowF20LineCap()
    {
      GraphicsPath hPath = new GraphicsPath();

      // Create the outline for our custom end cap.
      hPath.AddLine(new PointF(0, -2 * _designWidth), new PointF(-_designWidth / 2, -2 * _designWidth));
      hPath.AddLine(new PointF(-_designWidth / 2, -2 * _designWidth), new PointF(0, 0));
      hPath.AddLine(new PointF(0, 0), new PointF(_designWidth / 2, -2 * _designWidth));
      hPath.AddLine(new PointF(_designWidth / 2, -2 * _designWidth), new PointF(0, -2 * _designWidth));

      // Construct the hook-shaped end cap.
      _cap = new CustomLineCap(hPath, null);
      _cap.BaseInset = _designWidth * 2;
    }
Example #10
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;

			GraphicsPath hPath = new GraphicsPath();
			// Create the outline for our custom end cap.
			hPath.AddEllipse(-endPoint, -endPoint, 2 * endPoint, 2 * endPoint);
			CustomLineCap clone = new CustomLineCap(null, hPath, LineCap.Flat, endPoint); // we set the stroke path only
			clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
			return clone;
		}
Example #11
0
		protected CustomLineCap GetClone(Pen pen, float size, bool startCap)
		{
			float endPoint;

			endPoint = pen.Width == 0 ? 1 : size / pen.Width;

			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;
		}
Example #12
0
        public override void Draw_line(Panel panel)
        {
            Pen myPen = new Pen(Color.Black, 2);

            GraphicsPath hPath = new GraphicsPath();  // ç•«ç®­é ­çš„
            hPath.AddLine(new Point(5, 0), new Point(-5, 0));
            hPath.AddLine(new Point(5, 0), new Point(0, 10));
            hPath.AddLine(new Point(-5, 0), new Point(0, 10));

            CustomLineCap myNewArrow = new CustomLineCap(null, hPath);
            myNewArrow.SetStrokeCaps(LineCap.Round, LineCap.Round);
            myPen.StartCap = LineCap.Flat;
            myPen.CustomEndCap = myNewArrow;

            panel.CreateGraphics().DrawLine(myPen, Start, End);
            myPen.Dispose();
        }
Example #13
0
        public NetworkVisualSettings()
        {
            // Fix settings
            GraphicsPath arrowPath = new GraphicsPath();
            arrowPath.AddLine(new PointF(-4, -6), new PointF(0, 0));
            arrowPath.AddLine(new PointF(0, 0), new PointF(4, -6));
            this.stateArrowCap = new CustomLineCap(null, arrowPath);

            GraphicsPath arrowPath2 = new GraphicsPath();
            arrowPath2.AddLine(new PointF(-8, -12), new PointF(0, 0));
            arrowPath2.AddLine(new PointF(0, 0), new PointF(8, -12));
            this.resetArrowCap = new CustomLineCap(null, arrowPath2);
            this.resetArrowCap.WidthScale = 0.4F;

            this.arrowCap = new AdjustableArrowCap(7, 7, true);
            this.arrowCap.SetStrokeCaps(LineCap.Round, LineCap.Round);
            this.arrowCap.WidthScale = 0.4F;

            GraphicsPath roundPath = new GraphicsPath();
            roundPath.AddEllipse(-4F, -8F, 8F, 8F);
            this.roundCap = new CustomLineCap(roundPath, null);
            this.roundCap.WidthScale = 0.4F;
            this.roundCap.SetStrokeCaps(LineCap.Round, LineCap.Round);

            this.dashValues = new float[] { 1F, 5F };

            this.backgroundColor = Color.FromArgb(255, 255, 255);
            this.backgroundBrush = new SolidBrush(this.backgroundColor);

            this.DefaultColor = Color.FromArgb(0, 0, 0);
            this.StateColor = Color.FromArgb(0, 0, 0);
            this.ShadowColor = Color.FromArgb(0, 0, 0);
            this.SelectedColor = Color.FromArgb(50, 50, 250);
            this.MarkColor = Color.FromArgb(30, 200, 30);
            this.NotePenColor = Color.FromArgb(0, 0, 0);
            this.NoteBorderColor = Color.FromArgb(205, 219, 36);
            this.NoteBrushColor = Color.FromArgb(255, 255, 128);
            this.HelpColor = Color.FromArgb(200, 200, 200);
            this.MarkAsReadyToFireColor = Color.FromArgb(250, 50, 50);
            this.ClockColor = Color.FromArgb(0, 0, 200);

            FontStyle fontStlye = FontStyle.Bold | FontStyle.Italic;
            this.defaultFont = new Font("Arial", 10, fontStlye);
            this.noteFont = new Font("Arial", 10);
        }
Example #14
0
		private CustomLineCap GetClone(Pen pen, float size)
		{
			float scale = pen.Width == 0 ? 1 : size / (2 * pen.Width);
			if (scale <= 0)
				scale = 1e-3f;

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

			// Construct the hook-shaped end cap.
			CustomLineCap clone = new CustomLineCap(hPath, null, LineCap.Flat, 2); // we set the stroke path only
			clone.WidthScale = scale;
			return clone;
		}
Example #15
0
		private CustomLineCap GetClone(Pen pen, float size)
		{
			float endPoint;

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

			if (endPoint < 0)
				endPoint = 1e-3f * pen.Width;

			GraphicsPath hPath = new GraphicsPath();
			// Create the outline for our custom end cap.
			hPath.AddPolygon(new PointF[]{
        new PointF(0,-endPoint),
        new PointF(endPoint,0),
				new PointF(0, endPoint),
        new PointF(-endPoint,0),
      });
			CustomLineCap clone = new CustomLineCap(null, hPath, LineCap.Flat, endPoint); // we set the stroke path only
			clone.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
			return clone;
		}
        public clsVektor(int x1, int x2, int xStartPunkt, int yStartPunkt, Pen farbe)
        {
            this.x1 = x1;
            this.x2 = x2;

            xStart = xStartPunkt;
            yStart = yStartPunkt;
            //Den Stift transparent machen
            Pen tempfarbe = new Pen(Color.FromArgb(128,farbe.Color));
            //Der Pfeil am Ende des Vektors
            Point[] pts = { new Point(-3, 0), new Point(3, 0), new Point(0, 4), new Point(-3, 0) };
            GraphicsPath path = new GraphicsPath();
            path.AddLines(pts);
            GraphicsPath fill = new GraphicsPath();
            fill.FillMode = FillMode.Alternate;
            CustomLineCap customLineCap = new CustomLineCap(fill, path);
            tempfarbe.CustomEndCap = customLineCap;
            //Den fertig konfigurierten Stift speichern
            this.farbe = tempfarbe;
            //Die Werte in Bildschirmpixel umrechnen
            ÃœbertrageAufPixelEbene();
        }
Example #17
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°);

			GraphicsPath 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),
      });
			CustomLineCap 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;
		}
Example #18
0
 public CustomLineCap _getInhCap()
 {
     if (null == mInhCap)
     {
         int x_ = 5;
         int y_ = 10;
         int span_ = 2 * y_;
         GraphicsPath path_ = new GraphicsPath();
         path_.StartFigure();
         path_.AddPolygon(new Point[]{
             new Point(0, y_),
             new Point(x_, 0),
             new Point(y_, y_)
         });
         path_.AddLine(x_, y_, x_, span_);
         path_.CloseFigure();
         Matrix matrix_ = new Matrix();
         matrix_.Translate(-x_, -span_);
         path_.Transform(matrix_);
         mInhCap = new CustomLineCap(null, path_);
         mInhCap.BaseInset = span_;
     }
     return mInhCap;
 }
Example #19
0
 public CustomLineCap _getAggrCap()
 {
     if (null == mAggrCap)
     {
         int span_ = 10;
         int width_ = 10;
         int height_ = 10;
         GraphicsPath path_ = new GraphicsPath();
         path_.StartFigure();
         path_.AddPolygon(new PointF[] {
             new PointF(0, height_/2),
             new PointF(width_/2, height_),
             new PointF(width_,height_/2),
             new PointF(width_/2,0)
         });
         path_.CloseFigure();
         Matrix matrix_ = new Matrix();
         matrix_.Translate(-height_ / 2, -span_);
         path_.Transform(matrix_);
         mAggrCap = new CustomLineCap(null, path_);
         mAggrCap.BaseInset = span_;
     }
     return mAggrCap;
 }
Example #20
0
            private static bool CustomEndCapSerializable(CustomLineCap clp)
            {
                if (clp == null)
                    return false;
                if (clp is AdjustableArrowCap)
                    return true;

                return clp.GetType().IsSerializable;
            }
Example #21
0
                /// <summary>
                /// Serialization constructor
                /// </summary>
                /// <param name="info"></param>
                /// <param name="context"></param>
                public CustomLineCapRef(SerializationInfo info, StreamingContext context)
                {
                    var baseCap = (LineCap) info.GetInt32("BaseCap");
                    var baseInset = info.GetSingle("BaseInset");
                    var fillPath = (GraphicsPath) info.GetValue("FillPath", (typeof (GraphicsPath)));
                    var strokePath = (GraphicsPath)info.GetValue("StrokePath", (typeof(GraphicsPath)));

                    var startCap = (LineCap)info.GetInt32("StartCap");
                    var endCap = (LineCap)info.GetInt32("StartCap");
                    _clp = new CustomLineCap(fillPath, strokePath, baseCap, baseInset);
                    _clp.StrokeJoin = (LineJoin) info.GetInt32("StrokeJoin");
                    _clp.WidthScale = info.GetSingle("WidthScale");
                    _clp.SetStrokeCaps(startCap, endCap);
                }
Example #22
0
        private static void RenderLines(IGraphics ig)
        {
            ig.SmoothingMode = SmoothingMode.AntiAlias;

            var ow = new Pen(Color.Purple, 12.6f)
            {
                EndCap     = LineCap.Round,
                StartCap   = LineCap.Round,
                MiterLimit = 6f,
                LineJoin   = LineJoin.Miter
            };

            ig.SmoothingMode = SmoothingMode.None;

            var tp = new Pen(Color.Red, 2.7f)
            {
                DashStyle = DashStyle.DashDot
            };

            ig.DrawLine(tp, 70, 20, 190, 20);

            tp.DashStyle = DashStyle.Dash;

            ig.DrawLine(tp, 70, 30, 190, 30);

            tp.DashStyle   = DashStyle.Custom;
            tp.DashPattern = new float[] { 1, 8, 2, 2 };

            ig.DrawLine(tp, 70, 40, 190, 40);

            ig.SmoothingMode = SmoothingMode.AntiAlias;

            var pts = new PointF[4];

            pts[0] = new PointF(20, 50);
            pts[1] = new PointF(30, 90);
            pts[2] = new PointF(65, 60);
            pts[3] = new PointF(50, 40);
            ig.DrawLines(ow, pts);

            var polly = new Point[]
            {
                new Point(200, 40),
                new Point(220, 140),
                new Point(240, 100),
                new Point(290, 70),
                new Point(230, 10)
            };

            ig.DrawPolygon(tp, polly);

            //arrows
            var arr = new Pen(Color.DarkGoldenrod, 5.7f);

            {
                arr.Width    = 2;
                arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                const float arrowWidth   = 11.0f; // TUNE:
                const float arrowHeight  = 14f;   // TUNE:
                var         arrowOutline = new System.Drawing.Drawing2D.GraphicsPath();
                arrowOutline.AddLines(new PointF[] {
                    new PointF(-(arrowWidth / 2), -arrowHeight),
                    new PointF(0, 0),
                    new PointF(arrowWidth / 2, -arrowHeight),
                    new PointF(-(arrowWidth / 2), -arrowHeight)
                });
                var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline);
                generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round);
                generalizationArrow.BaseInset = arrowHeight;
                arr.CustomEndCap = generalizationArrow;
                ig.DrawLine(arr, 0, 120, 100, 200);
            }

            arr.Width = 5;
            var aac = new AdjustableArrowCap(5, 3, false);

            arr.EndCap       = LineCap.Custom;
            arr.CustomEndCap = aac;
            arr.StartCap     = LineCap.ArrowAnchor;
            ig.DrawLine(arr, 50, 120, 150, 200);

            arr.Width    = 7f;
            arr.EndCap   = LineCap.RoundAnchor;
            arr.StartCap = LineCap.SquareAnchor;
            ig.DrawLine(arr, 100, 120, 200, 200);

            arr.Width    = 9;
            arr.EndCap   = LineCap.DiamondAnchor;
            arr.StartCap = LineCap.ArrowAnchor;
            ig.DrawLine(arr, 150, 120, 250, 200);

            var al = new Point[]
            {
                new Point(200, 100),
                new Point(300, 200),
                new Point(300, 150)
            };

            arr.Width    = 9;
            arr.EndCap   = LineCap.DiamondAnchor;
            arr.StartCap = LineCap.DiamondAnchor;
            ig.DrawLines(arr, al);
        }
Example #23
0
		public void FixtureSetUp ()
		{
			default_pen = new Pen (Color.Empty);
			custom_line_cap = new CustomLineCap (new GraphicsPath (), new GraphicsPath ());
		}
        internal static void DrawConnector(Graphics graphics, Pen pen, Point[] points, Size connectorCapSize, Size maxCapSize, LineAnchor startConnectorCap, LineAnchor endConnectorCap)
        {
            if (points.GetLength(0) < 2)
                return;

            points = OptimizeConnectorPoints(points);

            //First we start with drawing start cap
            GraphicsPath startCap = null;
            float startCapInset = 0.0f;
            if (startConnectorCap != LineAnchor.None)
            {
                Point[] startSegment = new Point[] { points[0], points[1] };
                int capSize = (startSegment[0].Y == startSegment[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
                capSize += (capSize % 2);
                capSize = Math.Min(Math.Min(capSize, maxCapSize.Width), maxCapSize.Height);
                startCap = GetLineCap(startConnectorCap, capSize, out startCapInset);

                //Now if user has requested us to fill the line cap then we do so
                //THIS IS A WORKAROUND IN FILLING THE CUSTOM CAPS AS GDI+ HAS A 
                bool fill = (startCap != null && (((int)startConnectorCap % 2) == 0) && (startSegment[0].X == startSegment[1].X || startSegment[0].Y == startSegment[1].Y));
                if (fill)
                {
                    Matrix oldTransform = graphics.Transform;
                    graphics.TranslateTransform(startSegment[0].X, startSegment[0].Y);
                    if (startSegment[0].Y == startSegment[1].Y)
                        graphics.RotateTransform((startSegment[0].X < startSegment[1].X) ? 90.0f : 270.0f);
                    else
                        graphics.RotateTransform((startSegment[0].Y < startSegment[1].Y) ? 180.0f : 0.0f);
                    using (Brush penBrush = new SolidBrush(pen.Color))
                        graphics.FillPath(penBrush, startCap);
                    graphics.Transform = (oldTransform != null) ? oldTransform : new Matrix();
                }
            }

            GraphicsPath endCap = null;
            float endCapInset = 0.0f;
            if (endConnectorCap != LineAnchor.None)
            {
                Point[] endSegment = new Point[] { points[points.GetLength(0) - 2], points[points.GetLength(0) - 1] };
                int capSize = (endSegment[0].Y == endSegment[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
                capSize += (capSize % 2);
                capSize = Math.Min(Math.Min(capSize, maxCapSize.Width), maxCapSize.Height);
                endCap = GetLineCap(endConnectorCap, capSize, out endCapInset);

                //Now if user has requested us to fill the line cap then we do so,
                //THIS IS A WORKAROUND IN FILLING THE CUSTOM CAPS AS GDI+ HAS A 
                bool fill = (endCap != null && (((int)endConnectorCap % 2) == 0) && (endSegment[0].X == endSegment[1].X || endSegment[0].Y == endSegment[1].Y));
                if (fill)
                {
                    Matrix oldTransform = graphics.Transform;
                    graphics.TranslateTransform(endSegment[1].X, endSegment[1].Y);
                    if (endSegment[0].Y == endSegment[1].Y)
                        graphics.RotateTransform((endSegment[0].X < endSegment[1].X) ? 270.0f : 90.0f);
                    else
                        graphics.RotateTransform((endSegment[0].Y < endSegment[1].Y) ? 0.0f : 180.0f);
                    using (Brush penBrush = new SolidBrush(pen.Color))
                        graphics.FillPath(penBrush, endCap);
                    graphics.Transform = (oldTransform != null) ? oldTransform : new Matrix();
                }
            }

            if (startCap != null)
            {
                CustomLineCap customStartCap = new CustomLineCap(null, startCap);
                customStartCap.WidthScale = 1.0f / pen.Width;
                customStartCap.BaseInset = startCapInset;
                pen.CustomStartCap = customStartCap;
            }

            if (endCap != null)
            {
                CustomLineCap customEndCap = new CustomLineCap(null, endCap);
                customEndCap.WidthScale = 1.0f / pen.Width;
                customEndCap.BaseInset = endCapInset;
                pen.CustomEndCap = customEndCap;
            }

            using (GraphicsPath path = GetRoundedPath(points, StateDesignerConnector.ConnectorPadding / 2))
            {
                graphics.DrawPath(pen, path);
            }

            if (startCap != null)
            {
                CustomLineCap disposableLineCap = pen.CustomStartCap;
                pen.StartCap = LineCap.Flat;
                disposableLineCap.Dispose();
            }

            if (endCap != null)
            {
                CustomLineCap disposableLineCap = pen.CustomEndCap;
                pen.EndCap = LineCap.Flat;
                disposableLineCap.Dispose();
            }
        }
        /// <summary>
        /// Initialized a new instance of the OfficeLineCapPicker in order to provide 
        /// color picker control that could be used in a model or non-model form.
        /// </summary>
        public OfficeLineCapPicker()
        {
            InitializeComponent();
            SetCapObjects();
            // Set painting style for better performance.
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.UserPaint, true);

            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();
            generalizationCap = new CustomLineCap(null, gpath);

        }
        /// <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();
        }
Example #27
0
		private CustomLineCap GetClone(Pen pen, float size)
		{
			float scale = pen.Width == 0 ? 1 : size / (pen.Width * 2);
			if (scale <= 0)
				scale = 1e-3f;

			GraphicsPath 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,-1),
				  new PointF(1,0),
					new PointF(0, 1),
        new PointF(-1,0)
      });
			CustomLineCap clone = new CustomLineCap(hPath, null, LineCap.Flat, 0); // we set the stroke path only
			clone.WidthScale = scale;
			return clone;
		}
Example #28
0
 private static void SerializeLineCap(SerializationInfo info, string label, LineCap lineCap,
     CustomLineCap customLineCap)
 {
     if (lineCap == LineCap.Custom)
     {
         if (CustomEndCapSerializable(customLineCap))
         {
             info.AddValue(label + "Cap", (int)lineCap);
             info.AddValue("Custom" + label + "Cap", customLineCap);
         }
         else
             info.AddValue(label+"Cap", (int)LineCap.Round);
     }
     else
         info.AddValue(label+"Cap", (int)lineCap);
 }
Example #29
0
        private void Render(IGraphics ig)
        {
            string s = cbWhat.Text;

            if (string.IsNullOrEmpty(s))
            {
            }
            else if (s == "Clipping")
            {
                Pen pn  = new Pen(Color.LightGray, 5.6f);
                Pen pn2 = new Pen(Color.Yellow, 1.2f);

                ig.Clear(Color.Black);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.SetClip(new Rectangle(35, 35, 120, 120));

                ig.DrawRectangle(pn, 5, 5, 45, 70);
                ig.DrawRectangle(pn, 15, 25, 90, 120);
                ig.DrawRectangle(pn, 50, 30, 100, 170);
                ig.DrawRectangle(pn, 5, 80, 180, 30);
                ig.DrawRectangle(pn, 75, 10, 40, 160);

                ig.EndContainer(cnt);

                ig.DrawRectangle(pn2, 5, 5, 45, 70);
                ig.DrawRectangle(pn2, 15, 25, 90, 120);
                ig.DrawRectangle(pn2, 50, 30, 100, 170);
                ig.DrawRectangle(pn2, 5, 80, 180, 30);
                ig.DrawRectangle(pn2, 75, 10, 40, 160);
            }
            else if (s == "Transforms")
            {
                ig.Clear(Color.Black);

                ig.RotateTransform(15);
                ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.Red, 2.7f), 260, 80, 50, 40);

                ig.TranslateTransform(15, -5);

                GraphicsContainer cnt = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                ig.RotateTransform(5);
                ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40);
                ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40);

                GraphicsContainer cnt2 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.None;

                ig.RotateTransform(5);
                ig.ScaleTransform(1.1f, 1.2f);

                ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40);
                ig.DrawRectangle(new Pen(Color.YellowGreen, 2.7f), 62, 80, 40, 40);

                GraphicsContainer cnt3 = ig.BeginContainer();

                ig.SmoothingMode = SmoothingMode.HighQuality;

                Matrix mm = new Matrix();
                mm.Shear(0.3f, 0f);
                ig.Transform = mm;

                ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40);
                ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40);

                ig.EndContainer(cnt3);

                ig.EndContainer(cnt2);

                ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40);
                ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40);

                ig.EndContainer(cnt);

                ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40);
                ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40);

                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40);
            }
            else if (s == "Lines")
            {
                ig.SmoothingMode = SmoothingMode.AntiAlias;

                Pen ow = new Pen(Color.Purple, 12.6f);
                ow.EndCap     = LineCap.Round;
                ow.StartCap   = LineCap.Round;
                ow.MiterLimit = 6f;
                ow.LineJoin   = LineJoin.Miter;

                ig.SmoothingMode = SmoothingMode.None;

                Pen tp = new Pen(Color.Red, 2.7f);
                tp.DashStyle = DashStyle.DashDot;

                ig.DrawLine(tp, 70, 20, 190, 20);

                tp.DashStyle = DashStyle.Dash;

                ig.DrawLine(tp, 70, 30, 190, 30);

                tp.DashStyle   = DashStyle.Custom;
                tp.DashPattern = new float[] { 1, 8, 2, 2 };

                ig.DrawLine(tp, 70, 40, 190, 40);

                ig.SmoothingMode = SmoothingMode.AntiAlias;

                PointF[] pts = new PointF[4];
                pts[0] = new PointF(20, 50);
                pts[1] = new PointF(30, 90);
                pts[2] = new PointF(65, 60);
                pts[3] = new PointF(50, 40);
                ig.DrawLines(ow, pts);

                Point[] polly = new Point[]
                {
                    new Point(200, 40),
                    new Point(220, 140),
                    new Point(240, 100),
                    new Point(290, 70),
                    new Point(230, 10)
                };

                ig.DrawPolygon(tp, polly);

                //arrows
                Pen arr = new Pen(Color.DarkGoldenrod, 5.7f);

                {
                    arr.Width    = 2;
                    arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                    const float arrowWidth   = 11.0f; // TUNE:
                    const float arrowHeight  = 14f;   // TUNE:
                    var         arrowOutline = new System.Drawing.Drawing2D.GraphicsPath();
                    arrowOutline.AddLines(new PointF[] {
                        new PointF(-(arrowWidth / 2), -arrowHeight),
                        new PointF(0, 0),
                        new PointF((arrowWidth / 2), -arrowHeight),
                        new PointF(-(arrowWidth / 2), -arrowHeight)
                    });
                    var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline);
                    generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round);
                    generalizationArrow.BaseInset = arrowHeight;
                    arr.CustomEndCap = generalizationArrow;
                    ig.DrawLine(arr, 0, 120, 100, 200);
                }

                arr.Width = 5;
                AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false);
                arr.EndCap       = LineCap.Custom;
                arr.CustomEndCap = aac;
                arr.StartCap     = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 50, 120, 150, 200);

                arr.Width    = 7f;
                arr.EndCap   = LineCap.RoundAnchor;
                arr.StartCap = LineCap.SquareAnchor;
                ig.DrawLine(arr, 100, 120, 200, 200);

                arr.Width    = 9;
                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.ArrowAnchor;
                ig.DrawLine(arr, 150, 120, 250, 200);

                Point[] al = new Point[]
                {
                    new Point(200, 100),
                    new Point(300, 200),
                    new Point(300, 150)
                };

                arr.Width    = 9;
                arr.EndCap   = LineCap.DiamondAnchor;
                arr.StartCap = LineCap.DiamondAnchor;
                ig.DrawLines(arr, al);
            }
            else if (s == "Curves")
            {
                PointF[] bezzie = new PointF[]
                {
                    new PointF(20, 150),

                    new PointF(110, 190),
                    new PointF(120, 200),
                    new PointF(50, 220),

                    new PointF(60, 200),
                    new PointF(140, 180),
                    new PointF(100, 160),

                    new PointF(180, 260),
                    new PointF(200, 210),
                    new PointF(190, 210)
                };

                Pen bpn = new Pen(Color.MediumSeaGreen, 2.3f);
                bpn.DashStyle   = DashStyle.Custom;
                bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 };
                ig.DrawBeziers(bpn, bezzie);

                PointF[] curvy = new PointF[]
                {
                    new PointF(130, 40),
                    new PointF(70, 70),
                    new PointF(50, 20),
                    new PointF(120, 120),
                    new PointF(150, 80),
                    new PointF(80, 150),
                    new PointF(80, 110)
                };

                ig.DrawCurve(new Pen(Color.Blue, 5.7f), curvy);
                ig.DrawCurve(new Pen(Color.Red, 2.7f), curvy, 2, 3);
                ig.DrawCurve(new Pen(Color.Yellow, 1.7f), curvy, 1f);

                Point[] ccurvy = new Point[]
                {
                    new Point(280, 30),
                    new Point(260, 60),
                    new Point(200, 20),
                    new Point(290, 120),
                    new Point(290, 80),
                    new Point(230, 150),
                    new Point(150, 50)
                };
                ig.DrawClosedCurve(new Pen(Color.Green, 3.7f), ccurvy, 1f, FillMode.Alternate);
                ig.DrawClosedCurve(new Pen(Color.Purple, 1.7f), ccurvy, 0f, FillMode.Alternate);

                Point[] fcc = new Point[]
                {
                    new Point(160, 350),
                    new Point(190, 370),
                    new Point(130, 390),
                    new Point(190, 400),
                    new Point(195, 410),
                    new Point(100, 430),
                    new Point(160, 450)
                };
                ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f);
                ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f);
            }
            else if (s == "Transparency")
            {
                Point[] fillpoly = new Point[]
                {
                    new Point(20, 130),
                    new Point(60, 90),
                    new Point(30, 20),
                    new Point(80, 20),
                    new Point(15, 90),
                    new Point(100, 50),
                    new Point(0, 50)
                };

                Color col = Color.FromArgb(96, 255, 0, 0);

                ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding);

                ig.TranslateTransform(10, 10);
                ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30);
                ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate);
                ig.ResetTransform();

                ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270);
                ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270);
            }
            else if (s == "Fills")
            {
                LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum);

                ColorBlend blend = new ColorBlend(3);
                blend.Colors             = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue };
                blend.Positions          = new float[] { 0, .3f, 1f };
                gbr1.InterpolationColors = blend;

                Point[] sp = new Point[]
                {
                    new Point(145, 145),
                    new Point(305, 250),
                    new Point(220, 250),
                    new Point(180, 250)
                };
                ig.FillPolygon(gbr1, sp);

                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                Point[] sp2 = new Point[]
                {
                    new Point(25, 205),
                    new Point(75, 150),
                    new Point(110, 110),
                    new Point(40, 80)
                };
                ig.FillPolygon(gbr2, sp2);

                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20);
                ig.FillRectangle(gbr1, 200, 5, 20, 20);
                ig.FillRectangle(gbr2, 220, 5, 20, 20);

                ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20);
                ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20);
            }
            else if (s == "Arcs/Pies")
            {
                //GDI does not seem to draw arcs correctly except when the ellipse is a circle.
                //These arcs demonstrate the problem.  SVGGraphics calculates arcs correctly.
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60);
                ig.DrawArc(new Pen(Color.Black, 2.7f), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270);

                ig.DrawPie(new Pen(Color.Pink, 2.7f), 110, 50, 100, 100, 315, 90);
                ig.DrawPie(new Pen(Color.Purple, 2.7f), 110, 50, 100, 100, 250, -90);
                ig.DrawPie(new Pen(Color.DarkRed, 2.7f), 115, 55, 90, 90, 180, 270);
                ig.DrawPie(new Pen(Color.Red, 2.7f), 120, 60, 80, 80, 45, -270);
            }
            else if (s == "Text")
            {
                Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold);
                Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold);
                Font fnt3 = new Font("", 40, FontStyle.Underline);

                Rectangle    rc1  = new Rectangle(30, 30, 220, 20);
                StringFormat fmt1 = new StringFormat();
                fmt1.Alignment = StringAlignment.Near;

                ig.DrawRectangle(new Pen(Color.Blue), rc1);
                ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1);

                Rectangle    rc2  = new Rectangle(0, 0, 120, 20);
                StringFormat fmt2 = new StringFormat();
                fmt2.Alignment = StringAlignment.Center;

                ig.TranslateTransform(30, 160);
                ig.RotateTransform(90);

                ig.DrawRectangle(new Pen(Color.Blue), rc2);
                ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2);

                ig.ResetTransform();

                Rectangle    rc3  = new Rectangle(30, 90, 300, 30);
                StringFormat fmt3 = new StringFormat();
                fmt3.Alignment = StringAlignment.Far;

                ig.DrawRectangle(new Pen(Color.Blue), rc3);
                ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3);

                //measurestring
                const string mme = "MeasureString Is Impossible To Emulate";
                SizeF        siz = ig.MeasureString(mme, fnt1);
                ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, 150);
                ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height);
                siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical));
                ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height);
            }
            else if (s == "Rect-aligned Text")
            {
                ig.Clear(Color.White);
                ig.ScaleTransform(
                    (float)panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize,
                    (float)panel1.ClientSize.Height / RectAlignedTextTest.CanvasSize);
                RectAlignedTextTest.DrawTest(ig);
            }
            else if (s == "Images")
            {
                Icon ike = new Icon(GetType(), "App.ico");
                ig.DrawIcon(ike, 10, 10);
                //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40));

                Bitmap bmp = new Bitmap(GetType(), "test.bmp");
                ig.DrawImage(bmp, 100f, 150f);
                GraphicsContainer cnt = ig.BeginContainer();
                ig.RotateTransform(5);
                ig.DrawImage(bmp, 160f, 50f, 120f, 70f);
                ig.EndContainer(cnt);
                //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20);
            }
            else if (s == "Path")
            {
                /* The following example GraphicsPath code comes from the MSDN docs on the GraphicsPathIterator class
                 * https://msdn.microsoft.com/en-us/library/79k451ts.aspx
                 *
                 */
                // Create a graphics path.
                GraphicsPath myPath = new GraphicsPath();

                // Set up primitives to add to myPath.
                Point[]   myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) };
                Rectangle myRect   = new Rectangle(120, 120, 100, 100);

                // Add 3 lines, a rectangle, an ellipse, and 2 markers.
                myPath.AddLines(myPoints);
                myPath.SetMarkers();
                myPath.AddRectangle(myRect);
                myPath.SetMarkers();
                myPath.AddEllipse(220, 220, 100, 100);
                ig.DrawPath(new Pen(Color.Black, 1.7f), myPath);
                LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue);
                gbr2.WrapMode = WrapMode.TileFlipXY;
                ig.FillPath(gbr2, myPath);

                GraphicsPath myPath2 = new GraphicsPath();
                myPath2.AddLine(100, 100, 130, 120);
                myPath2.AddEllipse(120, 120, 120, 140);
                myPath2.AddBezier(130, 160, 170, 160, 150, 130, 200, 110);
                ig.DrawPath(new Pen(Color.Blue, 1.7f), myPath2);
            }
            else if (s == "Path 2 (Slow)")
            {
                SolidBrush   mySolidBrush   = new SolidBrush(Color.Aqua);
                GraphicsPath myGraphicsPath = new GraphicsPath();

                Point[] myPointArray =
                {
                    new Point(15, 20),
                    new Point(20, 40),
                    new Point(50, 30)
                };

                FontFamily   myFontFamily   = new FontFamily("Times New Roman");
                PointF       myPointF       = new PointF(50, 20);
                StringFormat myStringFormat = new StringFormat();

                myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
                myGraphicsPath.AddCurve(myPointArray);
                myGraphicsPath.AddString("a string in a path filled", myFontFamily,
                                         0, 24, myPointF, myStringFormat);
                myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
                ig.FillPath(mySolidBrush, myGraphicsPath);
                ig.DrawPath(new Pen(Color.Green, 1.7f), myGraphicsPath);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #30
0
        public void Paint(Graphics graphics, IDrawingSurface layer, ITile iTile, bool isPrint)
        {
            if (!m_enabled)
            {
                return;
            }

            //LibSys.StatusBar.Trace("Track::Paint()  - " + m_trackpoints.Count + " : " + Name);

            int prevX = 0;
            int prevY = 0;

            int   arrowWingsTrk        = Math.Max(15, (int)(7.0f * TrackPalette.penTrackThickness));
            int   arrowWingsRte        = Math.Max(18, (int)(9.0f * TrackPalette.penRouteThickness));
            float trackThicknessFactor = TrackPalette.penTrackThickness / 2.0f;

            Pen penHighlight  = new Pen(Color.Red, 3.0f * trackThicknessFactor);
            Pen penHighlight2 = new Pen(Color.Yellow, 3.0f * trackThicknessFactor);

            int diam = (int)Math.Ceiling(4.0f * trackThicknessFactor);
            int rad  = diam / 2;

            Waypoint _lastHighlightedWaypoint = null;

            int step = getStep(this, layer.getCameraElevation());

            bool doDrawPoints   = Project.drawTrackpoints && (layer.getCameraElevation() < DRAW_POINT_TRESHOLD);
            int  pointCount     = 0;
            int  lastArrowCount = 0;
//			Point tailPoint = Point.Empty;
            Point lastArrowPoint = Point.Empty;

            // prepare default brushes/pens, with either random or preset color:
            Brush trkBrush = getBrush();                        // filled circles, arrow heads
            Pen   trkPen   = getTrackPen();                     // lines
            Pen   rtePen   = getRoutePen();                     // lines
            Pen   rteTrkPen;

            // square (flat) Cap is a pain in neck; this kind of works:
            GraphicsPath objPath = new GraphicsPath();
//			objPath.AddRectangle(new Rectangle(0, -1, 0, 0));
            CustomLineCap squareCap = new System.Drawing.Drawing2D.CustomLineCap(objPath, null, LineCap.Flat);

            squareCap.WidthScale = 0.0f;

            bool skipOne;

            for (int i = 0; i < m_trackpoints.Count; i += step)
            {
                skipOne = false;
                try
                {
                    Waypoint wp1             = (Waypoint)m_trackpoints.GetByIndex(i);
                    bool     doDrawThisPoint = doDrawPoints;

                    if (wp1.ThumbImage != null)
                    {
                        skipOne = true;                                 // draw and move to next trackpoint; keep in sync with the stepping logic
                    }

                    pointCount++;
                    Waypoint wp2 = null;
                    if (i != m_trackpoints.Count - 1 && (i + step) < m_trackpoints.Count)                       // last point
                    {
                        wp2 = (Waypoint)m_trackpoints.GetByIndex(i + step);
                    }

                    if (!layer.insideScreenRectangle(wp1.Location) && wp2 != null && !layer.insideScreenRectangle(wp2.Location))
                    {
                        goto nextLoop;
                    }

                    Point p1 = isPrint ? layer.toPixelLocationPrint(wp1.Location, iTile) : layer.toPixelLocation(wp1.Location, iTile);
//					if(tailPoint.IsEmpty)
//					{
//						tailPoint = p1;
//					}

                    int    dd          = diam;
                    bool   staying     = false;
                    bool   doHighlight = false;
                    bool   hasContent  = wp1.hasContent;
                    bool   hasUrl      = wp1.Url != null && wp1.Url.Length > 0;
                    string stayLbl     = "";
                    if (TimeFilter.Enabled)
                    {
                        doHighlight = TimeFilter.passes(wp1.DateTime);
                        if (!doHighlight && TimeFilter.beforeFrom(wp1.DateTime))
                        {
                            // in case it doesn't pass directly, but we are in the middle of the track
                            // and the time filter boundaries are between this point and next point,
                            // we highlight both points because we are sitting there at this time.
                            if (i > 0 && wp2 != null)                                   // mid-track
                            {
                                if (TimeFilter.afterTo(wp2.DateTime))
                                {
                                    doHighlight = true;
                                    dd         *= 3;
                                    staying     = true;
                                    DateTime wp2LocalTime = Project.zuluToLocal(wp2.DateTime);
                                    stayLbl = "staying till " + wp2LocalTime.TimeOfDay;
                                }
                            }
                        }
                    }

                    if (SelectFilter.Enabled)
                    {
                        doHighlight = SelectFilter.passes(wp1);
                        dd          = 2;
                    }

                    if (doHighlight)
                    {
                        if (_lastHighlightedWaypoint == null)
                        {
                            _lastHighlightedWaypoint = wp1;
                        }
                        graphics.DrawEllipse(penHighlight, p1.X - dd, p1.Y - dd, dd * 2, dd * 2);
                        if (staying)
                        {
                            int  x    = p1.X + 10;
                            int  y    = p1.Y - dd * 2;
                            Font font = Project.getLabelFont(Project.FONT_SIZE_REGULAR + 2);
                            if (Project.waypointUseShadow)
                            {
                                graphics.DrawString(stayLbl, font, Project.blackBrush, x, y);
                                graphics.DrawString(stayLbl, font, Project.blackBrush, x + 2, y);
                                graphics.DrawString(stayLbl, font, Project.blackBrush, x, y - 2);
                                graphics.DrawString(stayLbl, font, Project.blackBrush, x + 2, y - 2);
                            }
                            graphics.DrawString(stayLbl, font, Project.whiteBrush, x + 1, y - 1);
                        }
                    }

                    if (hasUrl)
                    {
                        graphics.DrawEllipse(penHighlight2, p1.X - 4, p1.Y - 4, 8, 8);
                    }

                    if (hasContent)
                    {
                        if (!hasUrl)
                        {
                            graphics.DrawEllipse(Pens.Cyan, p1.X - 4, p1.Y - 4, 8, 8);
                        }
                        graphics.DrawEllipse(penHighlight, p1.X - 2, p1.Y - 2, 4, 4);
                    }

                    if (hasUrl || hasContent || (wp2 == null && (i == 0 || !Project.makeRouteMode)))                    // last point
                    {
                        int offsetX = 0;
                        int offsetY = 0;
                        if (isPrint)
                        {
                            Point pixelPosPrint = layer.toPixelLocationPrint(wp1.Location, null);
                            Point pixelPosDispl = wp1.PixelLocation;
                            offsetX = pixelPosPrint.X - pixelPosDispl.X;
                            offsetY = pixelPosPrint.Y - pixelPosDispl.Y;
                        }
                        wp1.PaintLabel(graphics, layer, iTile, isPrint, offsetX, offsetY);
                    }

                    if (wp2 != null)                                    // not the last point
                    {
                        Point p2 = isPrint ? layer.toPixelLocationPrint(wp2.Location, iTile) : layer.toPixelLocation(wp2.Location, iTile);

                        bool thickPen = false;
                        if (m_isRoute)
                        {
                            rteTrkPen = rtePen;
                        }
                        else
                        {
                            if (Project.trackElevColor)
                            {
                                double elevRange = ElevMax - ElevMin;
                                if (elevRange > 1.0d && elevRange < 20000.0d)
                                {
                                    double elevFactor = elevRange / 256.0d;
                                    double elev       = wp2.Location.Elev;
                                    int    r          = (int)((elev - ElevMin) / elevFactor);
                                    if (r > 255)
                                    {
                                        r = 255;
                                    }
                                    int b = 255 - r;
                                    int g = (255 - (r > b ? r : b)) * 2;                                                // will be high where R and B are close to equal, amounts to cyan

                                    Color legColor = Color.FromArgb(r, g, b);
                                    trkBrush = new SolidBrush(legColor);
                                    trkPen   = new Pen(trkBrush, (r > 250 ? 5.0f : 3.0f) * trackThicknessFactor);
                                    thickPen = true;
                                }
                            }
                            else if (Project.trackSpeedColor)
                            {
                                double speedRange = SpeedMax - SpeedMin;
                                if (speedRange > 1000.0d && speedRange < 1000000000.0d)
                                {
                                    double speedFactor = speedRange / 256.0d;
                                    double speed       = wp2.Speed;
                                    int    r           = (int)((speed - SpeedMin) / speedFactor);
                                    if (r > 255)
                                    {
                                        r = 255;
                                    }
                                    int b = 255 - r;
                                    int g = (255 - (r > b ? r : b)) * 2;                                                // will be high where R and B are close to equal, amounts to cyan

                                    Color legColor = Color.FromArgb(r, g, b);
                                    trkBrush = new SolidBrush(legColor);
                                    trkPen   = new Pen(trkBrush, (r > 250 ? 5.0f : 3.0f) * trackThicknessFactor);
                                    thickPen = true;
                                }
                            }
                            rteTrkPen = doHighlight ? penHighlight : trkPen;
                        }

                        int    dltaX  = p2.X - p1.X;
                        int    dltaY  = p2.Y - p1.Y;
                        double lenSq  = dltaX * dltaX + dltaY * dltaY;
                        int    dlta2X = p2.X - lastArrowPoint.X;
                        int    dlta2Y = p2.Y - lastArrowPoint.Y;
                        double lenSq2 = dlta2X * dlta2X + dlta2Y * dlta2Y;

                        if (lenSq2 > 10000.0d || lenSq > 900.0d)                        // big enough to hold arrow?
                        {
                            float arrowWidth  = thickPen ? 4 : 3;
                            float arrowHeight = 6;
                            bool  arrowFill   = true;

                            rteTrkPen.CustomEndCap = new AdjustableArrowCap(arrowWidth, arrowHeight, arrowFill);

                            lastArrowCount = pointCount;
                            lastArrowPoint = p2;
//							tailPoint = p2;
                            //doDrawThisPoint = false;
                        }
                        else
                        {
                            // no cap - null doesn't work here
                            rteTrkPen.CustomEndCap = squareCap;
                        }

                        graphics.DrawLine(rteTrkPen, p1, p2);

                        if (doDrawThisPoint && diam > 2)
                        {
                            graphics.FillEllipse(trkBrush, p2.X - rad, p2.Y - rad, diam, diam);
                        }

                        if (i == 0)
                        {
                            int offsetX = 0;
                            int offsetY = 0;
                            if (isPrint)
                            {
                                Point pixelPosPrint = layer.toPixelLocationPrint(wp1.Location, null);
                                Point pixelPosDispl = wp1.PixelLocation;
                                offsetX = pixelPosPrint.X - pixelPosDispl.X;
                                offsetY = pixelPosPrint.Y - pixelPosDispl.Y;
                            }
                            wp1.PaintLabel(graphics, layer, iTile, isPrint, offsetX, offsetY);
                            prevX = p1.X;
                            prevY = p1.Y;
                        }
                        else if ((p1.X - prevX) * (p1.X - prevX) + (p1.Y - prevY) * (p1.Y - prevY) > 900)
                        {
                            if (Project.showTrackpointNumbers)
                            {
                                // call simplified PaintLabel, not regular one:
                                PaintLabel(graphics, wp1.Name, p1.X, p1.Y, isPrint);
                            }
                            prevX = p1.X;
                            prevY = p1.Y;
                        }
                    }
                    else if (doDrawThisPoint)
                    {
                        graphics.FillEllipse(trkBrush, p1.X - rad, p1.Y - rad, diam, diam);
                    }
                }
                catch (Exception e)
                {
                    LibSys.StatusBar.Error("Track::Paint()  - " + e.Message);
                }

nextLoop:
                if (skipOne)
                {
                    i -= (step - 1);                                    // move to the next trackpoint
                    continue;
                }
                int pointsLeft = m_trackpoints.Count - i;
                if (pointsLeft > 1 && pointsLeft < step)
                {
                    step = pointsLeft - 2;
                    if (step < 1)
                    {
                        step = 1;
                    }
                }
            }

            if (Project.thumbDoDisplay)
            {
                SortedList ppts = Project.mainCommand.getWaypointsWithThumbs(m_id);
                for (int i = 0; i < ppts.Count; i++)
                {
                    Waypoint wpt            = (Waypoint)ppts.GetByIndex(i);
                    Pen      thumbBorderPen = Pens.Blue;
                    Pen      thumbCornerPen = new Pen(Color.Blue, 3.0f);
                    int      width          = wpt.ThumbImage.Width;
                    int      height         = wpt.ThumbImage.Height;
                    Point    p1             = isPrint ? layer.toPixelLocationPrint(wpt.Location, iTile) : layer.toPixelLocation(wpt.Location, iTile);
                    switch (wpt.ThumbPosition)
                    {
                    case 0:                                     // top right
                        graphics.DrawImage(wpt.ThumbImage, p1.X, p1.Y - height, width, height);
                        graphics.DrawRectangle(thumbBorderPen, p1.X, p1.Y - height, width - 1, height - 1);
                        graphics.DrawLine(thumbCornerPen, p1.X + 2, p1.Y, p1.X + 2, p1.Y - 10);
                        graphics.DrawLine(thumbCornerPen, p1.X, p1.Y - 2, p1.X + 10, p1.Y - 2);
                        break;

                    case 1:                                     // center
                    default:
                        graphics.DrawImage(wpt.ThumbImage, p1.X - width / 2, p1.Y - height / 2, width, height);
                        graphics.DrawRectangle(thumbBorderPen, p1.X - width / 2, p1.Y - height / 2, width - 1, height - 1);
                        break;
                    }
                    int offsetX = 0;
                    int offsetY = 0;
                    if (isPrint)
                    {
                        Point pixelPosPrint = layer.toPixelLocationPrint(wpt.Location, null);
                        Point pixelPosDispl = wpt.PixelLocation;
                        offsetX = pixelPosPrint.X - pixelPosDispl.X;
                        offsetY = pixelPosPrint.Y - pixelPosDispl.Y;
                    }
                    wpt.PaintLabel(graphics, layer, iTile, isPrint, offsetX, offsetY);
                }
            }

            if (_lastHighlightedWaypoint != null)
            {
                lastHighlightedWaypoint = _lastHighlightedWaypoint;
            }
        }
        public static CustomLineCap drawTriangleCap()
        {
            GraphicsPath hPath = new GraphicsPath();

            hPath.AddLine(new Point(-5, -5), new Point(5, -5));
            hPath.AddLine(new Point(5, -5), new Point(0, 0));
            hPath.AddLine(new Point(0, 0), new Point(-5, -5));
            hPath.CloseFigure();

            CustomLineCap cap = new CustomLineCap(null, hPath);

            //g.FillRegion(Brushes.White, new Region(hPath));
            return cap;
        }
        //one to Many cap, the "Many" side arrow
        public static CustomLineCap drawDoubleArrow()
        {
            GraphicsPath hPath = new GraphicsPath();

            //hPath.AddLine(new Point(-5, -5), new Point(5, -5));
            hPath.AddLine(new Point(5, -5), new Point(0, 0));
            hPath.AddLine(new Point(-5, -5), new Point(0,0));
            hPath.AddLine(new Point(0, 0), new Point(0, -5));
            hPath.AddLine(new Point(-5, -10), new Point(0, -5));
            hPath.AddLine(new Point(5, -10), new Point(0,-5));

            CustomLineCap cap = new CustomLineCap(null, hPath);
            //cap.SetStrokeCaps(LineCap.Round, LineCap.Round);
            return cap;
        }
        public static CustomLineCap drawDiamondCap()
        {
            GraphicsPath hPath = new GraphicsPath();

            hPath.AddLine(new Point(0, 0), new Point(-5, -7));
            hPath.AddLine(new Point(-5, -7), new Point(0, -14));
            hPath.AddLine(new Point(0, -14), new Point(5, -7));
            hPath.AddLine(new Point(5, -7), new Point(0, 0));
            hPath.CloseFigure();

            CustomLineCap cap = new CustomLineCap(null, hPath);

            //g.FillPath(Brushes.Black, hPath);
            return cap;
        }
Example #34
0
                private static void DeserializeLineCap(SerializationInfo info, string label, out LineCap lineCap, out CustomLineCap customLineCap)
                {
                    lineCap = (LineCap)info.GetInt32(label + "Cap");
                    customLineCap = null;
                    if (lineCap != LineCap.Custom)
                        return;

                    customLineCap = (CustomLineCap)info.GetValue("Custom" + label + "Cap", typeof(CustomLineCap));
                }
 internal static void DrawConnectors(Graphics graphics, Pen pen, Point[] points, Size connectorCapSize, Size maxCapSize, LineAnchor startConnectorCap, LineAnchor endConnectorCap)
 {
     if (points.GetLength(0) >= 2)
     {
         GraphicsPath path = null;
         float capinset = 0f;
         if (startConnectorCap != LineAnchor.None)
         {
             Point[] pointArray = new Point[] { points[0], points[1] };
             int num2 = (pointArray[0].Y == pointArray[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
             num2 += num2 % 2;
             num2 = Math.Min(Math.Min(num2, maxCapSize.Width), maxCapSize.Height);
             path = GetLineCap(startConnectorCap, num2, out capinset);
             if (((path != null) && ((startConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray[0].X == pointArray[1].X) || (pointArray[0].Y == pointArray[1].Y)))
             {
                 Matrix transform = graphics.Transform;
                 graphics.TranslateTransform((float) pointArray[0].X, (float) pointArray[0].Y);
                 if (pointArray[0].Y == pointArray[1].Y)
                 {
                     graphics.RotateTransform((pointArray[0].X < pointArray[1].X) ? 90f : 270f);
                 }
                 else
                 {
                     graphics.RotateTransform((pointArray[0].Y < pointArray[1].Y) ? 180f : 0f);
                 }
                 using (Brush brush = new SolidBrush(pen.Color))
                 {
                     graphics.FillPath(brush, path);
                     graphics.DrawPath(pen, path);
                 }
                 graphics.Transform = (transform != null) ? transform : new Matrix();
             }
         }
         GraphicsPath path2 = null;
         float num3 = 0f;
         if (endConnectorCap != LineAnchor.None)
         {
             Point[] pointArray2 = new Point[] { points[points.GetLength(0) - 2], points[points.GetLength(0) - 1] };
             int num4 = (pointArray2[0].Y == pointArray2[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
             num4 += num4 % 2;
             num4 = Math.Min(Math.Min(num4, maxCapSize.Width), maxCapSize.Height);
             path2 = GetLineCap(endConnectorCap, num4, out num3);
             if (((path2 != null) && ((endConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray2[0].X == pointArray2[1].X) || (pointArray2[0].Y == pointArray2[1].Y)))
             {
                 Matrix matrix2 = graphics.Transform;
                 graphics.TranslateTransform((float) pointArray2[1].X, (float) pointArray2[1].Y);
                 if (pointArray2[0].Y == pointArray2[1].Y)
                 {
                     graphics.RotateTransform((pointArray2[0].X < pointArray2[1].X) ? 270f : 90f);
                 }
                 else
                 {
                     graphics.RotateTransform((pointArray2[0].Y < pointArray2[1].Y) ? 0f : 180f);
                 }
                 using (Brush brush2 = new SolidBrush(pen.Color))
                 {
                     graphics.FillPath(brush2, path2);
                     graphics.DrawPath(pen, path2);
                 }
                 graphics.Transform = (matrix2 != null) ? matrix2 : new Matrix();
             }
         }
         if (path != null)
         {
             CustomLineCap cap = new CustomLineCap(null, path) {
                 WidthScale = 1f / pen.Width,
                 BaseInset = capinset
             };
             pen.CustomStartCap = cap;
         }
         if (path2 != null)
         {
             CustomLineCap cap2 = new CustomLineCap(null, path2) {
                 WidthScale = 1f / pen.Width,
                 BaseInset = num3
             };
             pen.CustomEndCap = cap2;
         }
         graphics.DrawLines(pen, points);
         if (path != null)
         {
             CustomLineCap customStartCap = pen.CustomStartCap;
             pen.StartCap = LineCap.Flat;
             customStartCap.Dispose();
         }
         if (path2 != null)
         {
             CustomLineCap customEndCap = pen.CustomEndCap;
             pen.EndCap = LineCap.Flat;
             customEndCap.Dispose();
         }
     }
 }