mirror of https://github.com/axmolengine/axmol.git
Merge pull request #796 from dumganhar/gles20
issue #1056: Added CCLabelBMFont alignment support.
This commit is contained in:
commit
26a29a439b
|
@ -32,12 +32,21 @@ Use any of these editors to generate BMFonts:
|
|||
****************************************************************************/
|
||||
#ifndef __CCBITMAP_FONT_ATLAS_H__
|
||||
#define __CCBITMAP_FONT_ATLAS_H__
|
||||
|
||||
#include "CCSpriteBatchNode.h"
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace cocos2d{
|
||||
NS_CC_BEGIN
|
||||
|
||||
enum {
|
||||
kCCLabelAutomaticWidth = -1,
|
||||
};
|
||||
|
||||
struct _KerningHashElement;
|
||||
struct _FontDefHashElement;
|
||||
|
||||
/**
|
||||
@struct ccBMFontDef
|
||||
|
@ -49,11 +58,11 @@ namespace cocos2d{
|
|||
//! origin and size of the font
|
||||
CCRect rect;
|
||||
//! The X amount the image should be offset when drawing the image (in pixels)
|
||||
int xOffset;
|
||||
short xOffset;
|
||||
//! The Y amount the image should be offset when drawing the image (in pixels)
|
||||
int yOffset;
|
||||
short yOffset;
|
||||
//! The amount to move the current position after drawing the character (in pixels)
|
||||
int xAdvance;
|
||||
short xAdvance;
|
||||
} ccBMFontDef;
|
||||
|
||||
/** @struct ccBMFontPadding
|
||||
|
@ -79,8 +88,8 @@ namespace cocos2d{
|
|||
{
|
||||
// XXX: Creating a public interface so that the bitmapFontArray[] is accesible
|
||||
public://@public
|
||||
//! The characters building up the font
|
||||
std::map<unsigned int, ccBMFontDef>* m_pBitmapFontArray;
|
||||
// BMFont definitions
|
||||
struct _FontDefHashElement* m_pFontDefDictionary;
|
||||
|
||||
//! FNTConfig: Common Height
|
||||
unsigned int m_uCommonHeight;
|
||||
|
@ -93,7 +102,7 @@ namespace cocos2d{
|
|||
public:
|
||||
CCBMFontConfiguration();
|
||||
virtual ~CCBMFontConfiguration();
|
||||
char * description();
|
||||
const char * description();
|
||||
/** allocates a CCBMFontConfiguration with a FNT file */
|
||||
static CCBMFontConfiguration * configurationWithFNTFile(const char *FNTfile);
|
||||
/** initializes a BitmapFontConfiguration with a FNT file */
|
||||
|
@ -107,6 +116,7 @@ namespace cocos2d{
|
|||
void parseKerningCapacity(std::string line);
|
||||
void parseKerningEntry(std::string line);
|
||||
void purgeKerningDictionary();
|
||||
void purgeFontDefDictionary();
|
||||
};
|
||||
|
||||
/** @brief CCLabelBMFont is a subclass of CCSpriteSheet.
|
||||
|
@ -149,15 +159,17 @@ namespace cocos2d{
|
|||
CC_PROPERTY(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB)
|
||||
protected:
|
||||
// string to render
|
||||
std::string m_sString;
|
||||
unsigned short* m_sString;
|
||||
std::string m_sString_initial;
|
||||
CCBMFontConfiguration *m_pConfiguration;
|
||||
CCTextAlignment m_pAlignment;
|
||||
float m_fWidth;
|
||||
bool m_bLineBreakWithoutSpaces;
|
||||
// offset of the texture atlas
|
||||
CCPoint m_tImageOffset;
|
||||
public:
|
||||
CCLabelBMFont()
|
||||
: m_cOpacity(0)
|
||||
, m_bIsOpacityModifyRGB(false)
|
||||
, m_sString("")
|
||||
, m_pConfiguration(NULL)
|
||||
{}
|
||||
CCLabelBMFont();
|
||||
|
||||
virtual ~CCLabelBMFont();
|
||||
/** Purges the cached data.
|
||||
Removes from memory the cached configurations and the atlas name dictionary.
|
||||
|
@ -166,16 +178,26 @@ namespace cocos2d{
|
|||
static void purgeCachedData();
|
||||
/** creates a bitmap font altas with an initial string and the FNT file */
|
||||
static CCLabelBMFont * labelWithString(const char *str, const char *fntFile);
|
||||
static CCLabelBMFont * labelWithString(const char *str, const char *fntFile, float width, CCTextAlignment alignment);
|
||||
static CCLabelBMFont * labelWithString(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset);
|
||||
|
||||
/** init a bitmap font altas with an initial string and the FNT file */
|
||||
bool initWithString(const char *str, const char *fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset);
|
||||
bool initWithString(const char *str, const char *fntFile, float width, CCTextAlignment alignment);
|
||||
bool initWithString(const char *str, const char *fntFile);
|
||||
/** updates the font chars based on the string to render */
|
||||
void createFontChars();
|
||||
// super method
|
||||
virtual void setString(const char *label);
|
||||
virtual void setString(const char *label, bool fromUpdate);
|
||||
virtual void updateString(bool fromUpdate);
|
||||
virtual const char* getString(void);
|
||||
virtual void setCString(const char *label);
|
||||
virtual void setAnchorPoint(const CCPoint& var);
|
||||
virtual void updateLabel();
|
||||
virtual void setAlignment(CCTextAlignment alignment);
|
||||
virtual void setWidth(float width);
|
||||
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
|
||||
#if CC_LABELBMFONT_DEBUG_DRAW
|
||||
virtual void draw();
|
||||
|
@ -192,6 +214,7 @@ namespace cocos2d{
|
|||
/** Purges the FNT config cache
|
||||
*/
|
||||
CC_DLL void FNTConfigRemoveCache( void );
|
||||
}// namespace cocos2d
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif //__CCBITMAP_FONT_ATLAS_H__
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue