2014-03-06 20:52:29 +08:00
|
|
|
#include "UIRichTextTest.h"
|
|
|
|
#include "cocostudio/CCArmatureDataManager.h"
|
|
|
|
#include "cocostudio/CCArmature.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UIRichTextTests::UIRichTextTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UIRichTextTest);
|
|
|
|
}
|
|
|
|
|
2014-03-06 20:52:29 +08:00
|
|
|
UIRichTextTest::UIRichTextTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIRichTextTest::~UIRichTextTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIRichTextTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2014-03-06 20:52:29 +08:00
|
|
|
|
2014-08-01 21:20:27 +08:00
|
|
|
auto config = Configuration::getInstance();
|
|
|
|
config->loadConfigFile("configs/config-test-ok.plist");
|
|
|
|
|
|
|
|
|
|
|
|
std::string str1 = config->getValue("Chinese").asString();
|
|
|
|
std::string str2 = config->getValue("Japanese").asString();
|
2014-07-28 17:24:37 +08:00
|
|
|
CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s",
|
|
|
|
str1.c_str(),
|
|
|
|
str1.length(),
|
|
|
|
StringUtils::getCharacterCountInUTF8String(str1),
|
2014-07-30 10:45:35 +08:00
|
|
|
Helper::getSubStringOfUTF8String(str1, 0, 5).c_str());
|
2014-07-28 17:24:37 +08:00
|
|
|
CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s",
|
|
|
|
str2.c_str(),
|
|
|
|
str2.length(),
|
|
|
|
StringUtils::getCharacterCountInUTF8String(str2),
|
2014-07-30 10:45:35 +08:00
|
|
|
Helper::getSubStringOfUTF8String(str2, 0, 2).c_str());
|
2014-07-28 17:24:37 +08:00
|
|
|
|
2014-03-06 20:52:29 +08:00
|
|
|
// 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-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().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-06-20 11:18:53 +08:00
|
|
|
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
|
2014-05-09 14:30:39 +08:00
|
|
|
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);
|
2014-06-20 14:03:33 +08:00
|
|
|
_richText->setContentSize(Size(100, 100));
|
2014-03-06 20:52:29 +08:00
|
|
|
|
2014-08-01 21:20:27 +08:00
|
|
|
RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "Marker Felt", 10);
|
2014-03-06 20:52:29 +08:00
|
|
|
RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
|
2014-08-01 21:20:27 +08:00
|
|
|
RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Helvetica", 10);
|
2014-07-28 17:24:37 +08:00
|
|
|
RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10);
|
2014-03-06 20:52:29 +08:00
|
|
|
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);
|
2014-06-20 14:03:33 +08:00
|
|
|
_richText->setContentSize(Size(100, 100));
|
2014-03-06 20:52:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_richText->ignoreContentAdaptWithSize(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|