/// <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); } } }
/// <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); } } }
/// <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); } } }
/// <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); } } }
/// <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); } } }
/// <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); } } }
/// <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(); } } }
/// <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); } }
/// <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); } }
/// <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(); } } }
// 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); } }
/// <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); } }
/// <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); } }
/// <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); } } }