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 + 1]; Point * thisVertices = vertices; for(unsigned int i = 0; 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 + 1) * 4; Point * pPolygonPtArr = new Point[dwPolygonPtMax]; Point * thisPolygonPt = pPolygonPtArr; int aa = 0; //左上角 tagCenter.x = minX + radius; tagCenter.y = maxY - radius; thisVertices = vertices; for(unsigned int i = 0; 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 = 0; 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 = 0; 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 = 0; 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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架