2014-03-06 20:52:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "UIRichTextTest.h"
|
|
|
|
#include "cocostudio/CCArmatureDataManager.h"
|
|
|
|
#include "cocostudio/CCArmature.h"
|
|
|
|
|
|
|
|
UIRichTextTest::UIRichTextTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIRichTextTest::~UIRichTextTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIRichTextTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getSize();
|
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:22:23 +08:00
|
|
|
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
|
2014-03-06 20:52:29 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-05-15 01:07:09 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.125));
|
2014-03-06 20:52:29 +08:00
|
|
|
_widget->addChild(alert);
|
|
|
|
|
|
|
|
|
2014-04-03 15:22:23 +08:00
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
|
2014-03-06 20:52:29 +08:00
|
|
|
button->setTouchEnabled(true);
|
|
|
|
button->setTitleText("switch");
|
2014-05-15 01:07:09 +08:00
|
|
|
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5));
|
2014-05-09 14:30:39 +08:00
|
|
|
// button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent));
|
|
|
|
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::touchEvent, this));
|
2014-03-24 10:12:40 +08:00
|
|
|
button->setLocalZOrder(10);
|
2014-03-06 20:52:29 +08:00
|
|
|
_widget->addChild(button);
|
|
|
|
|
|
|
|
|
|
|
|
// RichText
|
|
|
|
_richText = RichText::create();
|
|
|
|
_richText->ignoreContentAdaptWithSize(false);
|
|
|
|
_richText->setSize(Size(100, 100));
|
|
|
|
|
|
|
|
RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, "This color is white. ", "Helvetica", 10);
|
|
|
|
RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
|
|
|
|
RichElementText* re3 = RichElementText::create(3, Color3B::BLUE, 255, "This one is blue. ", "Helvetica", 10);
|
|
|
|
RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green. ", "Helvetica", 10);
|
|
|
|
RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10);
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png");
|
2014-03-06 20:52:29 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson");
|
2014-03-06 20:52:29 +08:00
|
|
|
cocostudio::Armature *pAr = cocostudio::Armature::create("100");
|
|
|
|
pAr->getAnimation()->play("Animation1");
|
|
|
|
|
|
|
|
RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);
|
|
|
|
RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10);
|
|
|
|
_richText->pushBackElement(re1);
|
|
|
|
_richText->insertElement(re2, 1);
|
|
|
|
_richText->pushBackElement(re3);
|
|
|
|
_richText->pushBackElement(re4);
|
|
|
|
_richText->pushBackElement(re5);
|
|
|
|
_richText->insertElement(reimg, 2);
|
|
|
|
_richText->pushBackElement(recustom);
|
|
|
|
_richText->pushBackElement(re6);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
|
2014-03-24 10:12:40 +08:00
|
|
|
_richText->setLocalZOrder(10);
|
2014-03-06 20:52:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
_widget->addChild(_richText);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
void UIRichTextTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
|
2014-03-06 20:52:29 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-09 14:30:39 +08:00
|
|
|
case Widget::TouchEventType::ENDED:
|
2014-03-06 20:52:29 +08:00
|
|
|
{
|
|
|
|
if (_richText->isIgnoreContentAdaptWithSize())
|
|
|
|
{
|
|
|
|
_richText->ignoreContentAdaptWithSize(false);
|
|
|
|
_richText->setSize(Size(100, 100));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_richText->ignoreContentAdaptWithSize(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|