**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Drawing / Samples / System.Drawing / TextureWrapModes.cs
blob8cb0bfa7271c028fe53724e8081a487913b8941d
1 //
2 // Sample application for drawing figures using TextureBrush
3 // with different WrapModes
4 //
5 // Author:
6 // Ravindra (rkumar@novell.com)
7 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
36 namespace MonoSamples.System.Drawing
38 public class TextureWrapModes
40 Image img; // To be used by brush
41 Graphics gr; // To be used for creating a new bitmap
42 Bitmap bmp;
43 int currentTop;
44 int spacing;
45 int left = 100;
46 int width = 450;
47 int height = 250;
49 public TextureWrapModes (string imgName, int wd, int ht, int top, int sp)
51 currentTop = top;
52 spacing = sp;
53 bmp = new Bitmap (wd,ht);
54 gr = Graphics.FromImage (bmp);
55 img = Image.FromFile ("./bitmaps/" + imgName);
58 public void DrawWrapModes ()
60 int top = currentTop;
61 top += spacing;
62 TextureBrush tbr = new TextureBrush (img);
64 // #1: Clamp
65 tbr.WrapMode = WrapMode.Clamp;
66 gr.FillRectangle (tbr, 0, 0, width, height);
67 top = top + height + spacing;
69 tbr = new TextureBrush (img);
71 // #2: Default
72 gr.FillRectangle (tbr, left, top, width, height);
73 top = top + height + spacing;
75 // #3: Tile
76 tbr.WrapMode = WrapMode.Tile;
77 gr.FillRectangle (tbr, left, top, width, height);
78 top = top + height + spacing;
80 // #4: TileFlipX
81 tbr.WrapMode = WrapMode.TileFlipX;
82 gr.FillRectangle (tbr, left, top, width, height);
83 top = top + height + spacing;
85 // #5: TileFlipY
86 tbr.WrapMode = WrapMode.TileFlipY;
87 gr.FillRectangle (tbr, left, top, width, height);
88 top = top + height + spacing;
90 // #6: TileFlipXY
91 tbr.WrapMode = WrapMode.TileFlipXY;
92 gr.FillRectangle (tbr, left, top, width, height);
93 top = top + height + spacing;
95 currentTop = top;
98 public void SaveDrawing ()
100 // save the bmp
101 bmp.Save ("TextureWrapModes.png", ImageFormat.Png);
104 // Main to draw the things
105 public static void Main ()
107 // Make sure that the image dimensions are
108 // sufficient to hold all the test results.
109 // TextureWrapModes (imgName, width, height, top, spacing)
111 TextureWrapModes twm = new TextureWrapModes ("horse.png", 650,
112 1850, 0, 50);
114 // Draw different wrapmodes
115 twm.DrawWrapModes ();
117 // Save the drawing when done
118 twm.SaveDrawing ();