AddRectangles() public method

public AddRectangles ( Rectangle rects ) : void
rects Rectangle
return void
Exemplo n.º 1
0
        public MapTimelineControl()
        {
            this.m_mtsSeek = new MapTimelineSeekButton();

            this.TimelineButtons = new List<MapObject>();

            GraphicsPath gpButtonPath = new GraphicsPath();
            gpButtonPath.AddLines(new Point[] { new Point(0, 6), new Point(6, 12), new Point(6, 6), new Point(12, 12), new Point(12, 0), new Point(6, 6), new Point(6, 0), new Point(0, 6) });
            gpButtonPath.CloseFigure();
            MapTimelineControlButton mtbButton = new MapTimelineControlButton(gpButtonPath, MapTimelineControlButtonType.Rewind);
            mtbButton.TimelineControlButtonClicked += new MapTimelineControlButton.TimelineControlButtonClickedHandler(mtbButton_TimelineControlButtonClicked);
            this.TimelineButtons.Add(mtbButton);

            gpButtonPath = new GraphicsPath();
            gpButtonPath.AddRectangles(new Rectangle[] { new Rectangle(0, 0, 4, 12), new Rectangle(8, 0, 4, 12) });
            mtbButton = new MapTimelineControlButton(gpButtonPath, MapTimelineControlButtonType.Pause);
            mtbButton.TimelineControlButtonClicked += new MapTimelineControlButton.TimelineControlButtonClickedHandler(mtbButton_TimelineControlButtonClicked);
            this.TimelineButtons.Add(mtbButton);

            gpButtonPath = new GraphicsPath();
            gpButtonPath.AddLines(new Point[] { new Point(1, 0), new Point(1, 12), new Point(9, 6), new Point(1, 0) });
            gpButtonPath.CloseFigure();
            mtbButton = new MapTimelineControlButton(gpButtonPath, MapTimelineControlButtonType.Play);
            mtbButton.ForegroundColour = Color.LightSeaGreen;
            mtbButton.TimelineControlButtonClicked += new MapTimelineControlButton.TimelineControlButtonClickedHandler(mtbButton_TimelineControlButtonClicked);
            this.TimelineButtons.Add(mtbButton);

            gpButtonPath = new GraphicsPath();
            gpButtonPath.AddLines(new Point[] { new Point(0, 0), new Point(0, 12), new Point(6, 6), new Point(6, 12), new Point(12, 6), new Point(6, 0), new Point(6, 6), new Point(0, 0) });
            gpButtonPath.CloseFigure();
            mtbButton = new MapTimelineControlButton(gpButtonPath, MapTimelineControlButtonType.FastForward);
            mtbButton.TimelineControlButtonClicked += new MapTimelineControlButton.TimelineControlButtonClickedHandler(mtbButton_TimelineControlButtonClicked);
            this.TimelineButtons.Add(mtbButton);

            this.SelectedButtonType = MapTimelineControlButtonType.Play;
            this.m_flControlChangeSpeed = 2.0F;
        }
Exemplo n.º 2
0
		public void StartClose_AddRectangles ()
		{
			GraphicsPath path = new GraphicsPath ();
			path.AddLine (1, 1, 2, 2);
			path.AddRectangles (new RectangleF[2] {
				new RectangleF (10, 10, 20, 20),
				new RectangleF (20, 20, 10, 10) });
			path.AddLine (10, 10, 20, 20);
			byte[] types = path.PathTypes;
			// check first types
			Assert.AreEqual (0, types[0], "start/Line");
			Assert.AreEqual (0, types[2], "start/Rectangles");
			// check last types
			Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
			Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
			Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
		}
Exemplo n.º 3
0
		public void AddRectangles_SamePoint ()
		{
			Rectangle r1 = new Rectangle (1, 1, 0, 0);
			Rectangle r2 = new Rectangle (1, 1, 1, 1);
			Rectangle r3 = new Rectangle (1, 2, 1, 1);

			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles (new Rectangle[] { r1, r2, r3 });
			Assert.AreEqual (8, gp.PointCount, "1-PointCount");
			// first rect is ignore, then all other 2x4 (8) points are present, no compression
		}
Exemplo n.º 4
0
		public void AddRectangles_Two ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles (new RectangleF[2] {
				new RectangleF (1f, 1f, 2f, 2f),
				new RectangleF (2f, 2f, 1f, 1f) } );
			RectangleF rect = gp.GetBounds ();
			Assert.AreEqual (1f, rect.X, "Bounds.X");
			Assert.AreEqual (1f, rect.Y, "Bounds.Y");
			Assert.AreEqual (2f, rect.Width, "Bounds.Width");
			Assert.AreEqual (2f, rect.Height, "Bounds.Height");
			// second rectangle is completely within the first one
			CheckRectangle (gp, 8);
		}
Exemplo n.º 5
0
		public void AddRectangles_Float ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
			CheckRectangle (gp, 4);
		}
Exemplo n.º 6
0
		public void AddRectangles_Float_Empty ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles ( new RectangleF[0]);
			CheckRectangle (gp, 4);
		}
Exemplo n.º 7
0
		public void AddRectangles_Float_Null ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles ((RectangleF[]) null);
		}
Exemplo n.º 8
0
		public void AddRectangles_RectangleArr()
		{
			path = new GraphicsPath();
			Rectangle [] rectangles = new Rectangle [] {new Rectangle (50, 50, 400, 80),
														new Rectangle (150, 150, 100, 400),
														new Rectangle (0, 0, 200, 480),
														new Rectangle (450, 450, 40, 80)};
			path.AddRectangles (rectangles);

			Assert.AreEqual (16, path.PointCount);
			
			PointF [] expectedPoints = new PointF [] {	new PointF(50f, 50f), 
														new PointF(450f, 50f), 
														new PointF(450f, 130f), 
														new PointF(50f, 130f), 
														new PointF(150f, 150f), 
														new PointF(250f, 150f), 
														new PointF(250f, 550f), 
														new PointF(150f, 550f), 
														new PointF(0f, 0f), 
														new PointF(200f, 0f), 
														new PointF(200f, 480f), 
														new PointF(0f, 480f), 
														new PointF(450f, 450f), 
														new PointF(490f, 450f), 
														new PointF(490f, 530f), 
														new PointF(450f, 530f)};
			
			for(int i = 0; i < path.PointCount; i++) {
				DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]);
			}

			byte [] expectedTypes = new byte [] {	(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath),
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath)};

			for (int i=0; i < expectedTypes.Length; i++) {
				Assert.AreEqual (expectedTypes [i], path.PathTypes [i]);
			}	

			t.Graphics.DrawPath (p, path);
			t.Show ();
			//t.AssertCompare ();
		}
Exemplo n.º 9
0
		static private GraphicsPath Rectangles ()
		{
			GraphicsPath path = new GraphicsPath ();
			path.AddRectangles (new Rectangle[2] {
				new Rectangle (20, 20, 100, 100),
				new Rectangle (100, 100, 20, 20)
				});
			return path;
		}
Exemplo n.º 10
0
        private void AddRectangles2(Graphics g)
        {
            // Adds a pattern of rectangles to a GraphicsPath object.
            GraphicsPath myPath = new GraphicsPath();
            RectangleF[] pathRects =
            {
                new RectangleF(20,20,100,200),
                new RectangleF(40,40,120,220),
                new RectangleF(60,60,240,140)
            };
            myPath.AddRectangles(pathRects);

            // Draw the path to the screen.
            Pen myPen = new Pen(Color.Black, 2);
            g.DrawPath(myPen, myPath);
        }
Exemplo n.º 11
0
        private static void CalculateLabelAroundOnLineString(SharpMap.Geometries.LineString line, ref BaseLabel label, Map map, System.Drawing.Graphics g, System.Drawing.SizeF textSize)
        {
            IList<SharpMap.Geometries.Point> sPoints = line.Vertices;

            // only get point in enverlop of map
            Collection<System.Drawing.PointF> colPoint = new Collection<System.Drawing.PointF>();
            bool bCheckStarted = false;
            for (int j = 0; j < sPoints.Count; j++)
            {
                if (map.Envelope.Grow(map.PixelSize * 10).Contains(sPoints[j]))
                {
                    //points[j] = map.WorldToImage(sPoints[j]);
                    colPoint.Add(map.WorldToImage(sPoints[j]));
                    bCheckStarted = true;
                }
                else if (bCheckStarted == true)
                {
                    // fix bug curved line out of map in center segment of line
                    break;
                }
            }

            if (colPoint.Count > 1)
            {
                label.TextOnPathLabel = new SharpMap.Rendering.TextOnPath();
                switch (label.Style.HorizontalAlignment)
                {
                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                        label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                        break;
                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                        label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                        break;
                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                        label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        break;
                    default:
                        label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        break;
                }
                switch (label.Style.VerticalAlignment)
                {
                    case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom:
                        label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.UnderPath;
                        break;
                    case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Top:
                        label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.OverPath;
                        break;
                    case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle:
                        label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                        break;
                    default:
                        label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                        break;
                }
                int idxStartPath = 0;
                int numberPoint = colPoint.Count;
                // start Optimzes Path points                
                int step = 100;
                if (colPoint.Count >= step * 2)
                {
                    numberPoint = step * 2; ;
                    switch (label.Style.HorizontalAlignment)
                    {
                        case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                            //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                            idxStartPath = 0;
                            break;
                        case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                            //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                            idxStartPath = colPoint.Count - step;
                            break;
                        case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                            //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                            idxStartPath = (int)colPoint.Count / 2 - step;
                            break;
                        default:
                            //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                            idxStartPath = (int)colPoint.Count / 2 - step;
                            break;
                    }
                }
                // end optimize path point
                System.Drawing.PointF[] points = new System.Drawing.PointF[numberPoint];
                int count = 0;
                if (colPoint[0].X <= colPoint[colPoint.Count - 1].X)
                {
                    for (int l = idxStartPath; l < numberPoint + idxStartPath; l++)
                    {
                        points[count] = colPoint[l];
                        count++;
                    }
                }
                else
                {
                    //reverse the path                    
                    for (int k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--)
                    {
                        points[count] = colPoint[k];
                        count++;
                    }
                }
                //get text size in page units ie pixels
                float textheight = label.Style.Font.Size;
                switch (label.Style.Font.Unit)
                {
                    case System.Drawing.GraphicsUnit.Display:
                        textheight = textheight * g.DpiY / 75;
                        break;
                    case System.Drawing.GraphicsUnit.Document:
                        textheight = textheight * g.DpiY / 300;
                        break;
                    case System.Drawing.GraphicsUnit.Inch:
                        textheight = textheight * g.DpiY;
                        break;
                    case System.Drawing.GraphicsUnit.Millimeter:
                        textheight = (float)(textheight / 25.4 * g.DpiY);
                        break;
                    case System.Drawing.GraphicsUnit.Pixel:
                        //do nothing
                        break;
                    case System.Drawing.GraphicsUnit.Point:
                        textheight = textheight * g.DpiY / 72;
                        break;
                }
                System.Drawing.Font topFont = new System.Drawing.Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style);
                //
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddLines(points);

                label.TextOnPathLabel.PathColorTop = System.Drawing.Color.Transparent;
                label.TextOnPathLabel.Text = label.Text;
                label.TextOnPathLabel.LetterSpacePercentage = 90;
                label.TextOnPathLabel.FillColorTop = new System.Drawing.SolidBrush(label.Style.ForeColor);
                label.TextOnPathLabel.Font = topFont;
                label.TextOnPathLabel.PathDataTop = path.PathData;
                label.TextOnPathLabel.Graphics = g;
                //label.TextOnPathLabel.ShowPath=true;
                //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen;
                if (label.Style.Halo != null)
                {
                    label.TextOnPathLabel.ColorHalo = label.Style.Halo;
                }
                else
                {
                    label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5); 
                }
                path.Dispose();

                // MeasureString to get region
                label.TextOnPathLabel.MeasureString = true;
                label.TextOnPathLabel.DrawTextOnPath();
                label.TextOnPathLabel.MeasureString = false;
                // Get Region label for CollissionDetection here.
                System.Drawing.Drawing2D.GraphicsPath pathRegion = new System.Drawing.Drawing2D.GraphicsPath();

                if (label.TextOnPathLabel.RegionList.Count > 0)
                {
                    //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2;
                    //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix();
                    //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]);
                    //if (label.TextOnPathLabel.PointsTextUp.Count > 0)
                    //{
                    //    for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--)
                    //    {
                    //        label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]);
                    //    }

                    //}                 
                    pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray());

                    // get box for detect colission here              
                    label.Box = new LabelBox(pathRegion.GetBounds());
                    //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box);
                }
                pathRegion.Dispose();
            }

        }
Exemplo n.º 12
0
        /// <summary>
        /// 设置边框控件可视区域
        /// </summary>
        /// <returns></returns>
        private GraphicsPath BuildFrame()
        {
            GraphicsPath path = new GraphicsPath();

            path.AddRectangles(smallRects);

            Rectangle[] rects1 = new Rectangle[8];
            rects1[0] = new Rectangle(linePoints[0], new Size(linePoints[1].X - linePoints[0].X, 1));
            rects1[1] = new Rectangle(linePoints[2], new Size(linePoints[3].X - linePoints[2].X, 1));
            rects1[2] = new Rectangle(linePoints[4], new Size(1, linePoints[5].Y - linePoints[4].Y));
            rects1[3] = new Rectangle(linePoints[6], new Size(1, linePoints[7].Y - linePoints[6].Y));
            rects1[4] = new Rectangle(linePoints[9], new Size(linePoints[8].X - linePoints[9].X, 1));
            rects1[5] = new Rectangle(linePoints[11], new Size(linePoints[10].X - linePoints[11].X, 1));
            rects1[6] = new Rectangle(linePoints[13], new Size(1, linePoints[12].Y - linePoints[13].Y));
            rects1[7] = new Rectangle(linePoints[15], new Size(1, linePoints[14].Y - linePoints[15].Y));

            path.AddRectangles(rects1);

            return path;
        }
Exemplo n.º 13
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Point StartPoint = new Point(0, 0);
            Point EndPoint = new Point(0, this.Height);

            if (_ProgressDirection == ProgressDir.Vertical)
            {
                EndPoint = new Point(this.Width, 0);
            }

            using (GraphicsPath gp = new GraphicsPath())
            {
                Rectangle rec = new Rectangle(0, 0, this.Width, this.Height);
                int rad = Convert.ToInt32(rec.Height / 2.5);
                if (rec.Width < rec.Height)
                    rad = Convert.ToInt32(rec.Width / 2.5);

                using (LinearGradientBrush _BackColorBrush = new LinearGradientBrush(StartPoint, EndPoint, _BackColor, _GradiantColor))
                {
                    _BackColorBrush.Blend = bBlend;
                    if (_RoundedCorners)
                    {
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.FillPath(_BackColorBrush, gp);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(_BackColorBrush, rec);
                    }
                }

                if (_Value > _Minimum)
                {
                    int lngth = Convert.ToInt32((double)(this.Width / (double)(_Maximum - _Minimum)) * _Value);
                    if (_ProgressDirection == ProgressDir.Vertical)
                    {
                        lngth = Convert.ToInt32((double)(this.Height / (double)(_Maximum - _Minimum)) * _Value);
                        rec.Y = rec.Height - lngth;
                        rec.Height = lngth;
                    }
                    else
                    {
                        rec.Width = lngth;
                    }

                    using (LinearGradientBrush _ProgressBrush = new LinearGradientBrush(StartPoint, EndPoint, _ProgressColor, _GradiantColor))
                    {
                        _ProgressBrush.Blend = bBlend;
                        if (_RoundedCorners)
                        {
                            if (_ProgressDirection == ProgressDir.Horizontal)
                            {
                                rec.Height -= 1;
                            }
                            else
                            {
                                rec.Width -= 1;
                            }

                            using (GraphicsPath gp2 = new GraphicsPath())
                            {
                                gp2.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                                gp2.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                                gp2.CloseFigure();
                                using (GraphicsPath gp3 = new GraphicsPath())
                                {
                                    using (Region rgn = new Region(gp))
                                    {
                                        rgn.Intersect(gp2);
                                        gp3.AddRectangles(rgn.GetRegionScans(new Matrix()));
                                    }
                                    e.Graphics.FillPath(_ProgressBrush, gp3);
                                }
                            }
                        }
                        else
                        {
                            e.Graphics.FillRectangle(_ProgressBrush, rec);
                        }
                    }
                }

                if (_Image != null)
                {
                    if (_ImageLayout == ImageLayoutType.Stretch)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0, this.Width, this.Height);
                    }
                    else if (_ImageLayout == ImageLayoutType.None)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0);
                    }
                    else
                    {
                        int xx = Convert.ToInt32((this.Width / 2) - (_Image.Width / 2));
                        int yy = Convert.ToInt32((this.Height / 2) - (_Image.Height / 2));
                        e.Graphics.DrawImage(_Image, xx, yy);
                    }
                }

                if (_ShowPercentage | _ShowText)
                {
                    string perc = "";
                    if (_ShowText)
                        perc = this.Text;
                    if (_ShowPercentage)
                        perc += Convert.ToString(Convert.ToInt32(((double)100 / (double)(_Maximum - _Minimum)) * _Value)) + "%";
                    using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
                    {
                        e.Graphics.DrawString(perc, this.Font, _ForeColorBrush, new Rectangle(0, 0, this.Width, this.Height), sf);
                    }
                }

                if (_Border)
                {
                    rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                    if (_RoundedCorners)
                    {
                        gp.Reset();
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.DrawPath(_BorderPen, gp);
                    }
                    else
                    {
                        e.Graphics.DrawRectangle(_BorderPen, rec);
                    }
                }
            }
        }
Exemplo n.º 14
0
        private static void CalculateLabelAroundOnLineString(SharpMap.Geometries.LineString line, ref BaseLabel label, Map map, System.Drawing.Graphics g, System.Drawing.SizeF textSize)
        {
            IList <SharpMap.Geometries.Point> sPoints = line.Vertices;

            // only get point in enverlop of map
            Collection <System.Drawing.PointF> colPoint = new Collection <System.Drawing.PointF>();
            bool bCheckStarted = false;

            for (int j = 0; j < sPoints.Count; j++)
            {
                if (map.Envelope.Grow(map.PixelSize * 10).Contains(sPoints[j]))
                {
                    //points[j] = map.WorldToImage(sPoints[j]);
                    colPoint.Add(map.WorldToImage(sPoints[j]));
                    bCheckStarted = true;
                }
                else if (bCheckStarted == true)
                {
                    // fix bug curved line out of map in center segment of line
                    break;
                }
            }

            if (colPoint.Count > 1)
            {
                label.TextOnPathLabel = new SharpMap.Rendering.TextOnPath();
                switch (label.Style.HorizontalAlignment)
                {
                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                    break;

                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                    break;

                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                    break;

                default:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                    break;
                }
                switch (label.Style.VerticalAlignment)
                {
                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.UnderPath;
                    break;

                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Top:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.OverPath;
                    break;

                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                    break;

                default:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                    break;
                }
                int idxStartPath = 0;
                int numberPoint  = colPoint.Count;
                // start Optimzes Path points
                int step = 100;
                if (colPoint.Count >= step * 2)
                {
                    numberPoint = step * 2;;
                    switch (label.Style.HorizontalAlignment)
                    {
                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                        idxStartPath = 0;
                        break;

                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                        idxStartPath = colPoint.Count - step;
                        break;

                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;

                    default:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;
                    }
                }
                // end optimize path point
                System.Drawing.PointF[] points = new System.Drawing.PointF[numberPoint];
                int count = 0;
                if (colPoint[0].X <= colPoint[colPoint.Count - 1].X)
                {
                    for (int l = idxStartPath; l < numberPoint + idxStartPath; l++)
                    {
                        points[count] = colPoint[l];
                        count++;
                    }
                }
                else
                {
                    //reverse the path
                    for (int k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--)
                    {
                        points[count] = colPoint[k];
                        count++;
                    }
                }
                //get text size in page units ie pixels
                float textheight = label.Style.Font.Size;
                switch (label.Style.Font.Unit)
                {
                case System.Drawing.GraphicsUnit.Display:
                    textheight = textheight * g.DpiY / 75;
                    break;

                case System.Drawing.GraphicsUnit.Document:
                    textheight = textheight * g.DpiY / 300;
                    break;

                case System.Drawing.GraphicsUnit.Inch:
                    textheight = textheight * g.DpiY;
                    break;

                case System.Drawing.GraphicsUnit.Millimeter:
                    textheight = (float)(textheight / 25.4 * g.DpiY);
                    break;

                case System.Drawing.GraphicsUnit.Pixel:
                    //do nothing
                    break;

                case System.Drawing.GraphicsUnit.Point:
                    textheight = textheight * g.DpiY / 72;
                    break;
                }
                System.Drawing.Font topFont = new System.Drawing.Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style);
                //
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddLines(points);

                label.TextOnPathLabel.PathColorTop          = System.Drawing.Color.Transparent;
                label.TextOnPathLabel.Text                  = label.Text;
                label.TextOnPathLabel.LetterSpacePercentage = 90;
                label.TextOnPathLabel.FillColorTop          = new System.Drawing.SolidBrush(label.Style.ForeColor);
                label.TextOnPathLabel.Font                  = topFont;
                label.TextOnPathLabel.PathDataTop           = path.PathData;
                label.TextOnPathLabel.Graphics              = g;
                //label.TextOnPathLabel.ShowPath=true;
                //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen;
                if (label.Style.Halo != null)
                {
                    label.TextOnPathLabel.ColorHalo = label.Style.Halo;
                }
                else
                {
                    label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5);
                }
                path.Dispose();

                // MeasureString to get region
                label.TextOnPathLabel.MeasureString = true;
                label.TextOnPathLabel.DrawTextOnPath();
                label.TextOnPathLabel.MeasureString = false;
                // Get Region label for CollissionDetection here.
                System.Drawing.Drawing2D.GraphicsPath pathRegion = new System.Drawing.Drawing2D.GraphicsPath();

                if (label.TextOnPathLabel.RegionList.Count > 0)
                {
                    //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2;
                    //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix();
                    //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]);
                    //if (label.TextOnPathLabel.PointsTextUp.Count > 0)
                    //{
                    //    for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--)
                    //    {
                    //        label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]);
                    //    }

                    //}
                    pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray());

                    // get box for detect colission here
                    label.Box = new LabelBox(pathRegion.GetBounds());
                    //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box);
                }
                pathRegion.Dispose();
            }
        }
Exemplo n.º 15
0
		public void AddRectangles_RectangleFArr()
		{
			path = new GraphicsPath();
			RectangleF [] rectangles = new RectangleF [] {	new RectangleF (50.10f, 50.11f, 400.1f, 80.15f),
															new RectangleF (150f, 150.87f, 100.09f, 400.99f),
															new RectangleF (0.123245f, 0.23f, 200.98f, 480.56f),
															new RectangleF (450.3333333333f, 450.6666666f, 40.8f, 80.4f)};
			path.AddRectangles (rectangles);

			Assert.AreEqual (16, path.PointCount);
			
			PointF [] expectedPoints = new PointF [] {	new PointF(50.1f, 50.11f), 
														new PointF(450.2f, 50.11f), 
														new PointF(450.2f, 130.26f), 
														new PointF(50.1f, 130.26f), 
														new PointF(150f, 150.87f), 
														new PointF(250.09f, 150.87f), 
														new PointF(250.09f, 551.86f), 
														new PointF(150f, 551.86f), 
														new PointF(0.123245f, 0.23f), 
														new PointF(201.1032f, 0.23f), 
														new PointF(201.1032f, 480.79f), 
														new PointF(0.123245f, 480.79f), 
														new PointF(450.3333f, 450.6667f), 
														new PointF(491.1333f, 450.6667f), 
														new PointF(491.1333f, 531.0667f), 
														new PointF(450.3333f, 531.0667f)};
			
			for(int i = 0; i < path.PointCount; i++) {
				DrawingTest.AssertAlmostEqual(expectedPoints [i], path.PathPoints [i]);
			}

			byte [] expectedTypes = new byte [] {	(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath),
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath)};

			for (int i=0; i < expectedTypes.Length; i++) {
				Assert.AreEqual (expectedTypes [i], path.PathTypes [i]);
			}	

			t.Graphics.DrawPath (p, path);
			t.Show ();
			//t.AssertCompare ();
		}
Exemplo n.º 16
0
		public void Reverse_Rectangles ()
		{
			using (GraphicsPath gp = new GraphicsPath ()) {
				Rectangle[] rects = new Rectangle[] { new Rectangle (1, 2, 3, 4), new Rectangle (5, 6, 7, 8) }; 
				gp.AddRectangles (rects);
				Reverse (gp);
			}
		}
Exemplo n.º 17
0
		public void AddRectangles_Int ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
			CheckRectangle (gp, 4);
		}
Exemplo n.º 18
0
		public void FillRectangles (Brush brush, RectangleF [] rects) {
			GraphicsPath path = new GraphicsPath();
			path.AddRectangles(rects);
			FillPath(brush,path);
		}