2010-07-06 15:46:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
2010-07-06 20:55:05 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-07-06 10:19:51 +08:00
|
|
|
#ifndef __CCTYPES_H__
|
|
|
|
#define __CCTYPES_H__
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCGeometry.h"
|
2010-11-12 17:26:01 +08:00
|
|
|
|
2010-12-28 15:05:55 +08:00
|
|
|
#include "CCGL.h"
|
2010-11-12 17:26:01 +08:00
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-06 10:19:51 +08:00
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
/** RGB color composed of bytes 3 bytes
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
typedef struct _ccColor3B
|
|
|
|
{
|
|
|
|
GLubyte r;
|
|
|
|
GLubyte g;
|
|
|
|
GLubyte b;
|
|
|
|
} ccColor3B;
|
|
|
|
|
|
|
|
//! helper macro that creates an ccColor3B type
|
|
|
|
static inline ccColor3B
|
|
|
|
ccc3(const GLubyte r, const GLubyte g, const GLubyte b)
|
|
|
|
{
|
2010-09-21 16:15:23 +08:00
|
|
|
ccColor3B c = {r, g, b};
|
2010-07-06 15:46:45 +08:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
//ccColor3B predefined colors
|
|
|
|
//! White color (255,255,255)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccWHITE={255,255,255};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Yellow color (255,255,0)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccYELLOW={255,255,0};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Blue color (0,0,255)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccBLUE={0,0,255};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Green Color (0,255,0)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccGREEN={0,255,0};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Red Color (255,0,0,)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccRED={255,0,0};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Magenta Color (255,0,255)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccMAGENTA={255,0,255};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Black Color (0,0,0)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccBLACK={0,0,0};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Orange Color (255,127,0)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccORANGE={255,127,0};
|
2010-07-06 15:46:45 +08:00
|
|
|
//! Gray Color (166,166,166)
|
2010-09-21 16:15:23 +08:00
|
|
|
static const ccColor3B ccGRAY={166,166,166};
|
2010-07-06 15:46:45 +08:00
|
|
|
|
|
|
|
/** RGBA color composed of 4 bytes
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
typedef struct _ccColor4B
|
|
|
|
{
|
2010-12-28 15:05:55 +08:00
|
|
|
GLubyte r;
|
|
|
|
GLubyte g;
|
|
|
|
GLubyte b;
|
|
|
|
GLubyte a;
|
2010-07-06 15:46:45 +08:00
|
|
|
} ccColor4B;
|
|
|
|
//! helper macro that creates an ccColor4B type
|
|
|
|
static inline ccColor4B
|
|
|
|
ccc4(const GLubyte r, const GLubyte g, const GLubyte b, const GLubyte o)
|
|
|
|
{
|
2010-09-21 16:15:23 +08:00
|
|
|
ccColor4B c = {r, g, b, o};
|
2010-07-06 15:46:45 +08:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** RGBA color composed of 4 floats
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
typedef struct _ccColor4F {
|
2010-12-28 15:05:55 +08:00
|
|
|
GLfloat r;
|
|
|
|
GLfloat g;
|
|
|
|
GLfloat b;
|
|
|
|
GLfloat a;
|
2010-07-06 15:46:45 +08:00
|
|
|
} ccColor4F;
|
|
|
|
|
|
|
|
/** Returns a ccColor4F from a ccColor3B. Alpha will be 1.
|
|
|
|
@since v0.99.1
|
|
|
|
*/
|
|
|
|
static inline ccColor4F ccc4FFromccc3B(ccColor3B c)
|
|
|
|
{
|
2010-07-08 15:13:07 +08:00
|
|
|
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, 1.f};
|
|
|
|
return c4;
|
2010-07-06 15:46:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns a ccColor4F from a ccColor4B.
|
|
|
|
@since v0.99.1
|
|
|
|
*/
|
|
|
|
static inline ccColor4F ccc4FFromccc4B(ccColor4B c)
|
|
|
|
{
|
2010-07-08 15:13:07 +08:00
|
|
|
ccColor4F c4 = {c.r/255.f, c.g/255.f, c.b/255.f, c.a/255.f};
|
|
|
|
return c4;
|
2010-07-06 15:46:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** returns YES if both ccColor4F are equal. Otherwise it returns NO.
|
|
|
|
@since v0.99.1
|
|
|
|
*/
|
2010-07-08 12:02:18 +08:00
|
|
|
static inline bool ccc4FEqual(ccColor4F a, ccColor4F b)
|
2010-07-06 15:46:45 +08:00
|
|
|
{
|
|
|
|
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** A vertex composed of 2 floats: x, y
|
|
|
|
@since v0.8
|
|
|
|
*/
|
2010-12-28 15:05:55 +08:00
|
|
|
typedef struct _ccVertex2F
|
|
|
|
{
|
|
|
|
GLfloat x;
|
|
|
|
GLfloat y;
|
|
|
|
} ccVertex2F;
|
|
|
|
|
2010-12-31 14:56:24 +08:00
|
|
|
static inline ccVertex2F vertex2(const float x, const float y)
|
|
|
|
{
|
|
|
|
ccVertex2F c = {x, y};
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
|
|
|
|
/** A vertex composed of 2 floats: x, y
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
typedef struct _ccVertex3F
|
|
|
|
{
|
2010-12-28 15:05:55 +08:00
|
|
|
GLfloat x;
|
|
|
|
GLfloat y;
|
|
|
|
GLfloat z;
|
2010-07-06 15:46:45 +08:00
|
|
|
} ccVertex3F;
|
2010-07-22 14:51:37 +08:00
|
|
|
|
2010-11-12 17:26:01 +08:00
|
|
|
static inline ccVertex3F vertex3(const float x, const float y, const float z)
|
|
|
|
{
|
|
|
|
ccVertex3F c = {x, y, z};
|
|
|
|
return c;
|
2010-07-22 14:51:37 +08:00
|
|
|
}
|
2010-07-06 15:46:45 +08:00
|
|
|
|
|
|
|
/** A texcoord composed of 2 floats: u, y
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
typedef struct _ccTex2F {
|
2010-12-28 15:05:55 +08:00
|
|
|
GLfloat u;
|
|
|
|
GLfloat v;
|
2010-07-06 15:46:45 +08:00
|
|
|
} ccTex2F;
|
|
|
|
|
2010-11-12 17:26:01 +08:00
|
|
|
static inline ccTex2F tex2(const float u, const float v)
|
|
|
|
{
|
|
|
|
ccTex2F t = {u , v};
|
|
|
|
return t;
|
2010-08-11 18:15:52 +08:00
|
|
|
}
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
|
|
|
|
//! Point Sprite component
|
|
|
|
typedef struct _ccPointSprite
|
|
|
|
{
|
|
|
|
ccVertex2F pos; // 8 bytes
|
|
|
|
ccColor4F colors; // 16 bytes
|
2010-12-28 15:05:55 +08:00
|
|
|
GLfloat size; // 4 bytes
|
2010-07-06 15:46:45 +08:00
|
|
|
} ccPointSprite;
|
|
|
|
|
|
|
|
//! A 2D Quad. 4 * 2 floats
|
|
|
|
typedef struct _ccQuad2 {
|
|
|
|
ccVertex2F tl;
|
|
|
|
ccVertex2F tr;
|
|
|
|
ccVertex2F bl;
|
|
|
|
ccVertex2F br;
|
|
|
|
} ccQuad2;
|
|
|
|
|
|
|
|
|
|
|
|
//! A 3D Quad. 4 * 3 floats
|
|
|
|
typedef struct _ccQuad3 {
|
|
|
|
ccVertex3F bl;
|
|
|
|
ccVertex3F br;
|
|
|
|
ccVertex3F tl;
|
|
|
|
ccVertex3F tr;
|
|
|
|
} ccQuad3;
|
|
|
|
|
|
|
|
//! A 2D grid size
|
|
|
|
typedef struct _ccGridSize
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
} ccGridSize;
|
|
|
|
|
|
|
|
//! helper function to create a ccGridSize
|
|
|
|
static inline ccGridSize
|
|
|
|
ccg(const int x, const int y)
|
|
|
|
{
|
|
|
|
ccGridSize v = {x, y};
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! a Point with a vertex point, a tex coord point and a color 4F
|
|
|
|
typedef struct _ccV2F_C4F_T2F
|
|
|
|
{
|
|
|
|
//! vertices (2F)
|
|
|
|
ccVertex2F vertices;
|
|
|
|
//! colors (4F)
|
|
|
|
ccColor4F colors;
|
|
|
|
//! tex coords (2F)
|
|
|
|
ccTex2F texCoords;
|
|
|
|
} ccV2F_C4F_T2F;
|
|
|
|
|
|
|
|
//! a Point with a vertex point, a tex coord point and a color 4B
|
|
|
|
typedef struct _ccV3F_C4B_T2F
|
|
|
|
{
|
|
|
|
//! vertices (3F)
|
|
|
|
ccVertex3F vertices; // 12 bytes
|
|
|
|
// char __padding__[4];
|
|
|
|
|
|
|
|
//! colors (4B)
|
|
|
|
ccColor4B colors; // 4 bytes
|
|
|
|
// char __padding2__[4];
|
|
|
|
|
|
|
|
// tex coords (2F)
|
|
|
|
ccTex2F texCoords; // 8 byts
|
|
|
|
} ccV3F_C4B_T2F;
|
|
|
|
|
|
|
|
//! 4 ccVertex3FTex2FColor4B
|
|
|
|
typedef struct _ccV3F_C4B_T2F_Quad
|
|
|
|
{
|
|
|
|
//! top left
|
|
|
|
ccV3F_C4B_T2F tl;
|
|
|
|
//! bottom left
|
|
|
|
ccV3F_C4B_T2F bl;
|
|
|
|
//! top right
|
|
|
|
ccV3F_C4B_T2F tr;
|
|
|
|
//! bottom right
|
|
|
|
ccV3F_C4B_T2F br;
|
|
|
|
} ccV3F_C4B_T2F_Quad;
|
|
|
|
|
|
|
|
//! 4 ccVertex2FTex2FColor4F Quad
|
|
|
|
typedef struct _ccV2F_C4F_T2F_Quad
|
|
|
|
{
|
|
|
|
//! bottom left
|
|
|
|
ccV2F_C4F_T2F bl;
|
|
|
|
//! bottom right
|
|
|
|
ccV2F_C4F_T2F br;
|
|
|
|
//! top left
|
|
|
|
ccV2F_C4F_T2F tl;
|
|
|
|
//! top right
|
|
|
|
ccV2F_C4F_T2F tr;
|
|
|
|
} ccV2F_C4F_T2F_Quad;
|
|
|
|
|
|
|
|
//! Blend Function used for textures
|
|
|
|
typedef struct _ccBlendFunc
|
|
|
|
{
|
|
|
|
//! source blend function
|
|
|
|
GLenum src;
|
|
|
|
//! destination blend function
|
|
|
|
GLenum dst;
|
|
|
|
} ccBlendFunc;
|
|
|
|
|
|
|
|
//! delta time type
|
|
|
|
//! if you want more resolution redefine it as a double
|
|
|
|
typedef float ccTime;
|
2010-07-06 10:19:51 +08:00
|
|
|
//typedef double ccTime;
|
2010-08-16 15:02:17 +08:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
UITextAlignmentLeft,
|
|
|
|
UITextAlignmentCenter,
|
|
|
|
UITextAlignmentRight,
|
|
|
|
} UITextAlignment;
|
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|
2010-07-06 10:19:51 +08:00
|
|
|
|
|
|
|
#endif //__CCTYPES_H__
|