2013-07-23 02:17:51 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
2013-07-27 07:04:21 +08:00
|
|
|
#ifndef _COCOS2D_CCLABEL_H_
|
|
|
|
#define _COCOS2D_CCLABEL_H_
|
2013-07-23 02:17:51 +08:00
|
|
|
|
|
|
|
#include "sprite_nodes/CCSpriteBatchNode.h"
|
2013-08-08 07:36:04 +08:00
|
|
|
#include "CCLabelTextFormatProtocol.h"
|
|
|
|
#include "ccTypes.h"
|
2013-07-23 02:17:51 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
enum class GlyphCollection {
|
2013-07-27 07:04:21 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
DYNAMIC,
|
|
|
|
NEHE,
|
|
|
|
ASCII,
|
|
|
|
CUSTOM
|
2013-07-27 07:04:21 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
};
|
|
|
|
|
2013-08-08 07:36:04 +08:00
|
|
|
//fwd
|
2013-08-15 21:38:27 +08:00
|
|
|
struct FontLetterDefinition;
|
2013-08-08 07:36:04 +08:00
|
|
|
class FontAtlas;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol, public LabelTextFormatProtocol
|
2013-07-23 02:17:51 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-23 05:43:45 +08:00
|
|
|
|
2013-08-13 07:16:34 +08:00
|
|
|
// static create
|
2013-08-13 06:41:29 +08:00
|
|
|
static Label* createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0 );
|
2013-08-13 07:16:34 +08:00
|
|
|
|
2013-08-13 06:09:28 +08:00
|
|
|
static Label* createWithBMFont( const char* label, const char* bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0 );
|
2013-07-23 05:43:45 +08:00
|
|
|
|
2013-08-08 07:36:04 +08:00
|
|
|
bool setText(const char *stringToRender, float lineWidth, TextHAlignment alignment = TextHAlignment::LEFT, bool lineBreakWithoutSpaces = false);
|
|
|
|
|
2013-08-13 07:16:34 +08:00
|
|
|
virtual void setString(const char *stringToRender);
|
2013-08-08 07:36:04 +08:00
|
|
|
virtual void setAlignment(TextHAlignment 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-08-13 07:16:34 +08:00
|
|
|
|
2013-08-08 07:36:04 +08:00
|
|
|
// RGBAProtocol
|
|
|
|
virtual bool isOpacityModifyRGB() const;
|
|
|
|
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);
|
|
|
|
virtual void setOpacity(GLubyte opacity);
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity);
|
|
|
|
virtual bool isCascadeOpacityEnabled() const;
|
|
|
|
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
|
|
|
|
virtual void setColor(const Color3B& color);
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor);
|
|
|
|
virtual bool isCascadeColorEnabled() const;
|
|
|
|
virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
|
|
|
|
virtual const Color3B& getColor(void) const;
|
|
|
|
virtual const Color3B& getDisplayedColor() const;
|
|
|
|
virtual unsigned char getOpacity() const;
|
|
|
|
virtual unsigned char getDisplayedOpacity() const;
|
|
|
|
|
|
|
|
// CCLabelTextFormat protocol implementation
|
|
|
|
virtual Sprite * getSpriteChild(int ID);
|
|
|
|
virtual Array * getChildrenLetters();
|
|
|
|
virtual Sprite * getSpriteForChar(unsigned short int theChar, int spriteIndexHint);
|
|
|
|
virtual float getLetterPosXLeft( Sprite* sp );
|
|
|
|
virtual float getLetterPosXRight( Sprite* sp );
|
2013-08-14 02:28:54 +08:00
|
|
|
|
2013-08-08 07:36:04 +08:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
virtual Rect getRectForChar(unsigned short c) ;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
virtual TextHAlignment getTextAlignment();
|
|
|
|
|
|
|
|
// label related stuff
|
|
|
|
virtual float getMaxLineWidth() ;
|
|
|
|
virtual bool breakLineWithoutSpace();
|
|
|
|
virtual Size getLabelContentSize();
|
|
|
|
virtual void setLabelContentSize(const Size &newSize);
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2013-08-13 07:16:34 +08:00
|
|
|
// carloX
|
|
|
|
const char * getString() const { return "not implemented"; }
|
2013-07-27 01:29:29 +08:00
|
|
|
|
2013-07-26 08:58:13 +08:00
|
|
|
private:
|
|
|
|
|
2013-08-13 07:16:34 +08:00
|
|
|
Label(FontAtlas *pAtlas, TextHAlignment alignment);
|
|
|
|
~Label();
|
|
|
|
|
|
|
|
static Label* createWithAtlas(FontAtlas *pAtlas, TextHAlignment alignment = TextHAlignment::LEFT, int lineSize = 0);
|
2013-08-08 07:36:04 +08:00
|
|
|
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
void alignText();
|
|
|
|
void hideAllLetters();
|
|
|
|
void moveAllSpritesToCache();
|
|
|
|
|
|
|
|
bool computeAdvancesForString(unsigned short int *stringToRender);
|
|
|
|
bool setCurrentString(unsigned short *stringToSet);
|
|
|
|
bool setOriginalString(unsigned short *stringToSet);
|
|
|
|
void resetCurrentString();
|
|
|
|
|
|
|
|
Sprite * getSprite();
|
|
|
|
Sprite * createNewSpriteFromLetterDefinition(FontLetterDefinition &theDefinition, Texture2D *theTexture);
|
|
|
|
Sprite * updateSpriteWithLetterDefinition(Sprite *spriteToUpdate, FontLetterDefinition &theDefinition, Texture2D *theTexture);
|
|
|
|
Sprite * getSpriteForLetter(unsigned short int newLetter);
|
|
|
|
Sprite * updateSpriteForLetter(Sprite *spriteToUpdate, unsigned short int newLetter);
|
|
|
|
|
2013-08-22 11:12:09 +08:00
|
|
|
Array * _spriteArray;
|
|
|
|
Array * _spriteArrayCache;
|
2013-08-08 07:36:04 +08:00
|
|
|
float _commonLineHeight;
|
|
|
|
bool _lineBreakWithoutSpaces;
|
|
|
|
float _width;
|
|
|
|
TextHAlignment _alignment;
|
|
|
|
unsigned short int * _currentUTF8String;
|
|
|
|
unsigned short int * _originalUTF8String;
|
|
|
|
Size * _advances;
|
|
|
|
FontAtlas * _fontAtlas;
|
|
|
|
Color3B _displayedColor;
|
|
|
|
Color3B _realColor;
|
|
|
|
bool _cascadeColorEnabled;
|
2013-08-13 04:29:54 +08:00
|
|
|
bool _cascadeOpacityEnabled;
|
|
|
|
unsigned char _displayedOpacity;
|
|
|
|
unsigned char _realOpacity;
|
|
|
|
bool _isOpacityModifyRGB;
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
};
|
|
|
|
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /*__COCOS2D_CCLABEL_H */
|