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

//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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值