diff --git a/cocos2dx/include/ccTypes.h b/cocos2dx/include/ccTypes.h index 2dad6b14c7..da45cd9f11 100644 --- a/cocos2dx/include/ccTypes.h +++ b/cocos2dx/include/ccTypes.h @@ -27,9 +27,11 @@ THE SOFTWARE. #ifndef __CCTYPES_H__ #define __CCTYPES_H__ +#include #include "cocoa/CCGeometry.h" #include "CCGL.h" + NS_CC_BEGIN /** RGB color composed of bytes 3 bytes @@ -358,6 +360,78 @@ typedef struct CCSize size; } 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 #endif //__CCTYPES_H__ diff --git a/cocos2dx/label_nodes/CCLabelTTF.cpp b/cocos2dx/label_nodes/CCLabelTTF.cpp index 6ddab7d42e..083703e6f6 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.cpp +++ b/cocos2dx/label_nodes/CCLabelTTF.cpp @@ -47,10 +47,8 @@ CCLabelTTF::CCLabelTTF() , m_string("") , m_shadowEnabled(false) , m_strokeEnabled(false) +, m_textFillColor(ccWHITE) { - m_textTintColor.r = 255; - m_textTintColor.g = 255; - m_textTintColor.b = 255; } CCLabelTTF::~CCLabelTTF() @@ -138,7 +136,7 @@ bool CCLabelTTF::initWithString(const char *string, const char *fontName, float return false; } -bool CCLabelTTF::initWithStringAndTextDefinition(const char *string, CCTextDefinition * textDefinition) +bool CCLabelTTF::initWithStringAndTextDefinition(const char *string, ccFontDefinition * textDefinition) { if (CCSprite::init()) { @@ -291,7 +289,7 @@ bool CCLabelTTF::updateTexture() #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 ); #else @@ -435,9 +433,9 @@ void CCLabelTTF::disableStroke(bool updateTexture) void CCLabelTTF::setFontFillColor(const ccColor3B &tintColor, bool updateTexture) { #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) this->updateTexture(); @@ -447,7 +445,7 @@ void CCLabelTTF::setFontFillColor(const ccColor3B &tintColor, bool updateTexture #endif } -void CCLabelTTF::setTextDefinition(CCTextDefinition *theDefinition) +void CCLabelTTF::setTextDefinition(ccFontDefinition *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(); 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_hAlignment = textDefinition.m_alignment; @@ -485,18 +483,15 @@ void CCLabelTTF::_updateWithTextDefinition(CCTextDefinition & textDefinition, bo } // fill color - if ( textDefinition.m_fontTint.m_tintEnabled ) - { - setFontFillColor(textDefinition.m_fontTint.m_tintColor, false); - } + setFontFillColor(textDefinition.m_fontFillColor, false); if (mustUpdateTexture) updateTexture(); } -CCTextDefinition CCLabelTTF::_prepareTextDefinition() +ccFontDefinition CCLabelTTF::_prepareTextDefinition() { - CCTextDefinition texDef; + ccFontDefinition texDef; texDef.m_fontSize = m_fFontSize * CC_CONTENT_SCALE_FACTOR(); texDef.m_fontName = *m_pFontName; @@ -528,7 +523,7 @@ CCTextDefinition CCLabelTTF::_prepareTextDefinition() } // text tint - texDef.m_fontTint.m_tintColor = m_textTintColor; + texDef.m_fontFillColor = m_textFillColor; return texDef; } diff --git a/cocos2dx/label_nodes/CCLabelTTF.h b/cocos2dx/label_nodes/CCLabelTTF.h index 48dd75fc23..d82ec2332a 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.h +++ b/cocos2dx/label_nodes/CCLabelTTF.h @@ -83,16 +83,13 @@ public: CCVerticalTextAlignment vAlignment); /** 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 */ - void setTextDefinition(CCTextDefinition *theDefinition); + void setTextDefinition(ccFontDefinition *theDefinition); /** get the text definition used by this label */ - CCTextDefinition * getTextDefinition(); - + ccFontDefinition * getTextDefinition(); @@ -146,8 +143,8 @@ private: protected: /** set the text definition for this label */ - void _updateWithTextDefinition(CCTextDefinition & textDefinition, bool mustUpdateTexture = true); - CCTextDefinition _prepareTextDefinition(); + void _updateWithTextDefinition(ccFontDefinition & textDefinition, bool mustUpdateTexture = true); + ccFontDefinition _prepareTextDefinition(); /** Dimensions of the label in Points */ CCSize m_tDimensions; @@ -172,7 +169,7 @@ protected: float m_strokeSize; /** font tint */ - ccColor3B m_textTintColor; + ccColor3B m_textFillColor; std::string m_string; }; diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 2ae731505d..a6c82ec518 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -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) - CCTextDefinition tempDef; + ccFontDefinition tempDef; tempDef.m_shadow.m_shadowEnabled = false; tempDef.m_stroke.m_strokeEnabled = false; - tempDef.m_fontTint.m_tintEnabled = false; + tempDef.m_fontName = std::string(fontName); tempDef.m_fontSize = fontSize; tempDef.m_dimensions = dimensions; tempDef.m_alignment = hAlignment; tempDef.m_vertAlignment = vAlignment; - - tempDef.m_fontTint.m_tintColor.r = 255; - tempDef.m_fontTint.m_tintColor.g = 255; - tempDef.m_fontTint.m_tintColor.b = 255; - + tempDef.m_fontFillColor = ccWHITE; + 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) @@ -575,9 +572,9 @@ bool CCTexture2D::initWithStringShadowStroke(const char *text, CCTextDefinition eAlign, textDefinition->m_fontName.c_str(), textDefinition->m_fontSize, - textDefinition->m_fontTint.m_tintColor.r / 255, - textDefinition->m_fontTint.m_tintColor.g / 255, - textDefinition->m_fontTint.m_tintColor.b / 255, + textDefinition->m_fontFillColor.r / 255, + textDefinition->m_fontFillColor.g / 255, + textDefinition->m_fontFillColor.b / 255, shadowEnabled, shadowDX, shadowDY, diff --git a/cocos2dx/textures/CCTexture2D.h b/cocos2dx/textures/CCTexture2D.h index 9267b350cd..4b4e12e556 100644 --- a/cocos2dx/textures/CCTexture2D.h +++ b/cocos2dx/textures/CCTexture2D.h @@ -98,70 +98,6 @@ typedef struct _ccTexParams { GLuint wrapT; } 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: /** @brief CCTexture2D class. @@ -210,7 +146,7 @@ public: /** Initializes a texture from a string with font name and font size */ 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*/ - bool initWithStringShadowStroke(const char *text, CCTextDefinition *textDefinition); + bool initWithStringShadowStroke(const char *text, ccFontDefinition *textDefinition); /** Initializes a texture from a PVR file */ bool initWithPVRFile(const char* file);