axmol/cocos/2d/CCLabelBMFont.h

150 lines
5.1 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies 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.
2011-07-08 14:32:09 +08:00
2012-03-22 09:46:07 +08:00
Use any of these editors to generate BMFonts:
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)
2011-07-08 14:32:09 +08:00
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
****************************************************************************/
#ifndef __CCBITMAP_FONT_ATLAS_H__
#define __CCBITMAP_FONT_ATLAS_H__
2012-03-22 09:46:07 +08:00
#include "CCLabel.h"
#if CC_LABELBMFONT_DEBUG_DRAW
#include "renderer/CCCustomCommand.h"
#endif
2012-03-22 09:46:07 +08:00
NS_CC_BEGIN
/** @brief LabelBMFont is a subclass of SpriteBatchNode.
2012-03-22 09:46:07 +08:00
Features:
- Treats each character like a Sprite. This means that each individual character can be:
2012-03-22 09:46:07 +08:00
- rotated
- scaled
- translated
- tinted
- change the opacity
2012-03-22 09:46:07 +08:00
- It can be used as part of a menu item.
- anchorPoint can be used to align the "label"
- Supports AngelCode text format
Limitations:
- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
because it might affect the rendering
LabelBMFont implements the protocol LabelProtocol, like Label and LabelAtlas.
LabelBMFont has the flexibility of Label, the speed of LabelAtlas and all the features of Sprite.
If in doubt, use LabelBMFont instead of LabelAtlas / Label.
2012-03-22 09:46:07 +08:00
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)
@since v0.8
*/
class CC_DLL CC_DEPRECATED_ATTRIBUTE LabelBMFont : public Node, public LabelProtocol, public BlendProtocol
2012-03-22 09:46:07 +08:00
{
public:
/**
* @js ctor
*/
LabelBMFont();
/**
* @js NA
* @lua NA
*/
virtual ~LabelBMFont();
/** creates a bitmap font atlas with an initial string and the FNT file */
2014-04-15 18:08:29 +08:00
static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vector2& imageOffset = Vector2::ZERO);
/** Creates an label.
*/
static LabelBMFont * create();
/** init a bitmap font atlas with an initial string and the FNT file */
2014-04-15 18:08:29 +08:00
bool initWithString(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vector2& imageOffset = Vector2::ZERO);
// super method
virtual void setString(const std::string& newString) override;
virtual const std::string& getString() const override;
virtual void setAlignment(TextHAlignment alignment);
virtual void setWidth(float width);
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
2012-11-15 17:16:51 +08:00
// RGBAProtocol
virtual bool isOpacityModifyRGB() const;
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);
2014-04-15 18:08:29 +08:00
void setFntFile(const std::string& fntFile, const Vector2& imageOffset = Vector2::ZERO);
const std::string& getFntFile() const;
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
virtual const BlendFunc &getBlendFunc() const override;
virtual Sprite * getLetter(int ID);
virtual Node * getChildByTag(int tag) override;
virtual void setColor(const Color3B& color) override;
virtual const Size& getContentSize() const override;
virtual Rect getBoundingBox() const override;
virtual std::string getDescription() const override;
#if CC_LABELBMFONT_DEBUG_DRAW
2014-04-23 14:59:45 +08:00
virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override;
#endif
private:
#if CC_LABELBMFONT_DEBUG_DRAW
CustomCommand _customDebugDrawCommand;
2014-04-23 14:59:45 +08:00
void drawDebugData(const Matrix& transform, bool transformUpdated);
#endif
// name of fntFile
std::string _fntFile;
2010-08-12 17:39:25 +08:00
Label* _label;
2010-08-12 17:39:25 +08:00
};
2012-03-22 09:46:07 +08:00
2012-06-20 18:09:11 +08:00
// end of GUI group
/// @}
/// @}
2012-03-22 09:46:07 +08:00
NS_CC_END
#endif //__CCBITMAP_FONT_ATLAS_H__