2013-07-23 02:17:51 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2015-03-19 10:38:12 +08:00
|
|
|
Copyright (c) 2013-2015 Chukong Technologies Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
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
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCSpriteBatchNode.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCCustomCommand.h"
|
2014-05-01 10:09:13 +08:00
|
|
|
#include "2d/CCFontAtlas.h"
|
2013-07-23 02:17:51 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
2015-03-24 14:12:58 +08:00
|
|
|
* @addtogroup _2d
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Possible GlyphCollection used by Label.
|
|
|
|
*
|
2015-03-25 10:59:04 +08:00
|
|
|
* Specify a collections of characters to be load when Label created.
|
|
|
|
* Consider using DYNAMIC.
|
2015-03-19 10:38:12 +08:00
|
|
|
*/
|
2013-07-23 02:17:51 +08:00
|
|
|
enum class GlyphCollection {
|
|
|
|
DYNAMIC,
|
|
|
|
NEHE,
|
|
|
|
ASCII,
|
|
|
|
CUSTOM
|
|
|
|
};
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* @brief Possible LabelEffect used by Label.
|
|
|
|
*
|
|
|
|
*/
|
2013-12-13 12:42:15 +08:00
|
|
|
enum class LabelEffect {
|
|
|
|
NORMAL,
|
|
|
|
OUTLINE,
|
|
|
|
SHADOW,
|
|
|
|
GLOW
|
|
|
|
};
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* @struct TTFConfig
|
2015-03-25 10:59:04 +08:00
|
|
|
* @see `GlyphCollection`
|
2015-03-19 10:38:12 +08:00
|
|
|
*/
|
2014-01-11 22:33:07 +08:00
|
|
|
typedef struct _ttfConfig
|
|
|
|
{
|
|
|
|
std::string fontFilePath;
|
|
|
|
int fontSize;
|
2015-03-25 10:59:04 +08:00
|
|
|
|
|
|
|
GlyphCollection glyphs;
|
2014-01-11 22:33:07 +08:00
|
|
|
const char *customGlyphs;
|
2015-03-25 10:59:04 +08:00
|
|
|
|
2014-01-15 17:21:08 +08:00
|
|
|
bool distanceFieldEnabled;
|
2014-03-05 15:54:40 +08:00
|
|
|
int outlineSize;
|
2014-01-11 22:33:07 +08:00
|
|
|
|
2014-03-13 18:46:35 +08:00
|
|
|
_ttfConfig(const char* filePath = "",int size = 12, const GlyphCollection& glyphCollection = GlyphCollection::DYNAMIC,
|
2014-03-05 15:54:40 +08:00
|
|
|
const char *customGlyphCollection = nullptr,bool useDistanceField = false,int outline = 0)
|
2014-01-11 22:33:07 +08:00
|
|
|
:fontFilePath(filePath)
|
2014-01-16 16:37:29 +08:00
|
|
|
,fontSize(size)
|
|
|
|
,glyphs(glyphCollection)
|
|
|
|
,customGlyphs(customGlyphCollection)
|
2014-01-15 17:21:08 +08:00
|
|
|
,distanceFieldEnabled(useDistanceField)
|
2014-03-05 15:54:40 +08:00
|
|
|
,outlineSize(outline)
|
|
|
|
{
|
|
|
|
if(outline > 0)
|
|
|
|
{
|
|
|
|
distanceFieldEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
2014-01-11 22:33:07 +08:00
|
|
|
}TTFConfig;
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* @brief Label is a subclass of SpriteBatchNode that knows how to render text labels.
|
|
|
|
*
|
|
|
|
* Label can be created with:
|
|
|
|
* - A true type font file.
|
|
|
|
* - A bitmap font file.
|
|
|
|
* - A char map file.
|
|
|
|
* - The built in system font.
|
|
|
|
*
|
|
|
|
* Bitmap Font supported editors:
|
|
|
|
* - http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
|
|
|
|
* - http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
|
|
|
|
* - http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
|
|
|
|
* - http://www.angelcode.com/products/bmfont/ (Free, Windows only)
|
2015-03-28 14:28:16 +08:00
|
|
|
* @js NA
|
2015-03-19 10:38:12 +08:00
|
|
|
*/
|
2014-01-23 13:42:27 +08:00
|
|
|
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol
|
2013-07-23 02:17:51 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-03-13 20:52:33 +08:00
|
|
|
static const int DistanceFieldFontSize;
|
2014-03-05 15:54:40 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/// @name Creators
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, with default settings.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
*/
|
2014-01-11 22:33:07 +08:00
|
|
|
static Label* create();
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, base on platform-dependent API.
|
|
|
|
*
|
|
|
|
* @param text The initial text.
|
|
|
|
* @param font A font file or a font family name.
|
|
|
|
* @param fontSize The font size. This value must be > 0.
|
|
|
|
* @param dimensions
|
|
|
|
* @param hAlignment The text horizontal alignment.
|
|
|
|
* @param vAlignment The text vertical alignment.
|
|
|
|
*
|
|
|
|
* @warning It will generate texture by the platform-dependent code.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
2014-03-10 19:42:43 +08:00
|
|
|
*/
|
2014-04-09 23:31:05 +08:00
|
|
|
static Label* createWithSystemFont(const std::string& text, const std::string& font, float fontSize,
|
2014-03-10 19:42:43 +08:00
|
|
|
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
|
|
|
|
TextVAlignment vAlignment = TextVAlignment::TOP);
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, base on FreeType2.
|
|
|
|
*
|
|
|
|
* @param text The initial text.
|
|
|
|
* @param fontFilePath A font file.
|
|
|
|
* @param fontSize The font size. This value must be > 0.
|
|
|
|
* @param dimensions
|
|
|
|
* @param hAlignment The text horizontal alignment.
|
|
|
|
* @param vAlignment The text vertical alignment.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
*/
|
|
|
|
static Label * createWithTTF(const std::string& text, const std::string& fontFilePath, float fontSize,
|
2014-03-10 19:42:43 +08:00
|
|
|
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
|
|
|
|
TextVAlignment vAlignment = TextVAlignment::TOP);
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, base on FreeType2.
|
|
|
|
*
|
|
|
|
* @param ttfConfig A pointer to a TTFConfig object.
|
|
|
|
* @param text The initial text.
|
|
|
|
* @param hAlignment The text horizontal alignment.
|
|
|
|
* @param maxLineWidth The max line width.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
* @see TTFConfig setTTFConfig setMaxLineWidth
|
|
|
|
*/
|
|
|
|
static Label* createWithTTF(const TTFConfig& ttfConfig, const std::string& text, TextHAlignment hAlignment = TextHAlignment::LEFT, int maxLineWidth = 0);
|
2013-07-23 05:43:45 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, with a bitmap font file.
|
|
|
|
*
|
|
|
|
* @param bmfontPath A bitmap font file, it's a FNT format.
|
|
|
|
* @param text The initial text.
|
|
|
|
* @param hAlignment Text horizontal alignment.
|
|
|
|
* @param maxLineWidth The max line width.
|
|
|
|
* @param imageOffset
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
* @see setBMFontFilePath setMaxLineWidth
|
|
|
|
*/
|
|
|
|
static Label* createWithBMFont(const std::string& bmfontPath, const std::string& text,
|
|
|
|
const TextHAlignment& hAlignment = TextHAlignment::LEFT, int maxLineWidth = 0,
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2& imageOffset = Vec2::ZERO);
|
2013-07-23 05:43:45 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, with char map configuration.
|
|
|
|
*
|
|
|
|
* @param charMapFile A char map file, it's a PNG format.
|
|
|
|
* @param itemWidth The width in points of each element.
|
|
|
|
* @param itemHeight The height in points of each element.
|
|
|
|
* @param startCharMap The starting char of the char map.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
*/
|
2014-01-16 16:37:29 +08:00
|
|
|
static Label * createWithCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, with char map configuration.
|
|
|
|
*
|
|
|
|
* @param texture A pointer to an existing Texture2D object.
|
|
|
|
* @param itemWidth The width in points of each element.
|
|
|
|
* @param itemHeight The height in points of each element.
|
|
|
|
* @param startCharMap The starting char of the char map.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
*/
|
2014-01-16 16:37:29 +08:00
|
|
|
static Label * createWithCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates and initializes a Label, with char map configuration.
|
|
|
|
*
|
|
|
|
* @param plistFile A configuration file of char map.
|
|
|
|
*
|
|
|
|
* @return An automatically released Label object.
|
|
|
|
*/
|
2014-01-16 16:37:29 +08:00
|
|
|
static Label * createWithCharMap(const std::string& plistFile);
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
// end of creators group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// @{
|
|
|
|
/// @name Font methods
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new TTF configuration to Label.
|
|
|
|
* @see `TTFConfig`
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual bool setTTFConfig(const TTFConfig& ttfConfig);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the TTF configuration object used by the Label.
|
|
|
|
* @see `TTFConfig`
|
|
|
|
*/
|
2014-04-10 10:23:00 +08:00
|
|
|
virtual const TTFConfig& getTTFConfig() const { return _fontConfig;}
|
2013-12-13 12:42:15 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets a new bitmap font to Label */
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual bool setBMFontFilePath(const std::string& bmfontFilePath, const Vec2& imageOffset = Vec2::ZERO);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the bitmap font used by the Label.*/
|
2014-03-17 18:33:15 +08:00
|
|
|
const std::string& getBMFontFilePath() const { return _bmFontPath;}
|
2014-01-11 22:33:07 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Sets a new char map configuration to Label.
|
|
|
|
*
|
|
|
|
* @see `createWithCharMap(const std::string&,int,int,int)`
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual bool setCharMap(const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new char map configuration to Label.
|
|
|
|
*
|
|
|
|
* @see `createWithCharMap(Texture2D*,int,int,int)`
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual bool setCharMap(Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new char map configuration to Label.
|
|
|
|
*
|
|
|
|
* @see `createWithCharMap(const std::string&)`
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual bool setCharMap(const std::string& plistFile);
|
2014-01-16 16:37:29 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Sets a new system font to Label.
|
|
|
|
*
|
|
|
|
* @param font A font file or a font family name.
|
|
|
|
* @warning
|
|
|
|
*/
|
|
|
|
virtual void setSystemFontName(const std::string& font);
|
|
|
|
|
|
|
|
/** Returns the system font used by the Label.*/
|
2014-04-10 10:23:00 +08:00
|
|
|
virtual const std::string& getSystemFontName() const { return _systemFont;}
|
2014-03-10 19:42:43 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/* Sets the system font size of Label.*/
|
2014-04-09 23:31:05 +08:00
|
|
|
virtual void setSystemFontSize(float fontSize);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the bitmap font path used by the Label.*/
|
2014-04-09 23:31:05 +08:00
|
|
|
virtual float getSystemFontSize() const { return _systemFontSize;}
|
2014-03-10 19:42:43 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* @warning This method is not recommended for game developers.
|
|
|
|
*/
|
2014-10-09 18:28:09 +08:00
|
|
|
virtual void requestSystemFontRefresh() { _systemFontDirty = true;}
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
// end of font methods
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/** Sets the text that this Label is to display.*/
|
2014-01-23 13:42:27 +08:00
|
|
|
virtual void setString(const std::string& text) override;
|
2014-01-11 22:33:07 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Return the text the Label is displaying.*/
|
2014-03-07 14:58:44 +08:00
|
|
|
virtual const std::string& getString() const override { return _originalUTF8String; }
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
int getStringNumLines() const;
|
|
|
|
|
|
|
|
int getStringLength() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the text color of Label.
|
|
|
|
*
|
|
|
|
* The text color is different from the color of Node.
|
|
|
|
*
|
|
|
|
* @warning Limiting use to only when the Label created with true type font or system font.
|
2014-06-12 12:01:15 +08:00
|
|
|
*/
|
|
|
|
virtual void setTextColor(const Color4B &color);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the text color of the Label.*/
|
2014-06-12 12:01:15 +08:00
|
|
|
const Color4B& getTextColor() const { return _textColor;}
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
/**
|
2015-03-19 10:38:12 +08:00
|
|
|
* Enable shadow effect to Label.
|
2014-03-05 15:54:40 +08:00
|
|
|
*
|
2015-03-19 10:38:12 +08:00
|
|
|
* @todo Support blur for shadow effect.
|
2014-03-05 15:54:40 +08:00
|
|
|
*/
|
2014-03-20 20:56:10 +08:00
|
|
|
virtual void enableShadow(const Color4B& shadowColor = Color4B::BLACK,const Size &offset = Size(2,-2), int blurRadius = 0);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Enable outline effect to Label.
|
|
|
|
* @warning Limiting use to only when the Label created with true type font or system font.
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual void enableOutline(const Color4B& outlineColor,int outlineSize = -1);
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Enable glow effect to Label.
|
|
|
|
* @warning Limiting use to only when the Label created with true type font.
|
|
|
|
*/
|
2014-03-20 20:56:10 +08:00
|
|
|
virtual void enableGlow(const Color4B& glowColor);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Disable all effect to Label.
|
|
|
|
*/
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual void disableEffect();
|
2014-03-07 14:58:44 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the Label's text horizontal alignment.*/
|
2014-03-10 20:35:36 +08:00
|
|
|
void setAlignment(TextHAlignment hAlignment) { setAlignment(hAlignment,_vAlignment);}
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the Label's text horizontal alignment.*/
|
2014-03-07 14:58:44 +08:00
|
|
|
TextHAlignment getTextAlignment() const { return _hAlignment;}
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the Label's text alignment.*/
|
2014-03-11 14:32:07 +08:00
|
|
|
void setAlignment(TextHAlignment hAlignment,TextVAlignment vAlignment);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the Label's text horizontal alignment.*/
|
2014-03-10 20:35:36 +08:00
|
|
|
void setHorizontalAlignment(TextHAlignment hAlignment) { setAlignment(hAlignment,_vAlignment); }
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the Label's text horizontal alignment.*/
|
2014-03-07 14:58:44 +08:00
|
|
|
TextHAlignment getHorizontalAlignment() const { return _hAlignment; }
|
2014-03-07 15:58:49 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the Label's text vertical alignment.*/
|
2014-03-10 20:35:36 +08:00
|
|
|
void setVerticalAlignment(TextVAlignment vAlignment) { setAlignment(_hAlignment,vAlignment); }
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/** Returns the Label's text vertical alignment.*/
|
2014-03-07 14:58:44 +08:00
|
|
|
TextVAlignment getVerticalAlignment() const { return _vAlignment; }
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Specify what happens when a line is too long for Label.
|
|
|
|
*
|
|
|
|
* @param breakWithoutSpace Lines are automatically broken between words if this value is false.
|
|
|
|
*/
|
2014-03-11 14:32:07 +08:00
|
|
|
void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
2013-08-13 07:16:34 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Makes the Label at most this line untransformed width.
|
|
|
|
* The Label's max line width be used for force line breaks if the value not equal zero.
|
2014-03-07 14:58:44 +08:00
|
|
|
*/
|
2015-01-20 11:46:43 +08:00
|
|
|
void setMaxLineWidth(float maxLineWidth);
|
|
|
|
float getMaxLineWidth() { return _maxLineWidth; }
|
2014-03-07 14:58:44 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Makes the Label exactly this untransformed width.
|
|
|
|
*
|
|
|
|
* The Label's width be used for text align if the value not equal zero.
|
2014-03-07 14:58:44 +08:00
|
|
|
*/
|
2015-01-20 11:46:43 +08:00
|
|
|
void setWidth(float width) { setDimensions(width,_labelHeight);}
|
|
|
|
float getWidth() const { return _labelWidth; }
|
2014-03-07 14:58:44 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Makes the Label exactly this untransformed height.
|
|
|
|
*
|
|
|
|
* The Label's height be used for text align if the value not equal zero.
|
|
|
|
* The text will display of incomplete when the size of Label not enough to support display all text.
|
2014-03-07 14:58:44 +08:00
|
|
|
*/
|
2015-01-20 11:46:43 +08:00
|
|
|
void setHeight(float height){ setDimensions(_labelWidth, height); }
|
|
|
|
float getHeight() const { return _labelHeight; }
|
2014-03-07 14:58:44 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the untransformed size of the Label in a more efficient way. */
|
2015-01-20 11:46:43 +08:00
|
|
|
void setDimensions(float width, float height);
|
2014-03-11 14:32:07 +08:00
|
|
|
const Size& getDimensions() const{ return _labelDimensions;}
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Update content immediately.*/
|
2014-03-10 19:42:43 +08:00
|
|
|
virtual void updateContent();
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Provides a way to treats each character like a Sprite.
|
|
|
|
* @warning No support system font.
|
|
|
|
*/
|
2014-02-19 20:26:14 +08:00
|
|
|
virtual Sprite * getLetter(int lettetIndex);
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Makes the Label to clip upper and lower margin for reduce height of Label.*/
|
2014-03-24 14:16:27 +08:00
|
|
|
void setClipMarginEnabled(bool clipEnabled) { _clipEnabled = clipEnabled; }
|
2015-03-19 10:38:12 +08:00
|
|
|
|
2014-03-25 16:37:34 +08:00
|
|
|
bool isClipMarginEnabled() const { return _clipEnabled; }
|
2014-06-12 12:01:15 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/** Sets the line height of the Label.
|
|
|
|
* @warning Not support system font.
|
|
|
|
* @since v3.2.0
|
2014-06-12 12:01:15 +08:00
|
|
|
*/
|
|
|
|
void setLineHeight(float height);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the line height of this Label.
|
|
|
|
* @warning Not support system font.
|
|
|
|
* @since v3.2.0
|
2014-06-12 12:01:15 +08:00
|
|
|
*/
|
|
|
|
float getLineHeight() const;
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* Sets the additional kerning of the Label.
|
|
|
|
*
|
|
|
|
* @warning Not support system font.
|
|
|
|
* @since v3.2.0
|
2014-06-12 12:01:15 +08:00
|
|
|
*/
|
|
|
|
void setAdditionalKerning(float space);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the additional kerning of the Label.
|
|
|
|
*
|
|
|
|
* @warning Not support system font.
|
|
|
|
* @since v3.2.0
|
2014-06-12 12:01:15 +08:00
|
|
|
*/
|
|
|
|
float getAdditionalKerning() const;
|
|
|
|
|
2014-04-02 14:57:00 +08:00
|
|
|
FontAtlas* getFontAtlas() { return _fontAtlas; }
|
2013-07-26 08:58:13 +08:00
|
|
|
|
2014-04-02 14:57:00 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
|
|
|
|
|
|
|
|
virtual bool isOpacityModifyRGB() const override;
|
|
|
|
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
|
|
|
|
virtual void updateDisplayedColor(const Color3B& parentColor) override;
|
|
|
|
virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
|
2013-12-13 06:30:22 +08:00
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
virtual void setScale(float scale) override;
|
|
|
|
virtual void setScaleX(float scaleX) override;
|
|
|
|
virtual void setScaleY(float scaleY) override;
|
|
|
|
virtual float getScaleX() const override;
|
|
|
|
virtual float getScaleY() const override;
|
|
|
|
|
|
|
|
virtual void addChild(Node * child, int zOrder=0, int tag=0) override;
|
2014-03-26 16:23:23 +08:00
|
|
|
virtual void sortAllChildren() override;
|
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-01-22 14:57:11 +08:00
|
|
|
|
2014-03-11 15:03:16 +08:00
|
|
|
virtual const Size& getContentSize() const override;
|
2014-03-10 19:42:43 +08:00
|
|
|
|
2014-03-28 15:58:28 +08:00
|
|
|
virtual Rect getBoundingBox() const override;
|
2014-03-28 11:03:39 +08:00
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
virtual void visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
|
|
|
|
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
2014-04-02 14:57:00 +08:00
|
|
|
|
2015-03-16 17:11:17 +08:00
|
|
|
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
|
2015-03-16 15:31:29 +08:00
|
|
|
|
2014-04-10 10:58:49 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static Label* create(const std::string& text, const std::string& font, float fontSize,
|
|
|
|
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,
|
|
|
|
TextVAlignment vAlignment = TextVAlignment::TOP);
|
2014-04-02 14:57:00 +08:00
|
|
|
|
2014-04-09 21:35:08 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void setFontDefinition(const FontDefinition& textDefinition);
|
|
|
|
CC_DEPRECATED_ATTRIBUTE const FontDefinition& getFontDefinition() const { return _fontDefinition; }
|
2014-04-02 14:57:00 +08:00
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
/**
|
|
|
|
* @deprecated Use `getLineHeight` instead.
|
|
|
|
*/
|
2014-10-23 17:54:15 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE int getCommonLineHeight() const { return (int)getLineHeight();}
|
2014-06-12 12:01:15 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
/**
|
2015-03-19 10:38:12 +08:00
|
|
|
* Constructor of Label.
|
2014-08-21 15:11:33 +08:00
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
Label(FontAtlas *atlas = nullptr, TextHAlignment hAlignment = TextHAlignment::LEFT,
|
|
|
|
TextVAlignment vAlignment = TextVAlignment::TOP,bool useDistanceField = false,bool useA8Shader = false);
|
2015-03-19 10:38:12 +08:00
|
|
|
|
2014-08-21 15:11:33 +08:00
|
|
|
/**
|
2015-03-19 10:38:12 +08:00
|
|
|
* Destructor of Label.
|
2014-08-21 15:11:33 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~Label();
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
protected:
|
2014-05-15 01:07:09 +08:00
|
|
|
void onDraw(const Mat4& transform, bool transformUpdated);
|
2014-03-06 07:49:08 +08:00
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
struct LetterInfo
|
|
|
|
{
|
|
|
|
FontLetterDefinition def;
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 position;
|
2014-02-19 20:26:14 +08:00
|
|
|
Size contentSize;
|
2014-03-17 18:33:15 +08:00
|
|
|
int atlasIndex;
|
2014-02-19 20:26:14 +08:00
|
|
|
};
|
2014-03-10 19:42:43 +08:00
|
|
|
enum class LabelType {
|
|
|
|
|
2014-03-10 20:35:36 +08:00
|
|
|
TTF,
|
|
|
|
BMFONT,
|
|
|
|
CHARMAP,
|
|
|
|
STRING_TEXTURE
|
2014-03-10 19:42:43 +08:00
|
|
|
};
|
|
|
|
|
2014-03-13 20:52:33 +08:00
|
|
|
virtual void setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled = false, bool useA8Shader = false);
|
2014-02-19 20:26:14 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
bool recordLetterInfo(const cocos2d::Vec2& point,const FontLetterDefinition& letterDef, int spriteIndex);
|
2014-03-05 15:54:40 +08:00
|
|
|
bool recordPlaceholderInfo(int spriteIndex);
|
2014-02-19 20:26:14 +08:00
|
|
|
|
|
|
|
void setFontScale(float fontScale);
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
virtual void alignText();
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2014-05-08 11:12:59 +08:00
|
|
|
bool computeHorizontalKernings(const std::u16string& stringToRender);
|
2014-05-08 21:30:12 +08:00
|
|
|
|
2014-02-10 11:21:54 +08:00
|
|
|
void computeStringNumLines();
|
2013-12-06 18:07:16 +08:00
|
|
|
|
2014-03-17 18:33:15 +08:00
|
|
|
void updateQuads();
|
2013-12-11 16:38:47 +08:00
|
|
|
|
|
|
|
virtual void updateColor() override;
|
|
|
|
|
2014-03-13 21:00:36 +08:00
|
|
|
virtual void updateShaderProgram();
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
|
|
void drawShadowWithoutBlur();
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void drawTextSprite(Renderer *renderer, uint32_t parentFlags);
|
2014-03-26 11:09:16 +08:00
|
|
|
|
2014-03-10 19:42:43 +08:00
|
|
|
void createSpriteWithFontDefinition();
|
|
|
|
|
2014-03-13 18:46:35 +08:00
|
|
|
void updateFont();
|
|
|
|
void reset();
|
|
|
|
|
2014-03-17 18:33:15 +08:00
|
|
|
std::string _bmFontPath;
|
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
bool _isOpacityModifyRGB;
|
2014-03-10 19:42:43 +08:00
|
|
|
bool _contentDirty;
|
2014-04-09 23:31:05 +08:00
|
|
|
|
2014-05-08 21:30:12 +08:00
|
|
|
bool _systemFontDirty;
|
2014-04-09 23:31:05 +08:00
|
|
|
std::string _systemFont;
|
|
|
|
float _systemFontSize;
|
2014-03-10 20:35:36 +08:00
|
|
|
LabelType _currentLabelType;
|
2014-03-07 14:58:44 +08:00
|
|
|
|
|
|
|
std::vector<SpriteBatchNode*> _batchNodes;
|
|
|
|
FontAtlas * _fontAtlas;
|
|
|
|
std::vector<LetterInfo> _lettersInfo;
|
|
|
|
|
|
|
|
TTFConfig _fontConfig;
|
|
|
|
|
2014-03-10 19:42:43 +08:00
|
|
|
//compatibility with older LabelTTF
|
|
|
|
Sprite* _textSprite;
|
|
|
|
FontDefinition _fontDefinition;
|
2014-04-14 13:42:37 +08:00
|
|
|
bool _compatibleMode;
|
2014-03-10 19:42:43 +08:00
|
|
|
|
2013-10-29 20:25:03 +08:00
|
|
|
//! used for optimization
|
2014-01-17 13:35:58 +08:00
|
|
|
Sprite *_reusedLetter;
|
2014-02-19 20:26:14 +08:00
|
|
|
Rect _reusedRect;
|
2014-03-07 14:58:44 +08:00
|
|
|
int _limitShowCount;
|
2014-01-15 17:21:08 +08:00
|
|
|
|
2014-06-12 12:01:15 +08:00
|
|
|
float _additionalKerning;
|
2014-01-17 13:35:58 +08:00
|
|
|
float _commonLineHeight;
|
2014-02-19 20:26:14 +08:00
|
|
|
bool _lineBreakWithoutSpaces;
|
2014-03-07 14:58:44 +08:00
|
|
|
int * _horizontalKernings;
|
|
|
|
|
2015-01-20 11:46:43 +08:00
|
|
|
float _maxLineWidth;
|
|
|
|
Size _labelDimensions;
|
|
|
|
float _labelWidth;
|
|
|
|
float _labelHeight;
|
2014-03-07 14:58:44 +08:00
|
|
|
TextHAlignment _hAlignment;
|
|
|
|
TextVAlignment _vAlignment;
|
|
|
|
|
|
|
|
int _currNumLines;
|
2014-05-08 11:12:59 +08:00
|
|
|
std::u16string _currentUTF16String;
|
2014-01-23 13:42:27 +08:00
|
|
|
std::string _originalUTF8String;
|
2014-03-07 14:58:44 +08:00
|
|
|
|
|
|
|
float _fontScale;
|
2013-12-13 12:42:15 +08:00
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
bool _useDistanceField;
|
|
|
|
bool _useA8Shader;
|
2013-12-13 12:42:15 +08:00
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
LabelEffect _currLabelEffect;
|
2014-03-20 20:56:10 +08:00
|
|
|
Color4B _effectColor;
|
|
|
|
Color4F _effectColorF;
|
2013-12-13 12:42:15 +08:00
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
GLuint _uniformEffectColor;
|
2014-03-20 20:56:10 +08:00
|
|
|
GLuint _uniformTextColor;
|
2014-03-07 14:58:44 +08:00
|
|
|
CustomCommand _customCommand;
|
2014-02-19 20:26:14 +08:00
|
|
|
|
2014-03-31 18:16:08 +08:00
|
|
|
bool _shadowDirty;
|
2014-03-26 11:09:16 +08:00
|
|
|
bool _shadowEnabled;
|
2014-03-05 15:54:40 +08:00
|
|
|
Size _shadowOffset;
|
|
|
|
int _shadowBlurRadius;
|
2014-05-15 01:07:09 +08:00
|
|
|
Mat4 _shadowTransform;
|
2014-03-26 11:09:16 +08:00
|
|
|
Color3B _shadowColor;
|
2014-04-01 14:15:35 +08:00
|
|
|
float _shadowOpacity;
|
2014-03-31 11:47:28 +08:00
|
|
|
Sprite* _shadowNode;
|
2014-03-05 15:54:40 +08:00
|
|
|
|
2014-04-09 21:35:08 +08:00
|
|
|
int _outlineSize;
|
|
|
|
|
2014-03-20 20:56:10 +08:00
|
|
|
Color4B _textColor;
|
|
|
|
Color4F _textColorF;
|
2014-03-05 15:54:40 +08:00
|
|
|
|
2014-03-24 14:16:27 +08:00
|
|
|
bool _clipEnabled;
|
2014-03-31 15:45:06 +08:00
|
|
|
bool _blendFuncDirty;
|
2015-03-19 10:38:12 +08:00
|
|
|
/// whether or not the sprite was inside bounds the previous frame
|
|
|
|
bool _insideBounds;
|
2014-03-24 14:16:27 +08:00
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Label);
|
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
friend class LabelTextFormatter;
|
2013-07-23 02:17:51 +08:00
|
|
|
};
|
|
|
|
|
2015-03-19 10:38:12 +08:00
|
|
|
// end group
|
|
|
|
/// @}
|
2013-08-08 07:36:04 +08:00
|
|
|
|
2013-07-23 02:17:51 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /*__COCOS2D_CCLABEL_H */
|