在路径上添加一个圆角矩形

来源:互联网 发布:传奇手游 app源码 编辑:程序博客网 时间:2024/06/15 11:01

//BOOL pathAddRoundRecangle( GraphicsPath *path , RectF rect , float roundSize )
//功能:在路径上添加一个圆角矩形
//程序员:黄江斌
//时间:8:40 2005-10-1
//最后修改时间:8:41 2005-10-1

BOOL yourClass::pathAddRoundRecangle(
            GraphicsPath *path ,
            RectF rect ,
            float roundSize )
{
 float left = rect.X;
 float top = rect.Y;
 float right = rect.Width + rect.X;
 float bottom = rect.Height + rect.Y;

 //如果取值不合法,指定roundSize为10或较短边的1/4
 if( roundSize <= 0 )
  roundSize = 10;
 float shortOne = rect.Width < rect.Height ? rect.Width : rect.Height;
 if( roundSize > shortOne / 4 )
  roundSize = shortOne / 4;

 //左上角
 path->AddArc( left , top , 2 * roundSize , 2 * roundSize , 180 , 90 );
 //上横线
 path->AddLine( left + roundSize , top , right - roundSize , top );
 //右上角
 path->AddArc( right - 2 * roundSize , top , 2 * roundSize , 2 * roundSize , 270 , 90 );
 //右竖线
 path->AddLine( right , top + roundSize , right , bottom - roundSize );
 //右下角
 path->AddArc( right - 2 * roundSize , bottom - 2 * roundSize , 2 * roundSize , 2 * roundSize , 0 , 90 );
 //下横线
 path->AddLine( left + roundSize , bottom , right - roundSize , bottom );
 //左下角
 path->AddArc( left , bottom - 2 * roundSize , 2 * roundSize , 2 * roundSize , 90 , 90 );
 //左竖线
 path->AddLine( left , top + roundSize , left , bottom - roundSize );


 return TRUE;
}

原创粉丝点击