DrawCurve() public méthode

public DrawCurve ( Pen pen, Point points, float tension = 0.5f ) : void
pen Pen
points Point
tension float
Résultat void
Exemple #1
0
        public void Draw(Graphics g, Player player)
        {
            if (ShootingPoints.Count > 0)
            {
                try
                {
                    g.DrawCurve(shootingPen, ShootingPoints.ToArray());
                    g.TranslateTransform(1, 0);
                    g.DrawCurve(shootingPen1, ShootingPoints.ToArray());
                    g.ResetTransform();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Shot.cs-Draw-EXCEPTION :  {0}", e.Message);
                }
                //STRELKA
                Point lastOne = (Point)ShootingPoints[ShootingPoints.Count-1];
                trianglePoints = new Point[3];

                trianglePoints[0] = new Point(lastOne.X - 2, lastOne.Y - 10);
                trianglePoints[1] = new Point(lastOne.X - 8, lastOne.Y + 2);
                trianglePoints[2] = new Point(lastOne.X + 4, lastOne.Y + 2);

                g.FillPolygon(new SolidBrush(Color.Black), trianglePoints);
                trianglePoints = new Point[3];
            }
        }
 public void Draw(Graphics g)
 {
     Pen borderPen = new Pen(Color.Black, this.pen.Width + 2);
     if (isSelected)
     {
         Pen selectedBorderPen = new Pen(Color.Green, this.pen.Width + 2);
         g.DrawCurve(selectedBorderPen, this.points.ToArray());
     }
     else g.DrawCurve(borderPen, this.points.ToArray());
     g.DrawCurve(pen, this.points.ToArray());
 }
Exemple #3
0
        public static void Draw(Graphics g, bool timer)
        {
            int L = 0;
              if (lines[0] != null)
            L = lines[0].Length;
              Point[] p = new Point[L];

              float x, y;
              g.DrawLine(Pens.Red, II(-50), JJ(0), II(50), JJ(0));
              g.DrawLine(Pens.Blue, II(0), JJ(-50), II(0), JJ(50));
              if (L > 0)
              {
            if (!timer)
            {
              for (int i = 0; i < L; i++)
              {
            x = lines[0][i].X;
            y = lines[0][i].Y;
            g.DrawRectangle(Pens.Green, II(x) - 2, JJ(y) - 2, 4, 4);
            p[i].X = II(x);
            p[i].Y = JJ(y);
              }
              g.DrawCurve(Pens.Green, p);

              for (int i = 0; i < L; i++)
              {
            x = lines[1][i].X;
            y = lines[1][i].Y;
            g.DrawRectangle(Pens.Orange, II(x) - 2, JJ(y) - 2, 4, 4);
            p[i].X = II(x);
            p[i].Y = JJ(y);
              }
              g.DrawCurve(Pens.Orange, p);
            }
            else
            {
              if (tmpLines != null)
              {
            for (int i = 0; i < L; i++)
            {
              x = tmpLines[i].X;
              y = tmpLines[i].Y;
              p[i].X = II(x);
              p[i].Y = JJ(y);
            }
            g.DrawCurve(Pens.Black, p);
              }
            }
              }
        }
Exemple #4
0
        public void DrawClosedCurve(Pen pen, PointD[] points, double offset, int numberOfSegments, double tension)
        {
            if (pen == null)
            {
                throw new ArgumentNullException("pen");
            }
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

            lock (bitmapLock) {
                double maxX = 0.0d;
                double maxY = 0.0d;

                for (long i = 0L; i < points.LongLength; i++)
                {
                    if ((points[i].X + offset) * tension > maxX)
                    {
                        maxX = (points[i].X + offset) * tension;
                    }
                    if ((points[i].Y + offset) * tension > maxY)
                    {
                        maxY = (points[i].Y + offset) * tension;
                    }
                }

                TryExpand(0.0d, 0.0d, maxX, maxY, pen.Width);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) {
                    g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None;
                    g.DrawCurve(pen, ToPointFArray(points), (int)offset, numberOfSegments, (float)tension);
                }
                Texturize();
            }
        }
 public override void OnDraw(System.Drawing.Graphics g)
 {
     try
     {
         if (pts != null)
         {
             System.Drawing.Pen pen = new System.Drawing.Pen(Color, width);
             if (pts.Length > 2)
             {
                 g.DrawClosedCurve(pen, pts, tension, FillMode.Winding);
                 if (fill)
                 {
                     g.FillClosedCurve(new System.Drawing.SolidBrush(fillColor), pts, FillMode.Winding, tension);
                 }
             }
             else if (pts.Length > 1)
             {
                 g.DrawCurve(pen, pts);
             }
             if ((pts.Length == 1 || pts.Length == 2) && step >= 0)
             {
                 g.DrawLine(pen, pts[pts.Length - 1], ptNew);
             }
         }
     }
     catch
     {
     }
 }
Exemple #6
0
        private void DrawTrack(System.Drawing.Graphics g, Pen p, out PointF scaledA, out PointF scaledB)
        {
            PointF[] points = new PointF[3];
            scaledA = new PointF(0, 0);
            scaledB = new PointF(0, 0);
            PointF scaledC = new PointF(0, 0);

            foreach (var line in F.segments)
            {
                scaledA   = line.A.Scale(F.xScale, F.yScale, F.subX, F.subY);
                scaledA.Y = F.pbCanvas.Height - scaledA.Y;
                scaledB   = line.B.Scale(F.xScale, F.yScale, F.subX, F.subY);
                scaledB.Y = F.pbCanvas.Height - scaledB.Y;

                if ((scaledA.X < 0 && scaledB.X < 0) || (scaledA.Y < 0 && scaledB.Y < 0))
                {
                    continue;
                }

                if (line.isCurved == true)
                {
                    scaledC.X = (line.C.Location.Location.X - F.subX) * F.xScale;
                    scaledC.Y = F.pbCanvas.Height - (line.C.Location.Location.Z - F.subY) * F.yScale;
                    points[0] = scaledA; points[1] = scaledC; points[2] = scaledB;
                    g.DrawCurve(p, points);
                }
                else
                {
                    g.DrawLine(p, scaledA, scaledB);
                }
            }
        }
Exemple #7
0
        public void Draw(Graphics graphics)
        {
            if (_points.Count < 2) return;

            graphics.TranslateTransform(_width / 2, _height / 2);
            var pen = new Pen(Color.Blue, 2f) { LineJoin = LineJoin.Bevel };

            graphics.DrawCurve(pen, _points.ToArray());
        }
Exemple #8
0
        public override void Draw(Graphics gfx, Point offset)
        {
            gfx.TranslateTransform(offset.X, offset.Y);

            if (Points.Count > 1)
                gfx.DrawCurve(pen, Points.ToArray());

            gfx.ResetTransform();
        }
Exemple #9
0
        public override void Draw(System.Drawing.Graphics g, System.Drawing.Pen pen)
        {
            for (float x = 0; x < MAX_X; x = x + 0.5f)
            {
                float y = _func(x);
                _points.Add(new PointF(x, y));
            }

            g.DrawCurve(pen, _points.ToArray());
        }
Exemple #10
0
 //划很多线
 public static void DrawLine(Graphics g, List<PointF> pointList)
 {
     PointF[] temps = new PointF[pointList.Count];
     for (int i = 0; i < pointList.Count; i++)
     {
         temps[i] = pointList[i];
     }
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
     g.DrawCurve(new Pen(Color.Red, 1), temps, 0.2F);
     //g.Dispose();
 }
        public override void Draw(RectangleF dirtyRect)
        {
            Graphics g = new Graphics();
            // Create a pen object:
            Pen aPen = new Pen(Color.Blue, 4);

            // Set line caps and dash style:
            aPen.StartCap = LineCap.Flat;
            aPen.EndCap = LineCap.ArrowAnchor;
            aPen.DashStyle = DashStyle.Dot;
            aPen.DashOffset = 50;

            //g.ScaleTransform(4,4);
            //draw straight line:
            g.DrawLine(aPen, 50, 30, 200, 30);
            // define point array to draw a curve:
            Point point1 = new Point(50, 200);
            Point point2 = new Point(100, 75);
            Point point3 = new Point(150, 60);
            Point point4 = new Point(200, 160);
            Point point5 = new Point(250, 250);
            Point[] Points ={ point1, point2, point3, point4, point5};
            g.DrawCurve(aPen, Points);

            aPen.Dispose();
            //g.Dispose();

            //Text rotation:
            RectangleF ClientRectangle = dirtyRect;
            string s = "A simple text string";

            Rectangle rect = new Rectangle((int)ClientRectangle.X, (int)ClientRectangle.Y,
                                           (int)ClientRectangle.Width, (int)ClientRectangle.Height);
            drawingRectangle = new Rectangle(rect.Location, rect.Size);
            Size sz = new Size(rect.Width, rect.Height);
            var font = new Font("Arialss",14.0f,FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
            SizeF stringSize = g.MeasureString(s, font);
            Point Middle = new Point(sz.Width / 30,
                                    sz.Height / 2 - (int)stringSize.Height / 2);
            g.DrawLine(Pens.Black, new Point(0, rect.Height/2), new Point(rect.Width, rect.Height/2));
            g.DrawLine(Pens.Black, new Point(rect.Width / 2, 0), new Point(rect.Width / 2, rect.Height));
            g.TranslateTransform(Middle.X, Middle.Y);
            g.RotateTransform (-90);
            //StringFormat format = new StringFormat(StringFormatFlags.NoClip);
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            //format.LineAlignment = StringAlignment.Center;
            g.DrawString (s, font, Brushes.Black, 0, 0, format);

            g.Dispose();
        }
Exemple #12
0
        /// <summary>
        /// Draw a polyline using an array of points and fills the interior
        /// cfr Lasso Select in Paint.Net
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="color"></param>
        /// <param name="points"></param>
        public static void DrawSelectionLasso(Graphics graphics, Color color, PointF[] points)
        {
            if (points.Length < 2)
            {
                return;
            }
            Pen pen = new Pen(color);
            graphics.DrawCurve(pen, points);
            pen.Dispose();

            Brush brush = new SolidBrush(Color.FromArgb(30, color));
            graphics.FillClosedCurve(brush, points);
            brush.Dispose();
        }
Exemple #13
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Graphics gr = e.Graphics;
            gr.TranslateTransform(origin.X, origin.Y);



            gr.DrawEllipse(new Pen(Color.Red), new RectangleF(0, 0, 1, 1));
            gr.DrawLine(new Pen(Color.Black), new Point(0, 100), new Point(0, -100));
            gr.DrawLine(new Pen(Color.Black), new Point(-100, 0), new Point(200, 0));
            //if (tr.ThreadState != ThreadState.Running)
            // tr.Start();
            //if(tr.ThreadState != ThreadState.Running)
            for (int i = 0; i <= 180; ++i)
            {
                curve[i]  = new Point(i, -(int)(Math.Sin(Math.PI / 180 * (i + offset)) * 90));
                curve2[i] = new Point(i, -(int)(Math.Cos(Math.PI / 180 * (i + offset)) * 90));
            }
            offset++;

            gr.DrawCurve(new Pen(Color.Blue), curve);
            gr.DrawCurve(new Pen(Color.Green), curve2);
        }
Exemple #14
0
        protected virtual void DrawLine(Graphics g, Pen pen)
        {
            pen.StartCap = LineCap.Round;
            pen.EndCap = LineCap.Round;

            if (CenterNodeActive)
            {
                g.DrawCurve(pen, new Point[] { StartPosition, CenterPosition, EndPosition });
            }
            else
            {
                g.DrawLine(pen, StartPosition, EndPosition);
            }
        }
Exemple #15
0
        // draw segmented curve
        private static void DrawSegmentedCurve(System.Drawing.Graphics Graphics, Pen Pen, PointF[] Points, int Start, int Length)
        {
            const int Count = 1000;
            int       End   = Start + Length - 1;

            for (int k = Start; k <= End; k += Count)
            {
                int m = End - k + 1;
                if (m > Count)
                {
                    m = Count;
                }
                Graphics.DrawCurve(Pen, Points, k, m);
            }
        }
Exemple #16
0
        protected override void DrawLine(Graphics g, Pen pen)
        {
            using (AdjustableArrowCap arrowCap = new AdjustableArrowCap(4, 6))
            {
                pen.CustomEndCap = arrowCap;

                if (CenterNodeActive)
                {
                    g.DrawCurve(pen, new Point[] { StartPosition, CenterPosition, EndPosition });
                }
                else
                {
                    g.DrawLine(pen, StartPosition, EndPosition);
                }
            }
        }
 void drawCurve(Graphics graphics, int a, int b)
 {
     Pen greenPen = new Pen(Color.Green);
     double x;
     double y;
     double bACosI;
     double twoPi = Math.PI * 2;
     List<Point> points = new List<Point>();
     for (double i = 0; i < twoPi; i += 0.001)
     {
         bACosI = b + a * Math.Cos(i);
         x = bACosI * Math.Cos(i);
         y = bACosI * Math.Sin(i);
         points.Add(new Point((int)x + offset, (int)y + offset));
     }
     drawAxis(graphics);
     graphics.DrawCurve(greenPen, points.ToArray());
 }
Exemple #18
0
 protected override void Finish(Point position)
 {
     StartPoint = new DrawingPoint((int)(position.X / ViewModel.Zoom), (int)(position.Y / ViewModel.Zoom));
     points.Add(StartPoint);
     if (ViewModel.Inpainting.CreateMask)
     {
         maskGraphics.DrawCurve(maskPen, points.ToArray());
         ViewModel.Mask = mask;
     }
     else
     {
         ViewModel.ComandList.AddNew(new Bitmap(ViewModel.Image.Source));
         Bitmap bitmap = ViewModel.Image.Source;
         graphics = Graphics.FromImage(bitmap);
         graphics.DrawCurve(pen, points.ToArray());
         ViewModel.RefreshImage();
         ViewModel.OnCommandExecuted();
     }
 }
Exemple #19
0
        public void dessine(Graphics g,Point offsetPoint)
        {
            if (this.isEnabled == true)
            {
                Point[] tabPoints = new Point[this.Path.Count];

                for (int i = 0; i < this.Path.Count; i++)
                {
                    int x = this.Path[i].X + offsetPoint.X;
                    int y = this.Path[i].Y + offsetPoint.Y;
                    tabPoints[i] = new Point(x, y);
                }

                float[] dashValues = { 1, 1 };
                Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 2);
                SolidBrush br = new SolidBrush(Color.FromArgb(155, Color.Green));
                pen.DashPattern = dashValues;

                if (tabPoints.Length > 1)
                {
                    if (this.isCurve == true)
                    {
                        g.DrawCurve(pen, tabPoints);
                    }
                    else
                    {
                        g.DrawLines(pen, tabPoints);
                    }
                }

                for (int i = 0; i < tabPoints.Length; i++)
                {

                    g.FillEllipse(br, new Rectangle(tabPoints[i].X - 3, tabPoints[i].Y - 3, 6, 6));

                }

                pen.Dispose();
                br.Dispose();
            }
        }
        /// <summary>
        /// Paints the bundle on the canvas
        /// </summary>
        /// <param name="g"></param>
        public override void Paint(System.Drawing.Graphics g)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //the shadow

            switch (mCurveType)
            {
            case MultiPointType.Straight:
                g.DrawLines(ArtPallet.BlackPen, mPoints);
                break;

            case MultiPointType.Polygon:
                g.DrawPolygon(ArtPallet.BlackPen, mPoints);
                break;

            case MultiPointType.Curve:
                //note that you can specify a tension of the curve here (greater than 0.0F)
                g.DrawCurve(ArtPallet.BlackPen, mPoints);
                break;
            }
        }
Exemple #21
0
        //Render a polygon
        private static void Render(DnaPolygon polygon, Graphics g, int scale)
        {
            if (polygon.IsComplex)
                return;

            Point[] points = GetGdiPoints(polygon.Points, scale);
            using (Brush brush = GetGdiBrush(polygon.Brush))
            {
                if (polygon.Splines)
                {
                    if (polygon.Filled)
                    {
                        g.FillClosedCurve(brush, points, FillMode.Winding);
                    }
                    else
                    {
                        using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width)))
                        {
                            g.DrawCurve(pen, points, 3F);
                        }
                    }
                }
                else
                {
                    if (polygon.Filled)
                    {
                        g.FillPolygon(brush, points, FillMode.Winding);
                    }
                    else
                    {
                        using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width)))
                        {
                            g.DrawPolygon(pen, points);
                        }
                    }
                }
            }
        }
        public void AddLines(Graphics g, ChartStyle cs)
        {
            // Plot lines:
            foreach (DataSeries ds in DataSeriesList) {
                if (ds.LineStyle.IsVisible == true) {
                    var aPen = new Pen (ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Lines) {
                        for (int i = 1; i < ds.PointList.Count; i++) {
                            g.DrawLine (aPen, cs.Point2D ((CGPoint)ds.PointList[i - 1]), cs.Point2D ((CGPoint)ds.PointList[i]));
                        }
                    } else if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Splines) {
                        var al = new ArrayList ();
                        for (int i = 0; i < ds.PointList.Count; i++) {
                            var pt = (CGPoint)ds.PointList[i];
                            if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax && pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                                al.Add (pt);
                        }

                        var pts = new PointF[al.Count];
                        for (int i = 0; i < pts.Length; i++)
                            pts[i] = cs.Point2D ((CGPoint)(al[i]));

                        g.DrawCurve (aPen, pts);
                    }
                    aPen.Dispose();
                }
            }

            foreach (DataSeries ds in DataSeriesList) {
                for (int i = 0; i < ds.PointList.Count; i++) {
                    var pt = (CGPoint)ds.PointList[i];
                    if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax && pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                        ds.SymbolStyle.DrawSymbol (g, cs.Point2D((CGPoint)ds.PointList[i]));
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// Add variable level of curved lines to the image
        /// </summary>
        /// <param name="graphics1">The graphics1.</param>
        /// <param name="rect">The rect.</param>
        private void AddLine(Graphics g, Rectangle rect)
        {
            int length;
            float width;
            int linecount;

            switch (LineNoise)
            {
                case LineNoiseLevel.None:
                    goto default;
                case LineNoiseLevel.Low:
                    length = 4;
                    width = Convert.ToSingle(_height / 31.25);
                    linecount = 1;
                    break;
                case LineNoiseLevel.Medium:
                    length = 5;
                    width = Convert.ToSingle(_height / 27.7777);
                    linecount = 1;
                    break;
                case LineNoiseLevel.High:
                    length = 3;
                    width = Convert.ToSingle(_height / 25);
                    linecount = 2;
                    break;
                case LineNoiseLevel.Extreme:
                    length = 3;
                    width = Convert.ToSingle(_height / 22.7272);
                    linecount = 3;
                    break;
                default:
                    return;
            }

            PointF[] pf = new PointF[length + 1];
            using (Pen p = new Pen(GetRandomColor(), width))
            {
                for (int l = 1; l <= linecount; l++)
                {
                    for (int i = 0; i <= length; i++)
                        pf[i] = RandomPoint(rect);

                    g.DrawCurve(p, pf, 1.75F);
                }
            }
        }
        private void DrawOne(Graphics g, int xmin, int xmax, int ymin, int ymax)
        {
            var shape = Shape.Arc;
            var color = new Color();
            var randomValue = RandomProvider.RandomGenerator.NextDouble();
            foreach (var probabilitiesOfShape in ProbabilitiesOfShapes)
            {
                if (randomValue < probabilitiesOfShape.Probability)
                {
                    shape = probabilitiesOfShape.Value;
                    break;
                }
            }

            randomValue = RandomProvider.RandomGenerator.NextDouble();

            foreach (var colorProbabilityPair in colorsCDFs)
            {
                if (randomValue < colorProbabilityPair.probability)
                {
                    color = colorProbabilityPair.color;
                    break;
                }
            }

            var pen = new Pen(color);

            var x1 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y1 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x2 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y2 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x3 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y3 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x4 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y4 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var w1 = RandomProvider.RandomGenerator.Next(x1, xmax + 1);
            var h1 = RandomProvider.RandomGenerator.Next(y1, ymax + 1);

            var angle1 = RandomProvider.RandomGenerator.Next(0, 360);

            switch (shape)
            {
                case Shape.Arc:
                    g.DrawArc(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.Bezier:
                    g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4);
                    break;
                case Shape.ClosedCurve:
                    g.DrawClosedCurve(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Curve:
                    g.DrawCurve(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Ellipse:
                    g.DrawEllipse(pen, x1, y1, w1, h1);
                    break;
                case Shape.Line:
                    g.DrawLine(pen, x1, y1, x2, y2);
                    break;
                case Shape.Lines:
                    g.DrawLines(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Pie:
                    g.DrawPie(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.Polygon:
                    g.DrawPolygon(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Rectangle:
                    g.DrawRectangle(pen, x1, y1, w1, h1);
                    break;
                case Shape.String:
                    g.DrawString(EnglishWordsDictionary.GetRandomWord(),
                        new Font("Cambria", RandomProvider.RandomGenerator.Next(1, 50)), new SolidBrush(color),
                        new PointF(x1, y1));
                    break;
                case Shape.FillClosedCurve:
                    g.FillClosedCurve(new SolidBrush(color),
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.FillEllipse:
                    g.FillEllipse(new SolidBrush(color), x1, y1, w1, h1);
                    break;
                case Shape.FillPie:
                    g.FillPie(new SolidBrush(color), x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.FillPolygon:
                    g.FillPolygon(new SolidBrush(color),
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.FillRectangle:
                    g.FillRectangle(new SolidBrush(color), x1, y1, w1, h1);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            // g.Save();
        }
Exemple #25
0
        /// <summary>
        /// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
        /// device using the specified smoothing property (<see cref="ZedGraph.Line.SmoothTension"/>).
        /// The routine draws the line segments and the area fill (if any, see <see cref="FillType"/>;
        /// the symbols are drawn by the <see cref="Symbol.Draw"/> method.  This method
        /// is normally only called by the Draw method of the
        /// <see cref="CurveItem"/> object.  Note that the <see cref="StepType"/> property
        /// is ignored for smooth lines (e.g., when <see cref="ZedGraph.Line.IsSmooth"/> is true).
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="curve">A <see cref="LineItem"/> representing this
        /// curve.</param>
        public void DrawSmoothFilledCurve( Graphics g, GraphPane pane,
                                CurveItem curve, float scaleFactor )
        {
            Line source = this;
            if ( curve.IsSelected )
                source = Selection.Line;

            PointF[] arrPoints;
            int count;
            IPointList points = curve.Points;

            if ( this.IsVisible && !this.Color.IsEmpty && points != null &&
                BuildPointsArray( pane, curve, out arrPoints, out count ) &&
                count > 2 )
            {
                float tension = _isSmooth ? _smoothTension : 0f;

                // Fill the curve if needed
                if ( this.Fill.IsVisible )
                {
                    Axis yAxis = curve.GetYAxis( pane );

                    using ( GraphicsPath path = new GraphicsPath( FillMode.Winding ) )
                    {
                        path.AddCurve( arrPoints, 0, count - 2, tension );

                        double yMin = yAxis._scale._min < 0 ? 0.0 : yAxis._scale._min;
                        CloseCurve( pane, curve, arrPoints, count, yMin, path );

                        RectangleF rect = path.GetBounds();
                        using ( Brush brush = source._fill.MakeBrush( rect ) )
                        {
                            if ( pane.LineType == LineType.Stack && yAxis.Scale._min < 0 &&
                                    this.IsFirstLine( pane, curve ) )
                            {
                                float zeroPix = yAxis.Scale.Transform( 0 );
                                RectangleF tRect = pane.Chart._rect;
                                tRect.Height = zeroPix - tRect.Top;
                                if ( tRect.Height > 0 )
                                {
                                    Region reg = g.Clip;
                                    g.SetClip( tRect );
                                    g.FillPath( brush, path );
                                    g.SetClip( pane.Chart._rect );
                                }
                            }
                            else
                                g.FillPath( brush, path );
                            //brush.Dispose();
                        }

                        // restore the zero line if needed (since the fill tends to cover it up)
                        yAxis.FixZeroLine( g, pane, scaleFactor, rect.Left, rect.Right );
                    }
                }

                // If it's a smooth curve, go ahead and render the path.  Otherwise, use the
                // standard drawcurve method just in case there are missing values.
                if ( _isSmooth )
                {
                    using ( Pen pen = GetPen( pane, scaleFactor ) )
                    {
                        // Stroke the curve
                        g.DrawCurve( pen, arrPoints, 0, count - 2, tension );

                        //pen.Dispose();
                    }
                }
                else
                    DrawCurve( g, pane, curve, scaleFactor );
            }
        }
Exemple #26
0
        public override void DrawSelfDefine(System.Drawing.Graphics g, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font FontText, System.Drawing.Font FontData)
        {
            linePen.Width = 1.0f;
            Font LableFont  = new Font("Arial", LableSize);
            Font AllSumFont = new Font("Arial", AllSumSize);


            //绘制横坐标和标题
            ReportViewUtils.drawString(g, Title, FontText, TextBrush, EStartX, EStartY, EViewWidth, TopPadding);
            g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX + CoordinateWidth, CoordinateStartY);
            if (!IsEnableGridLine)
            {
                g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY + 3);
                g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY - 3);
            }

            // 绘制围绕点旋转的文本
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            //绘制标签
            DrawRoateText.DrawString(g, LableX, LableFont, TextBrush, new PointF(CoordinateStartX + CoordinateWidth + padding, CoordinateStartY + padding), format, TextRotate);


            //数据源长度
            int dataLength = 0;

            if (CoordinateModels != null)
            {
                dataLength = CoordinateModels.Count / (ModelCount);
            }

            Point[] listPoint = new Point[dataLength];
            //绘制刻度
            float per_X = 0;

            if (IsEnableGridLine)
            {
                per_X = (CoordinateWidth * 1.0f) / Count_X;
            }
            else
            {
                per_X = (CoordinateWidth - padding) * 1.0f / Count_X;
            }
            for (int i = 0; i < Count_X + 1; i++)
            {
                //绘制刻度
                int x = (int)(CoordinateStartX + i * per_X);
                if (IsEnableGridLine)
                {
                    linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B);
                    g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - CoordinateHeight);
                }
                else
                {
                    g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - padding / 10);
                }

                if (dataLength > i)
                {
                    listPoint[i] = new Point(x, 0);
                }


                //绘制刻度值
                if (IsShowX_Scale)
                {
                    if (dataLength > i)
                    {
                        if (CoordinateDataModelBean != null)
                        {
                            DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X, CoordinateStartY + padding), format, TextRotate);
                        }
                    }
                }
            }
            linePen.Color = LineColor;


            //如果自动刷新时间, 则会刷新最大值, 从而刷新Y轴
            if (isAutoUpdateData)
            {
                if (CoordinateDataModelBean != null)
                {
                    if (CoordinateDataModelBean.Y_Data != null)
                    {
                        MaxNum = ReportViewUtils.getMaxNumFromData(CoordinateDataModelBean.Y_Data);
                    }
                }
            }

            //绘制Y轴
            g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX, CoordinateStartY - CoordinateHeight);
            if (!IsEnableGridLine)
            {
                g.DrawLine(linePen, CoordinateStartX + 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight);
                g.DrawLine(linePen, CoordinateStartX - 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight);
            }
            //绘制标签
            int lableLength = CoordinateDataModelBean.Lable_Y.Length;

            ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, LableY, LableFont, TextBrush, EStartX, CoordinateStartY - CoordinateHeight - padding, LeftPadding - 10, padding);
            //g.DrawString(LableY, LableFont, TextBrush, (padding - lableLength * lableSize) / 2 + startX, startY + topPadding);
            //对应到坐标上
            //规定Y轴刻度值
            float perNum = MaxNum / Count_Y;
            //规定Y轴刻度
            float per_Y = 0;

            if (IsEnableGridLine)
            {
                per_Y = (CoordinateHeight) * 1.0f / Count_Y;
            }
            else
            {
                per_Y = (CoordinateHeight - padding) * 1.0f / Count_Y;
            }
            //绘制刻度值和刻度
            linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B);
            for (int i = 0; i < Count_Y + 1; i++)
            {
                if (IsShowY_Scale)
                {
                    ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, perNum * i + "", LableFont, TextBrush, EStartX, CoordinateStartY - i * per_Y - padding / 2, LeftPadding - 10, padding);
                    //g.DrawString(perNum * i + "", LableFont, TextBrush, (padding - lableSize * 3) / 2 + startX, height - padding - i * per_Y - lableSize - bottomPadding);
                }
                int y = (int)(CoordinateStartY - i * per_Y);
                g.DrawLine(linePen, CoordinateStartX, y, CoordinateStartX + CoordinateWidth, y);
            }
            linePen.Color = LineColor;



            for (int j = 0; j < ModelCount; j++)
            {
                linePen.Color = CoordinateDataModelBean.CoordinateModelList[dataLength * j].ModelColor;
                //计算数据中的点对应到坐标的点
                bool isMouseIn = false;
                for (int i = 0; i < dataLength; i++)
                {
                    float dataY = CoordinateDataModelBean.Y_Data[i + dataLength * j];
                    //把数据对应到实际的坐标
                    int posY = (int)(CoordinateStartY - dataY * per_Y / perNum);
                    listPoint[i].Y = posY;
                    //重新定位数据模型的坐标
                    isMouseIn = adapter.DataList[i + dataLength * j].Area.IsMouseIn;
                    adapter.DataList[i + dataLength * j].Area = ReLoadAreaPosition(listPoint[i].X, listPoint[i].Y, (int)per_X, (int)per_Y);
                    //adapter.DataList[i].Area = new AreaPositionRect(listPoint[i].X, listPoint[i].Y, listPoint[i].X, listPoint[i].Y);
                    adapter.DataList[i + dataLength * j].Area.IsMouseIn = isMouseIn;
                }


                //绘制曲线
                if (IsDrawCurve)
                {
                    if (listPoint.Length > 0)
                    {
                        g.DrawCurve(linePen, listPoint, Tension);
                    }
                }

                if (IsFillPathCurve)
                {
                    Point[] point2 = new Point[4];

                    if (listPoint.Length > 0)
                    {
                        GraphicsPath path = null;
                        point2[0].X = listPoint[dataLength - 1].X;
                        point2[0].Y = listPoint[dataLength - 1].Y;
                        point2[1].X = listPoint[dataLength - 1].X;
                        point2[1].Y = CoordinateStartY;
                        point2[2].X = CoordinateStartX;
                        point2[2].Y = CoordinateStartY;

                        point2[3].X = CoordinateStartX;
                        point2[3].Y = listPoint[0].Y;
                        path        = CreatePath(listPoint, point2);
                        Brush fillBrush = new SolidBrush(Color.FromArgb(FillBrushAlpha, linePen.Color.R, linePen.Color.G, linePen.Color.B));
                        g.FillPath(fillBrush, path);
                        fillBrush.Dispose();
                        path.Dispose();
                    }
                }
                if (IsShowLegendnote)
                {
                    CalculateAllNum(dataLength, j);
                    ReportViewUtils.drawString(g, LocationModel.Location_Left_Left, Titles[j] + allNum + LableAllNum, LableFont, TextBrush, CoordinateStartX + CoordinateWidth + ((Width - EViewWidth) / 4 + LegendNoteWidth + 10), CoordinateStartY - CoordinateHeight + (LegendNoteHeight + padding) * j, (Width - EViewWidth) / 2, LegendNoteHeight + padding);
                    Rectangle    rect = new Rectangle(CoordinateStartX + CoordinateWidth + ((Width - EViewWidth) / 2 - LegendNoteWidth) / 2, CoordinateStartY - CoordinateHeight + (LegendNoteHeight + padding) * (j) + padding / 2, LegendNoteWidth, LegendNoteHeight);
                    GraphicsPath path = ReportViewUtils.CreateRoundedRectanglePath(rect, LegendNoteHeight / 2);
                    Brush        bbsh = new SolidBrush(linePen.Color);
                    g.FillPath(bbsh, path);
                    bbsh.Dispose();
                    path.Dispose();
                }
                //drawAllsumText(g, AllSumFont, TextBrush, CoordinateStartX, CoordinateStartY, CoordinateWidth, CoordinateHeight);
            }
            AllSumFont.Dispose();
            LableFont.Dispose();
        }
Exemple #27
0
		private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
			Color circle_color = Color.FromArgb (248, 0, 0);
			// draw the left hand of the circle 
			Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
			Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
			Point [] curve_points = new Point [3];
			curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
			curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
			curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);

			Pen pen = ResPool.GetSizedPen(circle_color, 2);
			dc.DrawArc (pen, lhs_circle_rect, 90, 180);
			dc.DrawArc (pen, rhs_circle_rect, 270, 180);					
			dc.DrawCurve (pen, curve_points);
			dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
		}
Exemple #28
0
        public void drawVector(Graphics drawing)
        {
            PointF[] Vector = new PointF[40];//set up array
            if(!hasStarted)//before you press start
            for (int i = 0; i < Vector.Length; i++)//iterate through
                Vector[i] = new PointF( Ballz[0].getX() + (float)i * startBallspeedX , Ballz[0].getY() + (float)i * -Math.Abs(forceVal));//set up the points according to ball position and x/yspeed

            Pen pen = new Pen(Color.Red);
            drawing.DrawCurve(pen, Vector);//draw the points on canvas
        }
Exemple #29
0
 private void drawLine(Graphics g, Random rand, Color generatecolor)
 {
     float lastpen = (float)(rand.NextDouble() * (MaxCurvePen - MinCurvePen) + MinCurvePen);
     float randpen = (float)(rand.NextDouble() * 2) - 1;
     float thispen = lastpen + randpen;
     Pen drawpen = new Pen(generatecolor, thispen);
     g.DrawCurve(drawpen, new PointF[] { new PointF(0, 100), new PointF(100, 80), new PointF(200, 120), new PointF(300, 80), new PointF(400, 100) }, 1.0f);
 }
Exemple #30
0
        //
        // CREATE ROUTE MAP
        //
        /// <summary>Creates and returns the route map as Bitmap.</summary>
        /// <returns>The route map.</returns>
        /// <param name="Width">The width of the bitmap to create.</param>
        /// <param name="Height">The height of the bitmap to create.</param>
        /// <param name="inGame"><c>true</c> = bitmap for in-game overlay | <c>false</c> = for standard window.</param>
        internal static Bitmap CreateRouteMap(int Width, int Height, bool inGame)
        {
            int n, n0, n1;

            RouteRange(out n, out n0, out n1);
            // find dimensions
            double x0 = double.PositiveInfinity, z0 = double.PositiveInfinity;
            double x1 = double.NegativeInfinity, z1 = double.NegativeInfinity;

            for (int i = n0; i <= n1; i++)
            {
                double x = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.X;
                double z = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Z;
                if (x < x0)
                {
                    x0 = x;
                }
                if (x > x1)
                {
                    x1 = x;
                }
                if (z < z0)
                {
                    z0 = z;
                }
                if (z > z1)
                {
                    z1 = z;
                }
            }
            // avoid 0 or negative height or width
            if (x0 >= x1 - 1.0)
            {
                x0 = x1 - 1.0;
            }
            if (z0 >= z1 - 1.0)
            {
                z0 = z1 - 1.0;
            }
            // remember area occupied so far
            double xMin, xMax, zMin, zMax;                              // used to track the bitmap area actually occupied by drawings

            xMin = x0;
            xMax = x1;
            zMin = z1;                                                                          // bitmap z goes down, while world z goes up
            zMax = z0;
            // fit route w/h ratio in image w/h ratio
            double wrh = (double)Width / (double)Height;

            if ((x1 - x0) / (z1 - z0) <= wrh)                           // if route ratio is taller than bitmap ratio
            {
                double dx = 0.5 * (z1 - z0) * wrh;                      //	scale (half of) x range as much as (half of) z range
                double px = 0.5 * (x0 + x1);                            //	x range mid point
                x0 = px - dx;                                           //	centre scaled x range around mid point
                x1 = px + dx;
            }
            else                                                                                // if route ratio is wider than bitmap ratio
            {                                                                                   //	do the opposite (scale z range on x)
                double dz = 0.5 * (x1 - x0) / wrh;
                double pz = 0.5 * (z0 + z1);
                z0 = pz - dz;
                z1 = pz + dz;
            }
            double ox = LeftPad, oy = TopPad;
            double w = (double)(Width - (LeftPad + RightPad));
            double h = (double)(Height - (TopPad + BottomPad));
            // horizontal and vertical scales
            double xd = w / (x1 - x0);
            double zd = h / (z1 - z0);

            // convert bitmap occupied area from world to bitmap coordinates
            xMin = ox + (xMin - x0) * xd;
            xMax = ox + (xMax - x0) * xd;
            zMin = oy + (z0 - zMin) * zd + h;
            zMax = oy + (z0 - zMax) * zd + h;
            // create bitmap
            int    mode = inGame ? 1 : 0;
            Bitmap b    = new Bitmap(Width, Height, inGame ? System.Drawing.Imaging.PixelFormat.Format32bppArgb
                                : System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            g.Clear(mapColors[mode].background);

            // ROUTE PATH
            {
                int  start = 0;
                bool atc   = false;
                n = n1 - n0 + 1;
                PointF[] p = new PointF[n];
                for (int i = 0; i < n; i++)
                {
                    double x = Program.CurrentRoute.Tracks[0].Elements[i + n0].WorldPosition.X;
                    double z = Program.CurrentRoute.Tracks[0].Elements[i + n0].WorldPosition.Z;
                    x    = ox + (x - x0) * xd;
                    z    = oy + (z0 - z) * zd + h;
                    p[i] = new PointF((float)x, (float)z);
                    // ATS / ATC
                    // for each track element, look for a StationStartEvent
                    for (int j = 0; j < Program.CurrentRoute.Tracks[0].Elements[i + n0].Events.Length; j++)
                    {
                        if (Program.CurrentRoute.Tracks[0].Elements[i + n0].Events[j] is StationStartEvent)
                        {
                            StationStartEvent e =
                                (StationStartEvent)Program.CurrentRoute.Tracks[0].Elements[i + n0].Events[j];
                            // if StationStartEvent found, look for a change in ATS/ATC control;
                            // if there is a change, draw all previous track elements
                            // with colour for the previous control state
                            if (Program.CurrentRoute.Stations[e.StationIndex].SafetySystem == SafetySystem.Atc)
                            {
                                if (!atc)
                                {
                                    atc = true;
                                    if (i - start - 1 > 0)
                                    {
                                        g.DrawCurve(mapColors[mode].normalMap, p, start, i - start - 1);
                                    }
                                    start = i;
                                }
                            }
                            else
                            {
                                if (atc)
                                {
                                    atc = false;
                                    if (i - start - 1 > 0)
                                    {
                                        g.DrawCurve(mapColors[mode].atcMap, p, start, i - start - 1);
                                    }
                                    start = i;
                                }
                            }
                            break;
                        }
                    }
                }
                // draw all remaining track element not drawn yet
                DrawSegmentedCurve(g, atc ? mapColors[mode].atcMap : mapColors[mode].normalMap, p, start, n - start - 1);
            }

            // STATION ICONS
            for (int i = n0; i <= n1; i++)
            {
                for (int j = 0; j < Program.CurrentRoute.Tracks[0].Elements[i].Events.Length; j++)
                {
                    if (Program.CurrentRoute.Tracks[0].Elements[i].Events[j] is StationStartEvent)
                    {
                        StationStartEvent e = (StationStartEvent)Program.CurrentRoute.Tracks[0].Elements[i].Events[j];
                        if (Program.CurrentRoute.Stations[e.StationIndex].Name != string.Empty)
                        {
                            double x = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.X;
                            double y = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Z;
                            x = ox + (x - x0) * xd;
                            y = oy + (z0 - y) * zd + h;
                            // station circle
                            RectangleF r = new RectangleF((float)x - StationRadius, (float)y - StationRadius,
                                                          StationDiameter, StationDiameter);
                            bool q = Program.CurrentRoute.Stations[e.StationIndex].PlayerStops();
                            g.FillEllipse(q ? mapColors[mode].actStatnFill : mapColors[mode].inactStatnFill, r);
                            g.DrawEllipse(q ? mapColors[mode].actStatnBrdr : mapColors[mode].inactStatnBrdr, r);
                            // adjust bitmap occupied area
                            if (r.Left < xMin)
                            {
                                xMin = r.Left;
                            }
                            if (r.Top < zMin)
                            {
                                zMin = r.Top;
                            }
                            if (r.Right > xMax)
                            {
                                xMax = r.Right;
                            }
                            if (r.Bottom > zMax)
                            {
                                zMax = r.Bottom;
                            }
                        }
                    }
                }
            }

            // STATION NAMES
            {
                double wh = w * h;
                Font   f  = new Font(FontFamily.GenericSansSerif, wh < 65536.0 ? 9.0f : 10.0f, GraphicsUnit.Pixel);
                for (int i = n0; i <= n1; i++)
                {
                    for (int j = 0; j < Program.CurrentRoute.Tracks[0].Elements[i].Events.Length; j++)
                    {
                        if (Program.CurrentRoute.Tracks[0].Elements[i].Events[j] is StationStartEvent)
                        {
                            StationStartEvent e = (StationStartEvent)Program.CurrentRoute.Tracks[0].Elements[i].Events[j];
                            if (Program.CurrentRoute.Stations[e.StationIndex].Name != string.Empty)
                            {
                                double x = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.X;
                                double y = Program.CurrentRoute.Tracks[0].Elements[i].WorldPosition.Z;
                                x = ox + (x - x0) * xd;
                                y = oy + (z0 - y) * zd + h;
                                bool   stop = Program.CurrentRoute.Stations[e.StationIndex].PlayerStops();
                                string t = Program.CurrentRoute.Stations[e.StationIndex].Name;
                                SizeF  m = g.MeasureString(t, f, Width, StringFormat.GenericDefault);
                                double sx = Program.CurrentRoute.Tracks[0].Elements[i].WorldSide.X;
                                double sz = Program.CurrentRoute.Tracks[0].Elements[i].WorldSide.Z;
                                double xt, yt;
                                if (Math.Sign(sx) == Math.Sign(sz))
                                {
                                    // descending
                                    bool o = (x - ox) * (h - y) <= (w - x) * (y - oy);
                                    if (o)
                                    {
                                        // up-right
                                        xt = x + StationTextPad;
                                        yt = y - StationTextPad - m.Height;
                                    }
                                    else
                                    {
                                        // down-left
                                        xt = x - StationTextPad - m.Width;
                                        yt = y + StationTextPad;
                                    }
                                }
                                else
                                {
                                    // ascending
                                    bool o = (h - y) * (w - x) <= (x - ox) * (y - oy);
                                    if (o)
                                    {
                                        // up-left
                                        xt = x - StationTextPad - m.Width;
                                        yt = y - StationTextPad - m.Height;
                                    }
                                    else
                                    {
                                        // down-right
                                        xt = x + StationTextPad;
                                        yt = y + StationTextPad;
                                    }
                                }
                                // constrain text within bitmap edges (taking into account also paddings)
                                if (xt < ox)
                                {
                                    xt = ox;
                                }
                                else if (xt + m.Width > w)
                                {
                                    xt = w - m.Width;
                                }
                                if (yt < oy)
                                {
                                    yt = oy;
                                }
                                else if (yt + m.Height > h)
                                {
                                    yt = h - m.Height;
                                }
                                RectangleF r = new RectangleF((float)xt - 1.0f, (float)yt - 1.0f, m.Width + 2.0f, m.Height + 2.0f);
                                g.FillRectangle(stop ? mapColors[mode].actNameFill : mapColors[mode].inactNameFill,
                                                r.Left, r.Top, r.Width, r.Height);
                                g.DrawRectangle(stop ? mapColors[mode].actNameBrdr : mapColors[mode].inactNameBrdr,
                                                r.Left, r.Top, r.Width, r.Height);
                                g.DrawString(t, f, stop ? mapColors[mode].actNameText : mapColors[mode].inactNameText,
                                             (float)xt, (float)yt);
                                // adjust bitmap occupied area
                                if (r.Left < xMin)
                                {
                                    xMin = r.Left;
                                }
                                if (r.Top < zMin)
                                {
                                    zMin = r.Top;
                                }
                                if (r.Right > xMax)
                                {
                                    xMax = r.Right;
                                }
                                if (r.Bottom > zMax)
                                {
                                    zMax = r.Bottom;
                                }
                            }
                        }
                    }
                }
            }
            // if in-game, trim unused parts of the bitmap
            if (inGame)
            {
                xMin -= LeftPad;
                xMax += RightPad;
                zMin -= TopPad;
                zMax += BottomPad;
                if (xMin < 0)
                {
                    xMin = 0;
                }
                if (xMax >= Width)
                {
                    xMax = Width - 1;
                }
                if (zMin < 0)
                {
                    zMin = 0;
                }
                if (zMax >= Height)
                {
                    zMax = Height - 1;
                }
                Bitmap nb = new Bitmap((int)(xMax - xMin + 1.0), (int)(zMax - zMin + 1.0));                     // round up
                g = System.Drawing.Graphics.FromImage(nb);
                g.DrawImage(b, (int)-xMin, (int)-zMin);                                                         // round down
                // set total bitmap world X and Z ranges from bitmap ranges
                lastRouteMinX = (int)((xMin - ox) / xd + x0);
                lastRouteMaxX = (int)((xMax - ox) / xd + x0);
                lastRouteMinZ = (int)(z0 - (zMax - oy - h) / zd);
                lastRouteMaxZ = (int)(z0 - (zMin - oy - h) / zd);
                return(nb);
            }
            //set total bitmap X and Z ranges
            lastRouteMinX = (int)(x0 - ox * (x1 - x0) / w);
            lastRouteMaxX = (int)(x1 + (Width - w - ox) * (x1 - x0) / w);
            lastRouteMinZ = (int)(z0 - oy * (z1 - z0) / h);
            lastRouteMaxZ = (int)(z1 + (Height - h - oy) * (z1 - z0) / h);
            return(b);
        }
        public override void DrawSelfDefine(System.Drawing.Graphics g, System.Drawing.Pen linePen, System.Drawing.Brush lineBrush, System.Drawing.Brush TextBrush, System.Drawing.Brush DataBrush, System.Drawing.Font FontText, System.Drawing.Font FontData)
        {
            linePen.Width = 1.0f;
            Font LableFont = null;

            if (IsLableFontBold)
            {
                LableFont = new Font("幼圆", LableSize, FontStyle.Bold);
            }
            else
            {
                LableFont = new Font("幼圆", LableSize);
            }

            Font AllSumFont = new Font("Arial", AllSumSize);

            //数据源长度
            int dataLength = 0;

            if (CoordinateModels != null)
            {
                dataLength = CoordinateModels.Count;
            }

            Point[] listPoint = new Point[dataLength];

            if (IsDrawTitle)
            {
                ReportViewUtils.drawString(g, Title, FontText, TextBrush, EStartX, EStartY, EViewWidth, TopPadding);
            }
            g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX + CoordinateWidth, CoordinateStartY);
            if (!IsEnableGridLine)
            {
                if (IsEnableArrow)
                {
                    g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY + 3);
                    g.DrawLine(linePen, CoordinateStartX + CoordinateWidth, CoordinateStartY, CoordinateStartX + CoordinateWidth - 6, CoordinateStartY - 3);
                }
            }


            // 绘制围绕点旋转的文本
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            //绘制标签
            DrawRoateText.DrawString(g, LableX, LableFont, TextBrush, new PointF(CoordinateStartX + CoordinateWidth + padding, CoordinateStartY + padding), format, TextRotate);

            //绘制刻度
            float per_X = 0;

            if (IsEnableGridLine)
            {
                per_X = (CoordinateWidth * 1.0f) / Count_X;
            }
            else
            {
                per_X = (CoordinateWidth - padding) * 1.0f / Count_X;
            }
            for (int i = 0; i < Count_X + 1; i++)
            {
                //绘制刻度
                int x = (int)(CoordinateStartX + i * per_X);
                if (IsEnableGridLine)
                {
                    linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B);
                    g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - CoordinateHeight);
                }
                else
                {
                    g.DrawLine(linePen, x, CoordinateStartY, x, CoordinateStartY - padding / 10);
                }

                if (dataLength > i)
                {
                    listPoint[i] = new Point(x, 0);
                }


                //绘制刻度值
                if (IsShowX_Scale)
                {
                    if (dataLength > i)
                    {
                        if (CoordinateDataModelBean != null)
                        {
                            if (IsRectAngle)
                            {
                                if (ConformCount == 0)
                                {
                                    DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X + per_X / 4, CoordinateStartY + padding), format, TextRotate);
                                }
                                else
                                {
                                    DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X + (ConformCount - 1) * 1.0f / 2 * per_X + per_X / 4, CoordinateStartY + padding), format, TextRotate);
                                }
                            }
                            else
                            {
                                DrawRoateText.DrawString(g, CoordinateDataModelBean.X_Data[i], LableFont, TextBrush, new PointF(CoordinateStartX + i * per_X, CoordinateStartY + padding), format, TextRotate);
                            }
                        }
                    }
                }
            }

            linePen.Color = LineColor;



            //如果自动刷新时间, 则会刷新最大值, 从而刷新Y轴
            if (isAutoUpdateData)
            {
                if (CoordinateDataModelBean != null)
                {
                    if (CoordinateDataModelBean.Y_Data != null)
                    {
                        MaxNum = ReportViewUtils.getMaxNumFromData(CoordinateDataModelBean.Y_Data);
                    }
                }
            }

            //绘制Y轴
            g.DrawLine(linePen, CoordinateStartX, CoordinateStartY, CoordinateStartX, CoordinateStartY - CoordinateHeight);
            if (!IsEnableGridLine)
            {
                if (IsEnableArrow)
                {
                    g.DrawLine(linePen, CoordinateStartX + 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight);
                    g.DrawLine(linePen, CoordinateStartX - 3, CoordinateStartY - CoordinateHeight + 6, CoordinateStartX, CoordinateStartY - CoordinateHeight);
                }
            }
            //绘制标签
            int lableLength = CoordinateDataModelBean.Lable_Y.Length;

            ReportViewUtils.drawString(g, LocationModel.Location_Right_Right + padding, LableY, LableFont, TextBrush, EStartX, CoordinateStartY - CoordinateHeight - padding, LeftPadding - 10, padding);
            //g.DrawString(LableY, LableFont, TextBrush, (padding - lableLength * lableSize) / 2 + startX, startY + topPadding);
            //对应到坐标上
            //规定Y轴刻度值
            float perNum = MaxNum / Count_Y;
            //规定Y轴刻度
            float per_Y = 0;

            if (IsEnableGridLine)
            {
                per_Y = (CoordinateHeight) * 1.0f / Count_Y;
            }
            else
            {
                per_Y = (CoordinateHeight - padding) * 1.0f / Count_Y;
            }
            //绘制刻度值和刻度
            linePen.Color = Color.FromArgb(30, LineColor.R, LineColor.G, LineColor.B);
            for (int i = 0; i < Count_Y + 1; i++)
            {
                if (IsShowY_Scale)
                {
                    ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, (int)perNum * i + "", LableFont, TextBrush, EStartX, CoordinateStartY - i * per_Y - padding / 2, LeftPadding - 10, padding);
                    //g.DrawString(perNum * i + "", LableFont, TextBrush, (padding - lableSize * 3) / 2 + startX, height - padding - i * per_Y - lableSize - bottomPadding);
                }
                int y = (int)(CoordinateStartY - i * per_Y);
                g.DrawLine(linePen, CoordinateStartX, y, CoordinateStartX + CoordinateWidth, y);
            }
            linePen.Color = LineColor;



            //计算数据中的点对应到坐标的点
            bool isMouseIn = false;

            for (int i = 0; i < dataLength; i++)
            {
                float dataY = CoordinateDataModelBean.Y_Data[i];
                //把数据对应到实际的坐标
                int posY = (int)(CoordinateStartY - dataY * per_Y / perNum);
                listPoint[i].Y = posY;
                //重新定位数据模型的坐标
                isMouseIn = adapter.DataList[i].Area.IsMouseIn;
                adapter.DataList[i].Area = ReLoadAreaPosition(listPoint[i].X, listPoint[i].Y, (int)per_X, (int)per_Y);
                //adapter.DataList[i].Area = new AreaPositionRect(listPoint[i].X, listPoint[i].Y, listPoint[i].X, listPoint[i].Y);
                adapter.DataList[i].Area.IsMouseIn = isMouseIn;
            }

            //绘制曲线
            if (IsDrawCurve)
            {
                if (listPoint.Length > 0)
                {
                    g.DrawCurve(linePen, listPoint, Tension);
                }
            }

            if (IsFillPathCurve)
            {
                Point[] point2 = new Point[4];

                if (listPoint.Length > 0)
                {
                    GraphicsPath path = null;
                    point2[0].X = listPoint[dataLength - 1].X;
                    point2[0].Y = listPoint[dataLength - 1].Y;
                    point2[1].X = listPoint[dataLength - 1].X;
                    point2[1].Y = CoordinateStartY;
                    point2[2].X = CoordinateStartX;
                    point2[2].Y = CoordinateStartY;

                    point2[3].X = CoordinateStartX;
                    point2[3].Y = listPoint[0].Y;
                    path        = CreatePath(listPoint, point2);
                    Brush fillBrush = new SolidBrush(Color.FromArgb(FillBrushAlpha, LineColor.R, LineColor.G, LineColor.B));
                    g.FillPath(fillBrush, path);
                    fillBrush.Dispose();
                    path.Dispose();
                }
            }
            drawAllsumText(g, AllSumFont, TextBrush, CoordinateStartX, CoordinateStartY, CoordinateWidth, CoordinateHeight);
            ////绘制点
            //for (int i = 0; i < dataLength; i++)
            //{
            //    Point item = listPoint[i];
            //    if (IsDrawDetailData)
            //    {
            //        //ReportViewUtils.drawString(g, LocationModel.Location_Right_Right, CoordinateDataModelBean.Y_Data[i] + "", FontData, DataBrush, StartX, StartY, LeftPadding, padding);
            //        g.DrawString(CoordinateDataModelBean.Y_Data[i] + "", FontData, DataBrush, (item.X), item.Y - 2 * DataSize);
            //    }
            //    g.FillEllipse(TextBrush, item.X - 2, item.Y - 2, 4, 4);
            //}
            AllSumFont.Dispose();
            LableFont.Dispose();
        }
Exemple #32
0
 public void Draw(Graphics g)
 {
     g.DrawCurve(BridgePen, Points);
 }
Exemple #33
0
 static private void DessinerChemin(Graphics Grfx, Pen P, SimWaypoint[] C)
 {
     Point[] Pnts = new Point[C.Length];
     if (Pnts.Length > 1)
     {
         for (int i = 0; i < Pnts.Length; i++)
         {
             Pnts[i].X = (int)C[i].DX;
             Pnts[i].Y = (int)C[i].DY;
         }
         Grfx.DrawCurve(P, Pnts);
     }
 }
Exemple #34
0
        /// <summary>
        /// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
        /// device using the specified smoothing property (<see cref="ZedGraph.Line.SmoothTension"/>).
        /// The routine draws the line segments and the area fill (if any, see <see cref="FillType"/>;
        /// the symbols are drawn by the <see cref="Symbol.Draw"/> method.  This method
        /// is normally only called by the Draw method of the
        /// <see cref="CurveItem"/> object.  Note that the <see cref="StepType"/> property
        /// is ignored for smooth lines (e.g., when <see cref="ZedGraph.Line.IsSmooth"/> is true).
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="points">A <see cref="PointPairList"/> of point values representing this
        /// curve.</param>
        /// <param name="isY2Axis">A value indicating to which Y axis this curve is assigned.
        /// true for the "Y2" axis, false for the "Y" axis.</param>
        public void DrawSmoothFilledCurve( Graphics g, GraphPane pane,
                                PointPairList points, bool isY2Axis, double scaleFactor)
        {
            PointF[]	arrPoints;
            int			count;

            if ( this.IsVisible && !this.Color.IsEmpty && points != null &&
                BuildPointsArray( pane, points, isY2Axis, out arrPoints, out count ) &&
                count > 2 )
            {
                Pen pen = new Pen(this.Color, pane.ScaledPenWidth(width, scaleFactor));
                pen.DashStyle = this.Style;
                float tension = this.isSmooth ? this.smoothTension : 0f;

                // Fill the curve if needed
                if ( this.Fill.IsVisible )
                {
                    GraphicsPath path = new GraphicsPath( FillMode.Winding );
                    path.AddCurve( arrPoints, 0, count-2, tension );

                    double yMin = pane.YAxis.Min < 0 ? 0.0 : pane.YAxis.Min;
                    //double yMin = pane.YAxis.Min;

                    CloseCurve( pane, arrPoints, isY2Axis, count, yMin, path );

                    Brush brush = this.fill.MakeBrush( path.GetBounds() );
                    g.FillPath( brush, path );

                    brush.Dispose();
                }

                // Stroke the curve
                g.DrawCurve( pen, arrPoints, 0, count-2, tension );
            }
        }
		/// <summary>
		/// Draws the temporary line(s) from the first point to the mouse.
		/// </summary>
		/// <param name="g"></param>
		public override void AfterPaint(Graphics g)
		{
			base.AfterPaint(g);

			PointF[] pts = new PointF[_Points.Count + 1];
			for (int i = 0; i < _Points.Count; i++)
				pts[i] = (PointF)_Points[i].RootLayerCoordinates;
			pts[_Points.Count] = (PointF)_positionCurrentMouseInRootLayerCoordinates;

			if (pts.Length >= 2)
				g.DrawCurve(Pens.Blue, pts, (float)_tension);

			/*

			for (int i = 1; i < this._currentPoint; i++)
				g.DrawLine(Pens.Blue, _Points[i - 1].printAreaCoord, _Points[i].printAreaCoord);

			if (_currentPoint > 0)
				g.DrawLine(Pens.Blue, _Points[_currentPoint - 1].printAreaCoord, _currentMousePrintAreaCoord);
			*/
		}
        void DrawLineBetweenPoints(Graphics g, Report rpt, Brush brush, Point[] points, int intLineSize)
        {
            if (points.Length <= 1)		// Need at least 2 points
                return;

            Pen p = null;
            try
            {
                // 20022008 AJM GJL - Added thicker lines


                p = new Pen(brush, intLineSize);    // todo - use line from style ????


                if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2)
                    g.DrawCurve(p, points, 0.5F);
                else
                    g.DrawLines(p, points);
            }
            finally
            {
                if (p != null)
                    p.Dispose();
            }
            return;
        }
 void DrawEdges(Graphics g, float scale)
 {
     Random r = new Random(0);
     Point[] points = new Point[4];
     foreach (Vertex v in graph.vertices.Values)
     {
         foreach (Edge e in v.outgoingEdges.Values)
         {
             if (e.ToVertex != graph.BottomVertex
                 && !e.fromPoint.IsEmpty && !e.toPoint.IsEmpty)
             {
                 int colorInt = r.Next(255*256*256);
                 int red = (colorInt >> 16) & 255;
                 int green = (colorInt >> 8) & 255;
                 int blue = colorInt & 255;
                 Brush brush = null;
                 if (e.selected)
                 {
                     Color foreColor = Color.FromArgb(150, 0, 255, 0);
                     Color backColor = Color.FromArgb(150, 255, 0, 0);
                     brush = new HatchBrush(HatchStyle.DiagonalCross, foreColor, backColor);
                 }
                 else if (e.brush != null)
                 {
                     brush = e.brush;
                 }
                 else
                 {
                     if (red <= green && red <= blue)
                         red = 0;
                     else if (green <= blue && green <= red)
                         green = 0;
                     else if (blue <= red && blue <= green)
                         blue = 0;
                     Color color = Color.FromArgb(100, red, green, blue);
                     Debug.Assert(!color.IsEmpty);
                     brush = new SolidBrush(color);
                     e.brush = brush;
                 }
                 Debug.Assert(brush != null);
                 float fWidth = e.weight*scale;
                 if (fWidth > minWidth && e.FromVertex.active && e.ToVertex.active)
                 {
                     int iWidth = (int)fWidth;
                     if (iWidth < 1)
                         iWidth = 1;
                     e.width = iWidth;
                     Pen pen = e.pen;
                     if (pen == null || pen.Width != iWidth || e.selected)
                     {
                         pen = new Pen(brush, iWidth);
                         if (!e.selected)
                             e.pen = pen;
                     }
                     Debug.Assert(pen != null);
                     int deltaX = e.toPoint.X - e.fromPoint.X;
                     int deltaY = e.toPoint.Y - e.fromPoint.Y;
                     deltaX = deltaX/4;
                     deltaY = deltaY/9;
                     int deltaY1 =   deltaY;
                     int deltaY2 = - deltaY;
                     if (deltaX < 0)
                     {
                         deltaX = 20;
                         if (Math.Abs(deltaY)*5 < iWidth*2)
                         {
                             deltaY1 = deltaY2 = iWidth*2;
                             deltaX = iWidth;
                         }
                     }
                     points[0] = e.fromPoint;
                     points[1] = new Point(e.fromPoint.X + deltaX, e.fromPoint.Y + deltaY1);
                     points[2] = new Point(e.  toPoint.X - deltaX, e.  toPoint.Y + deltaY2);
                     points[3] = e.toPoint;
                     g.DrawCurve(pen, points);
                     red = (red + 17) % 256;
                     green = (green + 101) % 256;
                     blue = (blue + 29) % 256;
                 }
             }
         }
     }
 }
        /// <summary>
        /// 画曲线
        /// </summary>
        /// <param name="objGraphics"></param>
        private void DrawContent(ref Graphics objGraphics, float[] fltCurrentValues, Color clrCurrentColor)
        {
            Pen CurvePen = new Pen(clrCurrentColor, CurveSize);
            PointF[] CurvePointF = new PointF[Keys.Length];
            float keys = 0;
            float values = 0;

            for (int i = 0; i < Keys.Length; i++)
            {
                keys = XSlice * i + XSpace;
                values = (Height - YSpace) + YSliceBegin - YSlice * (fltCurrentValues[i] / YSliceValue);
                CurvePointF[i] = new PointF(keys, values);
            }
            objGraphics.DrawCurve(CurvePen, CurvePointF, Tension);
        }
        private void DrawCurve(Color c, BorderStyleEnum bs, float w, Graphics g,
                                PointF[] points, int Offset, float Tension)
        {
            if (bs == BorderStyleEnum.None || c.IsEmpty || w <= 0)	// nothing to draw
                return;

            Pen p = null;
            try
            {
                p = new Pen(c, w);
                switch (bs)
                {
                    case BorderStyleEnum.Dashed:
                        p.DashStyle = DashStyle.Dash;
                        break;
                    case BorderStyleEnum.Dotted:
                        p.DashStyle = DashStyle.Dot;
                        break;
                    case BorderStyleEnum.Double:
                    case BorderStyleEnum.Groove:
                    case BorderStyleEnum.Inset:
                    case BorderStyleEnum.Solid:
                    case BorderStyleEnum.Outset:
                    case BorderStyleEnum.Ridge:
                    case BorderStyleEnum.WindowInset:
                    default:
                        p.DashStyle = DashStyle.Solid;
                        break;
                }
                PointF[] tmp = new PointF[points.Length];
                for (int i = 0; i < points.Length; i++)
                {

                    tmp[i].X = PixelsX(points[i].X + _left - _hScroll);
                    tmp[i].Y = PixelsY(points[i].Y + _top - _vScroll);
                }

                g.DrawCurve(p, tmp, Offset, tmp.Length - 1, Tension);
            }
            finally
            {
                if (p != null)
                    p.Dispose();
            }
        }
Exemple #40
0
		void DrawLineBetweenPoints(Graphics g, Brush brush, Point[] points)
		{
			if (points.Length <= 1)		// Need at least 2 points
				return;

			Pen p=null;
			try
			{
				p = new Pen(brush, 1);    // todo - use line from style ????
				if (ChartDefn.Subtype == ChartSubTypeEnum.Smooth && points.Length > 2)
					g.DrawCurve(p, points, 0.5F);
				else
					g.DrawLines(p, points);
			}
			finally
			{
				if (p != null)
					p.Dispose();
			}
			return;
		}