예제 #1
0
        static void DrawRoundRectangle(Xwt.Drawing.Context cr, double x, double y, double r, double w, double h)
        {
            const double ARC_TO_BEZIER = 0.55228475;
            double       radius_x      = r;
            double       radius_y      = r / 4;

            if (radius_x > w - radius_x)
            {
                radius_x = w / 2;
            }

            if (radius_y > h - radius_y)
            {
                radius_y = h / 2;
            }

            double c1 = ARC_TO_BEZIER * radius_x;
            double c2 = ARC_TO_BEZIER * radius_y;

            cr.NewPath();
            cr.MoveTo(x + radius_x, y);
            cr.RelLineTo(w - 2 * radius_x, 0.0);
            cr.RelCurveTo(c1, 0.0,
                          radius_x, c2,
                          radius_x, radius_y);
            cr.RelLineTo(0, h - 2 * radius_y);
            cr.RelCurveTo(0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y);
            cr.RelLineTo(-w + 2 * radius_x, 0);
            cr.RelCurveTo(-c1, 0, -radius_x, -c2, -radius_x, -radius_y);
            cr.RelLineTo(0, -h + 2 * radius_y);
            cr.RelCurveTo(0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y);
            cr.ClosePath();
        }