Esempio n. 1
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);
        }
Esempio n. 2
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;
		}
Esempio n. 3
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;
		}
Esempio n. 4
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;
		}
Esempio n. 5
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();
        }
Esempio n. 6
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;
		}
Esempio n. 7
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;
		}
Esempio n. 8
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);
                }
Esempio n. 9
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();
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
                Pen pn2 = new Pen(Color.Yellow);

                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), 260,80,50,40);
                ig.ResetTransform();
                ig.DrawRectangle(new Pen(Color.Red,2), 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), 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);
                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);
                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);

                {
                    arr.Width = 2;
                    arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                    var arrowWidth = 11.0f; // TUNE:
                    var 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);
                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), curvy);
                ig.DrawCurve(new Pen(Color.Red, 2), curvy, 2, 3);
                ig.DrawCurve(new Pen(Color.Yellow, 1), 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), ccurvy, 1f, FillMode.Alternate);
                ig.DrawClosedCurve(new Pen(Color.Purple, 1), 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(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), 120+5*3, 120, 110*3, 110, 0, 240);
                ig.DrawArc(new Pen(Color.Black, 2), 120+10*3, 125, 100*3, 100, 0, 210);
                ig.DrawArc(new Pen(Color.Black, 2), 120+15*3, 130, 90*3, 90, 0, 180);
                ig.DrawArc(new Pen(Color.Black, 2), 120+20*3, 135, 80*3, 80, 0, 150);
                ig.DrawArc(new Pen(Color.Black, 2), 120+25*3, 140, 70*3, 70, 0, 120);
                ig.DrawArc(new Pen(Color.Black, 2), 120+30*3, 145, 60*3, 60, 0, 90);
                ig.DrawArc(new Pen(Color.Black, 2), 120+35*3, 150, 50*3, 50, 0, 60);
                ig.DrawArc(new Pen(Color.Black, 2), 120+40*3, 155, 40*3, 40, 0, 270);

                ig.DrawPie(new Pen(Color.Pink, 2), 110, 50, 100, 100, 315, 90);
                ig.DrawPie(new Pen(Color.Purple, 2), 110, 50, 100, 100, 250, -90);
                ig.DrawPie(new Pen(Color.DarkRed, 2), 115, 55, 90, 90, 180, 270);
                ig.DrawPie(new Pen(Color.Red, 2), 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
                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)this.panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize,
                    (float)this.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
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 12
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;
		}
        private static bool drawCirclePicture(bool isVertical, string picturePath, 
            double azimuth, double azimuth_step, double sa_rbw,
            Dictionary<ChannelSetting, WatsEmiData> channelSamples,
            LimitSetting limitSetting)
        {
            try
            {
                Bitmap bmp = new Bitmap(300, 260);
                Graphics gs = Graphics.FromImage(bmp);
                Metafile mf = new Metafile(picturePath, gs.GetHdc());
                Graphics g = Graphics.FromImage(mf);
                using (Brush backgroundBrush = new SolidBrush(Color.White))
                {
                    g.FillRectangle(backgroundBrush, 0, 0, 300, 260);
                }

                using (Pen circlePen = new Pen(Color.Blue, 3.0f))
                {
                    g.DrawEllipse(circlePen, 45, 25, 210, 210);
                }

                ChannelPower power;
                ChannelPowerSpectrum spectrum;
                List<ChannelPowerSpectrum> spectrums = new List<ChannelPowerSpectrum>();
                foreach (KeyValuePair<ChannelSetting, WatsEmiData> pair in channelSamples)
                {
                    power = new ChannelPower(sa_rbw, pair.Key, limitSetting, pair.Value);
                    spectrum = new ChannelPowerSpectrum();
                    spectrum.startFreq = pair.Key.StartFreq;
                    spectrum.endFreq = pair.Key.EndFreq;
                    spectrum.isValidPower = (isVertical ? power.IsValidVPower : power.IsValidHPower);
                    spectrums.Add(spectrum);

                    power = new ChannelPower(sa_rbw, pair.Key.Pair, limitSetting, pair.Value);
                    spectrum = new ChannelPowerSpectrum();
                    spectrum.startFreq = pair.Key.Pair.StartFreq;
                    spectrum.endFreq = pair.Key.Pair.EndFreq;
                    spectrum.isValidPower = (isVertical ? power.IsValidVPairPower : power.IsValidHPairPower);
                    spectrums.Add(spectrum);
                }

                spectrums.Sort(SortSpectrumByStartFreq);
                float freqSpan = (float)(spectrums[0].endFreq - spectrums[spectrums.Count - 1].startFreq);
                int length;
                Rectangle rect;
                Color color;
                float drawAzimuth;
                for (int i = 0; i < spectrums.Count; i++)
                {
                    if (azimuth >= 0 && azimuth <= 90)
                        drawAzimuth = (float)azimuth - 90;
                    else if (azimuth >= 90 && azimuth <= 180)
                        drawAzimuth = (float)azimuth - 90;
                    else if (azimuth >= 180 && azimuth <= 270)
                        drawAzimuth =  (float)azimuth - 90;
                    else
                        drawAzimuth = (float)azimuth - 450;
                    Debug.WriteLine(spectrums[i].startFreq + " - " + spectrums[i].endFreq);
                    color = spectrums[i].isValidPower ? Color.Green : Color.Red;
                    using (Brush brush = new SolidBrush(color))
                    {
                        length = 2 * (int)(100 * (spectrums[i].endFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan);
                        rect = new Rectangle((300 - length) / 2, (260 - length) /2, length, length);
                        g.FillPie(brush, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step);
                    }

                    if (i != spectrums.Count - 1)
                    {
                        using (Brush whiteBrush = new SolidBrush(Color.White))
                        {
                            length = 2 * (int)(100 * (spectrums[i].startFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan);
                            rect = new Rectangle((300 - length) / 2, (260 - length) / 2, length, length);
                            g.FillPie(whiteBrush, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step);
                        }

                        using (Pen seperateCirclePen = new Pen(Color.White, 1.0f))
                        {
                            length = 2 * (int)(100 * (spectrums[i].endFreq - spectrums[spectrums.Count - 1].startFreq) / freqSpan);
                            rect = new Rectangle((300 - length) / 2, (260 - length) / 2, length, length);
                            g.DrawArc(seperateCirclePen, rect, (float)(drawAzimuth - azimuth_step / 2), (float)azimuth_step);
                        }
                    }
                }

                using (Pen directionPen = new Pen(Color.Blue, 2.0f))
                {
                    Point[] pt = new Point[]{new Point(50, 50), new Point(50, -50)};
                    GraphicsPath strokePath = new GraphicsPath();
                    strokePath.AddLine(new Point(0, 0), new Point(0, 5));
                    strokePath.AddLine(new Point(0, 5), new Point(3, 0));
                    strokePath.AddLine(new Point(0, 5), new Point(-3, 0));
                    CustomLineCap customLineCap = new CustomLineCap(null, strokePath);
                    customLineCap.SetStrokeCaps(LineCap.Round, LineCap.Round);
                    directionPen.CustomEndCap = customLineCap;

                    Point center = new Point(150, 130);
                    int endX, endY;
                    int deltX = (int)(Math.Abs(Math.Sin(azimuth * Math.PI / 180)) * 120);
                    int deltY = (int)(Math.Abs(Math.Cos(azimuth * Math.PI / 180)) * 120);
                    if (azimuth >= 0 && azimuth <= 90)
                    {
                        endX = 150 + deltX;
                        endY = 130 - deltY;
                    }
                    else if (azimuth >= 90 && azimuth <= 180)
                    {
                        endX = 150 + deltX;
                        endY = 130 + deltY;
                    }
                    else if (azimuth >= 180 && azimuth <= 270)
                    {
                        endX = 150 - deltX;
                        endY = 130 + deltY;
                    }
                    else
                    {
                        endX = 150 - deltX;
                        endY = 130 - deltY;
                    }
                    Point end = new Point(endX, endY);
                    g.DrawLine(directionPen, center, end);

                    using (Font font = new Font("Times New Roman", 10.0f))
                    {
                        string text = azimuth.ToString() + "\x00B0";
                        SizeF sizef = g.MeasureString(text, font, Int32.MaxValue);
                        float textX, textY;
                        if (azimuth >= 0 && azimuth <= 90)
                        {
                            textX = end.X - 1;
                            textY = end.Y - sizef.Height - 10;
                        }
                        else if (azimuth >= 90 && azimuth <= 180)
                        {
                            textX = end.X - 1;
                            textY = end.Y + sizef.Height;
                        }
                        else if (azimuth >= 180 && azimuth <= 270)
                        {
                            textX = end.X - sizef.Width / 2;
                            textY = end.Y + sizef.Height;
                        }
                        else
                        {
                            textX = end.X - sizef.Width / 2;
                            textY = end.Y - sizef.Height - 10;
                        }

                        RectangleF rf = new RectangleF(textX, textY, sizef.Width, sizef.Height);
                        g.DrawString(text, font, Brushes.Blue, rf);
                    }
                }

                g.Save();
                g.Dispose();
            }
            catch (System.Exception e)
            {
                File.Delete("c:\\watsLog.txt");
                FileStream fs = new FileStream("c:\\watsLog.txt", FileMode.CreateNew);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(e.Message);
                sw.WriteLine(e.StackTrace);
                sw.Flush();
                sw.Close();
                fs.Close();

                return false;
            }
            return true;
        }