fixed warn in test case.

This commit is contained in:
Dhilan007 2014-03-31 17:21:56 +08:00
parent 6c99f992dc
commit 72811d8869
2 changed files with 48 additions and 35 deletions

View File

@ -3,6 +3,13 @@
#include "renderer/CCRenderer.h" #include "renderer/CCRenderer.h"
#include "renderer/CCCustomCommand.h" #include "renderer/CCCustomCommand.h"
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
enum { enum {
kTagTileMap = 1, kTagTileMap = 1,
kTagSpriteManager = 1, kTagSpriteManager = 1,
@ -969,7 +976,7 @@ LabelTTFTest::LabelTTFTest()
menu->setPosition(Point(s.width - 50, s.height / 2 - 20)); menu->setPosition(Point(s.width - 50, s.height / 2 - 20));
this->addChild(menu); this->addChild(menu);
_plabel = NULL; _label = nullptr;
_horizAlign = TextHAlignment::LEFT; _horizAlign = TextHAlignment::LEFT;
_vertAlign = TextVAlignment::TOP; _vertAlign = TextVAlignment::TOP;
@ -978,7 +985,7 @@ LabelTTFTest::LabelTTFTest()
LabelTTFTest::~LabelTTFTest() LabelTTFTest::~LabelTTFTest()
{ {
CC_SAFE_RELEASE(_plabel); CC_SAFE_RELEASE(_label);
} }
void LabelTTFTest::updateAlignment() void LabelTTFTest::updateAlignment()
@ -986,21 +993,21 @@ void LabelTTFTest::updateAlignment()
auto blockSize = Size(200, 160); auto blockSize = Size(200, 160);
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
if (_plabel) if (_label)
{ {
_plabel->removeFromParentAndCleanup(true); _label->removeFromParentAndCleanup(true);
} }
CC_SAFE_RELEASE(_plabel); CC_SAFE_RELEASE(_label);
_plabel = LabelTTF::create(this->getCurrentAlignment(), "fonts/Marker Felt.ttf", 32, _label = LabelTTF::create(this->getCurrentAlignment(), "fonts/Marker Felt.ttf", 32,
blockSize, _horizAlign, _vertAlign); blockSize, _horizAlign, _vertAlign);
_plabel->retain(); _label->retain();
_plabel->setAnchorPoint(Point(0,0)); _label->setAnchorPoint(Point(0,0));
_plabel->setPosition(Point((s.width - blockSize.width) / 2, (s.height - blockSize.height)/2 )); _label->setPosition(Point((s.width - blockSize.width) / 2, (s.height - blockSize.height)/2 ));
this->addChild(_plabel); this->addChild(_label);
} }
void LabelTTFTest::setAlignmentLeft(Ref* sender) void LabelTTFTest::setAlignmentLeft(Ref* sender)
@ -1163,13 +1170,13 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment()
auto size = Director::getInstance()->getWinSize(); auto size = Director::getInstance()->getWinSize();
// create and initialize a Label // create and initialize a Label
this->_labelShouldRetain = LabelBMFont::create(LongSentencesExample, "fonts/markerFelt.fnt", size.width/1.5, TextHAlignment::CENTER); _labelShouldRetain = LabelBMFont::create(LongSentencesExample, "fonts/markerFelt.fnt", size.width/1.5, TextHAlignment::CENTER);
this->_labelShouldRetain->retain(); _labelShouldRetain->retain();
this->_arrowsBarShouldRetain = Sprite::create("Images/arrowsBar.png"); _arrowsBarShouldRetain = Sprite::create("Images/arrowsBar.png");
this->_arrowsBarShouldRetain->retain(); _arrowsBarShouldRetain->retain();
this->_arrowsShouldRetain = Sprite::create("Images/arrows.png"); _arrowsShouldRetain = Sprite::create("Images/arrows.png");
this->_arrowsShouldRetain->retain(); _arrowsShouldRetain->retain();
MenuItemFont::setFontSize(20); MenuItemFont::setFontSize(20);
auto longSentences = MenuItemFont::create("Long Flowing Sentences", CC_CALLBACK_1(BitmapFontMultiLineAlignment::stringChanged, this)); auto longSentences = MenuItemFont::create("Long Flowing Sentences", CC_CALLBACK_1(BitmapFontMultiLineAlignment::stringChanged, this));
@ -1199,24 +1206,24 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment()
right->setTag(RightAlign); right->setTag(RightAlign);
// position the label on the center of the screen // position the label on the center of the screen
this->_labelShouldRetain->setPosition(Point(size.width/2, size.height/2)); _labelShouldRetain->setPosition(Point(size.width/2, size.height/2));
this->_arrowsBarShouldRetain->setVisible(false); _arrowsBarShouldRetain->setVisible(false);
float arrowsWidth = (ArrowsMax - ArrowsMin) * size.width; float arrowsWidth = (ArrowsMax - ArrowsMin) * size.width;
this->_arrowsBarShouldRetain->setScaleX(arrowsWidth / this->_arrowsBarShouldRetain->getContentSize().width); _arrowsBarShouldRetain->setScaleX(arrowsWidth / this->_arrowsBarShouldRetain->getContentSize().width);
this->_arrowsBarShouldRetain->setPosition(Point(((ArrowsMax + ArrowsMin) / 2) * size.width, this->_labelShouldRetain->getPosition().y)); _arrowsBarShouldRetain->setPosition(Point(((ArrowsMax + ArrowsMin) / 2) * size.width, this->_labelShouldRetain->getPosition().y));
this->snapArrowsToEdge(); this->snapArrowsToEdge();
stringMenu->setPosition(Point(size.width/2, size.height - menuItemPaddingCenter)); stringMenu->setPosition(Point(size.width/2, size.height - menuItemPaddingCenter));
alignmentMenu->setPosition(Point(size.width/2, menuItemPaddingCenter+15)); alignmentMenu->setPosition(Point(size.width/2, menuItemPaddingCenter+15));
this->addChild(this->_labelShouldRetain); addChild(_labelShouldRetain);
this->addChild(this->_arrowsBarShouldRetain); addChild(_arrowsBarShouldRetain);
this->addChild(this->_arrowsShouldRetain); addChild(_arrowsShouldRetain);
this->addChild(stringMenu); addChild(stringMenu);
this->addChild(alignmentMenu); addChild(alignmentMenu);
} }
BitmapFontMultiLineAlignment::~BitmapFontMultiLineAlignment() BitmapFontMultiLineAlignment::~BitmapFontMultiLineAlignment()
@ -1246,13 +1253,13 @@ void BitmapFontMultiLineAlignment::stringChanged(cocos2d::Ref *sender)
switch(item->getTag()) switch(item->getTag())
{ {
case LongSentences: case LongSentences:
this->_labelShouldRetain->setString(LongSentencesExample); static_cast<LabelBMFont*>(_labelShouldRetain)->setString(LongSentencesExample);
break; break;
case LineBreaks: case LineBreaks:
this->_labelShouldRetain->setString(LineBreaksExample); static_cast<LabelBMFont*>(_labelShouldRetain)->setString(LineBreaksExample);
break; break;
case Mixed: case Mixed:
this->_labelShouldRetain->setString(MixedExample); static_cast<LabelBMFont*>(_labelShouldRetain)->setString(MixedExample);
break; break;
default: default:
@ -1272,13 +1279,13 @@ void BitmapFontMultiLineAlignment::alignmentChanged(cocos2d::Ref *sender)
switch(item->getTag()) switch(item->getTag())
{ {
case LeftAlign: case LeftAlign:
this->_labelShouldRetain->setAlignment(TextHAlignment::LEFT); static_cast<LabelBMFont*>(_labelShouldRetain)->setAlignment(TextHAlignment::LEFT);
break; break;
case CenterAlign: case CenterAlign:
this->_labelShouldRetain->setAlignment(TextHAlignment::CENTER); static_cast<LabelBMFont*>(_labelShouldRetain)->setAlignment(TextHAlignment::CENTER);
break; break;
case RightAlign: case RightAlign:
this->_labelShouldRetain->setAlignment(TextHAlignment::RIGHT); static_cast<LabelBMFont*>(_labelShouldRetain)->setAlignment(TextHAlignment::RIGHT);
break; break;
default: default:
@ -1325,7 +1332,7 @@ void BitmapFontMultiLineAlignment::onTouchesMoved(const std::vector<Touch*>& tou
float labelWidth = fabs(this->_arrowsShouldRetain->getPosition().x - this->_labelShouldRetain->getPosition().x) * 2; float labelWidth = fabs(this->_arrowsShouldRetain->getPosition().x - this->_labelShouldRetain->getPosition().x) * 2;
this->_labelShouldRetain->setWidth(labelWidth); static_cast<LabelBMFont*>(_labelShouldRetain)->setWidth(labelWidth);
} }
void BitmapFontMultiLineAlignment::snapArrowsToEdge() void BitmapFontMultiLineAlignment::snapArrowsToEdge()
@ -1736,3 +1743,9 @@ std::string LabelBMFontBinaryFormat::subtitle() const
{ {
return "This label uses font file in AngelCode binary format"; return "This label uses font file in AngelCode binary format";
} }
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher
#pragma warning (pop)
#endif

View File

@ -235,8 +235,8 @@ private:
void updateAlignment(); void updateAlignment();
const char* getCurrentAlignment(); const char* getCurrentAlignment();
private: private:
LabelTTF* _plabel;
TextHAlignment _horizAlign; TextHAlignment _horizAlign;
Node* _label;
TextVAlignment _vertAlign; TextVAlignment _vertAlign;
}; };
@ -285,7 +285,7 @@ public:
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event); void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
public: public:
LabelBMFont *_labelShouldRetain; Node *_labelShouldRetain;
Sprite *_arrowsBarShouldRetain; Sprite *_arrowsBarShouldRetain;
Sprite *_arrowsShouldRetain; Sprite *_arrowsShouldRetain;
MenuItemFont *_lastSentenceItem, *_lastAlignmentItem; MenuItemFont *_lastSentenceItem, *_lastAlignmentItem;
@ -383,7 +383,7 @@ public:
protected: protected:
void onDraw(const kmMat4 &transform, bool transformUpdated); void onDraw(const kmMat4 &transform, bool transformUpdated);
private: private:
LabelBMFont *label1; Node *label1;
CustomCommand _customCommand; CustomCommand _customCommand;
}; };