mirror of https://github.com/axmolengine/axmol.git
parent
88928fff99
commit
2219bde542
|
@ -23,5 +23,33 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCLabel.h"
|
||||
#include "CCLabelBMFontNew.h"
|
||||
#include "CCStringTTF.h"
|
||||
#include "CCFontDefinition.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Label* Label::createWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs )
|
||||
{
|
||||
const char *fontGlyphs = "abcdefghilmnopqrstuvzxywABCDEFGHILMNOPQRSTUVZXYW0123456789,. ";
|
||||
FontDefinitionTTF *def = FontDefinitionTTF::create(tttFilePath, size, fontGlyphs);
|
||||
|
||||
StringTTF* l = StringTTF::create(def);
|
||||
l->setString( label );
|
||||
return l;
|
||||
}
|
||||
|
||||
Label* Label::createWithBMFont( const char* label, const char* bmfontFilePath )
|
||||
{
|
||||
return LabelBMFontNew::create(label, bmfontFilePath);
|
||||
}
|
||||
|
||||
Label::Label()
|
||||
{
|
||||
}
|
||||
|
||||
Label::~Label()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -1,59 +1,61 @@
|
|||
///****************************************************************************
|
||||
// Copyright (c) 2013 Zynga 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.
|
||||
// ****************************************************************************/
|
||||
//
|
||||
//
|
||||
//#ifndef __COCOS2D_CCLABEL_H
|
||||
//#define __COCOS2D_CCLABEL_H
|
||||
//
|
||||
//#include "CCSpriteBatchNode.h"
|
||||
//
|
||||
//NS_CC_BEGIN
|
||||
//
|
||||
//enum class GlyphCollection {
|
||||
// DYNAMIC,
|
||||
// NEHE,
|
||||
// ASCII,
|
||||
// CUSTOM
|
||||
//};
|
||||
//
|
||||
//class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol
|
||||
//{
|
||||
//public:
|
||||
// static Label* createWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs = GlyphCollection::NEHE );
|
||||
// static Label* createWithBMFont( const char* label, const char* bmfontFilePath );
|
||||
//
|
||||
// virtual ~Label();
|
||||
//
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 Zynga 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.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef __COCOS2D_CCLABEL_H
|
||||
#define __COCOS2D_CCLABEL_H
|
||||
|
||||
#include "sprite_nodes/CCSpriteBatchNode.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
enum class GlyphCollection {
|
||||
DYNAMIC,
|
||||
NEHE,
|
||||
ASCII,
|
||||
CUSTOM
|
||||
};
|
||||
|
||||
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol
|
||||
{
|
||||
public:
|
||||
static Label* createWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs = GlyphCollection::NEHE );
|
||||
static Label* createWithBMFont( const char* label, const char* bmfontFilePath );
|
||||
|
||||
virtual ~Label();
|
||||
Label();
|
||||
|
||||
// bool initWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs = GlyphCollection::NEHE );
|
||||
// bool initWithBMFont( const char* label, const char* bmfontFilePath );
|
||||
//
|
||||
// // UTF-8 collection
|
||||
|
||||
// UTF-8 collection
|
||||
// void setGlyphCollection( const char* glyphCollection );
|
||||
// virtual void setHorizontalAlignment(TextAlignment alignment);
|
||||
// virtual void setVerticalAlignment(VerticalTextAlignment alignment);
|
||||
// virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
//
|
||||
|
||||
// // Overrides
|
||||
// virtual void setString(const char *newString) override;
|
||||
// virtual const char* getString(void) const override;
|
||||
|
@ -71,14 +73,13 @@
|
|||
// virtual void updateDisplayedColor(const Color3B& parentColor) override;
|
||||
// virtual bool isCascadeColorEnabled() const override;
|
||||
// virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override;
|
||||
//
|
||||
//protected:
|
||||
//
|
||||
//private:
|
||||
// Label();
|
||||
//
|
||||
//};
|
||||
//
|
||||
//NS_CC_END
|
||||
//
|
||||
//#endif /*__COCOS2D_CCLABEL_H */
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif /*__COCOS2D_CCLABEL_H */
|
||||
|
|
|
@ -41,10 +41,11 @@ Use any of these editors to generate BMFonts:
|
|||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "CCLabel.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CC_DLL LabelBMFontNew : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol, public LabelTextFormatProtocol
|
||||
class CC_DLL LabelBMFontNew: public Label, public LabelTextFormatProtocol
|
||||
{
|
||||
public:
|
||||
LabelBMFontNew();
|
||||
|
|
|
@ -83,6 +83,11 @@ bool StringTTF::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void StringTTF::setString(const char *stringToRender)
|
||||
{
|
||||
setText(stringToRender, 500, kTextAlignmentCenter, false);
|
||||
}
|
||||
|
||||
bool StringTTF::setText(const char *stringToRender, float lineWidth, TextAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
{
|
||||
if (!_fontDef)
|
||||
|
|
|
@ -27,17 +27,20 @@
|
|||
|
||||
#include "CCFontDefinition.h"
|
||||
#include "CCLabelTextFormatProtocol.h"
|
||||
#include "CCLabel.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class StringTTF : public Node , public LabelTextFormatProtocol, public RGBAProtocol
|
||||
class StringTTF : public Label, public LabelTextFormatProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
static StringTTF* create(FontDefinitionTTF *pDefinition, TextAlignment alignment = kTextAlignmentLeft);
|
||||
|
||||
// main interface
|
||||
bool setText(const char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
|
||||
bool setText(const char *stringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
|
||||
void setString(const char *stringToRender);
|
||||
const char* getString() const { return "not implemented"; }
|
||||
virtual void setAlignment(TextAlignment alignment);
|
||||
virtual void setWidth(float width);
|
||||
virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
|
||||
|
|
|
@ -40,7 +40,7 @@ Layer* restartAtlasAction();
|
|||
|
||||
static int sceneIdx = -1;
|
||||
|
||||
#define MAX_LAYER 30
|
||||
#define MAX_LAYER 32
|
||||
|
||||
Layer* createAtlasLayer(int nIndex)
|
||||
{
|
||||
|
@ -78,6 +78,8 @@ Layer* createAtlasLayer(int nIndex)
|
|||
case 27: return new TTFFontShadowAndStroke();
|
||||
case 28: return new LabelBMFontNewTest();
|
||||
case 29: return new LabelDyamicTest();
|
||||
case 30: return new NewLabelBMFontTest();
|
||||
case 31: return new NewLabelTTFTest();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -1698,11 +1700,11 @@ std::string LabelDyamicTest::subtitle()
|
|||
//
|
||||
NewLabelTTFTest::NewLabelTTFTest()
|
||||
{
|
||||
// Size size = Director::getInstance()->getWinSize();
|
||||
//
|
||||
// label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 28);
|
||||
// label->setPosition( Point(size.width/2, size.height/2) );
|
||||
// addChild(label);
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 28);
|
||||
label->setPosition( Point(size.width/2, size.height/2) );
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
NewLabelTTFTest::~NewLabelTTFTest()
|
||||
|
@ -1725,11 +1727,11 @@ std::string NewLabelTTFTest::subtitle()
|
|||
//
|
||||
NewLabelBMFontTest::NewLabelBMFontTest()
|
||||
{
|
||||
// Size size = Director::getInstance()->getWinSize();
|
||||
//
|
||||
// label = Label::createWithBMFont("Hello World", "fonts/bitmapFontTest2.fnt");
|
||||
// label->setPosition( Point(size.width/2, size.height/2) );
|
||||
// addChild(label);
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
label = Label::createWithBMFont("Hello World", "fonts/bitmapFontTest2.fnt");
|
||||
label->setPosition( Point(size.width/2, size.height/2) );
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
NewLabelBMFontTest::~NewLabelBMFontTest()
|
||||
|
|
|
@ -355,7 +355,7 @@ public:
|
|||
virtual std::string subtitle();
|
||||
|
||||
private:
|
||||
Node *label;
|
||||
Label *label;
|
||||
};
|
||||
|
||||
class NewLabelBMFontTest : public AtlasDemo
|
||||
|
@ -369,7 +369,7 @@ public:
|
|||
virtual std::string subtitle();
|
||||
|
||||
private:
|
||||
Node *label;
|
||||
Label *label;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue