当前位置:编程学习 > wap >>

CCLayerColor 设置圆角 ,CCLayerColor Rounded Rectangle Drawing

给CCLayerColor设置圆角

CCLayerColor Rounded Rectangle Drawing

[cpp]


[cpp]
/* ========================================================================================
 =  Add these methods to a file that gets included in your .pch or add these directly to  =
 =  CCDrawingPrimitives.h and .m                                                          =
 ==========================================================================================*/ 
 
/**
 *  Draws a rounded rectangle.
 *
 *  @param rect The rectangle to draw.
 *  @param cornerRadius The radius of the corners.
 *  @param smoothness A multiplier for the number of segments drawn for each corner. 2 or 3 is recommended.
 *  @param cornersToRound An array of BOOL values that signifies which corners we should round. The indices
 *          represent each corner as follows: 0 -> bottomLeft, 1 -> topLeft, 2 -> topRight, 3 -> bottomRight.
 */ 
void ccDrawSolidRoundedRect(CGRect rect, int cornerRadius, int smoothness, BOOL *cornersToRound) { 
    CGPoint origin = rect.origin; 
    CGSize size = rect.size; 
     
    // number of segments for each rounded corner, +1 for end point of the curve  
    int roundedCornerSegments = cornerRadius * smoothness + 1; 
     
    // get the total vertices we'll need to draw  
    int totalVertices = 0; 
    for (int i = 0; i < 4; i++) { 
        // add number of vertices needed for a rounded corner if we're rounding it,  
        // else just add 1 vertex for the corner  
        if (cornersToRound[i]) { 
            totalVertices += roundedCornerSegments; 
        } else { 
            totalVertices += 1; 
        } 
    } 
     
    ccVertex2F vertices[totalVertices]; 
     
    // create the vertices we're going to draw in clockwise fashion starting from bottom left corner  
    int currentVertexIndex = 0; 
    for (int i = 0; i < 4; i++) { 
        // if we don't want to draw the rounded corner just add a vertex at the corner point  
        if (!cornersToRound[i]) { 
            switch (i) { 
                case 0: vertices[currentVertexIndex] = (ccVertex2F){origin.x, origin.y}; break; 
                case 1: vertices[currentVertexIndex] = (ccVertex2F){origin.x, origin.y + size.height}; break; 
                case 2: vertices[currentVertexIndex] = (ccVertex2F){origin.x + size.width, origin.y + size.height}; break; 
                case 3: vertices[currentVertexIndex] = (ccVertex2F){origin.x + size.width, origin.y}; break; 
                default: break; 
            } 
            currentVertexIndex++; 
        } else { 
            // we want the corner rounded so add vertices for that rounded corner  
            switch (i) { 
                case 0: addCubicBezierVertices(ccp(origin.x + cornerRadius, origin.y), 
                                               ccp(origin.x + cornerRadius/2, origin.y), 
                                               ccp(origin.x, origin.y + cornerRadius/2), 
                                               ccp(origin.x, origin.y + cornerRadius), 
                                               roundedCornerSegments, &vertices[currentVertexIndex]); break; 
                case 1: addCubicBezierVertices(ccp(origin.x, origin.y + size.height - cornerRadius), 
                                               ccp(origin.x, origin.y + size.height - cornerRadius/2), 
                                               ccp(origin.x + cornerRadius/2, origin.y + size.height), 
                                               ccp(origin.x + cornerRadius, origin.y + size.height), 
                                         &nb

补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,