**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Drawing / Samples / System.Drawing / graphicsUi.cs
blob10c87ec7ebaf58a2e39667e40534f9bc374c60f2
1 //
2 // A sample application for some graphics.cs functions implementation
3 //
4 // Author:
5 // Jordi Mas i Hernàndez, jordi@ximian.com
6 //
7 //
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.Drawing.Imaging;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
35 namespace MonoSamples.System.Drawing
37 public class graphicsUI
39 public static void Main () {
41 Bitmap bmp = new Bitmap (500, 250);
42 Graphics dc = Graphics.FromImage (bmp);
44 Pen BluePen = new Pen (Color.Blue, 3);
45 Pen GreenPen = new Pen (Color.Green, 3);
46 Pen RedPen = new Pen (Color.Red, 3);
47 SolidBrush redBrush = new SolidBrush (Color.Red);
48 SolidBrush blueBrush = new SolidBrush (Color.Blue);
50 int x = 0;
51 int y = 0;
53 /* First Row */
54 dc.DrawRectangle (BluePen, x, y, 50, 50);
55 x += 50;
56 dc.DrawEllipse (RedPen, x, y, 70, 50);
57 dc.DrawArc (BluePen, x, y, 50, 40, (float) 0, (float) 120);
58 x += 70;
60 dc.DrawBezier (GreenPen, new Point (x, y + 5),
61 new Point (x + 50, y + 5),
62 new Point (x + 20, y + 20),
63 new Point (x + 50, y + 50));
64 x += 50;
66 PointF point1 = new PointF (10.0F + x, 10.0F);
67 PointF point2 = new PointF (10.0F + x, 5.0F);
68 PointF point3 = new PointF (40.0F + x, 5.0F);
69 PointF point4 = new PointF (50.0F + x, 10.0F);
70 PointF point5 = new PointF (60.0F + x, 20.0F);
71 PointF point6 = new PointF (70.0F + x, 40.0F);
72 PointF point7 = new PointF (50.0F + x, 50.0F);
73 PointF[] curvePoints = {point1, point2, point3, point4,
74 point5, point6, point7};
75 dc.DrawLines (RedPen, curvePoints);
76 float tension = 1.0F;
77 FillMode aFillMode = FillMode.Alternate;
78 dc.DrawClosedCurve (GreenPen, curvePoints, tension, aFillMode);
80 x += 80;
82 // FillClosedCurve
83 PointF point10 = new PointF (x, y + 15.0F);
84 PointF point20 = new PointF (x + 40.0F, y + 10.0F);
85 PointF point30 = new PointF (x + 50.0F, y + 40.0F);
86 PointF point40 = new PointF (x + 10.0F, y + 30.0F);
87 PointF[] points = {point10, point20, point30, point40};
88 FillMode newFillMode = FillMode.Winding;
89 dc.FillClosedCurve (redBrush, points, newFillMode, tension);
91 // Fill pie to screen.
92 dc.FillPie (blueBrush, x, 0, 200.0F, 100.0f, 300.0F, 45.0F);
94 /* second row */
95 y += 80;
96 x = 0;
98 // Clipping and Graphics container test
99 dc.SetClip (new Rectangle (5 + x, 5 + y, 75, 75));
101 // Begin a graphics container.
102 GraphicsContainer container = dc.BeginContainer ();
104 // Set an additional clipping region for the container.
105 dc.SetClip (new Rectangle (50 + x, 25 + y, 50, 37));
107 // Fill a red rectangle in the container.
108 dc.FillRectangle (redBrush, 0, 0, 200, 200);
110 dc.EndContainer (container);
111 SolidBrush blueBrushLight = new SolidBrush (
112 Color.FromArgb (128, 0, 0, 255));
113 dc.FillRectangle (blueBrushLight, 0, 0, 200, 200);
115 dc.ResetClip ();
116 Pen blackPen = new Pen (Color.FromArgb (255, 0, 0, 0), 2.0f);
117 dc.DrawRectangle (blackPen, 5 + x, 5 + y, 75, 75);
118 dc.DrawRectangle (blackPen, 50 + x, 25 + y, 50, 37);
120 x = 100;
121 y += 10;
123 Point[] ptstrans = {new Point(x, y), new Point (50 + x, 25 + y)};
124 dc.DrawLine (BluePen, ptstrans [0], ptstrans [1]);
125 dc.TranslateTransform (40.0F, 30.0F);
126 dc.TransformPoints (CoordinateSpace.Page, CoordinateSpace.World,
127 ptstrans);
128 dc.ResetTransform ();
129 dc.DrawLine (RedPen, ptstrans [0], ptstrans [1]);
131 bmp.Save ("graphicsui.bmp", ImageFormat.Bmp);