2010-07-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing / Brush.jvm.cs
1 using System;
2 using System.Drawing;
3 using System.Drawing.Drawing2D;
4 using System.Collections;
5
6 using awt = java.awt;
7 using image = java.awt.image;
8 using geom = java.awt.geom;
9
10
11 namespace System.Drawing
12 {
13         public abstract class Brush : MarshalByRefObject, ICloneable, IDisposable, awt.Paint {
14                 
15                 #region fields
16
17                 private Matrix _brushTransform = new Matrix();
18
19                 #endregion
20
21                 protected abstract java.awt.Paint NativeObject {
22                         get;
23                 }
24
25                 awt.PaintContext awt.Paint.createContext (image.ColorModel cm,
26                         awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
27                         awt.RenderingHints hints) {
28
29                         return createContextInternal(cm, deviceBounds, userBounds, xform, hints);
30                 }
31
32                 protected virtual awt.PaintContext createContextInternal (image.ColorModel cm,
33                         awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
34                         awt.RenderingHints hints) {
35
36                         Matrix.Multiply(xform, _brushTransform.NativeObject, MatrixOrder.Append);
37                         return NativeObject.createContext (cm, deviceBounds, userBounds, xform, hints);
38                 }
39
40                 int awt.Transparency.getTransparency () {
41                         return NativeObject.getTransparency ();
42                 }
43
44                 abstract public object Clone ();
45
46                 public void Dispose () {
47                         Dispose (true);
48                 }
49
50                 protected virtual void Dispose (bool disposing) {
51                 }
52
53                 protected Brush InternalClone() {
54                         Brush brush = (Brush)this.MemberwiseClone();
55                         brush._brushTransform = this._brushTransform.Clone();
56                         return brush;
57                 }
58
59                 #region Brush transform
60
61                 internal Matrix BrushTransform {
62                         get { return _brushTransform.Clone(); }
63                         set { 
64                                 if (value == null)
65                                         throw new ArgumentNullException("matrix");
66
67                                 value.CopyTo( _brushTransform ); 
68                         }
69                 }
70
71                 protected internal void BrushTranslateTransform (float dx, float dy) {
72                         BrushTranslateTransform(dx, dy, MatrixOrder.Prepend);
73                 }
74                 protected internal void BrushTranslateTransform (float dx, float dy, MatrixOrder order) {
75                         _brushTransform.Translate(dx,dy,order);
76                 }
77                 protected internal void BrushResetTransform () {
78                         _brushTransform.Reset();
79                 }
80                 protected internal void BrushRotateTransform (float angle) {
81                         BrushRotateTransform(angle, MatrixOrder.Prepend);
82                 }
83                 protected internal void BrushRotateTransform (float angle, MatrixOrder order) {
84                         _brushTransform.Rotate(angle, order);
85                 }
86                 protected internal void BrushScaleTransform (float sx, float sy) {
87                         BrushScaleTransform(sx, sy, MatrixOrder.Prepend);
88                 }
89                 protected internal void BrushScaleTransform (float sx, float sy, MatrixOrder order) {
90                         _brushTransform.Scale(sx, sy, order);
91                 }
92                 protected internal void BrushMultiplyTransform (Matrix matrix) {
93                         BrushMultiplyTransform(matrix, MatrixOrder.Prepend);
94                 }
95                 protected internal void BrushMultiplyTransform (Matrix matrix, MatrixOrder order) {
96                         if (matrix == null)\r
97                                 throw new ArgumentNullException("matrix");\r
98                         _brushTransform.Multiply(matrix, order);                        
99                 }
100
101                 #endregion
102         }
103 }
104