Exemplo n.º 1
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPolygon polygon, IAreaStyle style)
        {
            if (polygon == null || style == null)
            {
                return;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddPolygon(RenderUtil.CoordToPoint(polygon.Shell.Coordinates));
            foreach (ILinearRing l in polygon.Holes)
            {
                gp.AddPolygon(RenderUtil.CoordToPoint(l.Coordinates));
            }
            gp.CloseFigure();

            if (style.Fill != null)
            {
                RenderUtil.RenderFill(engine, graphics, gp, style.Fill);
            }

            if (style.Outline != null)
            {
                RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.AddPolygon(new Point[] { new Point(this.Width / 2, 0), new Point(0, this.Width / 2), new Point(this.Width, this.Width / 2) });
            myPath.AddPolygon(new Point[] { new Point(0, this.Width / 2), new Point(this.Width, this.Width / 2), new Point(this.Width / 2, this.Width) });
            Region myRegion = new Region(myPath);

            this.Region = myRegion;
        }
Exemplo n.º 3
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPolygon polygon, IAreaStyle style)
        {
            if (polygon == null || style == null) return;

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddPolygon(RenderUtil.CoordToPoint(polygon.Shell.Coordinates));
            foreach (ILinearRing l in polygon.Holes)
                gp.AddPolygon(RenderUtil.CoordToPoint(l.Coordinates));
            gp.CloseFigure();

            if (style.Fill != null) RenderUtil.RenderFill(engine, graphics, gp, style.Fill);

            if (style.Outline != null) RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
        }
Exemplo n.º 4
0
 private void Form1_Load(object sender, EventArgs e)
 {
     // Cut the form
     System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
     myPath.AddPolygon(new Point[] { new Point(0, 0), new Point(0, this.Height), new Point(this.Width, 0) });
     Region myRegion = new Region(myPath); this.Region = myRegion;
 }
Exemplo n.º 5
0
        public FieldButton(Point[] size, FIELDTYPE type)
        {
            //set triangle
            triangle = size;
            //add to shape
            shape.AddPolygon(triangle);
            //get background color from type
            switch (type)
            {
            case FIELDTYPE.GRASS:
                this.BackColor = Color.LawnGreen;
                break;

            case FIELDTYPE.MOUNTAIN:
                this.BackColor = Color.LightGray;
                break;

            case FIELDTYPE.WATER:
                this.BackColor = Color.LightBlue;
                break;

            case FIELDTYPE.WOODS:
                this.BackColor = Color.ForestGreen;
                break;

            default:
                this.BackColor = Color.Black;
                break;
            }
            InitializeComponent();
        }
Exemplo n.º 6
0
        public override void Draw(Point p)
        {
            myRectangle = new Rectangle(p, mySize);

            int x0 = mySize.Width / 3;
            int x1 = mySize.Width / 3 * 2;
            int x2 = mySize.Width;

            int y0 = mySize.Height / 3;
            int y1 = mySize.Height / 3 * 2;
            int y2 = mySize.Height;

            myPoints[0]  = new Point(p.X + x0, p.Y);
            myPoints[1]  = new Point(p.X + x1, p.Y);
            myPoints[2]  = new Point(p.X + x1, p.Y + y0);
            myPoints[3]  = new Point(p.X + x2, p.Y + y0);
            myPoints[4]  = new Point(p.X + x2, p.Y + y1);
            myPoints[5]  = new Point(p.X + x1, p.Y + y1);
            myPoints[6]  = new Point(p.X + x1, p.Y + y2);
            myPoints[7]  = new Point(p.X + x0, p.Y + y2);
            myPoints[8]  = new Point(p.X + x0, p.Y + y1);
            myPoints[9]  = new Point(p.X, p.Y + y1);
            myPoints[10] = new Point(p.X, p.Y + y0);
            myPoints[11] = new Point(p.X + x0, p.Y + y0);

            gp.AddPolygon(myPoints);

            Refresh();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draws the map regions to the graphics surface. The surface must
        /// have a transform applied to it to translate the Dereth coordinate
        /// space to the image's pixel coordinate space.
        /// </summary>
        public static void DrawRegions(Graphics g, Brush regionFill, Brush innerRegionFill)
        {
            LazyLoadRegions();
            System.Drawing.Drawing2D.GraphicsPath path      = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Drawing2D.GraphicsPath innerPath = new System.Drawing.Drawing2D.GraphicsPath();

            foreach (Polygon poly in mPolygonRegions)
            {
                path.AddPolygon(poly.Points);
            }
            if (mRectangleRegions.Length > 0)
            {
                path.AddRectangles(mRectangleRegions);
            }

            foreach (Polygon innerPoly in mInnerPolygonRegions)
            {
                innerPath.AddPolygon(innerPoly.Points);
            }
            if (mInnerRectangleRegions.Length > 0)
            {
                innerPath.AddRectangles(mInnerRectangleRegions);
            }

            Region region      = new Region(path);
            Region innerRegion = new Region(innerPath);

            region.Exclude(innerRegion);

            g.FillRegion(regionFill, region);
            g.FillRegion(innerRegionFill, innerRegion);
        }
Exemplo n.º 8
0
            public void set_inner_surfaces(List <surface_store> i_inner_surfaces)
            {
                // add inner surface one after another
                for (int i = 0; i < i_inner_surfaces.Count; i++)
                {
                    if (i_inner_surfaces[i].SignedPolygonArea() > 0) // check whether the inner surface is oriented clockwise (positive area = anti-clockwise)
                    {
                        // anti-clockwise orientation detected so reverse the orientation to be clockwise
                        i_inner_surfaces[i].reverse_surface_orinetation();
                    }
                    inner_surfaces.Add(i_inner_surfaces[i]); // inner surface is clockwise
                }
                //inner_surfaces.AddRange(i_inner_surfaces);

                foreach (surface_store surf in inner_surfaces) // cycle through all the inner surfaces
                {
                    // Set the path of inner surface
                    List <PointF> temp_sur_pts = new List <PointF>();
                    foreach (edge2d ed in surf.surface_edges)
                    {
                        temp_sur_pts.Add(ed.end_pt.get_point());
                    }

                    System.Drawing.Drawing2D.GraphicsPath inner_surface = new System.Drawing.Drawing2D.GraphicsPath();
                    inner_surface.StartFigure();
                    inner_surface.AddPolygon(temp_sur_pts.ToArray());
                    inner_surface.CloseFigure();


                    // set region
                    surface_region.Exclude(inner_surface); // exclude the inner surface region
                }
            }
Exemplo n.º 9
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            var shape  = new System.Drawing.Drawing2D.GraphicsPath();
            var point1 = new Point(0, 12);
            var point2 = new Point(133, 12);
            var point3 = new Point(141, 0);
            var point4 = new Point(149, 12);
            var point5 = new Point(282, 12);
            var point6 = new Point(282, 238);
            var point7 = new Point(0, 238);

            Point[] curvePoints =
            {
                point1,
                point2,
                point3,
                point4,
                point5,
                point6,
                point7
            };

            shape.AddPolygon(curvePoints);
            this.Region = new System.Drawing.Region(shape);
        }
Exemplo n.º 10
0
        void initGraph()
        {
            BorderPoints = new System.Drawing.Point[8];

            int psetBorderClear = 7;

            BorderPoints[0].X = psetBorderClear;
            BorderPoints[0].Y = 0;
            BorderPoints[1].X = 0;
            BorderPoints[1].Y = psetBorderClear;
            BorderPoints[2].X = 0;
            BorderPoints[2].Y = this.Height - psetBorderClear;
            BorderPoints[3].X = psetBorderClear;
            BorderPoints[3].Y = this.Height;
            BorderPoints[4].X = this.Width - psetBorderClear;
            BorderPoints[4].Y = this.Height;
            BorderPoints[5].X = this.Width;
            BorderPoints[5].Y = this.Height - psetBorderClear;
            BorderPoints[6].X = this.Width;
            BorderPoints[6].Y = psetBorderClear;
            BorderPoints[7].X = this.Width - psetBorderClear;
            BorderPoints[7].Y = 0;

            System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
            shape.AddPolygon(BorderPoints);
            this.Region = new System.Drawing.Region(shape);

            BackgroundImage = new Bitmap(this.Width, this.Height);
            graphicsmain    = Graphics.FromImage(BackgroundImage);
            BorderPen       = new Pen(System.Drawing.Brushes.Black, 2);
            graphicsmain.Clear(Color.Gainsboro);
            graphicsmain.DrawPolygon(BorderPen, BorderPoints);
        }
Exemplo n.º 11
0
        private void AdjustClipRegion()
        {
            // Limit region to draw/clip
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            int x1, y1, x2, y2, x3, y3, x4, y4;

            if (start.Y < end.Y)
            {
                x1 = 2 * indent;
                y1 = 0;
                x2 = Width - 1;
                y2 = Height - 2 * indent - 1;
                x3 = Width - 2 * indent - 1;
                y3 = Height - 1;
                x4 = 0;
                y4 = 2 * indent;
            }
            else
            {
                x1 = 0;
                y1 = Height - 2 * indent - 1;
                x2 = Width - 2 * indent - 1;
                y2 = 0;
                x3 = Width - 1;
                y3 = 2 * indent;
                x4 = 2 * indent;
                y4 = Height - 1;
            }
            Point[] clipPolygon = new Point[] {
                new Point(x1, y1), new Point(x2, y2),
                new Point(x3, y3), new Point(x4, y4)
            };
            path.AddPolygon(clipPolygon);
            this.Region = new System.Drawing.Region(path);
        }
Exemplo n.º 12
0
        /// <summary>
        /// aktualisiert das Feld nodeGraphics
        /// </summary>
        private void UpdateNodeGraphics()
        {
            if ((position != null) && (inSlope != null) && (outSlope != null))
            {
                // Linien zu den Stützpunkten
                _nodeGraphics[0] = new System.Drawing.Drawing2D.GraphicsPath(new PointF[] { inSlopeAbs, position }, new byte[] { 1, 1 });
                _nodeGraphics[1] = new System.Drawing.Drawing2D.GraphicsPath(new PointF[] { outSlopeAbs, position }, new byte[] { 1, 1 });

                // Stützpunkte
                System.Drawing.Drawing2D.GraphicsPath inPoint = new System.Drawing.Drawing2D.GraphicsPath();
                inPoint.AddEllipse(inSlopeRect);
                _nodeGraphics[2] = inPoint;

                System.Drawing.Drawing2D.GraphicsPath outPoint = new System.Drawing.Drawing2D.GraphicsPath();
                // wir versuchen ein Dreieck zu zeichnen *lol*
                Vector2 dir = outSlope.Normalized;
                outPoint.AddPolygon(
                    new PointF[] {
                    (6 * dir) + outSlopeAbs,
                    (6 * dir.RotateCounterClockwise(Math.PI * 2 / 3)) + outSlopeAbs,
                    (6 * dir.RotateCounterClockwise(Math.PI * 4 / 3)) + outSlopeAbs,
                    (6 * dir) + outSlopeAbs
                });
                _nodeGraphics[3] = outPoint;
            }
        }
        private void makeRegionsFromHistGramEdges(List <Coord>[] coord_HistGramEdges, List <Region> regions)
        {
            for (int i = 0; i < coord_HistGramEdges.Length; i++)
            {
                List <Coord> coords = coord_HistGramEdges[i];
                System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
                Region myRegion = new Region();
                myGraphicsPath.Reset();

                //添家多边形点
                Point[] Points = new Point[coords.Count];
                int     j      = 0;
                foreach (Coord coord in coords)
                {
                    Point p = new Point(coord.getX(), coord.getY());
                    Points[j] = p;
                    j++;
                }
                myGraphicsPath.AddPolygon(Points);
                myRegion.MakeEmpty();
                myRegion.Union(myGraphicsPath);
                //byte[] data = myRegion.GetRegionData().Data;
                //Console.WriteLine("myRegion.data.length " + data.Length);
                regions.Add(myRegion);
            }
        }
Exemplo n.º 14
0
        public void TestPathPointSymbolizer()
        {
            var fdt = CreatingData.CreatePointFeatureDataTableFromArrays(
                CreatingData.GetRandomOrdinates(50, -180, 180), CreatingData.GetRandomOrdinates(50, -90, 90), null);
            var geometryFeatureProvider = new SharpMap.Data.Providers.FeatureProvider(fdt);
            var layer = new SharpMap.Layers.VectorLayer("randompoints", geometryFeatureProvider);
            var pps =
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(new System.Drawing.Pen(System.Drawing.Color.Red, 2),
                                                                    new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.DodgerBlue), 20);
            layer.Style.PointSymbolizer = pps;
            var map = new SharpMap.Map(new System.Drawing.Size(720, 360));
            map.Layers.Add(layer);
            map.ZoomToExtents();
            map.GetMap().Save("PathPointSymbolizer1.bmp");

            pps.Rotation = -30;
            map.GetMap().Save("PathPointSymbolizer2.bmp");

            pps.Rotation = 0f;
            pps.Offset = new System.Drawing.PointF(4, 4);
            map.GetMap().Save("PathPointSymbolizer3.bmp");

            var gpTriangle1 = new System.Drawing.Drawing2D.GraphicsPath();
            gpTriangle1.AddPolygon(new [] { new System.Drawing.Point(0, 0), new System.Drawing.Point(5, 10), new System.Drawing.Point(10, 0), new System.Drawing.Point(0, 0), });
            var gpTriangle2 = new System.Drawing.Drawing2D.GraphicsPath();
            gpTriangle2.AddPolygon(new[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(-5, -10), new System.Drawing.Point(-10, 0), new System.Drawing.Point(0, 0), });
            pps = new
                SharpMap.Rendering.Symbolizer.PathPointSymbolizer(new[]
                                                        {
                                                            new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                                                                {
                                                                    Path = gpTriangle1,
                                                                    Line =
                                                                        new System.Drawing.Pen(
                                                                        System.Drawing.Color.Red, 2),
                                                                    Fill =
                                                                        new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.DodgerBlue)
                                                                },
                                                            new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition
                                                                {
                                                                    Path = gpTriangle2,
                                                                    Line =
                                                                        new System.Drawing.Pen(
                                                                        System.Drawing.Color.DodgerBlue, 2),
                                                                    Fill =
                                                                        new System.Drawing.SolidBrush(
                                                                        System.Drawing.Color.Red)
                                                                }

                                                        }){ Rotation = 45 };

            layer.Style.PointSymbolizer = pps;
            map.GetMap().Save("PathPointSymbolizer4.bmp");
            pps.Rotation = 180;
            map.GetMap().Save("PathPointSymbolizer5.bmp");

        }
        private void NonRectangularShare_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.AddPolygon(new Point[] { new Point(0, 0), new Point(0, this.Height), new Point(this.Width, 0) });
            Region myRegion = new Region(myPath);

            this.Region = myRegion;
        }
Exemplo n.º 16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddPolygon(new Point[] { new Point(0, 0), new Point(0, this.Height), new Point(this.Width, 0) });
            Region region = new Region(path);

            this.Region = region;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Renders a polygon to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="pol">Polygon to render</param>
        /// <param name="brush">Brush used for filling (null or transparent for no filling)</param>
        /// <param name="pen">Outline pen style (null if no outline)</param>
        /// <param name="clip">Specifies whether polygon clipping should be applied</param>
        /// <param name="map">Map reference</param>
        public static void DrawPolygon(System.Drawing.Graphics g, SharpMap.Geometries.Polygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map)
        {
            if (pol.ExteriorRing == null)
            {
                return;
            }
            if (pol.ExteriorRing.Vertices.Count > 2)
            {
                //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

                //Add the exterior polygon
                if (!clip)
                {
                    gp.AddPolygon(pol.ExteriorRing.TransformToImage(map));
                }
                else
                {
                    gp.AddPolygon(clipPolygon(pol.ExteriorRing.TransformToImage(map), map.Size.Width, map.Size.Height));
                }

                //Add the interior polygons (holes)
                for (int i = 0; i < pol.InteriorRings.Count; i++)
                {
                    if (!clip)
                    {
                        gp.AddPolygon(pol.InteriorRings[i].TransformToImage(map));
                    }
                    else
                    {
                        gp.AddPolygon(clipPolygon(pol.InteriorRings[i].TransformToImage(map), map.Size.Width, map.Size.Height));
                    }
                }

                // Only render inside of polygon if the brush isn't null or isn't transparent
                if (brush != null && brush != System.Drawing.Brushes.Transparent)
                {
                    g.FillPath(brush, gp);
                }
                // Create an outline if a pen style is available
                if (pen != null)
                {
                    g.DrawPath(pen, gp);
                }
            }
        }
Exemplo n.º 18
0
 public bool contains(System.Drawing.Point p)
 {
     System.Drawing.Drawing2D.GraphicsPath myGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
     //Region myRegion=new Region();
     myGraphicsPath.Reset();
     myGraphicsPath.AddPolygon(toPoints());
     return(myGraphicsPath.IsVisible(p));
 }
Exemplo n.º 19
0
        private void Form2_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            Point[] pts1 = { new Point(this.Width / 2, 0), new Point(this.Width, this.Height / 2), new Point(this.Width / 2, this.Height), new Point(0, this.Height / 2), };

            myPath.AddPolygon(pts1);

            this.Region = new Region(myPath);
        }
        public void Change_RetanglePicBox_To_TrianglePicBox(ref PictureBox p, int triangleTop)
        {
            Rectangle r = new Rectangle(0, 0, p.Width, p.Height);

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            switch (triangleTop)
            {
            case 1:     //top
                gp.AddPolygon(new Point[] {
                    new Point(r.Width / 2, 0),
                    new Point(r.Width, r.Height),
                    new Point(0, r.Height)
                });
                p.Region = new Region(gp);
                break;

            case 2:     // right
                gp.AddPolygon(new Point[] {
                    new Point(0, 0),
                    new Point(r.Width, r.Height / 2),
                    new Point(0, r.Height)
                });
                p.Region = new Region(gp);
                break;

            case 3:     // bot
                gp.AddPolygon(new Point[] {
                    new Point(0, 0),
                    new Point(r.Width, 0),
                    new Point(r.Width / 2, r.Height)
                });
                p.Region = new Region(gp);
                break;

            case 4:     // left
                gp.AddPolygon(new Point[] {
                    new Point(0, r.Height / 2),
                    new Point(r.Width, 0),
                    new Point(r.Width, r.Height)
                });
                p.Region = new Region(gp);
                break;
            }
        }
Exemplo n.º 21
0
        private void GetInsidePixel(out int ax, out int ay)
        {
            /*
             * // Find a random point "inside" the polygon (assume it only have one simple region)
             * // Average X and average Y
             * ax = ay = 0;
             * for (int i = 0; i < Points.Count; i++)
             * {
             *  ax += Points[i].X;
             *  ay += Points[i].Y;
             * }
             * ax /= Points.Count;
             * ay /= Points.Count;
             */

            // Or use a library function to get inside
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddPolygon(Points.ToArray());
            int n = Points.Count;

            for (int i = 0; i < n; i++)
            {
                int x = Points[i].X + Points[(i + 1) % n].X + Points[(i + 2) % n].X;
                int y = Points[i].Y + Points[(i + 1) % n].Y + Points[(i + 2) % n].Y;
                x /= 3; y /= 3;
                if (path.IsVisible(x, y))
                {
                    ax = x;
                    ay = y;
                    return;
                }
            }

            // The function should stop here
            // If can't find (unlucky) :) brute force all pixel
            int maxX = GetMaxX();
            int minX = GetMinX();
            int maxY = GetMaxY();
            int minY = GetMinY();

            for (int x = minX; x < maxX; x++)
            {
                for (int y = minY; y < maxY; y++)
                {
                    if (path.IsVisible(x, y))
                    {
                        ax = x;
                        ay = y;
                        return;
                    }
                }
            }

            // This line will never be called
            ax = 0; ay = 0;
        }
Exemplo n.º 22
0
        private void ParentForm_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath romb = new System.Drawing.Drawing2D.GraphicsPath();
            romb.AddPolygon(new Point[] { new Point(50, 500),
                                          new Point(550, 100),
                                          new Point(1100, 500),
                                          new Point(550, 900) });
            Region myRegion = new Region(romb);

            this.Region = myRegion;
        }
Exemplo n.º 23
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.AddPolygon(new Point[] { new Point(0, 0),
                                            new Point(0, this.Height),
                                            new Point(this.Width, 0) });
            Region myRegion = new Region(myPath);

            this.Region = myRegion;
            Form1 main = this.Owner as Form1;
        }
Exemplo n.º 24
0
        private void AboutEI_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            // треугольная форма
            myPath.AddPolygon(new Point[] { new Point(7, 7), new Point(this.Width - 7, 7), new Point(this.Width - 7, this.Height - 8) });

            Region myRegion = new Region(myPath);

            this.Region = myRegion;
            richTextBox1.AppendText("                                                      Ручной блокнот создан Archmage『 Enderian 』\n                                                                    (Малахов Игорь Дмитриевич)\n                                                           Могут сделать все по желанию,\n                                                                             помним про бонус \n                                                                                       Хейтеры скажут фотошоп,\n                                                                                                              я скажу - \n                                                                                           плагиат оригинального\n                                                                                                          блокнота =D");
        }
Exemplo n.º 25
0
        private void GreenPeace_Load(object sender, EventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath myPath =
                new System.Drawing.Drawing2D.GraphicsPath();
            myPath.AddPolygon(new Point[] { new Point(105, 245),
                                            new Point(235, 105),
                                            new Point(365, 245), new Point(235, 385) });
            Region myRegion = new Region(myPath);

            this.Region = myRegion;
        }
        /// <summary>
        /// 未知方法,(现已废弃,替代方法 PointInPolygon)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="pointColl"></param>
        /// <returns></returns>
        public static bool IsVisible_GraphicsPath(Point point, List <Point> pointColl)
        {
            System.Drawing.Drawing2D.GraphicsPath path       = new System.Drawing.Drawing2D.GraphicsPath();
            List <System.Drawing.Point>           pathPoints = new List <System.Drawing.Point>();

            foreach (var pathPoint in pointColl)
            {
                pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y)));
            }
            path.AddPolygon(pathPoints.ToArray());
            path.CloseFigure();
            return(path.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y))));
        }
Exemplo n.º 27
0
        public override void Draw(Point p)
        {
            myRectangle = new Rectangle(p, mySize);

            myPointArray[0] = new Point(p.X, myRectangle.Top + myRectangle.Height / 2);                     //left
            myPointArray[1] = new Point(p.X + myRectangle.Width / 2, myRectangle.Top);                      //top
            myPointArray[2] = new Point(p.X + myRectangle.Width, myRectangle.Top + myRectangle.Height / 2); //right
            myPointArray[3] = new Point(p.X + myRectangle.Width / 2, myRectangle.Top + myRectangle.Height); //bottom

            gp.AddPolygon(myPointArray);

            Refresh();
        }
Exemplo n.º 28
0
        public override void Draw(Point p)
        {
            myRectangle = new Rectangle(p, mySize);

            myPointArray[0] = new Point(p.X, myRectangle.Top + myRectangle.Height / 2);                                                               //left
            myPointArray[1] = new Point(p.X + myRectangle.Width / 2, myRectangle.Top - myDiagram.DefaultDecisionHeightIncrease);                      //top
            myPointArray[2] = new Point(p.X + myRectangle.Width, myRectangle.Top + myRectangle.Height / 2);                                           //right
            myPointArray[3] = new Point(p.X + myRectangle.Width / 2, myRectangle.Top + myRectangle.Height + myDiagram.DefaultDecisionHeightIncrease); //bottom

            gp.AddPolygon(myPointArray);

            Refresh();
        }
Exemplo n.º 29
0
 public FieldButton()
 {
     //set triangle for button shape
     triangle = new Point[3] {
         new Point(0, 0), new Point(100, 0), new Point(50, 86)
     };
     //set up shape and add triangle
     shape = new System.Drawing.Drawing2D.GraphicsPath();
     shape.AddPolygon(triangle);
     //set default background
     this.BackColor = Color.Black;
     InitializeComponent();
 }
Exemplo n.º 30
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            System.Drawing.Point[] DropPoints  = new System.Drawing.Point[] { new Point(0, 0), new Point(11, 0), new Point(5, 6) };
            System.Drawing.Point[] ClosePoints = new System.Drawing.Point[] { new Point(0, 0), new Point(2, 0), new Point(5, 3), new Point(8, 0), new Point(10, 0), new Point(6, 4), new Point(10, 8), new Point(8, 8), new Point(5, 5), new Point(2, 8), new Point(0, 8), new Point(4, 4) };
            Rectangle rec = new Rectangle();

            rec.Size = new Size(this.Width - 1, this.Height - 1);
            if (m_hot)
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                e.Graphics.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, this.Height), Helper.RenderColors.ControlButtonBackHighColor(m_RenderMode, m_BackHighColor), Helper.RenderColors.ControlButtonBackLowColor(m_RenderMode, m_BackLowColor)), rec);
                e.Graphics.DrawRectangle(new Pen(Helper.RenderColors.ControlButtonBorderColor(m_RenderMode, m_BorderColor)), rec);
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
            }
            System.Drawing.Drawing2D.GraphicsPath g = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Drawing2D.Matrix       m = new System.Drawing.Drawing2D.Matrix();
            int x = (int)((this.Width - 11) / 2);
            int y = (int)((this.Height - 11) / 2 + 1);

            if (m_style == ButtonStyle.Drop)
            {
                e.Graphics.FillRectangle(new SolidBrush(ForeColor), x, y, 11, 2);
                g.AddPolygon(DropPoints);
                m.Translate(x, y + 3);
                g.Transform(m);
                e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints);
            }
            else
            {
                g.AddPolygon(ClosePoints);
                m.Translate(x, y);
                g.Transform(m);
                e.Graphics.DrawPolygon(new Pen(ForeColor), g.PathPoints);
                e.Graphics.FillPolygon(new SolidBrush(ForeColor), g.PathPoints);
            }
            g.Dispose();
            m.Dispose();
        }
Exemplo n.º 31
0
        /// <summary>
        /// Calculates the points in a hexagon and makes it a button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ButtonPainter(object sender, PaintEventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsPath buttonPath =
                new System.Drawing.Drawing2D.GraphicsPath();
            Button hexagonButton = sender as Button;

            System.Drawing.Rectangle newRectangle = hexagonButton.ClientRectangle;
            e.Graphics.DrawPolygon(Pens.Black, Math.GetPoints(formatting.ButtonHeight, formatting.ButtonWidth));

            // Create a hexagon within the new rectangle.
            buttonPath.AddPolygon(Math.GetPoints(formatting.ButtonHeight, formatting.ButtonWidth));
            // Hexagon region.
            hexagonButton.Region = new System.Drawing.Region(buttonPath);
        }
Exemplo n.º 32
0
        private void GREENPEACE_Load(object sender, EventArgs e)
        {
            Point[] myRombus =
            {
                new Point(0,               this.Width / 2),
                new Point(this.Height / 2,              0),
                new Point(this.Height,     this.Width / 2),
                new Point(this.Height / 2, this.Width)
            };
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.AddPolygon(myRombus);
            Region myRegion = new Region(myPath);

            this.Region = myRegion;
        }
Exemplo n.º 33
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="points">points of the polygon</param>
 /// <param name="rType">Range Type</param>
 public RangePolygon(PointF[] points, RANGETYPE rType,int id)
 {
     this.rangeType = rType;
     this.polygonPoints = points;
     if(rType == RANGETYPE.TOP)
     {
         fillColor=Color.FromArgb(15,0,255,0);
     }
     else
     {
         fillColor=Color.FromArgb(15,255,0,0);
     }
     this.polygonID = id;
     graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
     graphicsPath.AddPolygon(polygonPoints);
 }
Exemplo n.º 34
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="points">points of the polygon</param>
 /// <param name="rType">Range Type</param>
 public RangePolygon(PointF[] points, RANGETYPE rType, int id)
 {
     this.rangeType     = rType;
     this.polygonPoints = points;
     if (rType == RANGETYPE.TOP)
     {
         fillColor = Color.FromArgb(15, 0, 255, 0);
     }
     else
     {
         fillColor = Color.FromArgb(15, 255, 0, 0);
     }
     this.polygonID = id;
     graphicsPath   = new System.Drawing.Drawing2D.GraphicsPath();
     graphicsPath.AddPolygon(polygonPoints);
 }
Exemplo n.º 35
0
        public void Start()
        {
            if (m_fixtures.Count == 0) return;
            MainForm.ProgressStartMarquee("Sorting fixtures ....");

            // Create paths out of the rivers
            Dictionary<WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath> riverPaths = new Dictionary<WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath>();
            foreach (WaterConfiguration rConf in rivers)
            {
                System.Drawing.Drawing2D.GraphicsPath riverPath = new System.Drawing.Drawing2D.GraphicsPath();
                System.Drawing.PointF[] points = rConf.GetCoordinates().Select(c => new System.Drawing.PointF(Convert.ToSingle(c.X * zoneConfiguration.MapScale), Convert.ToSingle(c.Y * zoneConfiguration.MapScale))).ToArray();
                riverPath.AddPolygon(points);
                riverPaths.Add(rConf, riverPath);
            }

            foreach (DrawableFixture model in m_fixtures)
            {
                // ignote the model if there are no polygons
                if(model.ProcessedPolygons.Count() == 0) continue;

                // UI options
                if (!DrawTrees && (model.IsTree || model.IsTreeCluster))
                {
                    continue;
                }

                if (!DrawFixtures && !(model.IsTree || model.IsTreeCluster))
                {
                    continue;
                }

                if (!DrawTreesAsImages && (model.IsTree || model.IsTreeCluster))
                {
                    model.RendererConf = FixtureRendererConfigurations.GetRendererById("TreeShaded");
                }

                double modelCenterX = zoneConfiguration.ZoneCoordinateToMapCoordinate(model.FixtureRow.X);
                double modelCenterY = zoneConfiguration.ZoneCoordinateToMapCoordinate(model.FixtureRow.Y);

                // Check if on river or not
                int riverHeight = 0;
                foreach (KeyValuePair<WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath> river in riverPaths)
                {
                    if (river.Value.IsVisible(Convert.ToSingle(modelCenterX), Convert.ToSingle(modelCenterY)))
                    {
                        riverHeight = river.Key.Height;
                        break;
                    }
                }

                if (riverHeight == 0 || (riverHeight != 0 && model.FixtureRow.Z > riverHeight))
                {
                    m_fixturesAboveWater.Add(model);
                }
                else
                {
                    m_fixturesUnderWater.Add(model);
                }
            }

            m_fixturesAboveWater = m_fixturesAboveWater.OrderBy(f => f.CanvasZ).ToList();
            m_fixturesUnderWater = m_fixturesUnderWater.OrderBy(f => f.CanvasZ).ToList();

            // Dispose all paths
            riverPaths.Select(d => d.Value).ToList().ForEach(r => r.Dispose());

            MainForm.ProgressReset();
        }
Exemplo n.º 36
0
        //private static bool rectIntersectWithPolygon(RectangleF rect, Path path)
        //{
        //    System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath();
        //    temp.Reset();
        //    List<PointF> points = default(List<PointF>);
        //    foreach(object i in path.content)
        //    {
        //        if(i is Node)
        //        {
        //            Node node = (Node)i;
        //            if(rect.Contains((float)node.lon, (float)node.lat))
        //                return true;
        //            points.Add(new PointF((float)node.lon, (float)node.lat));
        //        }
        //    }
        //    temp.AddPolygon(points.ToArray());
        //    Region myRegion = new Region();
        //    myRegion.MakeEmpty();
        //    myRegion.Union(temp);
        //    PointF tempPt = new PointF();
        //    tempPt.X = rect.X;
        //    tempPt.Y = rect.Y;
        //    if(pointInPolygon(tempPt, myRegion))
        //        return true;
        //    tempPt.X = rect.X + rect.Width;
        //    tempPt.Y = rect.Y;
        //    if(pointInPolygon(tempPt, myRegion))
        //        return true;
        //    tempPt.X = rect.X;
        //    tempPt.Y = rect.Y + rect.Height;
        //    if(pointInPolygon(tempPt, myRegion))
        //        return true;
        //    tempPt.X = rect.X + rect.Width;
        //    tempPt.Y = rect.Y + rect.Height;
        //    if(pointInPolygon(tempPt, myRegion))
        //        return true;
        //    return false;
        //}
        private static bool intersectPolygon(RectangleF rect, Path path)
        {
            System.Drawing.Drawing2D.GraphicsPath temp = new System.Drawing.Drawing2D.GraphicsPath();
            temp.Reset();

            //            List<PointF> points = default(List<PointF>);
            List<PointF> points = new List<PointF>();
            foreach (object i in path.content)
            {
                if (i is Node)
                {
                    Node node = (Node)i;

                    if (rect.Contains((float)node.lon, (float)node.lat))
                        return true;

                    points.Add(new PointF((float)node.lon, (float)node.lat));

                }
            }

            if (points.Count >= 3)
            {
                temp.AddPolygon(points.ToArray());
            }
            else if (points.Count == 2)
            {
                temp.AddLine(points[0], points[1]);
            }

            Region myRegion = new Region();
            myRegion.MakeEmpty();
            myRegion.Union(temp);

            PointF tempPt = new PointF();
            tempPt.X = rect.X;
            tempPt.Y = rect.Y;
            if (pointInPolygon(tempPt, myRegion))
                return true;

            tempPt.X = rect.X + rect.Width;
            tempPt.Y = rect.Y;
            if (pointInPolygon(tempPt, myRegion))
                return true;

            tempPt.X = rect.X;
            tempPt.Y = rect.Y + rect.Height;
            if (pointInPolygon(tempPt, myRegion))
                return true;

            tempPt.X = rect.X + rect.Width;
            tempPt.Y = rect.Y + rect.Height;
            if (pointInPolygon(tempPt, myRegion))
                return true;

            return false;
        }
Exemplo n.º 37
0
 void drawQuadTex(Graphics g, Bitmap tex, PointF[] quad) {
     System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
     gp.AddPolygon(new PointF[] { quad[0], quad[1], quad[3] });
     g.SetClip(gp, System.Drawing.Drawing2D.CombineMode.Replace);
     g.DrawImage(tex, new PointF[] { quad[0], quad[1], quad[3] });
     gp.Reset();
     gp.AddPolygon(new PointF[] { quad[2], quad[3], quad[1] });
     g.SetClip(gp, System.Drawing.Drawing2D.CombineMode.Replace);
     tex.RotateFlip(RotateFlipType.Rotate180FlipNone);
     g.DrawImage(tex, new PointF[] { quad[2], quad[3], quad[1] });
     tex.RotateFlip(RotateFlipType.Rotate180FlipNone);
     gp.Dispose();
     g.ResetClip();
 }
Exemplo n.º 38
0
        /// <summary>
        /// Analyzuje pole vertexů jako polygon a zjistí jeho geometrický střed (centroid), šířku a výšku
        /// </summary>
        /// <param name="Vertices">Pole vertexů</param>
        /// <returns>Výsledek analýzy polygonu</returns>
        public static GeometryDescriptor AnalyzeVertexGroup(PointF[] Vertices)
        {
            if (Vertices.Length <= 1)
                throw new ArgumentException();

            GeometryDescriptor Description = new GeometryDescriptor(Vertices);
            Description.FrontalArea = PolygonArea(Vertices);

            for (int i = 0,j = 0; i < Vertices.Length; i++)
            {
                j = (i + 1) % Vertices.Length;
                Description.Centroid.X += (Vertices[i].X + Vertices[j].X) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
                Description.Centroid.Y += (Vertices[i].Y + Vertices[j].Y) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
            }

            Description.ConvexHull = ConvexHull.GetConvexHull(Vertices);
            Description.Centroid.X /= (float)(Description.FrontalArea * 6);
            Description.Centroid.Y /= (float)(Description.FrontalArea * 6);

            using (System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath())
            {
                p.AddPolygon(Vertices);
                RectangleF r = p.GetBounds();

                Description.Width = r.Width;
                Description.Height = r.Height;
            }

            return Description;
        }
Exemplo n.º 39
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPoint point, IPointStyle style)
        {
            if (point == null || style == null)
                return;

            if (style.Type == global::LittleSharpRenderEngine.Style.Point.PointType.Symbol)
            {
                return;
            }
            else
            {
                int w = style.Size.Width / 2;
                int h = style.Size.Height / 2;
                System.Drawing.Point[] points;

                switch (style.Type)
                {
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Circle:
                        int pc = (int)Math.Max(8, Math.Log10(Math.Max(w, h)));
                        points = new System.Drawing.Point[pc + 1];

                        double fr = (2*Math.PI) / pc;

                        for (int i = 0; i < pc; i++)
                            points[i] = new System.Drawing.Point((int)(Math.Cos(fr * i) * w + point.X), (int)(Math.Sin(fr * i) * h + point.Y));
                        points[pc] = points[0];
                        break;
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Square:
                        points = new System.Drawing.Point[] 
                                {
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y - h),
                                };
                        break;
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Triangle:
                        points = new System.Drawing.Point[] 
                                {
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                };
                        break;
                    default:
                        return;
                }

                //TODO: Apply rotation
                if (style.Type != global::LittleSharpRenderEngine.Style.Point.PointType.Circle)
                {
                }

                //Apply offset
                for (int i = 0; i < points.Length; i++)
                {
                    points[i].X += (w - style.Center.X);
                    points[i].Y += (h - style.Center.Y);
                }

                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddPolygon(points);
                gp.CloseFigure();

                if (style.Fill != null)
                    RenderUtil.RenderFill(engine, graphics, gp, style.Fill);

                if (style.Outline != null)
                    RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
            }
        }
Exemplo n.º 40
0
        /*******************************/
        /// <summary>
        /// Creates a GraphicsPath from two Int Arrays with a specific number of points.
        /// </summary>
        /// <param name="xPoints">Int Array to set the X points of the GraphicsPath</param>
        /// <param name="yPoints">Int Array to set the Y points of the GraphicsPath</param>
        /// <param name="pointsNumber">Number of points to add to the GraphicsPath</param>
        /// <returns>A new GraphicsPath</returns>
        public static System.Drawing.Drawing2D.GraphicsPath CreateGraphicsPath(int[] xPoints, int[] yPoints, int pointsNumber)
        {
            System.Drawing.Drawing2D.GraphicsPath tempGraphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
            if (pointsNumber == 2)
                tempGraphicsPath.AddLine(xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
            else
            {
                System.Drawing.Point[] tempPointArray = new System.Drawing.Point[pointsNumber];
                for (int index = 0; index < pointsNumber; index++)
                    tempPointArray[index] = new System.Drawing.Point(xPoints[index], yPoints[index]);

                tempGraphicsPath.AddPolygon(tempPointArray);
            }
            return tempGraphicsPath;
        }
Exemplo n.º 41
0
        /// <summary>
        /// Renders a polygon to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="pol">Polygon to render</param>
        /// <param name="brush">Brush used for filling (null or transparent for no filling)</param>
        /// <param name="pen">Outline pen style (null if no outline)</param>
        /// <param name="clip">Specifies whether polygon clipping should be applied</param>
        /// <param name="map">Map reference</param>
        public static void DrawPolygon(System.Drawing.Graphics g, SharpMap.Geometries.Polygon pol, System.Drawing.Brush brush, System.Drawing.Pen pen, bool clip, SharpMap.Map map)
        {
            if (pol.ExteriorRing == null)
                return;
            if (pol.ExteriorRing.Vertices.Count > 2)
            {
                //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

                //Add the exterior polygon
                if (!clip)
                    gp.AddPolygon(pol.ExteriorRing.TransformToImage(map));
                else
                    gp.AddPolygon(clipPolygon(pol.ExteriorRing.TransformToImage(map), map.Size.Width, map.Size.Height));

                //Add the interior polygons (holes)
                for (int i = 0; i < pol.InteriorRings.Count; i++)
                    if (!clip)
                        gp.AddPolygon(pol.InteriorRings[i].TransformToImage(map));
                    else
                        gp.AddPolygon(clipPolygon(pol.InteriorRings[i].TransformToImage(map), map.Size.Width, map.Size.Height));

                // Only render inside of polygon if the brush isn't null or isn't transparent
                if (brush != null && brush != System.Drawing.Brushes.Transparent)
                    g.FillPath(brush, gp);
                // Create an outline if a pen style is available
                if (pen != null)
                    g.DrawPath(pen, gp);
            }
        }
Exemplo n.º 42
0
        /// <summary>
        /// aktualisiert das Feld nodeGraphics
        /// </summary>
        private void UpdateNodeGraphics()
        {
            if ((position != null) && (inSlope != null) && (outSlope != null))
                {
                // Linien zu den Stützpunkten
                _nodeGraphics[0] = new System.Drawing.Drawing2D.GraphicsPath(new PointF[] { inSlopeAbs, position }, new byte[] { 1, 1 });
                _nodeGraphics[1] = new System.Drawing.Drawing2D.GraphicsPath(new PointF[] { outSlopeAbs, position }, new byte[] { 1, 1 });

                // Stützpunkte
                System.Drawing.Drawing2D.GraphicsPath inPoint = new System.Drawing.Drawing2D.GraphicsPath();
                inPoint.AddEllipse(inSlopeRect);
                _nodeGraphics[2] = inPoint;

                System.Drawing.Drawing2D.GraphicsPath outPoint = new System.Drawing.Drawing2D.GraphicsPath();
                // wir versuchen ein Dreieck zu zeichnen *lol*
                Vector2 dir = outSlope.Normalized;
                outPoint.AddPolygon(
                    new PointF[] {
                        (6*dir) + outSlopeAbs,
                        (6*dir.RotateCounterClockwise(Math.PI * 2 / 3)) + outSlopeAbs,
                        (6*dir.RotateCounterClockwise(Math.PI * 4 / 3)) + outSlopeAbs,
                        (6*dir) + outSlopeAbs
                    });
                _nodeGraphics[3] = outPoint;
                }
        }
Exemplo n.º 43
0
        private double Area(BindableRect rect1)
        {
            System.Drawing.PointF[] vertices = new System.Drawing.PointF[] {
            rect1.BottomLeft.ToPointF(),
            rect1.TopLeft.ToPointF(),
            rect1.TopRight.ToPointF(),
            rect1.BottomRight.ToPointF()};

              var rectangle = new System.Drawing.Drawing2D.GraphicsPath();
              rectangle.AddPolygon(vertices);
              var region = new System.Drawing.Region(rectangle);

              var rects = region.GetRegionScans(new System.Drawing.Drawing2D.Matrix());
              float area = 0;
              foreach (var rc in rects)
            area += rc.Width * rc.Height;
              return area;
        }
Exemplo n.º 44
0
        private double AreaMiss(BindableRect rect1, BindableRect rect2)
        {
            System.Drawing.PointF[] vertices1 = new System.Drawing.PointF[] {
            rect1.BottomLeft.ToPointF(),
            rect1.TopLeft.ToPointF(),
            rect1.TopRight.ToPointF(),
            rect1.BottomRight.ToPointF()};
              var rectangle1 = new System.Drawing.Drawing2D.GraphicsPath();
              rectangle1.AddPolygon(vertices1);

              System.Drawing.PointF[] vertices2 = new System.Drawing.PointF[] {
            rect2.BottomLeft.ToPointF(),
            rect2.TopLeft.ToPointF(),
            rect2.TopRight.ToPointF(),
            rect2.BottomRight.ToPointF()};
              var rectangle2 = new System.Drawing.Drawing2D.GraphicsPath();
              rectangle2.AddPolygon(vertices2);

              var region = new System.Drawing.Region(rectangle1);
              region.Complement(rectangle2);

              var rects = region.GetRegionScans(new System.Drawing.Drawing2D.Matrix());
              float area = 0;
              foreach (var rc in rects)
            area += rc.Width * rc.Height;
              return area;
        }
Exemplo n.º 45
0
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int i;
            double w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
            this.ForeColor = Color.Black;
            Brush brosse =new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            double deltax,deltay,voldeltax,voldeltay;
            double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1=new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();

            PointF[] points = new PointF[4] ;
               double angle=0,norme=0;
            double sinx = 0, cosx = 1;
            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {

                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));

                    p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
                    p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
                    p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
                    p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
                    p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
                    p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
                    p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
                    p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);

                    System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;

                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }

                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }

            }
            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
            {
                if (projet.reseaux[nproj].nodes[i].i != 0)
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
                }
            }*/
        }