class renamed and moved to ccTypes.h

This commit is contained in:
carlo morgantini 2013-05-06 14:27:54 -07:00
parent cab90dd276
commit 04c890522d
5 changed files with 102 additions and 103 deletions

View File

@ -27,9 +27,11 @@ THE SOFTWARE.
#ifndef __CCTYPES_H__ #ifndef __CCTYPES_H__
#define __CCTYPES_H__ #define __CCTYPES_H__
#include <string>
#include "cocoa/CCGeometry.h" #include "cocoa/CCGeometry.h"
#include "CCGL.h" #include "CCGL.h"
NS_CC_BEGIN NS_CC_BEGIN
/** RGB color composed of bytes 3 bytes /** RGB color composed of bytes 3 bytes
@ -358,6 +360,78 @@ typedef struct
CCSize size; CCSize size;
} ccAnimationFrameData; } ccAnimationFrameData;
/**
types used for defining fonts properties (i.e. font name, size, stroke or shadow)
*/
// shadow attributes
typedef struct _ccFontShadow
{
public:
// shadow is not enabled by default
_ccFontShadow(): m_shadowEnabled(false) {}
// true if shadow enabled
bool m_shadowEnabled;
// shadow x and y offset
CCSize m_shadowOffset;
// shadow blurrines
float m_shadowBlur;
// shadow opacity
float m_shadowOpacity;
} ccFontShadow;
// stroke attributes
typedef struct _ccFontStroke
{
public:
// stroke is disabled by default
_ccFontStroke(): m_strokeEnabled(false) {}
// true if stroke enabled
bool m_strokeEnabled;
// stroke color
ccColor3B m_strokeColor;
// stroke size
float m_strokeSize;
} ccFontStroke;
// font attributes
typedef struct _ccFontDefinition
{
public:
_ccFontDefinition(): m_alignment(kCCTextAlignmentCenter),
m_vertAlignment(kCCVerticalTextAlignmentTop),
m_fontFillColor(ccWHITE)
{ m_dimensions = CCSizeMake(0,0); }
// font name
std::string m_fontName;
// font size
int m_fontSize;
// horizontal alignment
CCTextAlignment m_alignment;
// vertical alignment
CCVerticalTextAlignment m_vertAlignment;
// renering box
CCSize m_dimensions;
// font color
ccColor3B m_fontFillColor;
// font shadow
ccFontShadow m_shadow;
// font stroke
ccFontStroke m_stroke;
} ccFontDefinition;
NS_CC_END NS_CC_END
#endif //__CCTYPES_H__ #endif //__CCTYPES_H__

View File

@ -47,10 +47,8 @@ CCLabelTTF::CCLabelTTF()
, m_string("") , m_string("")
, m_shadowEnabled(false) , m_shadowEnabled(false)
, m_strokeEnabled(false) , m_strokeEnabled(false)
, m_textFillColor(ccWHITE)
{ {
m_textTintColor.r = 255;
m_textTintColor.g = 255;
m_textTintColor.b = 255;
} }
CCLabelTTF::~CCLabelTTF() CCLabelTTF::~CCLabelTTF()
@ -138,7 +136,7 @@ bool CCLabelTTF::initWithString(const char *string, const char *fontName, float
return false; return false;
} }
bool CCLabelTTF::initWithStringAndTextDefinition(const char *string, CCTextDefinition * textDefinition) bool CCLabelTTF::initWithStringAndTextDefinition(const char *string, ccFontDefinition * textDefinition)
{ {
if (CCSprite::init()) if (CCSprite::init())
{ {
@ -291,7 +289,7 @@ bool CCLabelTTF::updateTexture()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
CCTextDefinition texDef = _prepareTextDefinition(); ccFontDefinition texDef = _prepareTextDefinition();
tex->initWithStringShadowStroke( m_string.c_str(), &texDef ); tex->initWithStringShadowStroke( m_string.c_str(), &texDef );
#else #else
@ -435,9 +433,9 @@ void CCLabelTTF::disableStroke(bool updateTexture)
void CCLabelTTF::setFontFillColor(const ccColor3B &tintColor, bool updateTexture) void CCLabelTTF::setFontFillColor(const ccColor3B &tintColor, bool updateTexture)
{ {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
if (m_textTintColor.r != tintColor.r || m_textTintColor.g != tintColor.g || m_textTintColor.b != tintColor.b) if (m_textFillColor.r != tintColor.r || m_textFillColor.g != tintColor.g || m_textFillColor.b != tintColor.b)
{ {
m_textTintColor = tintColor; m_textFillColor = tintColor;
if (updateTexture) if (updateTexture)
this->updateTexture(); this->updateTexture();
@ -447,7 +445,7 @@ void CCLabelTTF::setFontFillColor(const ccColor3B &tintColor, bool updateTexture
#endif #endif
} }
void CCLabelTTF::setTextDefinition(CCTextDefinition *theDefinition) void CCLabelTTF::setTextDefinition(ccFontDefinition *theDefinition)
{ {
if (theDefinition) if (theDefinition)
{ {
@ -455,14 +453,14 @@ void CCLabelTTF::setTextDefinition(CCTextDefinition *theDefinition)
} }
} }
CCTextDefinition *CCLabelTTF::getTextDefinition() ccFontDefinition *CCLabelTTF::getTextDefinition()
{ {
CCTextDefinition *tempDefinition = new CCTextDefinition; ccFontDefinition *tempDefinition = new ccFontDefinition;
*tempDefinition = _prepareTextDefinition(); *tempDefinition = _prepareTextDefinition();
return tempDefinition; return tempDefinition;
} }
void CCLabelTTF::_updateWithTextDefinition(CCTextDefinition & textDefinition, bool mustUpdateTexture) void CCLabelTTF::_updateWithTextDefinition(ccFontDefinition & textDefinition, bool mustUpdateTexture)
{ {
m_tDimensions = CCSizeMake(textDefinition.m_dimensions.width, textDefinition.m_dimensions.height); m_tDimensions = CCSizeMake(textDefinition.m_dimensions.width, textDefinition.m_dimensions.height);
m_hAlignment = textDefinition.m_alignment; m_hAlignment = textDefinition.m_alignment;
@ -485,18 +483,15 @@ void CCLabelTTF::_updateWithTextDefinition(CCTextDefinition & textDefinition, bo
} }
// fill color // fill color
if ( textDefinition.m_fontTint.m_tintEnabled ) setFontFillColor(textDefinition.m_fontFillColor, false);
{
setFontFillColor(textDefinition.m_fontTint.m_tintColor, false);
}
if (mustUpdateTexture) if (mustUpdateTexture)
updateTexture(); updateTexture();
} }
CCTextDefinition CCLabelTTF::_prepareTextDefinition() ccFontDefinition CCLabelTTF::_prepareTextDefinition()
{ {
CCTextDefinition texDef; ccFontDefinition texDef;
texDef.m_fontSize = m_fFontSize * CC_CONTENT_SCALE_FACTOR(); texDef.m_fontSize = m_fFontSize * CC_CONTENT_SCALE_FACTOR();
texDef.m_fontName = *m_pFontName; texDef.m_fontName = *m_pFontName;
@ -528,7 +523,7 @@ CCTextDefinition CCLabelTTF::_prepareTextDefinition()
} }
// text tint // text tint
texDef.m_fontTint.m_tintColor = m_textTintColor; texDef.m_fontFillColor = m_textFillColor;
return texDef; return texDef;
} }

View File

@ -83,16 +83,13 @@ public:
CCVerticalTextAlignment vAlignment); CCVerticalTextAlignment vAlignment);
/** initializes the CCLabelTTF with a font name, alignment, dimension and font size */ /** initializes the CCLabelTTF with a font name, alignment, dimension and font size */
bool initWithStringAndTextDefinition(const char *string, CCTextDefinition * textDefinition); bool initWithStringAndTextDefinition(const char *string, ccFontDefinition * textDefinition);
/** set the text definition used by this label */ /** set the text definition used by this label */
void setTextDefinition(CCTextDefinition *theDefinition); void setTextDefinition(ccFontDefinition *theDefinition);
/** get the text definition used by this label */ /** get the text definition used by this label */
CCTextDefinition * getTextDefinition(); ccFontDefinition * getTextDefinition();
@ -146,8 +143,8 @@ private:
protected: protected:
/** set the text definition for this label */ /** set the text definition for this label */
void _updateWithTextDefinition(CCTextDefinition & textDefinition, bool mustUpdateTexture = true); void _updateWithTextDefinition(ccFontDefinition & textDefinition, bool mustUpdateTexture = true);
CCTextDefinition _prepareTextDefinition(); ccFontDefinition _prepareTextDefinition();
/** Dimensions of the label in Points */ /** Dimensions of the label in Points */
CCSize m_tDimensions; CCSize m_tDimensions;
@ -172,7 +169,7 @@ protected:
float m_strokeSize; float m_strokeSize;
/** font tint */ /** font tint */
ccColor3B m_textTintColor; ccColor3B m_textFillColor;
std::string m_string; std::string m_string;
}; };

View File

@ -430,22 +430,19 @@ bool CCTexture2D::initWithString(const char *text, const char *fontName, float f
{ {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
CCTextDefinition tempDef; ccFontDefinition tempDef;
tempDef.m_shadow.m_shadowEnabled = false; tempDef.m_shadow.m_shadowEnabled = false;
tempDef.m_stroke.m_strokeEnabled = false; tempDef.m_stroke.m_strokeEnabled = false;
tempDef.m_fontTint.m_tintEnabled = false;
tempDef.m_fontName = std::string(fontName); tempDef.m_fontName = std::string(fontName);
tempDef.m_fontSize = fontSize; tempDef.m_fontSize = fontSize;
tempDef.m_dimensions = dimensions; tempDef.m_dimensions = dimensions;
tempDef.m_alignment = hAlignment; tempDef.m_alignment = hAlignment;
tempDef.m_vertAlignment = vAlignment; tempDef.m_vertAlignment = vAlignment;
tempDef.m_fontFillColor = ccWHITE;
tempDef.m_fontTint.m_tintColor.r = 255;
tempDef.m_fontTint.m_tintColor.g = 255;
tempDef.m_fontTint.m_tintColor.b = 255;
return initWithStringShadowStroke(text, &tempDef); return initWithStringShadowStroke(text, &tempDef);
@ -499,7 +496,7 @@ bool CCTexture2D::initWithString(const char *text, const char *fontName, float f
} }
bool CCTexture2D::initWithStringShadowStroke(const char *text, CCTextDefinition *textDefinition) bool CCTexture2D::initWithStringShadowStroke(const char *text, ccFontDefinition *textDefinition)
{ {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
@ -575,9 +572,9 @@ bool CCTexture2D::initWithStringShadowStroke(const char *text, CCTextDefinition
eAlign, eAlign,
textDefinition->m_fontName.c_str(), textDefinition->m_fontName.c_str(),
textDefinition->m_fontSize, textDefinition->m_fontSize,
textDefinition->m_fontTint.m_tintColor.r / 255, textDefinition->m_fontFillColor.r / 255,
textDefinition->m_fontTint.m_tintColor.g / 255, textDefinition->m_fontFillColor.g / 255,
textDefinition->m_fontTint.m_tintColor.b / 255, textDefinition->m_fontFillColor.b / 255,
shadowEnabled, shadowEnabled,
shadowDX, shadowDX,
shadowDY, shadowDY,

View File

@ -98,70 +98,6 @@ typedef struct _ccTexParams {
GLuint wrapT; GLuint wrapT;
} ccTexParams; } ccTexParams;
/**
Extension used for requesting text with stroke or shadow
*/
// text shadow attributes
typedef class _ccTextShadow
{
public:
_ccTextShadow(): m_shadowEnabled(false) {}
bool m_shadowEnabled;
CCSize m_shadowOffset;
float m_shadowBlur;
float m_shadowOpacity;
} ccTextShadow;
// text stroke attributes
typedef class _ccTextStroke
{
public:
_ccTextStroke(): m_strokeEnabled(false) {}
bool m_strokeEnabled;
ccColor3B m_strokeColor;
float m_strokeSize;
} ccTextStroke;
// text tinting attributes
typedef class _ccTextTint
{
public:
_ccTextTint(): m_tintEnabled(false) {}
bool m_tintEnabled;
ccColor3B m_tintColor;
} ccTextTint;
// text attributes
class CCTextDefinition : public CCObject
{
public:
CCTextDefinition(): m_alignment(kCCTextAlignmentCenter),
m_vertAlignment(kCCVerticalTextAlignmentTop)
{ m_dimensions = CCSizeMake(0,0); }
std::string m_fontName;
int m_fontSize;
CCTextAlignment m_alignment;
CCVerticalTextAlignment m_vertAlignment;
CCSize m_dimensions;
ccTextTint m_fontTint;
ccTextShadow m_shadow;
ccTextStroke m_stroke;
} ;
//CLASS INTERFACES: //CLASS INTERFACES:
/** @brief CCTexture2D class. /** @brief CCTexture2D class.
@ -210,7 +146,7 @@ public:
/** Initializes a texture from a string with font name and font size */ /** Initializes a texture from a string with font name and font size */
bool initWithString(const char *text, const char *fontName, float fontSize); bool initWithString(const char *text, const char *fontName, float fontSize);
/** Initializes a texture from a string with dimensions, alignment, font name and font size shadow and stroke*/ /** Initializes a texture from a string with dimensions, alignment, font name and font size shadow and stroke*/
bool initWithStringShadowStroke(const char *text, CCTextDefinition *textDefinition); bool initWithStringShadowStroke(const char *text, ccFontDefinition *textDefinition);
/** Initializes a texture from a PVR file */ /** Initializes a texture from a PVR file */
bool initWithPVRFile(const char* file); bool initWithPVRFile(const char* file);