Пример #1
0
        public void Paint(Graphics graphics)
        {
            GraphicsPath path = new GraphicsPath();

            path.AddPolygon(this.hexagonPoints);
            path.CloseAllFigures();
            using (SolidBrush solidBrush = new SolidBrush(this.hexagonColor))
                graphics.FillPath((Brush)solidBrush, path);
            if (this.isHovered || this.isSelected)
            {
                SmoothingMode smoothingMode = graphics.SmoothingMode;
                graphics.SmoothingMode = SmoothingMode.AntiAlias;
                using (Pen pen = new Pen(Color.FromArgb(42, 91, 150), 2f))
                    graphics.DrawPath(pen, path);
                using (Pen pen = new Pen(Color.FromArgb(150, 177, 239), 1f))
                    graphics.DrawPath(pen, path);
                graphics.SmoothingMode = smoothingMode;
            }
            path.Dispose();
        }
Пример #2
0
        public GraphicsPath DrawStar(float Xc, float Yc, RectangleF rect, float RadiusInner)
        {
            GraphicsPath gp           = new GraphicsPath();
            float        xRadiusOuter = rect.Width / 2f;
            float        yRadiusOuter = rect.Height / 2f;

            Xc += xRadiusOuter;
            Yc += yRadiusOuter;
            float sin36        = (float)Math.Sin(0.62831853071795862);
            float sin72        = (float)Math.Sin(1.2566370614359173);
            float cos36        = (float)Math.Cos(0.62831853071795862);
            float cos72        = (float)Math.Cos(1.2566370614359173);
            float xInnerRadius = ((xRadiusOuter * cos72) / cos36) + (xRadiusOuter * RadiusInner);
            float yInnerRadius = ((yRadiusOuter * cos72) / cos36) + (yRadiusOuter * RadiusInner);

            Yc += (yRadiusOuter - (Yc - (yRadiusOuter * cos72))) / 4f;
            PointF[] pts = new PointF[] { new PointF(Xc, Yc - yRadiusOuter), new PointF(Xc + (xInnerRadius * sin36), Yc - (yInnerRadius * cos36)), new PointF(Xc + (xRadiusOuter * sin72), Yc - (yRadiusOuter * cos72)), new PointF(Xc + (xInnerRadius * sin72), Yc + (yInnerRadius * cos72)), new PointF(Xc + (xRadiusOuter * sin36), Yc + (yRadiusOuter * cos36)), new PointF(Xc, Yc + yInnerRadius), new PointF(Xc - (xRadiusOuter * sin36), Yc + (yRadiusOuter * cos36)), new PointF(Xc - (xInnerRadius * sin72), Yc + (yInnerRadius * cos72)), new PointF(Xc - (xRadiusOuter * sin72), Yc - (yRadiusOuter * cos72)), new PointF(Xc - (xInnerRadius * sin36), Yc - (yInnerRadius * cos36)) };
            gp.AddPolygon(pts);
            return(gp);
        }
Пример #3
0
        /// <summary>
        /// Paints the shape of the person object in the plex. Here you can let your imagination go.
        /// MAKE IT PERFORMANT, this is a killer method called 200.000 times a minute!
        /// </summary>
        /// <param name="g">The graphics canvas onto which to paint</param>
        public override void Paint(Graphics g)
        {
            base.Paint(g);

            Matrix m = g.Transform;             //keep reference to the current transform

            points = new PointF[] {
                new PointF(Rectangle.X, Rectangle.Y + mYShift),
                new PointF(Rectangle.X + mXShift, Rectangle.Y + mYShift),
                new PointF(Rectangle.X + mXShift, Rectangle.Y + mYShift - 10),
                new PointF(Rectangle.Right, Rectangle.Y + Rectangle.Height / 2),
                new PointF(Rectangle.X + mXShift, Rectangle.Bottom - mYShift + 10),
                new PointF(Rectangle.X + mXShift, Rectangle.Bottom - mYShift),
                new PointF(Rectangle.X, Rectangle.Bottom - mYShift)
            };
            GraphicsPath path = new GraphicsPath();

            path.AddPolygon(points);
            g.TranslateTransform(Rectangle.X + Rectangle.Width / 2, Rectangle.Y + Rectangle.Height / 2);
            g.RotateTransform(mAngle, MatrixOrder.Prepend);
            g.TranslateTransform(-Rectangle.X - Rectangle.Width / 2, -Rectangle.Y - Rectangle.Height / 2);
            g.FillPath(this.BackgroundBrush, path);
            if (IsSelected)
            {
                g.FillEllipse(Brushes.Green, Rectangle.Right - 5, Rectangle.Y + Rectangle.Height / 2 - 2, 5, 5);
                g.FillEllipse(Brushes.Yellow, Rectangle.X + mXShift, Rectangle.Y + mYShift - 2, 5, 5);
            }
            rotationPoint = new PointF(Rectangle.Right, Rectangle.Y + Rectangle.Height / 2);
            upperPoint    = new PointF(Rectangle.X + mXShift, Rectangle.Y);
            leftPoint     = new PointF(Rectangle.X, Rectangle.Y + mYShift);
            arrowPoint    = new PointF(Rectangle.X + mXShift, Rectangle.Y + mYShift - 2);
            PointF[] rp = new PointF[] { rotationPoint, upperPoint, leftPoint, arrowPoint };
            g.Transform.TransformPoints(rp);             //let the framework compute the new coordinates, much safer and mathematically correct
            g.Transform.TransformPoints(points);
            rotationPoint = rp[0];
            upperPoint    = rp[1];
            leftPoint     = rp[2];
            arrowPoint    = rp[3];
            // Reset world transformation.
            g.Transform = m;
        }
Пример #4
0
        private void PictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            mouseClicked = false;
            curp         = e.Location;
            switch (tool)
            {
            case ActiveTool.Eraser:
                gfx.DrawLine(eraser, prevp, curp);
                break;

            case ActiveTool.Pen:
                gfx.DrawLine(pen, prevp, curp);
                break;

            case ActiveTool.Line:
                gfx.DrawLine(pen, prevp, curp);
                break;

            case ActiveTool.Rectangle:
                gfx.DrawRectangle(pen, GetRectangle(prevp, curp));
                break;

            case ActiveTool.Ellipse:
                gfx.DrawEllipse(pen, GetRectangle(prevp, curp));
                break;

            case ActiveTool.Star:
                GraphicsPath gp = new GraphicsPath();
                gp.AddPolygon(new Point[]
                {
                    new Point(prevp.X, curp.Y),
                    new Point((curp.X - prevp.X) / 2 + prevp.X, prevp.Y),
                    new Point(curp.X, curp.Y),
                    new Point(prevp.X, prevp.Y + (curp.Y - prevp.Y) / 2),
                    new Point(curp.X, prevp.Y + (curp.Y - prevp.Y) / 2),
                    new Point(prevp.X, curp.Y)
                });
                gfx.DrawPath(pen, gp);
                break;
            }
        }
        public PreviewPrism(PointF[] ArrayVert_in)
        {
            PointF Centr = new PointF(0, 0);
            float  shift_X = 0, shift_Y = 0;

            ArrayVertices = new PointF[ArrayVert_in.Length];
            ArrayClienIn  = new PointF[ArrayVertices.Length];
            ClientSize    = new GraphicsPath();
            PointF[] Client = new PointF[4];
            Client[0].X = 421;
            Client[0].Y = 0;
            Client[1].X = 421;
            Client[1].Y = 340;
            Client[2].X = 1090;
            Client[2].Y = 340;
            Client[3].X = 1090;

            Client[3].Y = 0;
            ClientSize.AddPolygon(Client);
            ArrayVert_in.CopyTo(ArrayClienIn, 0);

            for (int i = 0; i != ArrayClienIn.Length; i++)
            {
                ArrayVertices[i].X = ArrayClienIn[i].X / 2;
                ArrayVertices[i].Y = ArrayClienIn[i].Y / 2;
            }
            for (int i = 0; i != ArrayVertices.Length; i++)
            {
                Centr.X += ArrayVertices[i].X;
                Centr.Y += ArrayVertices[i].Y;
            }
            Centr.X /= ArrayVertices.Length;
            Centr.Y /= ArrayVertices.Length;
            shift_X  = 766 - Centr.X;
            shift_Y  = 186 - Centr.Y;
            for (int i = 0; i != ArrayClienIn.Length; i++)
            {
                ArrayVertices[i].X += shift_X;
                ArrayVertices[i].Y += shift_Y;
            }
        }
Пример #6
0
        GraphicsPath GetSector(float startAngle, float endAngle, float r1, float r2)
        {
            GraphicsPath ret = new GraphicsPath();

            float[] xx = new float[4];
            float[] yy = new float[4];


            ret.AddArc(-r1, -r1, 2 * r1, 2 * r1, startAngle, endAngle - startAngle);
            GraphicsPath gptemp = new GraphicsPath();

            gptemp.AddArc(-r2, -r2, 2 * r2, 2 * r2, startAngle, endAngle - startAngle);

            ret.AddLine(ret.GetLastPoint(), gptemp.GetLastPoint());
            ret.AddArc(-r2, -r2, 2 * r2, 2 * r2, endAngle, -(endAngle - startAngle));
            //ret.AddArc(-r2, -r2, 2 * r2, 2 * r2, startAngle, endAngle - startAngle);
            ret.AddLine(gptemp.PathPoints[0], ret.PathPoints[0]);
            ret.CloseAllFigures();
            return(ret);

            startAngle *= (float)(Math.PI / 180.0f);
            endAngle   *= (float)(Math.PI / 180.0f);

            xx[0] = (float)(r1 * Math.Cos(startAngle));
            xx[1] = (float)(r2 * Math.Cos(startAngle));
            xx[2] = (float)(r1 * Math.Cos(endAngle));
            xx[3] = (float)(r2 * Math.Cos(endAngle));

            yy[0] = (float)(r1 * Math.Sin(startAngle));
            yy[1] = (float)(r2 * Math.Sin(startAngle));
            yy[2] = (float)(r1 * Math.Sin(endAngle));
            yy[3] = (float)(r2 * Math.Sin(endAngle));

            ret.AddPolygon(new PointF[] {
                new PointF(xx[0], yy[0]),
                new PointF(xx[1], yy[1]),
                new PointF(xx[2], yy[2]),
                new PointF(xx[3], yy[3]),
            });
            return(ret);
        }
Пример #7
0
        protected override void OnMouseMove(MouseEventArgs mevent)
        {
            base.OnMouseMove(mevent);
            if (isRotate)
            {
                //double a = Math.Atan2(mevent.Y - midPoint.Y, mevent.X - midPoint.X);
                using (var path = new GraphicsPath())
                {
                    path.AddPolygon(beginPoints);
                    Point tmp = new Point(this.Left + (mevent.X - tmpLocation.X),
                                          this.Top + (mevent.Y - tmpLocation.Y));
                    double a  = Math.Atan2(tmp.Y - midPoint.Y, tmp.X - midPoint.X);
                    var    n1 = (float)Math.Cos(a);
                    var    n2 = (float)Math.Sin(a);
                    var    n3 = -(float)Math.Sin(a);
                    var    n4 = (float)Math.Cos(a);
                    var    n5 = (float)((midPoint.X * (1 - Math.Cos(a)) + midPoint.Y * Math.Sin(a)));
                    var    n6 = (float)((midPoint.Y * (1 - Math.Cos(a)) - midPoint.X * Math.Sin(a)));
                    path.Transform(new Matrix(n1, n2, n3, n4, n5, n6));

                    for (int i = 0; i < beginPoints.Length - 1; ++i)
                    {
                        int xx = (int)path.PathPoints[i].X,
                            yy = (int)path.PathPoints[i].Y;
                        adjustPoints[i].Value = new Point(xx, yy);
                    }

                    int x = (int)path.PathPoints[path.PointCount - 1].X,
                        y = (int)path.PathPoints[path.PointCount - 1].Y;
                    this.Location = new Point(x, y);
                }

                //for (int i = 0; i < adjustPoints.Length; i++)
                //{
                //    adjustPoints[i].Value = new Point(
                //        beginPoints[i].X + this.Location.X - startLocation.X,
                //        beginPoints[i].Y + this.Location.Y - startLocation.Y);
                //}
                Common.history.update();
            }
        }
Пример #8
0
        private static Bitmap CutImage(AssetPreloadData asset, AssetPreloadData texture2DAsset, RectangleF textureRect, Sprite sprite)
        {
            var texture2D = new Texture2DConverter(new Texture2D(texture2DAsset, true));

            using (var originalImage = texture2D.ConvertToBitmap(false))
            {
                if (originalImage != null)
                {
                    var info  = texture2DAsset.InfoText;
                    var start = info.IndexOf("Format");
                    info           = info.Substring(start, info.Length - start);
                    asset.InfoText = $"Width: {textureRect.Width}\nHeight: {textureRect.Height}\n" + info;
                    var spriteImage = originalImage.Clone(textureRect, PixelFormat.Format32bppArgb);
                    using (var brush = new TextureBrush(spriteImage))
                    {
                        using (var path = new GraphicsPath())
                        {
                            foreach (var p in sprite.m_PhysicsShape)
                            {
                                path.AddPolygon(p);
                            }
                            using (var matr = new Matrix())
                            {
                                matr.Translate(sprite.m_Rect.Width * sprite.m_Pivot.X, sprite.m_Rect.Height * sprite.m_Pivot.Y);
                                matr.Scale(sprite.m_PixelsToUnits, sprite.m_PixelsToUnits);
                                path.Transform(matr);
                                var bitmap = new Bitmap((int)textureRect.Width, (int)textureRect.Height);
                                using (var graphic = Graphics.FromImage(bitmap))
                                {
                                    graphic.FillPath(brush, path);
                                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                    return(bitmap);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Пример #9
0
        private Bitmap RotateCenter(Bitmap bmpSrc, float theta)
        {
            if (theta == 180.0f)
            {
                Bitmap   bmpDest = new Bitmap(bmpSrc.Width, bmpSrc.Height);
                Graphics gDest   = Graphics.FromImage(bmpDest);

                gDest.DrawImage(bmpSrc, new Point(0, 0));

                bmpDest.RotateFlip(RotateFlipType.Rotate180FlipNone);

                return(bmpDest);
            }
            else
            {
                Matrix mRotate = new Matrix();
                mRotate.Translate(bmpSrc.Width / -2, bmpSrc.Height / -2, MatrixOrder.Append);
                mRotate.RotateAt(theta, new Point(0, 0), MatrixOrder.Append);

                GraphicsPath gp = new GraphicsPath();
                // transform image points by rotation matrix
                gp.AddPolygon(new Point[] { new Point(0, 0), new Point(bmpSrc.Width, 0), new Point(0, bmpSrc.Height) });
                gp.Transform(mRotate);
                PointF[] pts = gp.PathPoints;

                // create destination bitmap sized to contain rotated source image
                Rectangle bbox    = RotateBoundingBox(bmpSrc, mRotate);
                Bitmap    bmpDest = new Bitmap(bbox.Width, bbox.Height);

                Graphics gDest = Graphics.FromImage(bmpDest);
                Matrix   mDest = new Matrix();
                mDest.Translate(bmpDest.Width / 2, bmpDest.Height / 2, MatrixOrder.Append);
                gDest.Transform = mDest;
                gDest.DrawImage(bmpSrc, pts);
                gDest.DrawRectangle(Pens.Red, bbox);
                gDest.Dispose();
                gp.Dispose();

                return(bmpDest);
            }
        }
       public void UpdateGraphicsPath()
      {
          if (graphicsPath == null)
          {
              graphicsPath = new GraphicsPath();
          }
          else
          {
              graphicsPath.Reset();
          }

          {
              if (LocalPoints.Count == 0)
                  return;

              List<Point> pnts = new List<Point>();
              var last = Point.Empty;
              for (int i = 0; i < LocalPoints.Count; i++)
              {
                  Point p2 = new Point((int)LocalPoints[i].X, (int)LocalPoints[i].Y);
                  if(p2 == last)
                      continue;
                  
                  pnts.Add(p2);
                  last = p2;
              }

              //close it
              pnts.Add(new Point((int) LocalPoints[LocalPoints.Count - 1].X,
                  (int) LocalPoints[LocalPoints.Count - 1].Y));

              if (pnts.Count > 2)
              {
                  graphicsPath.AddPolygon(pnts.ToArray());
              }
              else if (pnts.Count == 2)
              {
                  graphicsPath.AddLines(pnts.ToArray());
              }
          }
      }
Пример #11
0
        /// <summary>
        /// Points for a laser
        /// </summary>
        /// <returns>Graphics path of default laser</returns>
        public static GraphicsPath getLaser()
        {
            GraphicsPath model = new GraphicsPath();

            PointF[] pts = new PointF[28];

            pts[0]  = new PointF(0, -5);
            pts[1]  = new PointF(-1, -5);
            pts[2]  = new PointF(-1, -4);
            pts[3]  = new PointF(-2, -4);
            pts[4]  = new PointF(-2, -3);
            pts[5]  = new PointF(-3, -3);
            pts[6]  = new PointF(-3, -0);
            pts[7]  = new PointF(-2, -0);
            pts[8]  = new PointF(-2, 2);
            pts[9]  = new PointF(-1, 2);
            pts[10] = new PointF(-1, 4);
            pts[11] = new PointF(-0.5f, 4);
            pts[12] = new PointF(-0.5f, 6);
            pts[13] = new PointF(-0, 6);

            pts[14] = new PointF(0, 6);
            pts[15] = new PointF(0.5f, 6);
            pts[16] = new PointF(0.5f, 4);
            pts[17] = new PointF(1, 4);
            pts[18] = new PointF(1, 2);
            pts[19] = new PointF(2, 2);
            pts[20] = new PointF(2, -0);
            pts[21] = new PointF(3, -0);
            pts[22] = new PointF(3, -3);
            pts[23] = new PointF(2, -3);
            pts[24] = new PointF(2, -4);
            pts[25] = new PointF(1, -4);
            pts[26] = new PointF(1, -5);
            pts[27] = new PointF(0, -5);

            model.StartFigure();
            model.AddPolygon(pts);
            model.CloseFigure();
            return(model);
        }
Пример #12
0
        // Calculate the outline of this hexagon, given its bounding box.
        // The outline is a closed polygon defined by six points.
        // This function runs once, the first time the hexagon is drawn.
        internal void calculateOutline(bool forced = false)
        {
            if (!forced && outline != null)
            {
                return;                                // already done; don't repeat
            }
            outline = new GraphicsPath();

            var x1 = bounds.Left + bounds.Width / 4;
            var x2 = bounds.Left + (3 * bounds.Width) / 4;
            var y1 = bounds.Top + bounds.Height / 2;

            outline.AddPolygon(new Point[] {
                new Point(x1, bounds.Top),
                new Point(x2, bounds.Top),
                new Point(bounds.Right, y1),
                new Point(x2, bounds.Bottom),
                new Point(x1, bounds.Bottom),
                new Point(bounds.Left, y1)
            });
        }
Пример #13
0
        public void CreatePath()
        {
            if (tempPointList.Count > 0)
            {
                path = new GraphicsPath();
                path.AddPolygon((Point[])tempPointList.ToArray(typeof(Point)));

                RectangleF rect = path.GetBounds();

                Boundary      = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
                boundaryShape = new BoundaryShape(Boundary);

                boundaryShape.ShapeMoved         += new BoundaryShape.ShapeMoveHandler(boundaryShape_ShapeMoved);
                boundaryShape.ShapeResized       += new BoundaryShape.ResizingShapeMoveHandler(boundaryShape_ShapeResized);
                boundaryShape.ShapePrepareResize += delegate(MouseEventArgs e)
                {
                    shapeResizing = true;
                };
                arrowPoints = tempPointList;
            }
        }
Пример #14
0
        private static bool PolygnIsIn(IList <EasyMap.Geometries.Point> source, IList <EasyMap.Geometries.Point> dest)
        {
            List <PointF> p1 = new List <PointF>();

            source.ToList().ForEach(p => { p1.Add(new PointF((float)p.X, (float)p.Y)); });
            GraphicsPath gp1 = new GraphicsPath();

            gp1.AddPolygon(p1.ToArray());
            Region region = new Region(gp1);
            bool   ret    = true;

            foreach (EasyMap.Geometries.Point p in dest)
            {
                if (ret && !region.IsVisible((float)p.X, (float)p.Y))
                {
                    ret = false;
                    break;
                }
            }
            return(ret);
        }
Пример #15
0
        static Edge2()
        {
            GraphicsPath hPath = new GraphicsPath();

            // Create the outline for the custom end cap.
            float sin = arrowSize * (float)Math.Sin(Math.PI / 3);
            float cos = arrowSize * 0.5f;

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

            // Construct the hook-shaped end cap.
            CustomLineCap HookCap = new CustomLineCap(hPath, null);

            // Set the start cap and end cap of the HookCap to be rounded.
            HookCap.SetStrokeCaps(LineCap.Round, LineCap.Round);

            linePen              = new Pen(Color.Black, 1f);
            linePen.StartCap     = LineCap.RoundAnchor;
            linePen.CustomEndCap = HookCap;
            linePen.LineJoin     = LineJoin.Round;
        }
Пример #16
0
        private void SetFromCircle()
        {
            int radian = 7;
            int w      = this.Width;
            int h      = this.Height;

            Point p1 = new Point(radian, 0);
            Point p2 = new Point(w - radian, 0);
            Point p3 = new Point(w, radian);
            Point p4 = new Point(w, h - radian);
            Point p5 = new Point(w - radian, h);
            Point p6 = new Point(radian, h);
            Point p7 = new Point(0, h - radian);
            Point p8 = new Point(0, radian);

            GraphicsPath shape = new GraphicsPath();

            Point[] p = new Point[] { p1, p2, p3, p4, p5, p6, p7, p8 };
            shape.AddPolygon(p);
            this.Region = new Region(shape);
        }
Пример #17
0
        private bool AddRegion(Point[] points)
        {
            GraphicsPath path = new GraphicsPath();

            path.AddPolygon(points);

            if (!UniteWithIntersectedRegions(path, points))
            {
                RegionInfo info = new RegionInfo(path, points, picImage.Image.Size);
                if (info.CountPixels > 0)
                {
                    int nothidden = Math.Max(messageLength - ctlRegions.HiddenBytes, 0);
                    info.Capacity = Math.Min(nothidden, info.MaximumCapacity);
                    drawnRegions.Add(info);
                    ctlRegions.Add(new RegionInfoListItem(info));
                    return(true);
                }
            }

            return(false);
        }
Пример #18
0
        public static GraphicsPath Star(float x, float y, float r, float r2, int n, float startAngle)
        {
            float phi    = 360 / n;
            float phi2   = phi / 2;
            int   n2     = 2 * n;
            var   points = new PointF[n2];
            float angle  = startAngle;

            for (int i = 0; i < n2; ++i)
            {
                float cr = (i & 1) != 0 ? r2 : r;
                float a  = Angle.ToRadians(angle);
                points[i].X = x + cr * (float)Math.Cos(a);
                points[i].Y = y + cr * (float)Math.Sin(a);
                angle      += phi2;
            }
            var res = new GraphicsPath(FillMode.Winding);

            res.AddPolygon(points);
            return(res);
        }
Пример #19
0
        private void SetRegion()
        {
            if (_triangular)
            {
                using (var path = new GraphicsPath())
                {
                    path.AddPolygon(new[]
                    {
                        new Point(0, this.Height),
                        (Point)this.Size,
                        new Point(this.Width, 0)
                    });

                    this.Region = new Region(path);
                }
            }
            else
            {
                this.Region = null;
            }
        }
Пример #20
0
 public void BrushTriangle(Triangle triangle)
 {
     PointF[] myPoints1 =
     {
         new PointF(triangle.M1.x * Score, triangle.M1.y * Score), new PointF(triangle.M2.x * Score, triangle.M2.y * Score),
         new PointF(triangle.M3.x * Score, triangle.M3.y * Score)
     };
     //PathGradientBrush pgradBrush = new PathGradientBrush(myPoints1);
     try
     {
         int i = (int)Math.Truncate((1 - triangle.DensityOfTriangle) * 255);
         //SolidBrush redBrush = new SolidBrush(Color.FromArgb(i, i, i));
         SolidBrush   redBrush  = new SolidBrush(Color.FromArgb(123, i, i, i));
         GraphicsPath graphPath = new GraphicsPath();
         graphPath.AddPolygon(myPoints1);
         gr.FillPath(redBrush, graphPath);
     }
     catch
     {
     }
 }
Пример #21
0
        private void panel1_Click(object sender, EventArgs e)
        {
            Graphics g = panel1.CreateGraphics();

            GraphicsPath gp = new GraphicsPath();

            gp.AddEllipse(30, 30, 360, 360);
            Rectangle r = new Rectangle(400, 30, 360, 360);

            gp.AddRectangle(r);
            Point[] points = { new Point(30, 600), new Point(70, 440), new Point(120, 700), new Point(400, 550), new Point(300, 450) };
            gp.AddPolygon(points);
            PathGradientBrush pgb = new PathGradientBrush(gp);

            pgb.CenterColor    = Color.White;
            pgb.SurroundColors = new Color[] { Color.Black };

            g.FillEllipse(pgb, 30, 30, 360, 360);
            g.FillRectangle(pgb, r);
            g.FillPolygon(pgb, points);
        }
Пример #22
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Point[] pontos =
            {
                new Point(50,   0),
                new Point(50,   0),
                new Point(640,  0),
                new Point(620, 30),
                new Point(430, 30),
                new Point(70,  30),
                new Point(60, 15)
            };

            GraphicsPath poly = new GraphicsPath();

            poly.AddPolygon(pontos);
            border_top.Region = new Region(poly);
            Pen borda = new Pen(Color.White, 5);

            e.Graphics.DrawPolygon(borda, pontos);
        }
        // TODO: Transform source triangle to destiantion triangle
        private void DrawTriangle(Graphics g, PointF[] srcPoints, PointF[] destPoints)
        {
            // Create buffer image
            var srcRect = ComputeRectangle(srcPoints);
            var newBmp  = new Bitmap((int)srcRect.Width, (int)srcRect.Height);

            using var bufferG = Graphics.FromImage(newBmp);

            // Restrict area to draw the image to
            using var gp = new GraphicsPath();
            gp.AddPolygon(srcPoints.Select(x => PointF.Subtract(x, new SizeF(srcRect.Location))).ToArray());
            bufferG.Clip = new Region(gp);

            // Cut image from source
            bufferG.DrawImage(_imageProvider.Image, new RectangleF(0, 0, srcRect.Width, srcRect.Height), srcRect, GraphicsUnit.Pixel);

            // Draw buffer image to final image
            var destRect = ComputeRectangle(destPoints);

            g.DrawImage(newBmp, destRect);
        }
Пример #24
0
        // See if the mouse is over a polygon's body.
        public static bool MouseIsOverPolygon(Point mouse_pt, List <Polygon> polygons, out Polygon hit_polygon)
        {
            // Examine each polygon.
            // Examine them in reverse order to check the ones on top first.
            for (int i = polygons.Count - 1; i >= 0; i--)
            {
                // Make a GraphicsPath representing the polygon.
                GraphicsPath path = new GraphicsPath();
                path.AddPolygon(polygons[i].ToArray());

                // See if the point is inside the GraphicsPath.
                if (path.IsVisible(mouse_pt))
                {
                    hit_polygon = polygons[i];
                    return(true);
                }
            }

            hit_polygon = null;
            return(false);
        }
 public void DrawEfateo(Graphics g)
 {
     try {
         for (int i = 0; i < this.ptsbdb.Count; i++)
         {
             GraphicsPath gp          = new GraphicsPath();
             Point[]      curvePoints = this.ptsbdb.ElementAt(i).ToArray();
             gp.AddPolygon(curvePoints);
             RectangleF rect = gp.GetBounds();
             gp.AddRectangle(rect);
             // Create pen.
             Pen blackPen = new Pen(Color.Red, 2);
             // Pen blackPen2 = new Pen(Color.Black, 2);
             g.DrawPath(blackPen, gp);
             //this.pts = new List<Point>();
         }
     }
     catch (Exception ex) {
         throw ex;
     }
 }
 public void DrawPolygonPoint(Graphics g)
 {
     try {
         if (this.pts.Count >= 3)
         {
             GraphicsPath gp          = new GraphicsPath();
             Point[]      curvePoints = this.pts.ToArray();
             gp.AddPolygon(curvePoints);
             this.rect = gp.GetBounds();
             // gp.AddRectangle(rect);
             // Create pen.
             Pen blackPen = new Pen(Color.Black, 2);
             // Pen blackPen2 = new Pen(Color.Black, 2);
             g.DrawPath(blackPen, gp);
             //this.pts = new List<Point>();
         }
     }
     catch (Exception ex) {
         Console.WriteLine(ex.StackTrace);
     }
 }
        public AlternateCompositionArrow()
        {
            PenWidth  = (int)_painter.PainterPen.Width;
            PenColor  = _painter.PainterPen.Color;
            FigurePen = new Pen(PenColor, PenWidth);

            GraphicsPath hPath = new GraphicsPath();

            Point[] filledRhombus = new Point[] {
                new Point(0, 0),
                new Point(-3, -6),
                new Point(0, -12),
                new Point(3, -6)
            };

            hPath.AddPolygon(filledRhombus);
            FigurePen.CustomStartCap = new CustomLineCap(hPath, null);
            FigurePen.CustomEndCap   = new AdjustableArrowCap(9, 9, false);

            figureType = SinglePainter.Painter.FigureType.AlternateCompositionArrow;
        }
Пример #28
0
        private void FancySidemenu_Paint(object sender, PaintEventArgs e)
        {
            int bottom = (int)(y + tabHeight);

            Region tab;

            Point[] points = new Point[]
            {
                new Point(0, y),
                new Point(tabWidth, y),
                new Point(Width, y + (int)(tabHeight / 2)),
                new Point(tabWidth, bottom),
                new Point(0, bottom)
            };

            using (GraphicsPath gp = new GraphicsPath())
            {
                gp.AddPolygon(points);
                tab = new Region(gp);
            }

            e.Graphics.FillRegion(highlightBrush, tab);

            Region graphicsClip = e.Graphics.Clip;
            Region region       = graphicsClip.Clone();

            region.Exclude(tab);
            e.Graphics.Clip = region;

            e.Graphics.FillRectangle(backBrush, new Rectangle(0, 0, Width, Height));

            e.Graphics.Clip = graphicsClip;

            for (int i = 0; i < tabs.Length; i += 1)
            {
                int y      = (int)(i * tabHeight);
                int height = TextRenderer.MeasureText(tabs[i], Font).Height;
                e.Graphics.DrawString(tabs[i], Font, brush, textMargin, y + (tabHeight - height) / 2);
            }
        }
Пример #29
0
        //采用简单填充符号绘制复合多边形
        private static void DrawMultiPolygonBySimpleFill(Graphics g, moRectangle extent, double mapScale, double dpm,
                                                         double mpu, moMultiPolygon multiPolygon, moSimpleFillSymbol symbol)
        {
            double sOffsetX = extent.MinX, sOffsetY = extent.MaxY; //获取投影坐标系相对屏幕坐标系的平移量
            //(1)转换为屏幕坐标
            Int32        sPartCount   = multiPolygon.Parts.Count;  //简单多边形的数目
            GraphicsPath sGraphicPath = new GraphicsPath();        //定义复合多边形,用于屏幕绘制

            for (Int32 i = 0; i <= sPartCount - 1; i++)
            {
                Int32    sPointCount   = multiPolygon.Parts.GetItem(i).Count; //当前简单多边形的顶点数目
                PointF[] sScreenPoints = new PointF[sPointCount];
                for (Int32 j = 0; j <= sPointCount - 1; j++)
                {
                    PointF  sScreenPoint = new PointF();
                    moPoint sCurPoint    = multiPolygon.Parts.GetItem(i).GetItem(j);
                    sScreenPoint.X   = (float)((sCurPoint.X - sOffsetX) * mpu / mapScale * dpm);
                    sScreenPoint.Y   = (float)((sOffsetY - sCurPoint.Y) * mpu / mapScale * dpm);
                    sScreenPoints[j] = sScreenPoint;
                }
                sGraphicPath.AddPolygon(sScreenPoints);
            }
            //(2)填充
            SolidBrush sBrush = new SolidBrush(symbol.Color);

            g.FillPath(sBrush, sGraphicPath);
            sBrush.Dispose();
            //(3)绘制边界
            if (symbol.Outline.SymbolType == moSymbolTypeConstant.SimpleLineSymbol)
            {
                moSimpleLineSymbol sOutline = symbol.Outline;
                if (sOutline.Visible == true)
                {
                    Pen sPen = new Pen(sOutline.Color, (float)(sOutline.Size / 1000 * dpm));
                    sPen.DashStyle = (DashStyle)sOutline.Style;
                    g.DrawPath(sPen, sGraphicPath);
                    sPen.Dispose();
                }
            }
        }
Пример #30
0
        private void DrawHat(Graphics gfx, int hatNum, Hat hat, int x, int y)
        {
            // set x,y to center of hat
            x += 25; y += 25;

            // construct right-pointing arrow
            var   area       = new Rectangle(0, 0, 24, 14);
            float bodyHeight = (area.Height / 3);
            float headWidth  = (area.Width / 3);
            float bodyWidth  = area.Width - headWidth;

            PointF[] points = new PointF[7];
            points[0] = new PointF(area.Left, area.Top + bodyHeight);
            points[1] = new PointF(area.Left + bodyWidth, area.Top + bodyHeight);
            points[2] = new PointF(area.Left + bodyWidth, area.Top);
            points[3] = new PointF(area.Right, area.Top + (area.Height / 2));
            points[4] = new PointF(area.Left + bodyWidth, area.Bottom);
            points[5] = new PointF(area.Left + bodyWidth, area.Bottom - bodyHeight);
            points[6] = new PointF(area.Left, area.Bottom - bodyHeight);

            for (int i = 0; i < 8; i++)
            {
                // 8 possible directions
                GraphicsPath path = new GraphicsPath();
                path.AddPolygon(points);

                var transform = new Matrix();
                transform.RotateAt(45.0f * i, new PointF(area.Left, area.Top + area.Height / 2));
                transform.Translate(12.0f, 0.0f);                 // move away from center

                transform.Translate(x, y, MatrixOrder.Append);
                path.Transform(transform);

                Hat current = ControllerState.HatLookup[(byte)((i + 2) % 8)];
                using (var pen = new Pen(Color.Black, 1.0f)) {
                    gfx.DrawPath(pen, path);
                }
                gfx.FillPath(hat == current ? Brushes.Green : Brushes.Red, path);
            }
        }
Пример #31
0
    public GraphicsPath DrawStar(float Xc, float Yc)
    {
        GraphicsPath gp = new GraphicsPath();
        Xc += RadiusOuter;
        Yc += RadiusOuter;
        // RadiusInner and InnerRadius: determines how far from the center the inner vertices of the star are.
        // RadiusOuter: determines the size of the star.
        // xc, yc: determine the location of the star.
        float sin36 = (float)Math.Sin(36.0 * Math.PI / 180.0);
        float sin72 = (float)Math.Sin(72.0 * Math.PI / 180.0);
        float cos36 = (float)Math.Cos(36.0 * Math.PI / 180.0);
        float cos72 = (float)Math.Cos(72.0 * Math.PI / 180.0);
        float InnerRadius = (RadiusOuter * cos72 / cos36) + RadiusInner;

        PointF[] pts = new PointF[10];
        pts[0] = new PointF(Xc, Yc - RadiusOuter);
        pts[1] = new PointF(Xc + InnerRadius * sin36, Yc - InnerRadius * cos36);
        pts[2] = new PointF(Xc + RadiusOuter * sin72, Yc - RadiusOuter * cos72);
        pts[3] = new PointF(Xc + InnerRadius * sin72, Yc + InnerRadius * cos72);
        pts[4] = new PointF(Xc + RadiusOuter * sin36, Yc + RadiusOuter * cos36);
        pts[5] = new PointF(Xc, Yc + InnerRadius);
        pts[6] = new PointF(Xc - RadiusOuter * sin36, Yc + RadiusOuter * cos36);
        pts[7] = new PointF(Xc - InnerRadius * sin72, Yc + InnerRadius * cos72);
        pts[8] = new PointF(Xc - RadiusOuter * sin72, Yc - RadiusOuter * cos72);
        pts[9] = new PointF(Xc - InnerRadius * sin36, Yc - InnerRadius * cos36);

        gp.AddPolygon(pts);

        return gp;
    }
Пример #32
0
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        int intRate = 0;
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        Color UseFillColor = new Color();
        Color UseBorderColor = new Color();
        GraphicsPath ShapePath = new GraphicsPath();
        float ptx;
        float pty;
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;

        pty = (this.Height - (RadiusOuter * 2)) / 2;
        intRate = 0;
        while (!(intRate == MaxRating))
        {
          ptx = intRate * (RadiusOuter * 2 + ShapeGap) + Padding.Left + (ShapeGap / 2);
          if (PaintRating > intRate)
          {
        if (!IsPainting & HighlightRateFill & (PaintRating != intRate + 1))
        {
          UseFillColor = ShapeColorHover;
          UseBorderColor = ShapeBorderHoverColor;
        }
        else if (IsPainting & HighlightRateHover & (PaintRating == intRate + 1))
        {
          UseFillColor = ShapeColorFill;
          UseBorderColor = ShapeBorderFilledColor;
        }
        else
        {
          UseFillColor = PaintColor;
          UseBorderColor = PaintBorderColor;
        }
          }
          else
          {
        UseFillColor = ShapeColorEmpty;
        UseBorderColor = ShapeBorderEmptyColor;
          }

          ShapePath.Reset();
          Point[] pts;
          switch (Shape)
          {
        case eShape.Star:
          ShapePath = DrawStar(ptx, pty);
          break;
        case eShape.Heart:
          ShapePath = DrawHeart(ptx, pty);
          break;
        case eShape.Square:
          ShapePath.AddRectangle(new Rectangle((int)ptx, (int)pty, (int)(RadiusOuter * 2), (int)(RadiusOuter * 2)));
          break;
        case eShape.Circle:
          ShapePath.AddEllipse(ptx, pty, RadiusOuter * 2, RadiusOuter * 2);
          break;
        case eShape.Diamond:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter)), new Point((int)(ptx + RadiusOuter), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter)) };
          ShapePath.AddPolygon(pts);
          break;
        case eShape.Triangle:
          pts = new Point[] { new Point((int)(ptx + RadiusOuter), (int)pty), new Point((int)(ptx + RadiusOuter * 2), (int)(pty + RadiusOuter * 2)), new Point((int)ptx, (int)(pty + RadiusOuter * 2)) };
          ShapePath.AddPolygon(pts);
          break;

          }

          e.Graphics.FillPath(new SolidBrush(UseFillColor), ShapePath);
          e.Graphics.DrawPath(new Pen(UseBorderColor, ShapeBorderWidth), ShapePath);

          if (ShapeNumberShow != eShapeNumberShow.None)
          {
        if (ShapeNumberShow == eShapeNumberShow.All | (ShapeNumberShow == eShapeNumberShow.RateOnly & PaintRating == intRate + 1))
        {
          e.Graphics.DrawString((intRate + 1).ToString(), ShapeNumberFont, new SolidBrush(ShapeNumberColor), new RectangleF(ShapeNumberIndent.X + ptx, ShapeNumberIndent.Y + pty, RadiusOuter * 2, RadiusOuter * 2), sf);
        }
          }

          intRate += 1;
        }

        if (LabelShow)
        {
          int R_x = (int)(((RadiusOuter * 2) * (MaxRating)) + LabelIndent + ((ShapeGap) * MaxRating) + Padding.Left);
          if (IsPainting)
          {
        RateLabel.Text = GetLabelText(LabelTypeHover);
          }
          else
          {
        RateLabel.Text = GetLabelText(LabelTypeText);
          }
          RateLabel.Width = (this.Width - R_x);
          RateLabel.Height = (this.Height);
          RateLabel.Location = new Point(R_x, 0);
        }
    }
Пример #33
0
    public bool IsFit(Point[] points)
    {
        // Note: rigorously calculating distance(point,ellipse) is very hard...
        // overlay the regions and compare the areas, for now.
        using (GraphicsPath polygp = new GraphicsPath())
        using (GraphicsPath elligp = new GraphicsPath())
        using (Matrix m = new Matrix())
        {
            // Set up gp for stroke.
            polygp.AddPolygon(points);

            // Set up gp for ellipse.
            elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);

            m.Translate((float)cx,(float)cy);
            m.Rotate((float)th);
            elligp.Transform(m);

            // Prepare regions for area-calculation.
            using (Region xor = new Region(elligp))
            using (Region isc = new Region(elligp))
            {
                xor.Xor(polygp);
                isc.Intersect(polygp);

                float badarea = Geometry.CalculateArea(xor);
                float iscarea = Geometry.CalculateArea(isc);
                float ratio = iscarea/badarea;

                //heuristic: 10.0 seems about right.
                return (ratio > 10f);
            }
        }
    }