axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp

1782 lines
68 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
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.
****************************************************************************/
2014-03-06 20:52:29 +08:00
#include "UIRichTextTest.h"
2016-03-21 21:04:06 +08:00
#include "editor-support/cocostudio/CCArmatureDataManager.h"
#include "editor-support/cocostudio/CCArmature.h"
2014-03-06 20:52:29 +08:00
2015-04-09 12:23:47 +08:00
USING_NS_CC;
using namespace cocos2d::ui;
UIRichTextTests::UIRichTextTests()
{
ADD_TEST_CASE(UIRichTextTest);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
ADD_TEST_CASE(UIRichTextXMLBasic);
ADD_TEST_CASE(UIRichTextXMLSmallBig);
ADD_TEST_CASE(UIRichTextXMLColor);
ADD_TEST_CASE(UIRichTextXMLSUIB);
ADD_TEST_CASE(UIRichTextXMLSUIB2);
ADD_TEST_CASE(UIRichTextXMLSUIB3);
ADD_TEST_CASE(UIRichTextXMLImg);
ADD_TEST_CASE(UIRichTextXMLUrl);
2016-03-07 09:50:47 +08:00
ADD_TEST_CASE(UIRichTextXMLUrlImg);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
ADD_TEST_CASE(UIRichTextXMLFace);
ADD_TEST_CASE(UIRichTextXMLBR);
ADD_TEST_CASE(UIRichTextXMLInvalid);
2016-03-07 09:50:47 +08:00
ADD_TEST_CASE(UIRichTextXMLOutline);
ADD_TEST_CASE(UIRichTextXMLShadow);
ADD_TEST_CASE(UIRichTextXMLGlow);
ADD_TEST_CASE(UIRichTextXMLExtend);
}
2014-03-06 20:52:29 +08:00
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextTest
//
2014-03-06 20:52:29 +08:00
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
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(),
2016-04-18 17:52:58 +08:00
static_cast<long>(str1.length()),
2014-07-28 17:24:37 +08:00
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(),
2016-04-18 17:52:58 +08:00
static_cast<long>(str2.length()),
2014-07-28 17:24:37 +08:00
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
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);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
2014-03-06 20:52:29 +08:00
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
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);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2014-03-06 20:52:29 +08:00
// RichText
_richText = RichText::create();
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
2014-03-06 20:52:29 +08:00
RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10);
2014-03-06 20:52:29 +08:00
RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 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);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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);
2015-07-28 11:38:21 +08:00
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
2014-03-06 20:52:29 +08:00
return true;
}
return false;
}
void UIRichTextTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
2014-03-06 20:52:29 +08:00
{
switch (type)
{
case Widget::TouchEventType::ENDED:
2014-03-06 20:52:29 +08:00
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_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
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
void UIRichTextTest::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextTest::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLBasic
//
bool UIRichTextXMLBasic::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("This is just a simple text. no xml tags here. testing the basics. testing word-wrapping. testing, testing, testing");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLBasic::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLBasic::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLBasic::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLSmallBig
//
bool UIRichTextXMLSmallBig::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("Regular size.<small>smaller size.</small><big>bigger.<small>normal.</small>bigger</big>.normal.");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLSmallBig::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLSmallBig::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLSmallBig::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLColor
//
bool UIRichTextXMLColor::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("Default color.<font color='#ff0000'>red.<font color='#00ff00'>green</font>red again.</font>default again");
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLColor::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLColor::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLColor::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLSUIB
//
bool UIRichTextXMLSUIB::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("system font: <u>underline</u><i>italics</i><b>bold</b><del>strike-through</del>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLSUIB::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLSUIB::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLSUIB::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLSUIB2
//
bool UIRichTextXMLSUIB2::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("<font face='fonts/Marker Felt.ttf' size='24'>ttf font: <u>underline</u><i>italics</i><b>bold</b><del>strike-through</del></font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLSUIB2::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLSUIB2::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLSUIB2::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLSUIB3
//
bool UIRichTextXMLSUIB3::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("<font face='fonts/Marker Felt.ttf' size='20'>ttf font: <i><u>italics and underline</u></i><del><b>bold and strike-through</b></del></font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLSUIB3::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLSUIB3::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLSUIB3::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLImg
//
bool UIRichTextXMLImg::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("you should see an image here: <img src='cocosui/sliderballnormal.png'/> and this is text again. and this is the same image, but bigger: <img src='cocosui/sliderballnormal.png' width='30' height='30' /> and here goes text again");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLImg::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLImg::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLUrl
//
bool UIRichTextXMLUrl::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("This link will redirect you to google: <a href='http://www.google.com'>click me</a>");
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLUrl::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLUrl::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLUrl::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
2016-03-07 09:50:47 +08:00
//
// UIRichTextXMLUrlImg
//
bool UIRichTextXMLUrlImg::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
2016-03-07 09:50:47 +08:00
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2016-03-07 09:50:47 +08:00
// RichText
_richText = RichText::createWithXML("This link will redirect you to google: <a href='http://www.google.com'><img src=\"cocosui/ccicon.png\" height=\"48\" width=\"48\" /></a>");
2016-03-07 09:50:47 +08:00
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLUrlImg::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLUrlImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLUrlImg::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLFace
//
bool UIRichTextXMLFace::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("<font size='20' face='fonts/Marker Felt.ttf'>Marker Felt 20.<font face='fonts/arial.ttf'>Arial 20.</font></font><font face='font/Thonburi.ttf' size='24' color='#0000ff'>Thonburi 24 blue</font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(120, 100));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLFace::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLFace::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLFace::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
//
// UIRichTextXMLBR
//
bool UIRichTextXMLBR::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
Adds xml support in UIRichText Supported tags: - <small>: makes the font 20% smaller - <big>: makes the font 25% bigger - <img src="" />: to add an image - <font face="path to font" size="size" color="#00ffaa">: font attributes - <i>: italics - <b>: bold - <u>: underline - <del> strike-through - </br>: new line Also adds support for strikethrough, italics, bold and underlie to `Label` Contains tests for UIRichText and Label Squashed commit of the following: commit a0d6ae0513d40dbf414930210ab032a49d8984a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:39:21 2016 -0800 cleanup LabelTestNew commit 0cf423af85d88a42fc1317207feeb3d05da7f8ab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 19 20:34:53 2016 -0800 adds maaaany tests ...and fixes width and height in <img src=""> commit e8ba6acd5d79bbc766d7aa02ef166e166c801d01 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 19:41:37 2016 -0800 Label + URL working Ok commit 36689e29ee3d77310e92264a09084cc06e30664c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 15 18:24:44 2016 -0800 adding this code just in case... ... should use a listener component instead commit af03708950e74483b875d0baad593aa6ed242a04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 14 20:23:36 2016 -0800 URL node plus <de><u> and <a img commit e3a4930b012c0b3756752dac6ffb5ad43d24ae99 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Jan 13 18:42:18 2016 -0800 strikethrough and underline implemented they support multiline and horizontal alignment as well includes test however vertical alignment might not work commit 640ccf39f56e153db46785a61be7000e898174c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 18:14:57 2016 -0800 bug fixes commit 5e41fb76e91c571639585a609a255eb41797a302 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 16:47:20 2016 -0800 adds italics and bold "disable test" commit 202c5a45bb9c8ea160b9f6880ef858874e07814b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Jan 12 14:40:13 2016 -0800 adds italics test commit d1a8b421445053cc36860fc376f52692a3672dfe Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Jan 11 20:53:23 2016 -0800 italics is working ok commit fdd02087fce920c27c2409301ec88685fe68085b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Jan 8 17:18:56 2016 -0800 color, size and face working commit c01bdef6b1d49f8805b69d4c162b74cd00c8f5b3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Jan 7 19:02:16 2016 -0800 initial commit
2016-01-20 12:41:31 +08:00
// RichText
_richText = RichText::createWithXML("this is one line.<br/>this should be in another line.<br/>and this is another line");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLBR::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLBR::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLBR::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
//
// UIRichTextXMLInvalid
//
bool UIRichTextXMLInvalid::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("Invalid XML test", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
// RichText
_richText = RichText::createWithXML("this is an invalid xml. <i>no closing tag");
if (_richText)
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
}
return true;
}
return false;
}
2016-03-07 09:50:47 +08:00
//
// UIRichTextXMLOutline
//
bool UIRichTextXMLOutline::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("Outline", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
2016-03-07 09:50:47 +08:00
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2016-03-07 09:50:47 +08:00
// RichText
_richText = RichText::createWithXML("<font face='fonts/Marker Felt.ttf' size=\"24\"><outline color=\"#D2B48C\" size=\"2\">OUTLINE</outline></font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLOutline::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLOutline::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLOutline::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
2016-03-07 09:50:47 +08:00
//
// UIRichTextXMLShadow
//
bool UIRichTextXMLShadow::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("Shadow", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
2016-03-07 09:50:47 +08:00
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2016-03-07 09:50:47 +08:00
// RichText
_richText = RichText::createWithXML("<font size=\"24\"><shadow color=\"#4169E1\" offsetWidth=\"8\" offsetHeight=\"-8\" blurRadius=\"2\">SHADOW</shadow></font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(150, 100));
2016-03-07 09:50:47 +08:00
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLShadow::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLShadow::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLShadow::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
2016-03-07 09:50:47 +08:00
//
// UIRichTextXMLGlow
//
bool UIRichTextXMLGlow::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("Glow", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
2016-03-07 09:50:47 +08:00
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2016-03-07 09:50:47 +08:00
// RichText
_richText = RichText::createWithXML("<font face=\"fonts/Marker Felt.ttf\" size=\"24\"><glow color=\"#AFEEEE\">GLOW</glow></font>");
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLGlow::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLGlow::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLGlow::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}
2016-03-07 09:50:47 +08:00
//
// UIRichTextXMLExtend
//
bool UIRichTextXMLExtend::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add the alert
Text *alert = Text::create("Extend", "fonts/Marker Felt.ttf", 30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
_widget->addChild(alert);
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setTouchEnabled(true);
button->setTitleText("switch");
button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::touchEvent, this));
button->setLocalZOrder(10);
_widget->addChild(button);
Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button2->setTouchEnabled(true);
button2->setTitleText("wrap mode");
button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
2016-03-07 09:50:47 +08:00
button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::switchWrapMode, this));
button2->setLocalZOrder(10);
_widget->addChild(button2);
Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button3->setTouchEnabled(true);
button3->setTitleText("alignment");
button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::switchAlignment, this));
button3->setLocalZOrder(10);
_widget->addChild(button3);
2016-03-07 09:50:47 +08:00
/* Tag extension */
RichText::setTagDescription("CloseNormal", false, [](const ValueMap& tagAttrValueMap) {
RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseNormal.png");
return make_pair(ValueMap(), richElement);
});
RichText::setTagDescription("CloseSelected", false, [](const ValueMap& tagAttrValueMap) {
RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseSelected.png");
return make_pair(ValueMap(), richElement);
});
/* Defaults */
ValueMap defaults;
defaults[RichText::KEY_FONT_COLOR_STRING] = "#FFF";
defaults[RichText::KEY_FONT_SIZE] = 12.0f;
defaults[RichText::KEY_FONT_FACE] = "fonts/Marker Felt.ttf";
defaults[RichText::KEY_ANCHOR_FONT_COLOR_STRING] = "#f0f8ff";
defaults[RichText::KEY_ANCHOR_TEXT_BOLD] = false;
defaults[RichText::KEY_ANCHOR_TEXT_ITALIC] = false;
//defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_NONE;
//defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_DEL;
defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_UNDER;
//defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_NONE;
//defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_OUTLINE;
//defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_SHADOW;
//defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_GLOW;
defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_COLOR] = "#D2B48C";
defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_SIZE] = 4;
defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_COLOR] = "#4169E1";
defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH] = 4.0f;
defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT] = -4.0f;
defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS] = 0;
defaults[RichText::KEY_ANCHOR_TEXT_GLOW_COLOR] = "#AFEEEE";
// RichText
_richText = RichText::createWithXML("<span>CloseNormal-tag:<br /><CloseNormal /><br /><br />CloseSelected-tag:<br /><CloseSelected></CloseSelected></span>",
defaults,
[](const std::string& url) {
Application::getInstance()->openURL(url);
});
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
_richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
_richText->setLocalZOrder(10);
_widget->addChild(_richText);
// test remove all children, this call won't effect the test
_richText->removeAllChildren();
return true;
}
return false;
}
void UIRichTextXMLExtend::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::ENDED:
{
if (_richText->isIgnoreContentAdaptWithSize())
{
_richText->ignoreContentAdaptWithSize(false);
_richText->setContentSize(Size(100, 100));
}
else
{
_richText->ignoreContentAdaptWithSize(true);
}
}
break;
default:
break;
}
}
void UIRichTextXMLExtend::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
{
if (type == Widget::TouchEventType::ENDED)
{
auto wrapMode = _richText->getWrapMode();
wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
_richText->setWrapMode(wrapMode);
}
}
void UIRichTextXMLExtend::switchAlignment(Ref *sender, Widget::TouchEventType type) {
if (type == Widget::TouchEventType::ENDED)
{
auto alignment = _richText->getHorizontalAlignment();
alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment)+1) % 3);
_richText->setHorizontalAlignment(alignment);
}
}