Cocos2d-x绘制圆角矩形
/*
* @brief 画圆角矩形
* @param origin 矩形开始点
* @param destination 矩形结束点
* @param radius 圆角半径
* @param segments 圆角等份数,等份越多,圆角越平滑
* @param bFill 是否填充
* @param color 填充颜色
* @attention
*/
void DrawPrimitivesTest::ccDrawRoundRect( Point origin, Point destination, float radius, unsigned int segments, bool bFill, Color4F color)
{
//算出1/4圆 const float coef = 0.5f * (float)M_PI / segments;
Point * vertices = new Point[segments + ];
Point * thisVertices = vertices;
for(unsigned int i = ; i <= segments; ++i, ++thisVertices)
{
float rads = (segments - i)*coef;
thisVertices->x = (int)(radius * sinf(rads));
thisVertices->y = (int)(radius * cosf(rads));
}
//
Point tagCenter;
float minX = MIN(origin.x, destination.x);
float maxX = MAX(origin.x, destination.x);
float minY = MIN(origin.y, destination.y);
float maxY = MAX(origin.y, destination.y); unsigned int dwPolygonPtMax = (segments + ) * ;
Point * pPolygonPtArr = new Point[dwPolygonPtMax];
Point * thisPolygonPt = pPolygonPtArr;
int aa = ;
//左上角
tagCenter.x = minX + radius;
tagCenter.y = maxY - radius;
thisVertices = vertices;
for(unsigned int i = ; i <= segments; ++i, ++thisPolygonPt, ++thisVertices)
{
thisPolygonPt->x = tagCenter.x - thisVertices->x;
thisPolygonPt->y = tagCenter.y + thisVertices->y;
++aa;
}
//右上角
tagCenter.x = maxX - radius;
tagCenter.y = maxY - radius;
thisVertices = vertices + segments;
for(unsigned int i = ; i <= segments; ++i, ++thisPolygonPt, --thisVertices)
{
thisPolygonPt->x = tagCenter.x + thisVertices->x;
thisPolygonPt->y = tagCenter.y + thisVertices->y;
++aa;
}
//右下角
tagCenter.x = maxX - radius;
tagCenter.y = minY + radius;
thisVertices = vertices;
for(unsigned int i = ; i <= segments; ++i, ++thisPolygonPt, ++thisVertices)
{
thisPolygonPt->x = tagCenter.x + thisVertices->x;
thisPolygonPt->y = tagCenter.y - thisVertices->y;
++aa;
}
//左下角
tagCenter.x = minX + radius;
tagCenter.y = minY + radius;
thisVertices = vertices + segments;
for(unsigned int i = ; i <= segments; ++i, ++thisPolygonPt, --thisVertices)
{
thisPolygonPt->x = tagCenter.x - thisVertices->x;
thisPolygonPt->y = tagCenter.y - thisVertices->y;
++aa;
} if(bFill){
DrawPrimitives::drawSolidPoly(pPolygonPtArr, dwPolygonPtMax, color);
}else
{
DrawPrimitives::setDrawColor4F(color.r, color.g, color.b, color.a);
DrawPrimitives::drawPoly(pPolygonPtArr, dwPolygonPtMax, true);
} CC_SAFE_DELETE_ARRAY(vertices);
CC_SAFE_DELETE_ARRAY(pPolygonPtArr);
}
Cocos2d-x绘制圆角矩形的更多相关文章
- 在Microsoft Expression Blend 2 中绘制圆角矩形按钮
原文:在Microsoft Expression Blend 2 中绘制圆角矩形按钮 /* 声明:转载请保留此信息:http://www.BrawDraw.com, http://www.ZPXP.c ...
- canva绘制圆角矩形
在做组态的时候,需要支持矩形圆角格式,但是因为canvas本身不带有圆角矩形,需要自行算出坐标进行绘制 方案一.统一圆角 <!DOCTYPE html> <html> < ...
- Android中绘制圆角矩形图片及任意形状图片
圆角矩形图片在苹果的产品中很流行,相比于普通的矩形,很多人都喜欢圆角矩形的图片,因为它避开了直角的生硬,带来更好的用户体验,下面是几个设计的例子: 下面在Android中实现将普通的矩形图片绘制成圆角 ...
- Delphi中绘制圆角矩形的窗体
制作圆角矩形的窗体: 01.procedure TPortForm.FormCreate(Sender: Tobject); 02.var hr :thandle; 03.begin 04.hr:=c ...
- C# 绘制圆角矩形
Graphics g = e.Graphics; // 圆角半径 ; // 要实现 圆角化的 矩形 Rectangle rect = , , panel4.Width - cRadius, panel ...
- canvas 绘制圆角矩形
<!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</ ...
- 使用Draw rect 绘制圆角矩形
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPush ...
- 详解使用CSS3绘制矩形、圆角矩形、圆形、椭圆形、三角形、弧
1.矩形 绘制矩形应该是最简单的了,直接设置div的宽和高,填充颜色,效果就出来了. 2.圆角矩形 绘制圆角矩形也很简单,在1的基础上,在使用css3的border-radius,即可. 3.圆 根据 ...
- Android开发之自定义圆角矩形图片ImageView的实现
android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了,其原理就是首先获取到图片的Bitmap ...
随机推荐
- MD5 和的价值体现在哪里,它是用来做什么的?
MD5 和的价值体现在哪里,它是用来做什么的? MD5 和是由字母和数字构成的字符串,起到了文件指纹的作用.如果两个文件有相同的 MD5 和值,那么,文件完全相同.您可以为每一软件下载使用所提供的 M ...
- Android 相关的资源
源码分析: http://blog.csdn.net/luoshengyang/article/details/8923485 中文博客: 英文博客: https://github.com/andro ...
- HTTP响应状态码
1XX:代表提示信息 2XX:代表成功信息 3XX:代表重定向 4XX:代表客户端错误信息 5XX:代表服务器错误 信息 500:500 错误是服务器内部错误 ,而且是程序上错误 为多,可能是你的用户 ...
- NLP资料
https://towardsdatascience.com/how-to-get-started-in-nlp-6a62aa4eaeff?source=rss-299377188126------3
- [Windows Azure] Guidelines for Connecting to Windows Azure SQL Database
Guidelines for Connecting to Windows Azure SQL Database 6 out of 12 rated this helpful - Rate this t ...
- win10+VS2015+boost_1.60.0
安装boost库的初衷boost库是一个C++'准'标准库,对于一个C++程序员来说,了解强大的boost库是很有必要的.当然,在学习使用这样一个强大的库之前,首先要学会安装.本文讲述了boost_1 ...
- Lua中的loadfile,dofile,require使用,最后还有调试
1.loadfile---只编译,不运行. loadfile编译代码成中间码并且返回编译后的chunk作为一个函数,而不执行代码:另外loadfile不会抛出错误信息而是返回错误代号. loadstr ...
- Centos7 ss搭建
1.安装pip Pip 是 Python 的包管理工具,下载ss十分方便,但是centos是没有pip的,我们需要安装一个. yum install python-setuptools & e ...
- shell 删除文件过期文件
删除创建时间大于30天的文件 find /archivelog -ctime + | xargs rm -rf -amin n #查找系统中最后N分钟访问的文件 -atime n #查找系统中最后n* ...
- WCF终结点——终结点地址(EndpointAddress)
终结点的地址的Uri属性作为终结点地址的唯一标示. 包括客户端终结点和服务端终结点. 一.服务端终结点: 服务端的终结点通过宿主的添加方法暴露出来,从而成为可以调用的资源. 下面是将服务绑定到宿主的代 ...