Ejemplo n.º 1
0
 /// <summary>
 /// <para>Subtract another region from this one.</para>
 /// </summary>
 ///
 /// <param name="r">
 /// <para>The other region to subtract from this one.  If
 /// <paramref name="r"/> is <see langword="null"/> or disposed,
 /// the method does nothing.</para>
 /// </param>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to empty.</para>
 /// </remarks>
 public void Subtract(Region r)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else if (r == null || r.region == IntPtr.Zero)
         {
             // Nothing to do here: subtracting an empty region.
         }
         else if (r == this)
         {
             // Subtract the region from itself: result is empty.
             Xlib.XDestroyRegion(region);
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else
         {
             Xlib.XSubtractRegion(region, r.region, region);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// <para>Xor another region with this one.</para>
 /// </summary>
 ///
 /// <param name="r">
 /// <para>The other region to xor with this one.  If
 /// <paramref name="r"/> is <see langword="null"/> or disposed,
 /// then it will be treated as the empty region.</para>
 /// </param>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be treated
 /// as empty prior to the xor operation.</para>
 /// </remarks>
 public void Xor(Region r)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         if (r == null || r.region == IntPtr.Zero)
         {
             // Xor of an empty and a non-empty region gives
             // the non-empty region as the result.
         }
         else if (r == this)
         {
             // Xor the region with itself: result is empty.
             Xlib.XDestroyRegion(region);
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else
         {
             Xlib.XXorRegion(region, r.region, region);
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// <para>Intersect another region with this one.</para>
 /// </summary>
 ///
 /// <param name="r">
 /// <para>The other region to intersect with this one.  If
 /// <paramref name="r"/> is <see langword="null"/> or disposed,
 /// the method operates as an intersection with the empty region.</para>
 /// </param>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to empty.</para>
 /// </remarks>
 public void Intersect(Region r)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else if (r == null || r.region == IntPtr.Zero)
         {
             Xlib.XDestroyRegion(region);
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else if (r != this)
         {
             Xlib.XIntersectRegion(r.region, region, region);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// <para>Subtract an explicitly-specified rectangle from
 /// this region.</para>
 /// </summary>
 ///
 /// <param name="x">
 /// <para>The X co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="y">
 /// <para>The Y co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="width">
 /// <para>The width of the rectangle.</para>
 /// </param>
 ///
 /// <param name="height">
 /// <para>The height of the rectangle.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to empty.</para>
 /// </remarks>
 public void Subtract(int x, int y, int width, int height)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else
         {
             XRectangle xrect = new XRectangle(x, y, width, height);
             IntPtr     reg   = Xlib.XCreateRegion();
             if (reg == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
             Xlib.XUnionRectWithRegion(ref xrect, reg, reg);
             Xlib.XSubtractRegion(region, reg, region);
             Xlib.XDestroyRegion(reg);
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// <para>Determine if another region overlaps with this region.</para>
 /// </summary>
 ///
 /// <param name="r">
 /// <para>The other region to test against this region.</para>
 /// </param>
 ///
 /// <returns>
 /// <para>Returns <see langword="true"/> if <paramref name="r"/> overlaps
 /// with this region; <see langword="false"/> otherwise.</para>
 /// </returns>
 public bool Overlaps(Region r)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             return(false);
         }
         else if (r == null || r.region == IntPtr.Zero)
         {
             return(false);
         }
         else if (r == this)
         {
             return(true);
         }
         else
         {
             IntPtr reg = Xlib.XCreateRegion();
             if (reg == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
             Xlib.XIntersectRegion(region, r.region, reg);
             bool result = (Xlib.XEmptyRegion(reg) == 0);
             Xlib.XDestroyRegion(reg);
             return(result);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// <para>Intersect a rectangle with this region.</para>
 /// </summary>
 ///
 /// <param name="rect">
 /// <para>The rectangle to intersect with this region.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to empty.</para>
 /// </remarks>
 public void Intersect(Rectangle rect)
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         else
         {
             IntPtr reg = Xlib.XCreateRegion();
             if (reg == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
             XRectangle xrect = new XRectangle
                                    (rect.x, rect.y, rect.width, rect.height);
             Xlib.XUnionRectWithRegion(ref xrect, reg, reg);
             Xlib.XIntersectRegion(reg, region, region);
             Xlib.XDestroyRegion(reg);
         }
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// <para>Construct a new <see cref="T:Xsharp.Region"/>
 /// instance that is initially set to the empty region.</para>
 /// </summary>
 public Region()
 {
     lock (typeof(Region))
     {
         region = Xlib.XCreateRegion();
         if (region == IntPtr.Zero)
         {
             Display.OutOfMemory();
         }
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// <para>Construct a new <see cref="T:Xsharp.Region"/>
 /// instance that is initially set to the same area as
 /// a rectangle.</para>
 /// </summary>
 ///
 /// <param name="rect">
 /// <para>The rectangle to set the region to initially.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 public Region(Rectangle rect)
 {
     lock (typeof(Region))
     {
         region = Xlib.XCreateRegion();
         if (region == IntPtr.Zero)
         {
             Display.OutOfMemory();
         }
         Union(rect.x, rect.y, rect.width, rect.height);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// <para>Construct a new <see cref="T:Xsharp.Region"/>
 /// instance that is initially set to the same area as
 /// an explicitly-specified rectangle.</para>
 /// </summary>
 ///
 /// <param name="x">
 /// <para>The X co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="y">
 /// <para>The Y co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="width">
 /// <para>The width of the rectangle.</para>
 /// </param>
 ///
 /// <param name="height">
 /// <para>The height of the rectangle.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 public Region(int x, int y, int width, int height)
 {
     lock (typeof(Region))
     {
         region = Xlib.XCreateRegion();
         if (region == IntPtr.Zero)
         {
             Display.OutOfMemory();
         }
         Union(x, y, width, height);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// <para>Construct a new <see cref="T:Xsharp.Region"/>
        /// instance that is initially set to a polygon.</para>
        /// </summary>
        ///
        /// <param name="points">
        /// <para>An array of points that defines the polygon.</para>
        /// </param>
        ///
        /// <param name="fillRule">
        /// <para>The area fill rule to use for the polygon.</para>
        /// </param>
        ///
        /// <exception cref="T:System.ArgumentNullException">
        /// <para>Raised if <paramref name="points"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        ///
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <para>Raised if <paramref name="points"/> has less than 3
        /// elements.</para>
        /// </exception>
        ///
        /// <exception cref="T:Xsharp.XException">
        /// <para>Raised if any of the elements in <paramref name="points"/>
        /// has co-ordinates that are out of range, or if
        /// <paramref name="fillRule"/> is invalid.</para>
        /// </exception>
        public Region(Point[] points, FillRule fillRule)
        {
            // Validate the parameters.
            if (points == null)
            {
                throw new ArgumentNullException("points");
            }
            else if (points.Length < 3)
            {
                throw new ArgumentOutOfRangeException
                          ("points", S._("X_PolygonNeeds3Pts"));
            }

            // Convert "points" into an "XPoint[]" array.
            XPoint[] pts = new XPoint [points.Length];
            try
            {
                checked
                {
                    for (int index = 0; index < points.Length; ++index)
                    {
                        pts[index].x = (short)(points[index].x);
                        pts[index].y = (short)(points[index].y);
                    }
                }
            }
            catch (OverflowException)
            {
                throw new XException(S._("X_PointCoordRange"));
            }

            // Validate the fill rule.
            if (fillRule != FillRule.EvenOddRule &&
                fillRule != FillRule.WindingRule)
            {
                throw new XException
                          (String.Format(S._("X_FillRule"), (int)fillRule));
            }

            // Create the polygon region.
            lock (typeof(Region))
            {
                region = Xlib.XPolygonRegion(pts, pts.Length,
                                             (int)fillRule);
                if (region == IntPtr.Zero)
                {
                    Display.OutOfMemory();
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// <para>Set this region to empty.</para>
 /// </summary>
 public void SetEmpty()
 {
     lock (typeof(Region))
     {
         if (region != IntPtr.Zero)
         {
             Xlib.XDestroyRegion(region);
         }
         region = Xlib.XCreateRegion();
         if (region == IntPtr.Zero)
         {
             Display.OutOfMemory();
         }
     }
 }
Ejemplo n.º 12
0
 // Get the Xlib region structure, and make sure it is non-NULL.
 internal IntPtr GetRegion()
 {
     lock (typeof(Region))
     {
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         return(region);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// <para>Union an explicitly-specified rectangle with this region.</para>
 /// </summary>
 ///
 /// <param name="x">
 /// <para>The X co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="y">
 /// <para>The Y co-ordinate of the top-left corner of the rectangle.</para>
 /// </param>
 ///
 /// <param name="width">
 /// <para>The width of the rectangle.</para>
 /// </param>
 ///
 /// <param name="height">
 /// <para>The height of the rectangle.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to the rectangle.</para>
 /// </remarks>
 public void Union(int x, int y, int width, int height)
 {
     lock (typeof(Region))
     {
         XRectangle xrect = new XRectangle(x, y, width, height);
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         Xlib.XUnionRectWithRegion(ref xrect, region, region);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// <para>Union a rectangle with this region.</para>
 /// </summary>
 ///
 /// <param name="rect">
 /// <para>The rectangle to union with this region.</para>
 /// </param>
 ///
 /// <exception cref="T:Xsharp.XException">
 /// <para>Raised if the rectangle co-ordinates are out of range.</para>
 /// </exception>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to <paramref name="rect"/>.</para>
 /// </remarks>
 public void Union(Rectangle rect)
 {
     lock (typeof(Region))
     {
         XRectangle xrect = new XRectangle
                                (rect.x, rect.y, rect.width, rect.height);
         if (region == IntPtr.Zero)
         {
             region = Xlib.XCreateRegion();
             if (region == IntPtr.Zero)
             {
                 Display.OutOfMemory();
             }
         }
         Xlib.XUnionRectWithRegion(ref xrect, region, region);
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// <para>Union another region with this one.</para>
 /// </summary>
 ///
 /// <param name="r">
 /// <para>The other region to union with this one.  If <paramref name="r"/>
 /// is <see langword="null"/>, the same as <see langword="this"/>, or
 /// disposed, then this method will do nothing.</para>
 /// </param>
 ///
 /// <remarks>
 /// <para>If this region has been disposed, then it will be re-created
 /// with its initial contents set to a copy of <paramref name="r"/>.</para>
 /// </remarks>
 public void Union(Region r)
 {
     lock (typeof(Region))
     {
         if (r != null && r != this && r.region != IntPtr.Zero)
         {
             if (region == IntPtr.Zero)
             {
                 region = Xlib.XCreateRegion();
                 if (region == IntPtr.Zero)
                 {
                     Display.OutOfMemory();
                 }
             }
             Xlib.XUnionRegion(region, r.region, region);
         }
     }
 }