コード例 #1
0
		public static Path CreateRectanglePath (this Context g, Rectangle r)
		{
			g.Save ();
			
			g.MoveTo (r.X, r.Y);
			g.LineTo (r.X + r.Width, r.Y);
			g.LineTo (r.X + r.Width, r.Y + r.Height);
			g.LineTo (r.X, r.Y + r.Height);
			g.LineTo (r.X, r.Y);
			
			Path path = g.CopyPath ();
			g.Restore ();
			
			return path;
		}
コード例 #2
0
        public static Path CreateRoundedRectanglePath(this Context g, Rectangle r, double radius)
        {
            g.Save ();

            if ((radius > r.Height / 2) || (radius > r.Width / 2))
                radius = Math.Min (r.Height / 2, r.Width / 2);

            g.MoveTo (r.X, r.Y + radius);
            g.Arc (r.X + radius, r.Y + radius, radius, Math.PI, -Math.PI / 2);
            g.LineTo (r.X + r.Width - radius, r.Y);
            g.Arc (r.X + r.Width - radius, r.Y + radius, radius, -Math.PI / 2, 0);
            g.LineTo (r.X + r.Width, r.Y + r.Height - radius);
            g.Arc (r.X + r.Width - radius, r.Y + r.Height - radius, radius, 0, Math.PI / 2);
            g.LineTo (r.X + radius, r.Y + r.Height);
            g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
            g.ClosePath ();

            Path p = g.CopyPath ();
            g.Restore ();

            return p;
        }
コード例 #3
0
        public static Path CreatePolygonPath(this Context g, Cairo.Point[][] polygonSet)
        {
            g.Save ();
            Cairo.Point p;
            for (int i =0; i < polygonSet.Length; i++)
            {
                if (polygonSet[i].Length == 0)
                    continue;

                p = polygonSet[i][0];
                g.MoveTo (p.X, p.Y);

                for (int j =1; j < polygonSet[i].Length; j++)
                {
                    p = polygonSet[i][j];
                    g.LineTo (p.X, p.Y);
                }
                g.ClosePath ();
            }

            Path path = g.CopyPath ();

            g.Restore ();

            return path;
        }
コード例 #4
0
        public static Path CreateEllipsePath(this Context g, Rectangle r)
        {
            double rx = r.Width / 2;
            double ry = r.Height / 2;
            double cx = r.X + rx;
            double cy = r.Y + ry;
            double c1 = 0.552285;

            g.Save ();

            g.MoveTo (cx + rx, cy);

            g.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry);
            g.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy);
            g.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry);
            g.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy);

            g.ClosePath ();

            Path path = g.CopyPath ();

            g.Restore ();

            return path;
        }