// Ravindra (rkumar@novell.com)
//
// (C) Ximian, Inc. http://www.ximian.com
-// (C) Novell, Inc. http://www.novell.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006 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
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Drawing;
using System.Runtime.InteropServices;
namespace System.Drawing.Drawing2D
GDIPlus.CheckStatus (status);
}
- public Matrix (Rectangle rect , Point[] plgpts)
+ public Matrix (Rectangle rect, Point[] plgpts)
{
- Status status = GDIPlus.GdipCreateMatrix3I (rect, plgpts, out nativeMatrix);
+ if (plgpts == null)
+ throw new ArgumentNullException ("plgpts");
+ if (plgpts.Length != 3)
+ throw new ArgumentException ("plgpts");
+
+ Status status = GDIPlus.GdipCreateMatrix3I (ref rect, plgpts, out nativeMatrix);
GDIPlus.CheckStatus (status);
}
- public Matrix (RectangleF rect , PointF[] pa)
+ public Matrix (RectangleF rect, PointF[] plgpts)
{
- Status status = GDIPlus.GdipCreateMatrix3 (rect, pa, out nativeMatrix);
+ if (plgpts == null)
+ throw new ArgumentNullException ("plgpts");
+ if (plgpts.Length != 3)
+ throw new ArgumentException ("plgpts");
+
+ Status status = GDIPlus.GdipCreateMatrix3 (ref rect, plgpts, out nativeMatrix);
GDIPlus.CheckStatus (status);
}
// properties
public float[] Elements {
get {
- IntPtr tmp = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (float)) * 6);
- float [] retval = new float [6];
-
- Status status = GDIPlus.GdipGetMatrixElements (nativeMatrix, tmp);
- GDIPlus.CheckStatus (status);
-
- Marshal.Copy (tmp, retval, 0, 6);
-
- Marshal.FreeHGlobal (tmp);
- return retval;
+ float [] retval = new float [6];
+ IntPtr tmp = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (float)) * 6);
+ try {
+ Status status = GDIPlus.GdipGetMatrixElements (nativeMatrix, tmp);
+ GDIPlus.CheckStatus (status);
+ Marshal.Copy (tmp, retval, 0, 6);
+ }
+ finally {
+ Marshal.FreeHGlobal (tmp);
+ }
+ return retval;
}
}
public void Dispose ()
{
- Status status = GDIPlus.GdipDeleteMatrix (nativeMatrix);
- GDIPlus.CheckStatus (status);
+ if (nativeMatrix != IntPtr.Zero) {
+ Status status = GDIPlus.GdipDeleteMatrix (nativeMatrix);
+ GDIPlus.CheckStatus (status);
+ nativeMatrix = IntPtr.Zero;
+ }
+
+ GC.SuppressFinalize (this);
}
public override bool Equals (object obj)
Multiply (matrix, MatrixOrder.Prepend);
}
- public void Multiply (Matrix matrix, MatrixOrder order)
- {
+ public void Multiply (Matrix matrix, MatrixOrder order)
+ {
+ if (matrix == null)
+ throw new ArgumentNullException ("matrix");
+
Status status = GDIPlus.GdipMultiplyMatrix (nativeMatrix, matrix.nativeMatrix, order);
GDIPlus.CheckStatus (status);
}
public void RotateAt (float angle, PointF point, MatrixOrder order)
{
+ if ((order < MatrixOrder.Prepend) || (order > MatrixOrder.Append))
+ throw new ArgumentException ("order");
+
angle *= (float) (Math.PI / 180.0); // degrees to radians
float cos = (float) Math.Cos (angle);
float sin = (float) Math.Sin (angle);
public void TransformPoints (Point[] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
+
Status status = GDIPlus.GdipTransformMatrixPointsI (nativeMatrix, pts, pts.Length);
GDIPlus.CheckStatus (status);
}
public void TransformPoints (PointF[] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
+
Status status = GDIPlus.GdipTransformMatrixPoints (nativeMatrix, pts, pts.Length);
GDIPlus.CheckStatus (status);
}
public void TransformVectors (Point[] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
+
Status status = GDIPlus.GdipVectorTransformMatrixPointsI (nativeMatrix, pts, pts.Length);
GDIPlus.CheckStatus (status);
}
public void TransformVectors (PointF[] pts)
{
+ if (pts == null)
+ throw new ArgumentNullException ("pts");
+
Status status = GDIPlus.GdipVectorTransformMatrixPoints (nativeMatrix, pts, pts.Length);
GDIPlus.CheckStatus (status);
}