2013-07-11 02:59:05 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _StringTTF_h
|
|
|
|
#define _StringTTF_h
|
|
|
|
|
|
|
|
#include "CCFontDefinition.h"
|
|
|
|
#include "CCLabelTextFormatProtocol.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-07-13 03:39:47 +08:00
|
|
|
class StringTTF : public Node , public LabelTextFormatProtocol, public RGBAProtocol
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2013-07-19 04:13:41 +08:00
|
|
|
StringTTF(LabelFontDefinition *pDefinition, TextAlignment alignment = kTextAlignmentLeft);
|
2013-07-11 02:59:05 +08:00
|
|
|
~StringTTF();
|
|
|
|
|
|
|
|
bool setText(char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
|
2013-07-12 08:17:29 +08:00
|
|
|
|
2013-07-13 03:39:47 +08:00
|
|
|
// main interface
|
2013-07-12 08:17:29 +08:00
|
|
|
virtual void setAlignment(TextAlignment alignment);
|
|
|
|
virtual void setWidth(float width);
|
|
|
|
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
|
|
|
virtual void setScale(float scale);
|
|
|
|
virtual void setScaleX(float scaleX);
|
|
|
|
virtual void setScaleY(float scaleY);
|
|
|
|
|
2013-07-19 04:13:41 +08:00
|
|
|
|
2013-07-13 03:39:47 +08:00
|
|
|
// RGBAProtocol
|
|
|
|
|
|
|
|
virtual bool isOpacityModifyRGB() const;
|
|
|
|
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);
|
|
|
|
virtual unsigned char getOpacity() const;
|
|
|
|
virtual unsigned char getDisplayedOpacity() const;
|
|
|
|
virtual void setOpacity(GLubyte opacity);
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity);
|
|
|
|
virtual bool isCascadeOpacityEnabled() const;
|
|
|
|
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
|
|
|
|
virtual const Color3B& getColor(void) const;
|
|
|
|
virtual const Color3B& getDisplayedColor() const;
|
|
|
|
virtual void setColor(const Color3B& color);
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor);
|
|
|
|
virtual bool isCascadeColorEnabled() const;
|
|
|
|
virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
// CCLabelTextFormat protocol implementation
|
|
|
|
|
|
|
|
// sprite related stuff
|
2013-07-12 08:17:29 +08:00
|
|
|
virtual Sprite * getSpriteChild(int ID);
|
|
|
|
virtual Array * getChildrenLetters();
|
|
|
|
virtual Sprite * getSpriteForChar(unsigned short int theChar, int spriteIndexHint);
|
2013-07-11 02:59:05 +08:00
|
|
|
virtual float getLetterPosXLeft( Sprite* sp );
|
|
|
|
virtual float getLetterPosXRight( Sprite* sp );
|
|
|
|
|
|
|
|
// font related stuff
|
|
|
|
virtual int getCommonLineHeight();
|
|
|
|
virtual int getKerningForCharsPair(unsigned short first, unsigned short second);
|
|
|
|
virtual int getXOffsetForChar(unsigned short c);
|
|
|
|
virtual int getYOffsetForChar(unsigned short c);
|
|
|
|
virtual int getAdvanceForChar(unsigned short c, int hintPositionInString);
|
2013-07-12 08:17:29 +08:00
|
|
|
virtual Rect getRectForChar(unsigned short c) ;
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
// string related stuff
|
|
|
|
virtual int getStringNumLines();
|
|
|
|
virtual int getStringLenght();
|
|
|
|
virtual unsigned short getCharAtStringPosition(int position);
|
|
|
|
virtual unsigned short * getUTF8String();
|
|
|
|
virtual void assignNewUTF8String(unsigned short *newString);
|
2013-07-12 08:17:29 +08:00
|
|
|
virtual TextAlignment getTextAlignment();
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
// label related stuff
|
|
|
|
virtual float getMaxLineWidth() ;
|
|
|
|
virtual bool breakLineWithoutSpace();
|
2013-07-12 08:17:29 +08:00
|
|
|
virtual Size getLabelContentSize();
|
2013-07-11 02:59:05 +08:00
|
|
|
virtual void setLabelContentSize(const Size &newSize);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
void alignText();
|
|
|
|
void hideAllLetters();
|
|
|
|
void moveAllSpritesToCache();
|
|
|
|
bool computeAdvancesForString(const char *stringToRender);
|
|
|
|
bool computeAdvancesForString(unsigned short int *stringToRender);
|
|
|
|
bool setCurrentString(unsigned short *stringToSet);
|
2013-07-19 04:13:41 +08:00
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
Sprite * getSprite();
|
|
|
|
Sprite * createNewSpriteFromLetterDefinition(LetterDefinition &theDefinition, Texture2D *theTexture);
|
|
|
|
Sprite * updateSpriteWithLetterDefinition(Sprite *spriteToUpdate, LetterDefinition &theDefinition, Texture2D *theTexture);
|
|
|
|
Sprite * getSpriteForLetter(unsigned short int newLetter);
|
|
|
|
Sprite * updateSpriteForLetter(Sprite *spriteToUpdate, unsigned short int newLetter);
|
|
|
|
|
|
|
|
Array _spriteArray;
|
|
|
|
Array _spriteArrayCache;
|
|
|
|
float _commonLineHeight;
|
|
|
|
bool _lineBreakWithoutSpaces;
|
|
|
|
float _width;
|
|
|
|
TextAlignment _alignment;
|
|
|
|
LabelFontDefinition* _fontDef;
|
|
|
|
unsigned short int * _currentUTF8String;
|
|
|
|
Size * _advances;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-12 05:41:03 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
#endif
|
|
|
|
|
2013-07-12 05:41:03 +08:00
|
|
|
|