2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-04 10:59:35 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2011-03-19 10:59:01 +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.
|
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)
|
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCBITMAP_FONT_ATLAS_H__
|
|
|
|
#define __CCBITMAP_FONT_ATLAS_H__
|
2012-03-22 09:46:07 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCLabel.h"
|
2014-04-22 23:18:23 +08:00
|
|
|
#if CC_LABELBMFONT_DEBUG_DRAW
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/renderer/CCCustomCommand.h"
|
2014-04-22 23:18:23 +08:00
|
|
|
#endif
|
2012-03-22 09:46:07 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief LabelBMFont is a subclass of SpriteBatchNode.
|
2012-03-22 09:46:07 +08:00
|
|
|
|
|
|
|
Features:
|
2013-06-20 14:13:12 +08:00
|
|
|
- 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
|
2012-09-17 15:02:24 +08:00
|
|
|
- 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
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2014-03-28 14:18:01 +08:00
|
|
|
class CC_DLL CC_DEPRECATED_ATTRIBUTE LabelBMFont : public Node, public LabelProtocol, public BlendProtocol
|
2012-03-22 09:46:07 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
LabelBMFont();
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~LabelBMFont();
|
2012-12-06 18:51:33 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
/** 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);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 18:32:44 +08:00
|
|
|
/** Creates an label.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static LabelBMFont * create();
|
2012-06-14 18:32:44 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
/** 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);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// super method
|
2013-11-08 04:42:16 +08:00
|
|
|
virtual void setString(const std::string& newString) override;
|
2013-03-20 13:55:43 +08:00
|
|
|
|
2013-11-08 04:42:16 +08:00
|
|
|
virtual const std::string& getString() const override;
|
2014-02-20 22:33:52 +08:00
|
|
|
|
2013-07-27 07:04:21 +08:00
|
|
|
virtual void setAlignment(TextHAlignment alignment);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void setWidth(float width);
|
|
|
|
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// RGBAProtocol
|
2013-07-04 08:22:15 +08:00
|
|
|
virtual bool isOpacityModifyRGB() const;
|
|
|
|
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);
|
2011-12-28 14:46:49 +08:00
|
|
|
|
2014-04-15 18:08:29 +08:00
|
|
|
void setFntFile(const std::string& fntFile, const Vector2& imageOffset = Vector2::ZERO);
|
2013-11-15 09:19:16 +08:00
|
|
|
const std::string& getFntFile() const;
|
2013-12-13 06:30:22 +08:00
|
|
|
|
2014-02-20 22:33:52 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
|
|
|
|
|
|
|
|
virtual const BlendFunc &getBlendFunc() const override;
|
|
|
|
|
2014-03-28 14:18:01 +08:00
|
|
|
virtual Sprite * getLetter(int ID);
|
2014-02-20 22:33:52 +08:00
|
|
|
virtual Node * getChildByTag(int tag) override;
|
|
|
|
|
2014-03-28 14:18:01 +08:00
|
|
|
virtual void setColor(const Color3B& color) override;
|
2014-02-20 22:33:52 +08:00
|
|
|
|
2014-03-28 15:58:28 +08:00
|
|
|
virtual const Size& getContentSize() const override;
|
|
|
|
virtual Rect getBoundingBox() const override;
|
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-04-23 15:05:02 +08:00
|
|
|
#if CC_LABELBMFONT_DEBUG_DRAW
|
2014-04-23 14:59:45 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override;
|
2014-04-23 15:05:02 +08:00
|
|
|
#endif
|
2013-12-13 06:30:22 +08:00
|
|
|
|
2014-04-23 15:05:02 +08:00
|
|
|
private:
|
2011-07-04 10:59:35 +08:00
|
|
|
#if CC_LABELBMFONT_DEBUG_DRAW
|
2014-04-22 23:18:23 +08:00
|
|
|
CustomCommand _customDebugDrawCommand;
|
2014-04-23 14:59:45 +08:00
|
|
|
void drawDebugData(const Matrix& transform, bool transformUpdated);
|
2014-04-23 15:05:02 +08:00
|
|
|
#endif
|
2013-02-28 10:37:47 +08:00
|
|
|
|
|
|
|
// name of fntFile
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string _fntFile;
|
2010-08-12 17:39:25 +08:00
|
|
|
|
2014-02-20 22:33:52 +08:00
|
|
|
Label* _label;
|
2010-08-12 17:39:25 +08:00
|
|
|
|
2014-02-20 22:33:52 +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
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
#endif //__CCBITMAP_FONT_ATLAS_H__
|