2013-07-26 16:45:26 +00:00
|
|
|
//
|
2008-10-09 22:35:02 +00:00
|
|
|
// Mono.Cairo.Pattern.cs
|
|
|
|
//
|
|
|
|
// Author: Jordi Mas (jordi@ximian.com)
|
|
|
|
// Hisham Mardam Bey (hisham.mardambey@gmail.com)
|
|
|
|
// (C) Ximian Inc, 2004.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2004 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.Collections;
|
|
|
|
|
|
|
|
namespace Cairo {
|
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
public class Pattern : IDisposable
|
|
|
|
{
|
|
|
|
[Obsolete]
|
2013-03-05 20:11:46 +00:00
|
|
|
protected IntPtr pattern = IntPtr.Zero;
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
public static Pattern Lookup (IntPtr pattern, bool owner)
|
2008-10-09 22:35:02 +00:00
|
|
|
{
|
|
|
|
if (pattern == IntPtr.Zero)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
PatternType pt = NativeMethods.cairo_pattern_get_type (pattern);
|
|
|
|
switch (pt) {
|
|
|
|
case PatternType.Solid:
|
2013-07-26 16:45:26 +00:00
|
|
|
return new SolidPattern (pattern, owner);
|
2008-10-09 22:35:02 +00:00
|
|
|
case PatternType.Surface:
|
2013-07-26 16:45:26 +00:00
|
|
|
return new SurfacePattern (pattern, owner);
|
2008-10-09 22:35:02 +00:00
|
|
|
case PatternType.Linear:
|
2013-07-26 16:45:26 +00:00
|
|
|
return new LinearGradient (pattern, owner);
|
2008-10-09 22:35:02 +00:00
|
|
|
case PatternType.Radial:
|
2013-07-26 16:45:26 +00:00
|
|
|
return new RadialGradient (pattern, owner);
|
2008-10-09 22:35:02 +00:00
|
|
|
default:
|
2013-07-26 16:45:26 +00:00
|
|
|
return new Pattern (pattern, owner);
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
[Obsolete]
|
|
|
|
protected Pattern ()
|
|
|
|
{
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
internal Pattern (IntPtr handle, bool owned)
|
2008-10-09 22:35:02 +00:00
|
|
|
{
|
2013-11-04 23:22:28 +00:00
|
|
|
if (handle == IntPtr.Zero)
|
|
|
|
throw new ArgumentException ("handle should not be NULL", "handle");
|
|
|
|
|
2013-03-05 22:53:49 +00:00
|
|
|
Handle = handle;
|
2013-07-26 16:45:26 +00:00
|
|
|
if (!owned)
|
|
|
|
NativeMethods.cairo_pattern_reference (handle);
|
2013-03-05 22:53:49 +00:00
|
|
|
if (CairoDebug.Enabled)
|
|
|
|
CairoDebug.OnAllocated (handle);
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Pattern ()
|
|
|
|
{
|
2013-03-05 20:11:46 +00:00
|
|
|
Dispose (false);
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
[Obsolete ("Use the SurfacePattern constructor")]
|
|
|
|
public Pattern (Surface surface)
|
|
|
|
: this ( NativeMethods.cairo_pattern_create_for_surface (surface.Handle), true)
|
|
|
|
{
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
[Obsolete]
|
|
|
|
protected void Reference ()
|
|
|
|
{
|
2013-11-04 23:22:28 +00:00
|
|
|
CheckDisposed ();
|
2013-07-26 16:45:26 +00:00
|
|
|
NativeMethods.cairo_pattern_reference (pattern);
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2011-02-18 05:00:12 +00:00
|
|
|
public void Dispose ()
|
2008-10-09 22:35:02 +00:00
|
|
|
{
|
|
|
|
Dispose (true);
|
2013-03-05 20:11:46 +00:00
|
|
|
GC.SuppressFinalize (this);
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose (bool disposing)
|
|
|
|
{
|
2013-03-05 22:53:49 +00:00
|
|
|
if (!disposing || CairoDebug.Enabled)
|
|
|
|
CairoDebug.OnDisposed<Pattern> (Handle, disposing);
|
2013-03-05 20:11:46 +00:00
|
|
|
|
2013-11-04 23:14:33 +00:00
|
|
|
if (Handle == IntPtr.Zero)
|
2013-03-05 20:11:46 +00:00
|
|
|
return;
|
|
|
|
|
2013-03-05 22:53:49 +00:00
|
|
|
NativeMethods.cairo_pattern_destroy (Handle);
|
|
|
|
Handle = IntPtr.Zero;
|
2013-03-05 20:11:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 23:22:28 +00:00
|
|
|
protected void CheckDisposed ()
|
|
|
|
{
|
|
|
|
if (Handle == IntPtr.Zero)
|
|
|
|
throw new ObjectDisposedException ("Object has already been disposed");
|
|
|
|
}
|
|
|
|
|
2013-03-05 20:11:46 +00:00
|
|
|
[Obsolete ("Use Dispose()")]
|
2013-07-26 16:45:26 +00:00
|
|
|
public void Destroy ()
|
|
|
|
{
|
|
|
|
Dispose ();
|
2011-02-18 05:00:12 +00:00
|
|
|
}
|
|
|
|
|
2008-10-09 22:35:02 +00:00
|
|
|
public Status Status
|
|
|
|
{
|
2013-11-04 23:22:28 +00:00
|
|
|
get {
|
|
|
|
CheckDisposed ();
|
|
|
|
return NativeMethods.cairo_pattern_status (Handle);
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
2013-07-26 16:45:26 +00:00
|
|
|
|
|
|
|
public Extend Extend
|
|
|
|
{
|
2013-11-04 23:22:28 +00:00
|
|
|
get {
|
|
|
|
CheckDisposed ();
|
|
|
|
return NativeMethods.cairo_pattern_get_extend (Handle);
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
CheckDisposed ();
|
|
|
|
NativeMethods.cairo_pattern_set_extend (Handle, value);
|
|
|
|
}
|
2013-07-26 16:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Matrix Matrix {
|
|
|
|
set {
|
2013-11-04 23:22:28 +00:00
|
|
|
CheckDisposed ();
|
2013-07-26 16:45:26 +00:00
|
|
|
NativeMethods.cairo_pattern_set_matrix (Handle, value);
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
get {
|
2013-11-04 23:22:28 +00:00
|
|
|
CheckDisposed ();
|
2008-10-09 22:35:02 +00:00
|
|
|
Matrix m = new Matrix ();
|
2013-07-26 16:45:26 +00:00
|
|
|
NativeMethods.cairo_pattern_get_matrix (Handle, m);
|
2008-10-09 22:35:02 +00:00
|
|
|
return m;
|
2013-07-26 16:45:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2013-07-26 23:41:40 +00:00
|
|
|
#pragma warning disable 612
|
2013-07-26 16:45:26 +00:00
|
|
|
public IntPtr Handle {
|
|
|
|
get { return pattern; }
|
|
|
|
private set { pattern = value; }
|
|
|
|
}
|
2013-07-26 23:41:40 +00:00
|
|
|
#pragma warning restore 612
|
2008-10-09 22:35:02 +00:00
|
|
|
|
2013-07-26 16:45:26 +00:00
|
|
|
[Obsolete]
|
|
|
|
public IntPtr Pointer {
|
|
|
|
get { return pattern; }
|
|
|
|
}
|
2011-02-19 03:57:39 +00:00
|
|
|
|
2008-10-09 22:35:02 +00:00
|
|
|
public PatternType PatternType {
|
2013-11-04 23:22:28 +00:00
|
|
|
get {
|
|
|
|
CheckDisposed ();
|
|
|
|
return NativeMethods.cairo_pattern_get_type (Handle);
|
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
2013-07-26 16:45:26 +00:00
|
|
|
}
|
2008-10-09 22:35:02 +00:00
|
|
|
}
|
|
|
|
|