2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
|
|
|
|
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 __CCLABEL_H__
|
|
|
|
#define __CCLABEL_H__
|
|
|
|
#include "CCSprite.h"
|
|
|
|
#include "CCTexture2D.h"
|
|
|
|
|
2010-08-11 18:09:10 +08:00
|
|
|
namespace cocos2d{
|
|
|
|
|
2010-12-24 17:07:31 +08:00
|
|
|
/** @brief CCLabelTTF is a subclass of CCTextureNode that knows how to render text labels
|
2010-08-11 18:09:10 +08:00
|
|
|
*
|
2010-12-24 17:07:31 +08:00
|
|
|
* All features from CCTextureNode are valid in CCLabelTTF
|
2010-08-11 18:09:10 +08:00
|
|
|
*
|
2011-07-08 14:32:09 +08:00
|
|
|
* CCLabelTTF objects are slow. Consider using CCLabelAtlas or CCLabelBMFont instead.
|
2010-08-11 18:09:10 +08:00
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCLabelTTF : public CCSprite, public CCLabelProtocol
|
2010-08-11 18:09:10 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-03-15 11:59:45 +08:00
|
|
|
CCLabelTTF();
|
|
|
|
virtual ~CCLabelTTF();
|
2010-08-11 18:09:10 +08:00
|
|
|
char * description();
|
2010-12-24 17:07:31 +08:00
|
|
|
/** creates a CCLabelTTF from a fontname, alignment, dimension and font size */
|
2011-03-18 14:31:29 +08:00
|
|
|
static CCLabelTTF * labelWithString(const char *label, CCSize dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
|
2010-12-24 17:07:31 +08:00
|
|
|
/** creates a CCLabelTTF from a fontname and font size */
|
|
|
|
static CCLabelTTF * labelWithString(const char *label, const char *fontName, float fontSize);
|
|
|
|
/** initializes the CCLabelTTF with a font name, alignment, dimension and font size */
|
2011-03-18 14:31:29 +08:00
|
|
|
bool initWithString(const char *label, CCSize dimensions, CCTextAlignment alignment, const char *fontName, float fontSize);
|
2010-12-24 17:07:31 +08:00
|
|
|
/** initializes the CCLabelTTF with a font name and font size */
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithString(const char *label, const char *fontName, float fontSize);
|
2010-08-11 18:09:10 +08:00
|
|
|
|
|
|
|
/** changes the string to render
|
2010-12-24 17:07:31 +08:00
|
|
|
* @warning Changing the string is as expensive as creating a new CCLabelTTF. To obtain better performance use CCLabelAtlas
|
2010-08-11 18:09:10 +08:00
|
|
|
*/
|
|
|
|
virtual void setString(const char *label);
|
2010-12-28 15:05:55 +08:00
|
|
|
virtual const char* getString(void);
|
2010-08-31 11:20:37 +08:00
|
|
|
|
|
|
|
virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; }
|
2010-08-11 18:09:10 +08:00
|
|
|
protected:
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize m_tDimensions;
|
2011-03-18 14:31:29 +08:00
|
|
|
CCTextAlignment m_eAlignment;
|
2011-03-15 11:59:45 +08:00
|
|
|
std::string * m_pFontName;
|
2010-08-11 18:09:10 +08:00
|
|
|
float m_fFontSize;
|
2011-03-15 11:59:45 +08:00
|
|
|
std::string * m_pString;
|
2010-08-11 18:09:10 +08:00
|
|
|
};
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
} //namespace cocos2d
|
|
|
|
#endif //__CCLABEL_H__
|
|
|
|
|