New test.
[mono.git] / mcs / class / Mono.Cairo / snippets / Snippets.cs
index 3a887717f80fd5e983c4d7487bb63e50ce0ab2b7..25d29c6d50901c6434e166d360329e45123be425 100644 (file)
@@ -6,8 +6,6 @@ namespace Cairo.Snippets
 {
        public class Snippets
        {
-               public static readonly double M_PI = Math.PI;
-                       
                public static string[] snippets = {
                        "arc",
                        "arc_negative",
@@ -33,24 +31,25 @@ namespace Cairo.Snippets
                        "xxx_self_intersect"
                };
        
-               public static void InvokeSnippet (Snippets snip, string snippet, Graphics cr, double width, double height)
+               static Type[] types = new Type[] {typeof (Context), typeof (int), typeof (int)};
+               public static void InvokeSnippet (Snippets snip, string snippet, Context cr, int width, int height)
                {
-                       MethodInfo m = snip.GetType ().GetMethod(snippet, new Type[] {typeof(Graphics), typeof(double), typeof(double)});
+                       MethodInfo m = snip.GetType ().GetMethod(snippet, types);
                        m.Invoke (snip, new Object[] {cr, width, height});
                }
 
-               public void Normalize (Graphics cr, double width, double height)
+               public void Normalize (Context cr, int width, int height)
                {
                        cr.Scale (width, height);
                        cr.LineWidth = 0.04;
                }
        
-               public void arc(Graphics cr, double width, double height)
+               public void arc(Context cr, int width, int height)
                {
                        PointD c = new PointD (0.5, 0.5);
                        double radius = 0.4;
-                       double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
-                       double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */
+                       double angle1 = 45.0  * (Math.PI/180.0);  /* angles are specified */
+                       double angle2 = 180.0 * (Math.PI/180.0);  /* in radians           */
 
                        Normalize(cr, width, height);
 
@@ -58,8 +57,8 @@ namespace Cairo.Snippets
                        cr.Stroke();
 
                        // draw helping lines
-                       cr.SetSourceRGBA(1,0.2,0.2, 0.6);
-                       cr.Arc(c.X, c.Y, 0.05, 0, 2*M_PI);
+                       cr.Color = new Color (1, 0.2, 0.2, 0.6);
+                       cr.Arc(c.X, c.Y, 0.05, 0, 2*Math.PI);
                        cr.Fill();
                        cr.LineWidth = 0.03;
                        cr.Arc(c.X, c.Y, radius, angle1, angle1);
@@ -69,12 +68,12 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
        
-               public void arc_negative(Graphics cr, double width, double height)
+               public void arc_negative(Context cr, int width, int height)
                {
                        PointD c = new PointD(0.5, 0.5);
                        double radius = 0.4;
-                       double angle1 = 45.0  * (M_PI/180.0);  /* angles are specified */
-                       double angle2 = 180.0 * (M_PI/180.0);  /* in radians           */
+                       double angle1 = 45.0  * (Math.PI/180.0);  /* angles are specified */
+                       double angle2 = 180.0 * (Math.PI/180.0);  /* in radians           */
 
                        Normalize(cr, width, height);
 
@@ -82,8 +81,8 @@ namespace Cairo.Snippets
                        cr.Stroke();
 
                        // draw helping lines
-                       cr.SetSourceRGBA(1,0.2,0.2, 0.6);
-                       cr.Arc(c.X, c.Y, 0.05, 0, 2*M_PI);
+                       cr.Color = new Color (1, 0.2, 0.2, 0.6);
+                       cr.Arc(c.X, c.Y, 0.05, 0, 2*Math.PI);
                        cr.Fill();
                        cr.LineWidth = 0.03;
                        cr.Arc(c.X, c.Y, radius, angle1, angle1);
@@ -93,17 +92,17 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
        
-               public void clip(Graphics cr, double width, double height)
+               public void clip(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
 
-                       cr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
+                       cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
                        cr.Clip();
 
                        cr.NewPath();  // current path is not consumed by cairo_clip()
                        cr.Rectangle(0, 0, 1, 1);
                        cr.Fill();
-                       cr.SetSourceRGB(0, 1, 0);
+                       cr.Color = new Color (0, 1, 0);
                        cr.MoveTo(0, 0);
                        cr.LineTo(1, 1);
                        cr.MoveTo(1, 0);
@@ -111,10 +110,10 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void clip_image(Graphics cr, double width, double height)
+               public void clip_image(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
-                       cr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI);
+                       cr.Arc (0.5, 0.5, 0.3, 0, 2*Math.PI);
                        cr.Clip ();
                        cr.NewPath (); // path not consumed by clip()
 
@@ -130,7 +129,7 @@ namespace Cairo.Snippets
                        image.Destroy ();
                }
 
-               public void curve_to(Graphics cr, double width, double height)
+               public void curve_to(Context cr, int width, int height)
                {
                        double x=0.1,  y=0.5;
                        double x1=0.4, y1=0.9, x2=0.6, y2=0.1, x3=0.9, y3=0.5;
@@ -142,7 +141,7 @@ namespace Cairo.Snippets
 
                        cr.Stroke();
 
-                       cr.SetSourceRGBA(1, 0.2, 0.2, 0.6);
+                       cr.Color = new Color (1, 0.2, 0.2, 0.6);
                        cr.LineWidth = 0.03;
                        cr.MoveTo(x,y);
                        cr.LineTo(x1,y1);
@@ -151,7 +150,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void curve_rectangle(Graphics cr, double width, double height)
+               public void curve_rectangle(Context cr, int width, int height)
                {
                        // a custom shape, that could be wrapped in a function
                        double x0          = 0.1,   //< parameters like cairo_rectangle
@@ -205,15 +204,13 @@ namespace Cairo.Snippets
                        cr.ClosePath();
 
                        // and fill/stroke it
-                       cr.Save();
-               cr.SetSourceRGB(0.5, 0.5, 1);
-               cr.Fill();
-                       cr.Restore();
-                       cr.SetSourceRGBA(0.5, 0, 0, 0.5);
+                       cr.Color = new Color (0.5, 0.5, 1);
+                       cr.FillPreserve();
+                       cr.Color = new Color (0.5, 0, 0, 0.5);
                        cr.Stroke();
                }
 
-               public void fill_and_stroke(Graphics cr, double width, double height)
+               public void fill_and_stroke(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
 
@@ -223,14 +220,14 @@ namespace Cairo.Snippets
                        cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
                        cr.ClosePath();
 
-                       cr.SetSourceRGB(0, 0, 1);
+                       cr.Color = new Color (0, 0, 1);
                        cr.FillPreserve();
-                       cr.SetSourceRGB(0, 0, 0);
+                       cr.Color = new Color (0, 0, 0);
 
                        cr.Stroke();
                }
 
-               public void fill_and_stroke2(Graphics cr, double width, double height)
+               public void fill_and_stroke2(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
 
@@ -246,14 +243,14 @@ namespace Cairo.Snippets
                        cr.RelLineTo(-0.2, -0.2);
                        cr.ClosePath();
 
-                   cr.SetSourceRGB(0, 0, 1);
-                   cr.FillPreserve();
-                       cr.SetSourceRGB(0, 0, 0);
+                       cr.Color = new Color (0, 0, 1);
+                       cr.FillPreserve();
+                       cr.Color = new Color (0, 0, 0);
 
                        cr.Stroke();
                }
 
-               public void gradient(Graphics cr, double width, double height)
+               public void gradient(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
 
@@ -268,11 +265,11 @@ namespace Cairo.Snippets
                        rg.AddColorStop(0, new Color (1, 1, 1, 1));
                        rg.AddColorStop(1, new Color (0, 0, 0, 1));
                        cr.Source = rg;
-                       cr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
+                       cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
                        cr.Fill();
                }
 
-               public void image(Graphics cr, double width, double height)
+               public void image(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
                        ImageSurface image = new ImageSurface ("data/romedalen.png");
@@ -280,7 +277,7 @@ namespace Cairo.Snippets
                        int h = image.Height;
 
                        cr.Translate (0.5, 0.5);
-                       cr.Rotate (45* M_PI/180);
+                       cr.Rotate (45* Math.PI/180);
                        cr.Scale  (1.0/w, 1.0/h);
                        cr.Translate (-0.5*w, -0.5*h);
 
@@ -289,7 +286,7 @@ namespace Cairo.Snippets
                        image.Destroy ();
                }
                
-               public void imagepattern(Graphics cr, double width, double height)
+               public void imagepattern(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
                        
@@ -301,7 +298,7 @@ namespace Cairo.Snippets
                        pattern.Extend = Extend.Repeat;
 
                        cr.Translate (0.5, 0.5);
-                       cr.Rotate (M_PI / 4);
+                       cr.Rotate (Math.PI / 4);
                        cr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
                        cr.Translate (- 0.5, - 0.5);
 
@@ -318,7 +315,7 @@ namespace Cairo.Snippets
                        image.Destroy ();
                }
                
-               public void path(Graphics cr, double width, double height)
+               public void path(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
                        cr.MoveTo(0.5, 0.1);
@@ -329,7 +326,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void set_line_cap(Graphics cr, double width, double height)
+               public void set_line_cap(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
                        cr.LineWidth = 0.12;
@@ -347,7 +344,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
 
                        // draw helping lines
-                       cr.SetSourceRGB(1,0.2,0.2);
+                       cr.Color = new Color (1,0.2,0.2);
                        cr.LineWidth = 0.01;
                        cr.MoveTo(0.25, 0.2); 
                        cr.LineTo(0.25, 0.8);
@@ -358,7 +355,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void set_line_join(Graphics cr, double width, double height)
+               public void set_line_join(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
                        cr.LineWidth = 0.16;
@@ -381,7 +378,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void text(Graphics cr, double width, double height)
+               public void text(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
                        cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Bold);
@@ -393,20 +390,20 @@ namespace Cairo.Snippets
                        cr.MoveTo(0.27, 0.65);
                        cr.TextPath("void");
                        cr.Save();
-                       cr.SetSourceRGB(0.5,0.5,1);
+                       cr.Color = new Color (0.5,0.5,1);
                        cr.Fill();
                        cr.Restore();
                        cr.LineWidth = 0.01;
                        cr.Stroke();
 
                        // draw helping lines
-                       cr.SetSourceRGBA(1, 0.2, 0.2, 0.6);
-                       cr.Arc(0.04, 0.53, 0.02, 0, 2*M_PI);
-                       cr.Arc(0.27, 0.65, 0.02, 0, 2*M_PI);
+                       cr.Color = new Color (1.0, 0.2, 0.2, 0.6);
+                       cr.Arc(0.04, 0.53, 0.02, 0, 2*Math.PI);
+                       cr.Arc(0.27, 0.65, 0.02, 0, 2*Math.PI);
                        cr.Fill();
                }
 
-               public void text_align_center(Graphics cr, double width, double height)
+               public void text_align_center(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
 
@@ -420,8 +417,8 @@ namespace Cairo.Snippets
                        cr.ShowText("cairo");
 
                        // draw helping lines
-                       cr.SetSourceRGBA(1, 0.2, 0.2, 0.6);
-                       cr.Arc(x, y, 0.05, 0, 2*M_PI);
+                       cr.Color = new Color (1, 0.2, 0.2, 0.6);
+                       cr.Arc(x, y, 0.05, 0, 2*Math.PI);
                        cr.Fill();
                        cr.MoveTo(0.5, 0);
                        cr.RelLineTo(0, 1);
@@ -430,7 +427,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
        
-               public void text_extents(Graphics cr, double width, double height)
+               public void text_extents(Context cr, int width, int height)
                {
                        double x=0.1;
                        double y=0.6;
@@ -446,8 +443,8 @@ namespace Cairo.Snippets
                        cr.ShowText(utf8);
 
                        // draw helping lines
-                       cr.SetSourceRGBA(1, 0.2, 0.2, 0.6);
-                       cr.Arc(x, y, 0.05, 0, 2*M_PI);
+                       cr.Color = new Color (1, 0.2, 0.2, 0.6);
+                       cr.Arc(x, y, 0.05, 0, 2*Math.PI);
                        cr.Fill();
                        cr.MoveTo(x,y);
                        cr.RelLineTo(0, -extents.Height);
@@ -456,7 +453,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void xxx_clip_rectangle(Graphics cr, double width, double height)
+               public void xxx_clip_rectangle(Context cr, int width, int height)
                {
                        Normalize (cr, width, height);
 
@@ -475,7 +472,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void xxx_dash(Graphics cr, double width, double height)
+               public void xxx_dash(Context cr, int width, int height)
                {
                        double[] dashes = new double[] {
                                0.20,  // ink
@@ -496,32 +493,32 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void xxx_long_lines(Graphics cr, double width, double height)
+               public void xxx_long_lines(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
 
                        cr.MoveTo(0.1, -50);
                        cr.LineTo(0.1,  50);
-                       cr.SetSourceRGB(1, 0 ,0);
+                       cr.Color = new Color (1, 0 ,0);
                        cr.Stroke();
 
                        cr.MoveTo(0.2, -60);
                        cr.LineTo(0.2,  60);
-                       cr.SetSourceRGB(1, 1 ,0);
+                       cr.Color = new Color (1, 1 ,0);
                        cr.Stroke();
 
                        cr.MoveTo(0.3, -70);
                        cr.LineTo(0.3,  70);
-                       cr.SetSourceRGB(0, 1 ,0);
+                       cr.Color = new Color (0, 1 ,0);
                        cr.Stroke();
 
                        cr.MoveTo(0.4, -80);
                        cr.LineTo(0.4,  80);
-                       cr.SetSourceRGB(0, 0 ,1);
+                       cr.Color = new Color (0, 0 ,1);
                        cr.Stroke();
                }
 
-               public void xxx_multi_segment_caps(Graphics cr, double width, double height)
+               public void xxx_multi_segment_caps(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);
 
@@ -539,7 +536,7 @@ namespace Cairo.Snippets
                        cr.Stroke();
                }
 
-               public void xxx_self_intersect(Graphics cr, double width, double height)
+               public void xxx_self_intersect(Context cr, int width, int height)
                {
                        Normalize(cr, width, height);