示例#1
0
		// a region with an "empty ctor" graphic path is "empty" (i.e. not infinite)
		private void CheckEmpty (string prefix, Region region)
		{
			Assert.IsTrue (region.IsEmpty (graphic), prefix + "IsEmpty");
			Assert.IsFalse (region.IsInfinite (graphic), prefix + "graphic");

			RectangleF rect = region.GetBounds (graphic);
			Assert.AreEqual (0f, rect.X, prefix + "GetBounds.X");
			Assert.AreEqual (0f, rect.Y, prefix + "GetBounds.Y");
			Assert.AreEqual (0f, rect.Width, prefix + "GetBounds.Width");
			Assert.AreEqual (0f, rect.Height, prefix + "GetBounds.Height");
		}
示例#2
0
        public GraphicsContext(Graphics g)
        {
            Matrix transform = g.Transform;

            if (!transform.IsIdentity)
            {
                _transformOffset = transform.Offset;
            }
            transform.Dispose();

            Region clip = g.Clip;

            if (clip.IsInfinite(g))
            {
                clip.Dispose();
            }
            else
            {
                _clipRegion = clip;
            }
        }
        public GraphicsContext(Graphics g)
        {
            Matrix transform = g.Transform;

            if (!transform.IsIdentity)
            {
                float[] elements = transform.Elements;
                this.transformOffset.X = elements[4];
                this.transformOffset.Y = elements[5];
            }
            transform.Dispose();
            Region clip = g.Clip;

            if (clip.IsInfinite(g))
            {
                clip.Dispose();
            }
            else
            {
                this.clipRegion = clip;
            }
        }
        /// <devdoc>
        ///     Creates a WindowsRegion from a System.Drawing.Region. 
        /// </devdoc>
        public static WindowsRegion FromRegion( Region region, Graphics g ){
            if (region.IsInfinite(g)){
                // An infinite region would cover the entire device region which is the same as
                // not having a clipping region. Observe that this is not the same as having an
                // empty region, which when clipping to it has the effect of excluding the entire
                // device region.
                // To remove the clip region from a dc the SelectClipRgn() function needs to be
                // called with a null region ptr - that's why we use the empty constructor here.
                // GDI+ will return IntPtr.Zero for Region.GetHrgn(Graphics) when the region is
                // Infinite.
                return new WindowsRegion();
            }

            return WindowsRegion.FromHregion(region.GetHrgn(g), true);
        }
 public static WindowsRegion FromRegion(Region region, Graphics g)
 {
     if (region.IsInfinite(g))
     {
         return new WindowsRegion();
     }
     return FromHregion(region.GetHrgn(g), true);
 }
示例#6
0
		public void GetHrgn_Empty_MakeInfinite ()
		{
			Region r = new Region (new GraphicsPath ());
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");

			r.MakeInfinite ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
			r.ReleaseHrgn (h);
		}
示例#7
0
		public void EmptyPathWithInfiniteRegion ()
		{
			GraphicsPath gp = new GraphicsPath ();
			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (gp);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
示例#8
0
		public void Region_Rectangle_IsInfinite ()
		{
			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangle (new Rectangle (-4194304, -4194304, 8388608, 8388608));
			CheckInfiniteBounds (gp);

			Region region = new Region (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
		}
示例#9
0
		public void InfinityTranslate ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Translate (10, 10);
				Assert.IsTrue (r.IsInfinite (graphic), "after");
				CheckEmpty ("InfinityTranslate", r);
			}
		}
示例#10
0
		public void InfinityIntersectTransform ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Intersect (new Rectangle (-10, -10, 20, 20));
				using (Matrix m = new Matrix (2, 0, 0, 0.5f, 10, 10)) {
					r.Transform (m);
				}
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (-10, bounds.X, "X");
				Assert.AreEqual (5, bounds.Y, "Y");
				Assert.AreEqual (40, bounds.Width, "Width");
				Assert.AreEqual (10, bounds.Height, "Height");
			}
		}
示例#11
0
		public void InfinityIntersectTranslate ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Intersect (new Rectangle (-10, -10, 20, 20));
				r.Translate (10, 10);
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (0, bounds.X, "X");
				Assert.AreEqual (0, bounds.Y, "Y");
				Assert.AreEqual (20, bounds.Width, "Width");
				Assert.AreEqual (20, bounds.Height, "Height");
			}
		}
示例#12
0
		public void InfinityExclude ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				r.Exclude (new Rectangle (5, 5, 10, 10));
				Assert.IsFalse (r.IsInfinite (graphic), "after");
				RectangleF bounds = r.GetBounds (graphic);
				Assert.AreEqual (-4194304, bounds.X, "X");
				Assert.AreEqual (-4194304, bounds.Y, "Y");
				Assert.AreEqual (8388608, bounds.Width, "Width");
				Assert.AreEqual (8388608, bounds.Height, "Height");
			}
		}
示例#13
0
		public void Region_Infinite_MultipleRectangles ()
		{
			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "Empty.IsInfinite");

			GraphicsPath gp = new GraphicsPath ();
			gp.AddRectangle (new Rectangle (-4194304, -4194304, 8388608, 8388608));
			region = new Region (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "OneRectangle.IsInfinite");

			gp.AddRectangle (new Rectangle (1, 1, 2, 2));
			region = new Region (gp);
			Assert.IsFalse (region.IsInfinite (graphic), "TwoOverlappingRectangle.IsInfinite");

			gp = new GraphicsPath ();
			gp.AddRectangle (new Rectangle (-4194304, -4194304, 4194304, 8388608));
			gp.AddRectangle (new Rectangle (0, -4194304, 4194304, 8388608));
			Assert.IsFalse (region.IsInfinite (graphic), "TwoSideBySideRectangle.IsInfinite");
		}
示例#14
0
		public void TestInfiniteAndEmpty()
		{
			Bitmap bmp = new Bitmap (600, 800);
			Graphics dc = Graphics.FromImage (bmp);
			Rectangle rect1, rect2;
			Region rgn1;
			RectangleF [] rects;
			Matrix matrix = new Matrix ();

			rect1 = new Rectangle (500, 30, 60, 80);
			rect2 = new Rectangle (520, 40, 60, 80);
			rgn1 = new Region (rect1);
			rgn1.Union (rect2);

			Assert.AreEqual (false, rgn1.IsEmpty (dc));
			Assert.AreEqual (false, rgn1.IsInfinite (dc));

			rgn1.MakeEmpty();
			Assert.AreEqual (true, rgn1.IsEmpty (dc));

			rgn1 = new Region (rect1);
			rgn1.Union (rect2);
			rgn1.MakeInfinite ();
			rects = rgn1.GetRegionScans (matrix);

			Assert.AreEqual (1, rects.Length);
			Assert.AreEqual (-4194304, rects[0].X);
			Assert.AreEqual (-4194304, rects[0].Y);
			Assert.AreEqual (8388608, rects[0].Width);
			Assert.AreEqual (8388608, rects[0].Height);
			Assert.AreEqual (true, rgn1.IsInfinite (dc));
		}
		public void GetHrgn_Infinite_MakeEmpty ()
		{
			Region r = new Region ();
			Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
			Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
			Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");

			r.MakeEmpty ();
			Assert.IsTrue (r.IsEmpty (graphic), "Empty");
			Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
			IntPtr h = r.GetHrgn (graphic);
			Assert.IsFalse (h == IntPtr.Zero, "Handle!=0");
#if NET_2_0
			r.ReleaseHrgn (h);
#endif
		}
示例#16
0
		public void Region_Curve_IsInfinite ()
		{
			Point[] points = new Point[2] { new Point (-4194304, -4194304), new Point (4194304, 4194304) };
			GraphicsPath gp = new GraphicsPath ();
			gp.AddCurve (points);
			CheckInfiniteBounds (gp);

			Region region = new Region (gp);
			Assert.IsFalse (region.IsInfinite (graphic), "IsInfinite");
			// note: infinity isn't based on the bounds
		}
示例#17
0
		public void Region_Polygon5_IsInfinite ()
		{
			// overlap the first/last point
			Point[] points = new Point[5] { new Point (-4194304, -4194304), new Point (-4194304, 4194304), new Point (4194304, 4194304), new Point (4194304, -4194304), new Point (-4194304, -4194304) };
			GraphicsPath gp = new GraphicsPath ();
			gp.AddPolygon (points);
			CheckInfiniteBounds (gp);

			Region region = new Region (gp);
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
		}
示例#18
0
		public void InfinityScaleDown ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				using (Matrix m = new Matrix ()) {
					m.Scale (0.5f, 0.5f);
					r.Transform (m);
				}
				Assert.IsTrue (r.IsInfinite (graphic), "after");
				CheckEmpty ("InfinityScaleDown", r);
			}
		}
示例#19
0
		public void InfinityRotate ()
		{
			using (Region r = new Region ()) {
				Assert.IsTrue (r.IsInfinite (graphic), "before");
				using (Matrix m = new Matrix ()) {
					m.Rotate (45);
					r.Transform (m);
				}
				Assert.IsTrue (r.IsInfinite (graphic), "after");
				CheckEmpty ("InfinityRotate", r);
			}
		}
示例#20
0
		public void Complement_383878 ()
		{
			using (Region clipRegion = new Region ()) {
				clipRegion.MakeInfinite ();

				Rectangle smaller = new Rectangle (5, 5, -10, -10);
				Rectangle bigger = new Rectangle (-5, -5, 12, 12);

				clipRegion.Intersect (smaller);
				clipRegion.Complement (bigger);

				Assert.IsFalse (clipRegion.IsEmpty (graphic), "IsEmpty");
				Assert.IsFalse (clipRegion.IsInfinite (graphic), "IsInfinite");

				RectangleF [] rects = clipRegion.GetRegionScans (new Matrix ());
				Assert.AreEqual (2, rects.Length, "Length");
				Assert.AreEqual (new RectangleF (5, -5, 2, 10), rects [0], "0");
				Assert.AreEqual (new RectangleF (-5, 5, 12, 2), rects [1], "1");
			}
		}
示例#21
0
		public void EmptyRegionWithInfiniteRegion ()
		{
			Region empty = new Region ();
			empty.MakeEmpty ();
			Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");

			Region region = new Region ();
			Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");

			region.Union (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");

			region.Xor (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");

			region.Exclude (empty);
			Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");

			region.Intersect (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");

			region.MakeInfinite ();
			region.Complement (empty);
			Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
		}
示例#22
0
文件: Region.cs 项目: nlhepler/mono
		public void ctor_void () {
			Region r1 = new Region ();
			Assert.IsTrue (r1.IsInfinite (t.Graphics));
		}