{
public class Snippets
{
- public static readonly double M_PI = Math.PI;
-
public static string[] snippets = {
"arc",
"arc_negative",
"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);
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);
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);
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);
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);
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()
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;
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);
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
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);
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);
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);
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");
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);
image.Destroy ();
}
- public void imagepattern(Graphics cr, double width, double height)
+ public void imagepattern(Context cr, int width, int height)
{
Normalize (cr, width, height);
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);
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);
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;
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);
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;
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);
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);
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);
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;
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);
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);
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
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);
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);