2011-01-30 23:00:03 +00:00
|
|
|
// Copyright (C) 2011 Novell, Inc (http://www.novell.com)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
// a copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
// permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be
|
|
|
|
// included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
namespace Cairo
|
|
|
|
{
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
public struct RectangleInt {
|
|
|
|
public int X;
|
|
|
|
public int Y;
|
|
|
|
public int Width;
|
|
|
|
public int Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum RegionOverlap {
|
|
|
|
In,
|
|
|
|
Out,
|
|
|
|
Part,
|
|
|
|
}
|
|
|
|
|
|
|
|
public class Region : IDisposable {
|
|
|
|
|
|
|
|
IntPtr handle;
|
|
|
|
public IntPtr Handle {
|
|
|
|
get { return handle; }
|
|
|
|
}
|
|
|
|
|
|
|
|
~Region ()
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
Console.WriteLine ("Cairo.Region finalizer reached - developer must dispose regions manually to avoid leakage due to thread-safety concerns.");
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 05:00:12 +00:00
|
|
|
public Region (IntPtr handle) : this (handle, false) {}
|
2011-01-30 23:00:03 +00:00
|
|
|
|
2011-02-18 05:00:12 +00:00
|
|
|
public Region (IntPtr handle, bool owned)
|
2011-01-30 23:00:03 +00:00
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
this.handle = handle;
|
|
|
|
if (!owned)
|
|
|
|
NativeMethods.cairo_region_reference (handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Region ()
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
handle = NativeMethods.cairo_region_create ();
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Region (RectangleInt rect)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
handle = NativeMethods.cairo_region_create_rectangle (ref rect);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Region (RectangleInt[] rects)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
handle = NativeMethods.cairo_region_create_rectangles (rects, rects.Length);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Region Copy ()
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return new Region (NativeMethods.cairo_region_copy (Handle), true);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose ()
|
|
|
|
{
|
|
|
|
if (handle != IntPtr.Zero)
|
2011-02-18 05:00:12 +00:00
|
|
|
NativeMethods.cairo_region_destroy (Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
handle = IntPtr.Zero;
|
2011-02-18 05:00:12 +00:00
|
|
|
GC.SuppressFinalize (this);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals (object obj)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return (obj is Region) && NativeMethods.cairo_region_equal (Handle, (obj as Region).Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 05:00:12 +00:00
|
|
|
public override int GetHashCode ()
|
|
|
|
{
|
|
|
|
return Handle.GetHashCode ();
|
|
|
|
}
|
2011-01-30 23:00:03 +00:00
|
|
|
|
|
|
|
public Status Status {
|
2011-02-18 05:00:12 +00:00
|
|
|
get { return NativeMethods.cairo_region_status (Handle); }
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public RectangleInt Extents {
|
|
|
|
get {
|
|
|
|
RectangleInt result;
|
2011-02-18 05:00:12 +00:00
|
|
|
NativeMethods.cairo_region_get_extents (Handle, out result);
|
2011-01-30 23:00:03 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int NumRectangles {
|
2011-02-18 05:00:12 +00:00
|
|
|
get { return NativeMethods.cairo_region_num_rectangles (Handle); }
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public RectangleInt GetRectangle (int nth)
|
|
|
|
{
|
|
|
|
RectangleInt val;
|
2011-02-18 05:00:12 +00:00
|
|
|
NativeMethods.cairo_region_get_rectangle (Handle, nth, out val);
|
2011-01-30 23:00:03 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsEmpty {
|
2011-02-18 05:00:12 +00:00
|
|
|
get { return NativeMethods.cairo_region_is_empty (Handle); }
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public RegionOverlap ContainsPoint (RectangleInt rectangle)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_contains_rectangle (Handle, ref rectangle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool ContainsPoint (int x, int y)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_contains_point (Handle, x, y);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Translate (int dx, int dy)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
NativeMethods.cairo_region_translate (Handle, dx, dy);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status Subtract (Region other)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_subtract (Handle, other.Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status SubtractRectangle (RectangleInt rectangle)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_subtract_rectangle (Handle, ref rectangle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status Intersect (Region other)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_intersect (Handle, other.Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status IntersectRectangle (RectangleInt rectangle)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_intersect_rectangle (Handle, ref rectangle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status Union (Region other)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_union (Handle, other.Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status UnionRectangle (RectangleInt rectangle)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_union_rectangle (Handle, ref rectangle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status Xor (Region other)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_xor (Handle, other.Handle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Status XorRectangle (RectangleInt rectangle)
|
|
|
|
{
|
2011-02-18 05:00:12 +00:00
|
|
|
return NativeMethods.cairo_region_xor_rectangle (Handle, ref rectangle);
|
2011-01-30 23:00:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|