typo fix and coding style improvements.

This commit is contained in:
Dhilan007 2014-03-11 14:32:07 +08:00
parent 11d3acd478
commit 792e182e12
2 changed files with 25 additions and 46 deletions

View File

@ -50,7 +50,7 @@ Label* Label::create()
return ret;
}
Label* Label::createWithFontDefinition(const std::string& text, FontDefinition &textDefinition)
Label* Label::createWithFontDefinition(const std::string& text, const FontDefinition &textDefinition)
{
auto ret = new Label();
@ -258,6 +258,7 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b
, _maxLineWidth(0)
, _labelWidth(0)
, _labelHeight(0)
, _labelDimensions(Size::ZERO)
, _hAlignment(alignment)
, _currentUTF16String(nullptr)
, _originalUTF16String(nullptr)
@ -456,7 +457,7 @@ void Label::setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment)
void Label::setMaxLineWidth(unsigned int maxLineWidth)
{
if (_maxLineWidth != maxLineWidth)
if (_labelWidth == 0 && _maxLineWidth != maxLineWidth)
{
_maxLineWidth = maxLineWidth;
_contentDirty = true;
@ -470,8 +471,11 @@ void Label::setDimensions(unsigned int width,unsigned int height)
_fontDefinition._dimensions.width = width;
_fontDefinition._dimensions.height = height;
_labelHeight = height;
_labelWidth = width;
_labelHeight = height;
_labelDimensions.width = width;
_labelDimensions.height = height;
_maxLineWidth = width;
_contentDirty = true;
}
@ -481,15 +485,8 @@ void Label::setLineBreakWithoutSpace(bool breakWithoutSpace)
{
if (breakWithoutSpace != _lineBreakWithoutSpaces)
{
// store
_lineBreakWithoutSpaces = breakWithoutSpace;
// need to align text again
if(_currentUTF16String)
{
resetCurrentString();
alignText();
}
_contentDirty = true;
}
}
@ -572,7 +569,7 @@ void Label::alignText()
if(_maxLineWidth > 0 && _contentSize.width > _maxLineWidth && LabelTextFormatter::multilineText(this) )
LabelTextFormatter::createStringSprites(this);
if(_labelWidth >0 || (_currNumLines > 1 && _hAlignment != TextHAlignment::LEFT))
if(_labelWidth > 0 || (_currNumLines > 1 && _hAlignment != TextHAlignment::LEFT))
LabelTextFormatter::alignText(this);
int strLen = cc_wcslen(_currentUTF16String);
@ -667,25 +664,6 @@ bool Label::setCurrentString(unsigned short *stringToSet)
return true;
}
void Label::resetCurrentString()
{
if ((!_currentUTF16String) && (!_originalUTF16String))
return;
// set the new string
if (_currentUTF16String)
{
delete [] _currentUTF16String;
_currentUTF16String = 0;
}
int stringLenght = cc_wcslen(_originalUTF16String);
_currentUTF16String = new unsigned short int [stringLenght + 1];
memcpy(_currentUTF16String, _originalUTF16String, stringLenght * 2);
_currentUTF16String[stringLenght] = 0;
}
void Label::updateSpriteWithLetterDefinition(const FontLetterDefinition &theDefinition, Texture2D *theTexture)
{
_reusedRect.size.height = theDefinition.height;
@ -757,7 +735,7 @@ void Label::setLabelEffect(LabelEffect effect,const Color3B& effectColor)
void Label::enableGlow(const Color3B& glowColor)
{
if(_useDistanceField == false)
if(! _useDistanceField)
return;
_currLabelEffect = LabelEffect::GLOW;
_effectColor = glowColor;
@ -943,7 +921,7 @@ void Label::updateContent()
setOriginalString(utf16String);
if (_textSprite)
{
_textSprite->removeFromParent();
Node::removeChild(_textSprite,true);
_textSprite = nullptr;
}
if (_fontAtlas)
@ -1018,7 +996,7 @@ void Label::setFontSize(int fontSize)
{
if (_currentLabelType == LabelType::TTF)
{
if (_fontConfig.distanceFieldEnabled == true)
if (_fontConfig.distanceFieldEnabled)
{
_fontConfig.fontSize = fontSize;
this->setFontScale(1.0f * fontSize / DefultFontSize);
@ -1048,7 +1026,7 @@ Sprite * Label::getLetter(int lettetIndex)
if (! _textSprite && lettetIndex < _limitShowCount)
{
if(_lettersInfo[lettetIndex].def.validDefinition == false)
if(! _lettersInfo[lettetIndex].def.validDefinition)
return nullptr;
Sprite* sp = static_cast<Sprite*>(this->getChildByTag(lettetIndex));

View File

@ -110,7 +110,7 @@ public:
* @warning It will generate texture by the platform-dependent code and create Sprite for show text.
* To obtain better performance use createWithTTF/createWithBMFont/createWithCharMap
*/
static Label * createWithFontDefinition(const std::string& text, FontDefinition &textDefinition);
static Label * createWithFontDefinition(const std::string& text, const FontDefinition &textDefinition);
/** set TTF configuration for Label */
virtual bool setTTFConfig(const TTFConfig& ttfConfig);
@ -130,7 +130,7 @@ public:
const FontDefinition& getFontDefinition() const { return _fontDefinition; }
/** changes the string to render
* @warning It is as expensive as changing the string if you havn¡¯t set up using TTF/BMFont/CharMap for label.
* @warning It is as expensive as changing the string if you haven't set up TTF/BMFont/CharMap for the label.
*/
virtual void setString(const std::string& text) override;
@ -158,7 +158,7 @@ public:
void setAlignment(TextHAlignment hAlignment) { setAlignment(hAlignment,_vAlignment);}
TextHAlignment getTextAlignment() const { return _hAlignment;}
virtual void setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment);
void setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment);
void setHorizontalAlignment(TextHAlignment hAlignment) { setAlignment(hAlignment,_vAlignment); }
TextHAlignment getHorizontalAlignment() const { return _hAlignment; }
@ -166,13 +166,13 @@ public:
void setVerticalAlignment(TextVAlignment vAlignment) { setAlignment(_hAlignment,vAlignment); }
TextVAlignment getVerticalAlignment() const { return _vAlignment; }
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
void setLineBreakWithoutSpace(bool breakWithoutSpace);
/** Sets the max line width of the label.
* The label's max line width be used for force line breaks if the set value not equal zero.
* The label's width and max line width has not always to be equal.
*/
virtual void setMaxLineWidth(unsigned int maxLineWidth);
void setMaxLineWidth(unsigned int maxLineWidth);
unsigned int getMaxLineWidth() { return _maxLineWidth;}
/** Sets the untransformed size of the label.
@ -190,16 +190,17 @@ public:
unsigned int getHeight() const { return _labelHeight;}
/** Sets the untransformed size of the label in a more efficient way. */
virtual void setDimensions(unsigned int width,unsigned int height);
void setDimensions(unsigned int width,unsigned int height);
const Size& getDimensions() const{ return _labelDimensions;}
/** update content immediately.*/
virtual void updateContent();
virtual void setFontName(const std::string& fontName);
const std::string& getFontName() const { return _fontDefinition._fontName;}
virtual const std::string& getFontName() const { return _fontDefinition._fontName;}
virtual void setFontSize(int fontSize);
int getFontSize() const { return _fontDefinition._fontSize;}
virtual int getFontSize() const { return _fontDefinition._fontSize;}
virtual bool isOpacityModifyRGB() const override;
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
@ -212,8 +213,8 @@ public:
// string related stuff
int getStringNumLines() const { return _currNumLines;}
CC_DEPRECATED_ATTRIBUTE int getStringLenght() const { return getStringLength(); }
int getStringLength() const;
CC_DEPRECATED_ATTRIBUTE int getStringLenght() const { return getStringLength(); }
virtual void visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated) override;
virtual void draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) override;
@ -271,7 +272,6 @@ protected:
bool computeHorizontalKernings(unsigned short int *stringToRender);
bool setCurrentString(unsigned short *stringToSet);
bool setOriginalString(unsigned short *stringToSet);
void resetCurrentString();
void computeStringNumLines();
void updateSpriteWithLetterDefinition(const FontLetterDefinition &theDefinition, Texture2D *theTexture);
@ -308,6 +308,7 @@ protected:
int * _horizontalKernings;
unsigned int _maxLineWidth;
Size _labelDimensions;
unsigned int _labelWidth;
unsigned int _labelHeight;
TextHAlignment _hAlignment;