cococococos 2 d-Xノード(CCLabelBMFont.h)API
7970 ワード
本論文はhttp://blog.csdn.net/runaying ,引用は出典を明記しなければならない!
cococococos 2 d-Xノード(CCLabelBMFont.h)API
みなさんがよりよく勉強できるように、私のブログを見ることを強くおすすめします。 Cocos 2 d-X権威ガイドノート
cococococos 2 d-Xノード(CCLabelBMFont.h)API
みなさんがよりよく勉強できるように、私のブログを見ることを強くおすすめします。 Cocos 2 d-X権威ガイドノート
///cocos2d-x-3.0alpha0/cocos2dx/label_nodes
#ifndef __CCBITMAP_FONT_ATLAS_H__
#define __CCBITMAP_FONT_ATLAS_H__
#include "sprite_nodes/CCSpriteBatchNode.h"
#include "support/data_support/uthash.h"
#include <map>
#include <sstream>
#include <iostream>
#include <vector>
NS_CC_BEGIN
/**
* @addtogroup GUI
* @{
* @addtogroup label
* @{
*/
enum {
kLabelAutomaticWidth = -1,
};
struct _FontDefHashElement;
/**
@ ccBMFontDef
BMFont
*/
typedef struct _BMFontDef {
//!
unsigned int charID;
//! font
Rect rect;
//! X ( )
short xOffset;
//! Y ( )
short yOffset;
//! ( )
short xAdvance;
} ccBMFontDef;
/** @ ccBMFontPadding
BMFont
@since v0.8.2
*/
typedef struct _BMFontPadding {
/// padding left //
int left;
/// padding top //
int top;
/// padding right //
int right;
/// padding bottom //
int bottom;
} ccBMFontPadding;
typedef struct _FontDefHashElement
{
unsigned int key; // key. font unicode
ccBMFontDef fontDef; // font
UT_hash_handle hh;
} tFontDefHashElement;
// targetSet wqual .
typedef struct _KerningHashElement
{
int key; // hash . 16-bit 16-bit
int amount;
UT_hash_handle hh;
} tKerningHashElement;
/** @ CCBMFontConfiguration .fnt
@since v0.8
*/
class CC_DLL CCBMFontConfiguration : public Object
{
// XXX: bitmapFontArray[]
public://@public
// BMFont
tFontDefHashElement *_fontDefDictionary;
//! FNTConfig: (issue( ) #1343)
int _commonHeight;
//!
ccBMFontPadding _padding;
//! atlas( )
std::string _atlasName;
//!
tKerningHashElement *_kerningDictionary;
//
std::set<unsigned int> *_characterSet;
public:
/**
* @js ctor
*/
CCBMFontConfiguration();
/**
* @js NA
* @lua NA
*/
virtual ~CCBMFontConfiguration();
/**
* @js NA
* @lua NA
*/
const char * description() const;
/** FNT , CCBMFontConfiguration*/
static CCBMFontConfiguration * create(const char *FNTfile);
/** FNT , CCBMFontConfiguration*/
bool initWithFNTfile(const char *FNTfile);
inline const char* getAtlasName(){ return _atlasName.c_str(); }
inline void setAtlasName(const char* atlasName) { _atlasName = atlasName; }
std::set<unsigned int>* getCharacterSet() const;
private:
std::set<unsigned int>* parseConfigFile(const char *controlFile);
void parseCharacterDefinition(std::string line, ccBMFontDef *characterDefinition);
void parseInfoArguments(std::string line);
void parseCommonArguments(std::string line);
void parseImageFileName(std::string line, const char *fntFile);
void parseKerningEntry(std::string line);
void purgeKerningDictionary();
void purgeFontDefDictionary();
};
/** @brief LabelBMFont SpriteBatchNode .
:
- Sprite , :
- rotated( )
- scaled()( )
- translated( )
- tinted( )
-
- 。
- “ ”
- AngelCode
Limitations:
- (0.5F,0.5F),
LabelBMFont LabelProtocol, Label 、 LabelAtlas.
LabelBMFont Label, LabelAtlas , Sprite .
, LabelBMFont LabelAtlas / Label.
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 LabelBMFont : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol
{
public:
/**
* @js ctor
*/
LabelBMFont();
/**
* @js NA
* @lua NA
*/
virtual ~LabelBMFont();
/** .
atlas 。
@since v0.99.3
*/
static void purgeCachedData();
/** str FNT bitmap( ) */
static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment, Point imageOffset);
static LabelBMFont * create(const char *str, const char *fntFile, float width, TextHAlignment alignment);
static LabelBMFont * create(const char *str, const char *fntFile, float width);
static LabelBMFont * create(const char *str, const char *fntFile);
/** label.
*/
static LabelBMFont * create();
bool init();
/** str FNT bitmap( ) */
bool initWithString(const char *str, const char *fntFile, float width = kLabelAutomaticWidth, TextHAlignment alignment = TextHAlignment::LEFT, Point imageOffset = Point::ZERO);
/** */
void createFontChars();
// super method
virtual void setString(const char *newString);
virtual void setString(const char *newString, bool needUpdateLabel);
virtual const char* getString(void) const;
virtual void setCString(const char *label);
virtual void setAnchorPoint(const Point& var);
virtual void updateLabel();
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);
// RGBAProtocol
virtual bool isOpacityModifyRGB() const;
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);
virtual GLubyte getOpacity() const;
virtual GLubyte getDisplayedOpacity() const;
virtual void setOpacity(GLubyte opacity);
virtual void updateDisplayedOpacity(GLubyte parentOpacity);
virtual bool isCascadeOpacityEnabled() const;
virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled);
virtual const Color3B& getColor(void) const;
virtual const Color3B& getDisplayedColor() const;
virtual void setColor(const Color3B& color);
virtual void updateDisplayedColor(const Color3B& parentColor);
virtual bool isCascadeColorEnabled() const;
virtual void setCascadeColorEnabled(bool cascadeColorEnabled);
void setFntFile(const char* fntFile);
const char* getFntFile();
#if CC_LABELBMFONT_DEBUG_DRAW
virtual void draw();
#endif // CC_LABELBMFONT_DEBUG_DRAW
private:
char * atlasNameFromFntFile(const char *fntFile);
int kerningAmountForFirst(unsigned short first, unsigned short second);
float getLetterPosXLeft( Sprite* characterSprite );
float getLetterPosXRight( Sprite* characterSprite );
protected:
virtual void setString(unsigned short *newString, bool needUpdateLabel);
//
unsigned short* _string;
// fntFile
std::string _fntFile;
// ( )
unsigned short* _initialString;
std::string _initialStringUTF8;
//
TextHAlignment _alignment;
//
float _width;
CCBMFontConfiguration *_configuration;
bool _lineBreakWithoutSpaces;
// texture atlas
Point _imageOffset;
// char
Sprite *_reusedChar;
// texture RGBA
GLubyte _displayedOpacity;
GLubyte _realOpacity;
Color3B _displayedColor;
Color3B _realColor;
bool _cascadeColorEnabled;
bool _cascadeOpacityEnabled;
/** RGBAProtocol */
bool _isOpacityModifyRGB;
};
/** FNT
*/
CC_DLL CCBMFontConfiguration * FNTConfigLoadFile( const char *file );
/** FNT
*/
CC_DLL void FNTConfigRemoveCache( void );
// end of GUI group
/// @}
/// @}
NS_CC_END
#endif //__CCBITMAP_FONT_ATLAS_H__