example_canvas_curverect.cpp

角丸矩形
角丸矩形のサンプルコード
canvas_curverect.png

角丸矩形

void DlgSample::Draw(SGRect region)
{
    SGDialog::Draw(region);

    SGCanvasDraw cd( this );
    if( cd.CvBegin() ){

        int x0 = 25;
        int y0 = 25;
        int rect_width  = 200;
        int rect_height = 200;
        int radius = 100;
        int x1 = x0+rect_width;
        int y1 = y0+rect_height;

        cd.CvMoveTo(x0, y0 + radius);
        cd.CvCurveTo(x0 , y0, x0 , y0, x0 + radius, y0);
        cd.CvLineTo(x1 - radius, y0);
        cd.CvCurveTo(x1, y0, x1, y0, x1, y0 + radius);
        cd.CvLineTo(x1 , y1 - radius);
        cd.CvCurveTo(x1, y1, x1, y1, x1 - radius, y1);
        cd.CvLineTo(x0 + radius, y1);
        cd.CvCurveTo(x0, y1, x0, y1, x0, y1- radius);
        cd.CvClosePath();

        cd.CvColor(200,0,0);
        cd.CvSetLineWidth(20);
        cd.CvPreservePath();
        cd.CvStroke();

        cd.CvColor(128,64,128);
        cd.CvSetLineWidth(10);
        cd.CvPreservePath();
        cd.CvStroke();

        cd.CvColor(128,128,255);
        cd.CvFill();

        cd.CvEnd();
    }
}

PlusG リファレンスマニュアル Ver 2.0.0