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>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.º 4
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.º 5
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.º 6
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.º 7
0
 /// <summary>
 /// <para>Dispose an instance of <see cref="T:Xsharp.Region"/>.</para>
 /// </summary>
 ///
 /// <remarks>
 /// <para>This method implements the <see cref="T:System.IDisposeable"/>
 /// interface.</para>
 /// </remarks>
 public void Dispose()
 {
     lock (typeof(Region))
     {
         if (region != IntPtr.Zero)
         {
             Xlib.XDestroyRegion(region);
             region = IntPtr.Zero;
         }
     }
 }
Ejemplo n.º 8
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();
         }
     }
 }