make fallbacks for GdiCharSet, GdiVerticalFont
[mono.git] / mcs / class / System.Drawing / System.Drawing / TextureBrush.jvm.cs
1 //
2 // System.Drawing.TextureBrush.cs
3 //
4 // Author:
5 //   Dennis Hayes (dennish@Raytek.com)
6 //   Ravindra (rkumar@novell.com)
7 //
8 // (C) 2002 Ximian, Inc
9 // (C) 2004 Novell, Inc.
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.Drawing.Drawing2D;
37 using System.Drawing.Imaging;
38
39 using awt = java.awt;
40 using geom = java.awt.geom;
41 using image = java.awt.image;
42
43 namespace System.Drawing {
44         /// <summary>
45         /// Summary description for TextureBrush.
46         /// </summary>
47         public sealed class TextureBrush : Brush {
48                 readonly awt.TexturePaint _nativeObject;
49                 RectangleF _sourceRectangle;
50                 Image _texture = null;
51                 WrapMode _wrapMode;
52
53                 protected override java.awt.Paint NativeObject {
54                         get {
55                                 return _nativeObject;
56                         }
57                 }
58
59                 #region ctors
60
61                 public TextureBrush (Image image) : this (image, WrapMode.Tile) {
62                 }
63
64                 public TextureBrush (Image image, WrapMode wrapMode) : 
65                         this( image, wrapMode, new RectangleF(0, 0, image.Width, image.Height )){
66                 }
67
68                 public TextureBrush (Image image, Rectangle dstRect) : 
69                         this( image, WrapMode.Tile, dstRect ) {
70                 }
71
72                 public TextureBrush (Image image, RectangleF dstRect) : 
73                         this( image, WrapMode.Tile, dstRect ) {
74                 }
75
76                 public TextureBrush (Image image, Rectangle dstRect, ImageAttributes imageAttr) : this( image, dstRect ) {
77                         // TBD: Implement ImageAttributes
78                 }
79
80                 public TextureBrush (Image image, RectangleF dstRect, ImageAttributes imageAttr) : this( image, dstRect ) {
81                         // TBD: Implement ImageAttributes
82                 }
83
84                 public TextureBrush (Image image, WrapMode wrapMode, Rectangle dstRect) :
85                         this( image, wrapMode, new RectangleF(dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height )){
86                 }
87
88                 public TextureBrush (Image image, WrapMode wrapMode, RectangleF dstRect) {
89                         // TBD: check if not metafile
90                         _sourceRectangle = dstRect;
91                         _texture = (Image)((Bitmap)image).Clone(dstRect, image.PixelFormat);
92                         _wrapMode = wrapMode;
93
94                         if (wrapMode != Drawing2D.WrapMode.Tile)
95                                 image = CreateWrappedImage(_texture, wrapMode);
96                         else
97                                 image = _texture;
98
99                         _nativeObject = new awt.TexturePaint((image.BufferedImage)image.NativeObject.CurrentImage.NativeImage,
100                                 new geom.Rectangle2D.Float(0, 0, image.Width, image.Height));
101                 }
102
103                 #endregion
104
105                 #region CreateWrappedImage
106
107                 private Image CreateWrappedImage(Image image, WrapMode wrapMode) {
108                         Image b = null;
109                         Graphics g = null;
110
111                         switch (wrapMode) {
112                                 case Drawing2D.WrapMode.TileFlipX :
113                                         b = new Bitmap(image.Width * 2, image.Height);
114                                         g = Graphics.FromImage( b );
115                                         g.DrawImage(image, new Matrix());
116                                         g.DrawImage(image, new Matrix(-1, 0, 0, 1, image.Width * 2 - 1, 0));
117                                         break;
118                                 case Drawing2D.WrapMode.TileFlipY :
119                                         b = new Bitmap(image.Width, image.Height * 2);
120                                         g = Graphics.FromImage( b );
121                                         g.DrawImage(image, new Matrix());
122                                         g.DrawImage(image, new Matrix(1, 0, 0, -1, 0, image.Height * 2 - 1));
123                                         break;
124                                 case Drawing2D.WrapMode.TileFlipXY :
125                                         b = new Bitmap(image.Width * 2, image.Height * 2);
126                                         g = Graphics.FromImage( b );
127                                         g.DrawImage(image, new Matrix());
128                                         g.DrawImage(image, new Matrix(-1, 0, 0, 1, image.Width * 2 - 1, 0));
129                                         g.DrawImage(image, new Matrix(1, 0, 0, -1, 0, image.Height * 2 - 1));
130                                         g.DrawImage(image, new Matrix(-1, 0, 0, -1, image.Width * 2 - 1, image.Height * 2 - 1));
131                                         break;
132                                 case Drawing2D.WrapMode.Clamp :
133                                         // TBD: Implement WrapMode.Clamp
134                                         return image;
135                                 default : 
136                                         b = image;
137                                         break;
138                         }
139
140                         return b;
141                 }
142
143                 #endregion
144
145                 #region properties
146
147                 public Image Image {
148                         get {
149                                 return (Image)_texture.Clone();
150                         }
151                 }
152
153                 public Matrix Transform {
154                         get {                                   
155                                 return BrushTransform;
156                         }
157                         set {
158                                 BrushTransform = value;
159                         }
160                 }
161
162                 public WrapMode WrapMode {
163                         get {
164                                 return _wrapMode;
165                         }
166                         set {
167                                 _wrapMode = value;
168                         }
169                 }
170
171                 #endregion
172
173                 #region public methods
174
175                 public override object Clone () {
176                         TextureBrush copy = (TextureBrush)InternalClone();
177
178                         if (_texture != null)
179                                 copy._texture = (Image)_texture.Clone();
180
181                         return copy;
182                 }
183
184                 public void MultiplyTransform (Matrix matrix) {
185                         base.BrushMultiplyTransform( matrix );
186                 }
187
188                 public void MultiplyTransform (Matrix matrix, MatrixOrder order) {
189                         base.BrushMultiplyTransform( matrix, order );
190                 }
191
192                 public void ResetTransform () {
193                         base.BrushResetTransform();
194                 }
195
196                 public void RotateTransform (float angle) {
197                         base.BrushRotateTransform( angle );
198                 }
199
200                 public void RotateTransform (float angle, MatrixOrder order) {
201                         base.BrushRotateTransform( angle, order );
202                 }
203
204                 public void ScaleTransform (float sx, float sy) {
205                         base.BrushScaleTransform( sx, sy );
206                 }
207
208                 public void ScaleTransform (float sx, float sy, MatrixOrder order) {
209                         base.BrushScaleTransform( sx, sy, order );
210                 }
211
212                 public void TranslateTransform (float dx, float dy) {
213                         base.BrushTranslateTransform( dx, dy );
214                 }
215
216                 public void TranslateTransform (float dx, float dy, MatrixOrder order) {
217                         base.BrushTranslateTransform( dx, dy, order );
218                 }
219
220                 #endregion
221         }
222 }