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 ...
随机推荐
- error_page 改变状态码为新的状态码,并显示指定内容
server { listen 80; server_name www.espressos.com; location / { root /data0/www/bbs; index index.htm ...
- jsack
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr016.html#BABGHEJB
- BD
销售圣经:终极销售资源(销售必读,行业经典) 销售圣经2:销售之神的21.5条销售法则 Heart and Sell: 10 Universal Truths Every Salesperson Ne ...
- [Windows Azure] How to use the Table Storage Service
How to use the Table Storage Service version 1.7 version 2.0 This guide will show you how to perform ...
- K-th string
这两天参加了hihocoder上的小竞赛,下面把自己做的记录一下!(最痛心的是,开始竟然把main函数,写成了mian,浪费了将近一个小时时间,伤不起啊) Description Consider a ...
- django rest_framework入门
1.rest_framework的作用 1)可以对orm和非orm资源序列化 2)支持restful风格编程(POST,PUT,PATCH) 3)使用类视图编写API的view,而不是函数视图,类视图 ...
- python(44):array和matrix的运算
在NumPy中,array用于表示通用的N维数组,matrix则特定用于线性代数计算.array和matrix都可以用来表示矩阵,二者在进行乘法操作时,有一些不同之处. 使用array时,运算符 * ...
- DIOCP开源项目-DIOCP3的LoadRunner11测试报告
昨天有个多年的群友(B3.Locet)用LoadRunner11对DIOCP3做压力测试,说测试的时候出现了大量的10053,10054的报告.昨天晚上下载了个LoadRunner11, 今天捣鼓了下 ...
- delphi中Webbrowser疑难问题集锦<转>
1.获得网页中变量值 htm中<script> var currID=123</script> 程序中可以这么调用 id := Form1.WebBrows ...
- nexus maven私服搭建
1.在服务器上安装jdk 2.下载 nexus-3.14.0-04-unix.tar.gz,并上传到服务器/opt目录 3.解压 tar -zxvf nexus-3.14.0-04-unix.tar. ...