Brush.jvm.cs: fixed transform methods, createContext
[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                 protected abstract java.awt.Paint NativeObject {
15                         get;
16                 }
17
18                 awt.PaintContext awt.Paint.createContext (image.ColorModel cm,
19                         awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
20                         awt.RenderingHints hints) {
21
22                         return createContextInternal(cm, deviceBounds, userBounds, xform, hints);
23                 }
24
25                 protected virtual awt.PaintContext createContextInternal (image.ColorModel cm,
26                         awt.Rectangle deviceBounds, geom.Rectangle2D userBounds, geom.AffineTransform xform,
27                         awt.RenderingHints hints) {
28
29                         Matrix.Multiply(xform, _brushTransform.NativeObject, MatrixOrder.Append);
30                         return NativeObject.createContext (cm, deviceBounds, userBounds, xform, hints);
31                 }
32
33                 int awt.Transparency.getTransparency () {
34                         return NativeObject.getTransparency ();
35                 }
36
37                 abstract public object Clone ();
38
39                 public void Dispose () {
40                         Dispose (true);
41                 }
42
43                 protected virtual void Dispose (bool disposing) {
44                 }
45
46                 #region Brush transform
47
48                 private readonly Matrix _brushTransform = new Matrix();
49
50                 protected Matrix BrushTransform {
51                         get { return _brushTransform.Clone(); }
52                         set { 
53                                 if (value == null)
54                                         throw new ArgumentNullException("matrix");
55
56                                 value.CopyTo( _brushTransform ); 
57                         }
58                 }
59
60                 protected void BrushTranslateTransform (float dx, float dy) {
61                         BrushTranslateTransform(dx, dy, MatrixOrder.Prepend);
62                 }
63                 protected void BrushTranslateTransform (float dx, float dy, MatrixOrder order) {
64                         _brushTransform.Translate(dx,dy,order);
65                 }
66                 protected void BrushResetTransform () {
67                         _brushTransform.Reset();
68                 }
69                 protected void BrushRotateTransform (float angle) {
70                         BrushRotateTransform(angle, MatrixOrder.Prepend);
71                 }
72                 protected void BrushRotateTransform (float angle, MatrixOrder order) {
73                         _brushTransform.Rotate(angle, order);
74                 }
75                 protected void BrushScaleTransform (float sx, float sy) {
76                         BrushScaleTransform(sx, sy, MatrixOrder.Prepend);
77                 }
78                 protected void BrushScaleTransform (float sx, float sy, MatrixOrder order) {
79                         _brushTransform.Scale(sx, sy, order);
80                 }
81                 protected void BrushMultiplyTransform (Matrix matrix) {
82                         BrushMultiplyTransform(matrix, MatrixOrder.Prepend);
83                 }
84                 protected void BrushMultiplyTransform (Matrix matrix, MatrixOrder order) {
85                         if (matrix == null)\r
86                                 throw new ArgumentNullException("matrix");\r
87                         _brushTransform.Multiply(matrix, order);                        
88                 }
89
90                 #endregion
91
92                 // TODO: implement transform methods.
93
94 //              ~Brush ()
95 //              {
96 //                      Dispose (false);
97 //              }
98         }
99 }
100