cocos2d-x节点(ccTypes.h)API

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(ccTypes.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

字体属性、texture属性、RGB组成......

///cocos2d-x-3.0alpha0/cocos2dx/include
//字体属性、texture属性、RGB组成......


#ifndef __CCTYPES_H__
#define __CCTYPES_H__

#include <string>
#include "cocoa/CCGeometry.h"
#include "CCGL.h"


NS_CC_BEGIN

/** RGB颜色组成的字节3字节
@since v3.0
 */
struct Color3B
{
    Color3B(): r(0), g(0), b(0) {}
    
    Color3B(GLubyte _r, GLubyte _g, GLubyte _b)
        : r(_r)
        , g(_g)
        , b(_b)
    {}
    
    bool equals(const Color3B &other)
    {
        return (this->r == other.r &&
                this->g == other.g &&
                this->b == other.b);
    }
    
    GLubyte r;
    GLubyte g;
    GLubyte b;
    
    const static Color3B WHITE;
    const static Color3B YELLOW;
    const static Color3B BLUE;
    const static Color3B GREEN;
    const static Color3B RED;
    const static Color3B MAGENTA;
    const static Color3B BLACK;
    const static Color3B ORANGE;
    const static Color3B GRAY;
};

struct Color4F;

/** 组成 RGBA 颜色(4 字节)
@since v3.0
*/
struct Color4B
{
    Color4B(GLubyte _r, GLubyte _g, GLubyte _b, GLubyte _a)
        : r(_r)
        , g(_g)
        , b(_b)
        , a(_a)
    {}
    
    Color4B(): r(0), g(0), b(0), a(0) {}
    
    // 此功能应该使用 Color4F, so implement it in .cpp file.
    explicit Color4B(const Color4F &color4F);

    GLubyte r;
    GLubyte g;
    GLubyte b;
    GLubyte a;

    const static Color4B WHITE;
    const static Color4B YELLOW;
    const static Color4B BLUE;
    const static Color4B GREEN;
    const static Color4B RED;
    const static Color4B MAGENTA;
    const static Color4B BLACK;
    const static Color4B ORANGE;
    const static Color4B GRAY;
};


/** RGBA color 由 4 floats 组成
@since v3.0
*/
struct Color4F
{
    Color4F(float _r, float _g, float _b, float _a)
        : r(_r)
        , g(_g)
        , b(_b)
        , a(_a)
    {}
    
    explicit Color4F(const Color3B &color3B)
        : r(color3B.r / 255.0f)
        , g(color3B.g / 255.0f)
        , b(color3B.b / 255.0f)
        , a(1.f)
    {}
    
    explicit Color4F(const Color4B &color4B)
        : r(color4B.r / 255.0f)
        , g(color4B.g / 255.0f)
        , b(color4B.b / 255.0f)
        , a(color4B.a / 255.0f)
    {}
    
    Color4F(): r(0.f), g(0.f), b(0.f), a(0.f) {}
    
    bool equals(const Color4F &other)
    {
        return (this->r == other.r &&
                this->g == other.g &&
                this->b == other.b &&
                this->a == other.a);
    }
    
    GLfloat r;
    GLfloat g;
    GLfloat b;
    GLfloat a;

    const static Color4F WHITE;
    const static Color4F YELLOW;
    const static Color4F BLUE;
    const static Color4F GREEN;
    const static Color4F RED;
    const static Color4F MAGENTA;
    const static Color4F BLACK;
    const static Color4F ORANGE;
    const static Color4F GRAY;
};

/** A vertex 由 2 floats 组成: x, y
 @since v3.0
 */
struct Vertex2F
{
    Vertex2F(float _x, float _y) :x(_x), y(_y) {}
    
    Vertex2F(): x(0.f), y(0.f) {}
    
    GLfloat x;
    GLfloat y;
};


/** A vertex 由 2 floats 组成: x, y
 @since v3.0
 */
struct Vertex3F
{
    Vertex3F(float _x, float _y, float _z)
        : x(_x)
        , y(_y)
        , z(_z)
    {}
    
    Vertex3F(): x(0.f), y(0.f), z(0.f) {}
    
    GLfloat x;
    GLfloat y;
    GLfloat z;
};
        
/** A texcoord(textureCoord 纹理坐标) composed(组成) of 2 floats: u, y
 @since v3.0
 */
struct Tex2F {
    Tex2F(float _u, float _v): u(_u), v(_v) {}
    
    Tex2F(): u(0.f), v(0.f) {}
    
    GLfloat u;
    GLfloat v;
};

 
//! Point Sprite component(组件)
struct PointSprite
{
    Vertex2F   pos;        // 8 bytes
    Color4B    color;      // 4 bytes
    GLfloat    size;       // 4 bytes
};

//!    A 2D Quad. 4 * 2 floats      //四
struct Quad2
{
    Vertex2F        tl;
    Vertex2F        tr;
    Vertex2F        bl;
    Vertex2F        br;
};


//!    A 3D Quad. 4 * 3 floats      //四
struct Quad3 {
    Vertex3F        bl;
    Vertex3F        br;
    Vertex3F        tl;
    Vertex3F        tr;
};
//备注 :texcoord 是纹理坐标,在后续的Pixel shader中会用到用来读取纹理颜色
//! 一个顶点, a tex coord point(纹理坐标) and a color 4B   //顶点
struct V2F_C4B_T2F
{
    //! vertices (2F)               //顶点
    Vertex2F       vertices;
    //! colors (4B)
    Color4B        colors;
    //! tex coords (2F)
    Tex2F          texCoords;
};

//! 一个顶点, a tex coord point(纹理坐标) and a color 4F       //顶点
struct V2F_C4F_T2F
{
    //! vertices (2F)       //顶点
    Vertex2F       vertices;
    //! colors (4F)
    Color4F        colors;
    //! tex coords (2F)
    Tex2F          texCoords;
};

//! 一个顶点, a tex coord point(纹理坐标) and a color 4B   //顶点
struct V3F_C4B_T2F
{
    //! vertices (3F)               //顶点
    Vertex3F     vertices;            // 12 bytes

    //! colors (4B)
    Color4B      colors;              // 4 bytes

    // tex coords (2F)
    Tex2F        texCoords;           // 8 bytes
};

//! A Triangle of V2F_C4B_T2F           //三角形
struct V2F_C4B_T2F_Triangle
{
	//! Point A
	V2F_C4B_T2F a;
	//! Point B
	V2F_C4B_T2F b;
	//! Point B
	V2F_C4B_T2F c;
};

//! A Quad of V2F_C4B_T2F
struct V2F_C4B_T2F_Quad
{
    //! bottom left             //下
    V2F_C4B_T2F    bl;
    //! bottom right            //下
    V2F_C4B_T2F    br;
    //! top left
    V2F_C4B_T2F    tl;
    //! top right
    V2F_C4B_T2F    tr;
};

//! 4 Vertex3FTex2FColor4B
struct V3F_C4B_T2F_Quad
{
    //! top left
    V3F_C4B_T2F    tl;
    //! bottom left           //下
    V3F_C4B_T2F    bl;
    //! top right
    V3F_C4B_T2F    tr;
    //! bottom right
    V3F_C4B_T2F    br;
};

//! 4 Vertex2FTex2FColor4F Quad
struct V2F_C4F_T2F_Quad
{
    //! bottom left           //下
    V2F_C4F_T2F    bl;
    //! bottom right           //下
    V2F_C4F_T2F    br;
    //! top left
    V2F_C4F_T2F    tl;
    //! top right
    V2F_C4F_T2F    tr;
};

//!  textures 使用的混合函数
struct BlendFunc
{
    //! source blend function           //源混合功能
    GLenum src;
    //! destination blend function      //目标混合功能
    GLenum dst;

    //! Blending(混合) disabled. Uses {GL_ONE, GL_ZERO}
    const static BlendFunc DISABLE;
    //! Blending(混合) enabled for textures with Alpha premultiplied(预乘). Uses {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}
    const static BlendFunc ALPHA_PREMULTIPLIED;
    //! Blending(混合) enabled for textures with Alpha NON(非) premultiplied(预乘). Uses {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}
    const static BlendFunc ALPHA_NON_PREMULTIPLIED;
    //! Enables Additive(附加) blending(混合). Uses {GL_SRC_ALPHA, GL_ONE}
    const static BlendFunc ADDITIVE;
};

// Label::VAlignment        //对齐
// Label::HAlignment

// XXX: 如果这些枚举被编辑, and/or 重新排序, 都会更新 Texture2D.m
//! Vertical text alignment type                //垂直
enum class TextVAlignment
{
    TOP,
    CENTER,
    BOTTOM,
};

// XXX: 如果这些枚举被编辑, and/or 重新排序, 都会更新 Texture2D.m
//! Horizontal text alignment type              //水平
enum class TextHAlignment
{
    LEFT,
    CENTER,
    RIGHT,
};

// animation 中的粒子系统的类型

// texture coordinates(坐标)for a quad        //四
struct T2F_Quad
{
    //! bottom left             //下
    Tex2F    bl;
    //! bottom right            //下
    Tex2F    br;
    //! top left
    Tex2F    tl;
    //! top right
    Tex2F    tr;
};

// ParticleSystemQuad 动画的 延迟、texture 坐标、持有尺寸(以像素为单位)
struct AnimationFrameData
{
    T2F_Quad texCoords;
    float delay;
    Size size; 
};

/**
 定义的字体属性类型 (i.e. font name, size, stroke(笔画样式)or 阴影)
 */


// 阴影属性
struct FontShadow
{
public:
    
    // 默认情况下,不启用阴影
    FontShadow()
        : _shadowEnabled(false)
        , _shadowBlur(0)
        , _shadowOpacity(0)
    {}

    // true 启用阴影
    bool   _shadowEnabled;
    // 阴影偏移(x,y)
	Size   _shadowOffset;
    // 模糊阴影
	float  _shadowBlur;
    // 阴影透明度
	float  _shadowOpacity;
};

// stroke(描边)属性
struct FontStroke
{
public:
    
    // 默认情况下禁止 stroke
    FontStroke()
	    : _strokeEnabled(false)
        , _strokeColor(Color3B::BLACK)
        , _strokeSize(0)
    {}
    
    // true if stroke enabled
    bool      _strokeEnabled;
    // stroke color
	Color3B   _strokeColor;
    // stroke size
    float     _strokeSize;
    
};

// font attributes
struct FontDefinition
{
public:
    /**
     * @js NA
     * @lua NA
     */
    FontDefinition()
        : _fontSize(0)
        , _alignment(TextHAlignment::CENTER)
        , _vertAlignment(TextVAlignment::TOP)
    	, _dimensions(Size::ZERO)
        , _fontFillColor(Color3B::WHITE)
    {}
    
    // font name
    std::string           _fontName;
    // font size
    int                   _fontSize;
    // horizontal alignment                 //水平对齐
    TextHAlignment        _alignment;
    // vertical alignment                      //垂直对齐
    TextVAlignment _vertAlignment;
    // renering(渲染) box
    Size                  _dimensions;
    // font color
    Color3B               _fontFillColor;
    // font shadow
    FontShadow            _shadow;
    // font stroke
    FontStroke            _stroke;
    
};

/**
 @brief 设备的加速的报告,每个单元轴 g-force(力的大小)
 */
class Acceleration
{
public:
    double x;
    double y;
    double z;
    
    double timestamp;
    
    Acceleration(): x(0), y(0), z(0), timestamp(0) {}
};

NS_CC_END

#endif //__CCTYPES_H__


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值