PuzzleSDK
UIRichTextTest.cpp
浏览该文件的文档.
1/****************************************************************************
2Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4http://www.cocos2d-x.org
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23****************************************************************************/
24
25#include "UIRichTextTest.h"
26#include "editor-support/cocostudio/CCArmatureDataManager.h"
27#include "editor-support/cocostudio/CCArmature.h"
28
30using namespace cocos2d::ui;
31
32UIRichTextTests::UIRichTextTests()
33{
52}
53
54
55//
56// UIRichTextTest
57//
59{
60 if (UIScene::init())
61 {
62 Size widgetSize = _widget->getContentSize();
63
64 auto config = Configuration::getInstance();
65 config->loadConfigFile("configs/config-test-ok.plist");
66
67
68 std::string str1 = config->getValue("Chinese").asString();
69 std::string str2 = config->getValue("Japanese").asString();
70 CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s",
71 str1.c_str(),
72 static_cast<long>(str1.length()),
73 StringUtils::getCharacterCountInUTF8String(str1),
74 Helper::getSubStringOfUTF8String(str1, 0, 5).c_str());
75 CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s",
76 str2.c_str(),
77 static_cast<long>(str2.length()),
78 StringUtils::getCharacterCountInUTF8String(str2),
79 Helper::getSubStringOfUTF8String(str2, 0, 2).c_str());
80
81 // Add the alert
82 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
83 alert->setColor(Color3B(159, 168, 176));
84 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
85 _widget->addChild(alert);
86
87 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
88 button->setTouchEnabled(true);
89 button->setTitleText("switch");
90 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
91 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::touchEvent, this));
92 button->setLocalZOrder(10);
93 _widget->addChild(button);
94
95 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
96 button2->setTouchEnabled(true);
97 button2->setTitleText("wrap mode");
98 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
99 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchWrapMode, this));
100 button2->setLocalZOrder(10);
101 _widget->addChild(button2);
102
103 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
104 button3->setTouchEnabled(true);
105 button3->setTitleText("alignment");
106 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
107 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchAlignment, this));
108 button3->setLocalZOrder(10);
109 _widget->addChild(button3);
110
111 // RichText
112 _richText = RichText::create();
113 _richText->ignoreContentAdaptWithSize(false);
114 _richText->setContentSize(Size(100, 100));
115
116 RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10);
117 RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
118 RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 10);
119 RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10);
120 RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10);
121
122 RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png");
123
124// TODO
125// cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson");
126// cocostudio::Armature *pAr = cocostudio::Armature::create("100"); //
127// pAr->getAnimation()->play("Animation1");
128
129// RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);
130 RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10);
131 _richText->pushBackElement(re1);
132 _richText->insertElement(re2, 1);
133 _richText->pushBackElement(re3);
134 _richText->pushBackElement(re4);
135 _richText->pushBackElement(re5);
136 _richText->insertElement(reimg, 2);
137// _richText->pushBackElement(recustom);
138 _richText->pushBackElement(re6);
139
140 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
141 _richText->setLocalZOrder(10);
142
143
144 _widget->addChild(_richText);
145
146 // test remove all children, this call won't effect the test
147 _richText->removeAllChildren();
148
149 return true;
150 }
151 return false;
152}
153
154void UIRichTextTest::touchEvent(Ref *pSender, Widget::TouchEventType type)
155{
156 switch (type)
157 {
158 case Widget::TouchEventType::ENDED:
159 {
160 if (_richText->isIgnoreContentAdaptWithSize())
161 {
162 _richText->ignoreContentAdaptWithSize(false);
163 _richText->setContentSize(Size(100, 100));
164 }
165 else
166 {
167 _richText->ignoreContentAdaptWithSize(true);
168 }
169 }
170 break;
171
172 default:
173 break;
174 }
175}
176
177void UIRichTextTest::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
178{
179 if (type == Widget::TouchEventType::ENDED)
180 {
181 auto wrapMode = _richText->getWrapMode();
182 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
183 _richText->setWrapMode(wrapMode);
184 }
185}
186
187void UIRichTextTest::switchAlignment(Ref *sender, Widget::TouchEventType type) {
188 if (type == Widget::TouchEventType::ENDED)
189 {
190 auto alignment = _richText->getHorizontalAlignment();
191 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
192 _richText->setHorizontalAlignment(alignment);
193 }
194}
195
196//
197// UIRichTextXMLBasic
198//
200{
201 if (UIScene::init())
202 {
203 Size widgetSize = _widget->getContentSize();
204
205 // Add the alert
206 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
207 alert->setColor(Color3B(159, 168, 176));
208 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
209 _widget->addChild(alert);
210
211
212 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
213 button->setTouchEnabled(true);
214 button->setTitleText("switch");
215 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
216 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::touchEvent, this));
217 button->setLocalZOrder(10);
218 _widget->addChild(button);
219
220 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
221 button2->setTouchEnabled(true);
222 button2->setTitleText("wrap mode");
223 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
224 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::switchWrapMode, this));
225 button2->setLocalZOrder(10);
226 _widget->addChild(button2);
227
228 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
229 button3->setTouchEnabled(true);
230 button3->setTitleText("alignment");
231 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
232 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::switchAlignment, this));
233 button3->setLocalZOrder(10);
234 _widget->addChild(button3);
235
236 // RichText
237 _richText = RichText::createWithXML("This is just a simple text. no xml tags here. testing the basics. testing word-wrapping. testing, testing, testing");
238 _richText->ignoreContentAdaptWithSize(false);
239 _richText->setContentSize(Size(100, 100));
240
241 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
242 _richText->setLocalZOrder(10);
243
244
245 _widget->addChild(_richText);
246
247 // test remove all children, this call won't effect the test
248 _richText->removeAllChildren();
249
250 return true;
251 }
252 return false;
253}
254
255void UIRichTextXMLBasic::touchEvent(Ref *pSender, Widget::TouchEventType type)
256{
257 switch (type)
258 {
259 case Widget::TouchEventType::ENDED:
260 {
261 if (_richText->isIgnoreContentAdaptWithSize())
262 {
263 _richText->ignoreContentAdaptWithSize(false);
264 _richText->setContentSize(Size(100, 100));
265 }
266 else
267 {
268 _richText->ignoreContentAdaptWithSize(true);
269 }
270 }
271 break;
272
273 default:
274 break;
275 }
276}
277
278void UIRichTextXMLBasic::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
279{
280 if (type == Widget::TouchEventType::ENDED)
281 {
282 auto wrapMode = _richText->getWrapMode();
283 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
284 _richText->setWrapMode(wrapMode);
285 }
286}
287
288void UIRichTextXMLBasic::switchAlignment(Ref *sender, Widget::TouchEventType type) {
289 if (type == Widget::TouchEventType::ENDED)
290 {
291 auto alignment = _richText->getHorizontalAlignment();
292 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
293 _richText->setHorizontalAlignment(alignment);
294 }
295}
296
297//
298// UIRichTextXMLSmallBig
299//
301{
302 if (UIScene::init())
303 {
304 Size widgetSize = _widget->getContentSize();
305
306 // Add the alert
307 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
308 alert->setColor(Color3B(159, 168, 176));
309 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
310 _widget->addChild(alert);
311
312
313 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
314 button->setTouchEnabled(true);
315 button->setTitleText("switch");
316 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
317 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::touchEvent, this));
318 button->setLocalZOrder(10);
319 _widget->addChild(button);
320
321 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
322 button2->setTouchEnabled(true);
323 button2->setTitleText("wrap mode");
324 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
325 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::switchWrapMode, this));
326 button2->setLocalZOrder(10);
327 _widget->addChild(button2);
328
329 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
330 button3->setTouchEnabled(true);
331 button3->setTitleText("alignment");
332 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
333 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::switchAlignment, this));
334 button3->setLocalZOrder(10);
335 _widget->addChild(button3);
336
337 // RichText
338 _richText = RichText::createWithXML("Regular size.<small>smaller size.</small><big>bigger.<small>normal.</small>bigger</big>.normal.");
339 _richText->ignoreContentAdaptWithSize(false);
340 _richText->setContentSize(Size(100, 100));
341
342 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
343 _richText->setLocalZOrder(10);
344
345
346 _widget->addChild(_richText);
347
348 // test remove all children, this call won't effect the test
349 _richText->removeAllChildren();
350
351 return true;
352 }
353 return false;
354}
355
356void UIRichTextXMLSmallBig::touchEvent(Ref *pSender, Widget::TouchEventType type)
357{
358 switch (type)
359 {
360 case Widget::TouchEventType::ENDED:
361 {
362 if (_richText->isIgnoreContentAdaptWithSize())
363 {
364 _richText->ignoreContentAdaptWithSize(false);
365 _richText->setContentSize(Size(100, 100));
366 }
367 else
368 {
369 _richText->ignoreContentAdaptWithSize(true);
370 }
371 }
372 break;
373
374 default:
375 break;
376 }
377}
378
379void UIRichTextXMLSmallBig::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
380{
381 if (type == Widget::TouchEventType::ENDED)
382 {
383 auto wrapMode = _richText->getWrapMode();
384 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
385 _richText->setWrapMode(wrapMode);
386 }
387}
388
389void UIRichTextXMLSmallBig::switchAlignment(Ref *sender, Widget::TouchEventType type) {
390 if (type == Widget::TouchEventType::ENDED)
391 {
392 auto alignment = _richText->getHorizontalAlignment();
393 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
394 _richText->setHorizontalAlignment(alignment);
395 }
396}
397
398//
399// UIRichTextXMLColor
400//
402{
403 if (UIScene::init())
404 {
405 Size widgetSize = _widget->getContentSize();
406
407 // Add the alert
408 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
409 alert->setColor(Color3B(159, 168, 176));
410 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
411 _widget->addChild(alert);
412
413
414 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
415 button->setTouchEnabled(true);
416 button->setTitleText("switch");
417 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
418 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::touchEvent, this));
419 button->setLocalZOrder(10);
420 _widget->addChild(button);
421
422 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
423 button2->setTouchEnabled(true);
424 button2->setTitleText("wrap mode");
425 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
426 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::switchWrapMode, this));
427 button2->setLocalZOrder(10);
428 _widget->addChild(button2);
429
430 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
431 button3->setTouchEnabled(true);
432 button3->setTitleText("alignment");
433 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
434 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::switchAlignment, this));
435 button3->setLocalZOrder(10);
436 _widget->addChild(button3);
437
438 // RichText
439 _richText = RichText::createWithXML("Default color.<font color='#ff0000'>red.<font color='#00ff00'>green</font>red again.</font>default again");
440 _richText->ignoreContentAdaptWithSize(false);
441 _richText->setContentSize(Size(100, 100));
442
443 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
444 _richText->setLocalZOrder(10);
445
446
447 _widget->addChild(_richText);
448
449 // test remove all children, this call won't effect the test
450 _richText->removeAllChildren();
451
452 return true;
453 }
454 return false;
455}
456
457void UIRichTextXMLColor::touchEvent(Ref *pSender, Widget::TouchEventType type)
458{
459 switch (type)
460 {
461 case Widget::TouchEventType::ENDED:
462 {
463 if (_richText->isIgnoreContentAdaptWithSize())
464 {
465 _richText->ignoreContentAdaptWithSize(false);
466 _richText->setContentSize(Size(100, 100));
467 }
468 else
469 {
470 _richText->ignoreContentAdaptWithSize(true);
471 }
472 }
473 break;
474
475 default:
476 break;
477 }
478}
479
480void UIRichTextXMLColor::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
481{
482 if (type == Widget::TouchEventType::ENDED)
483 {
484 auto wrapMode = _richText->getWrapMode();
485 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
486 _richText->setWrapMode(wrapMode);
487 }
488}
489
490void UIRichTextXMLColor::switchAlignment(Ref *sender, Widget::TouchEventType type) {
491 if (type == Widget::TouchEventType::ENDED)
492 {
493 auto alignment = _richText->getHorizontalAlignment();
494 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
495 _richText->setHorizontalAlignment(alignment);
496 }
497}
498
499//
500// UIRichTextXMLSUIB
501//
503{
504 if (UIScene::init())
505 {
506 Size widgetSize = _widget->getContentSize();
507
508 // Add the alert
509 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
510 alert->setColor(Color3B(159, 168, 176));
511 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
512 _widget->addChild(alert);
513
514
515 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
516 button->setTouchEnabled(true);
517 button->setTitleText("switch");
518 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
519 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::touchEvent, this));
520 button->setLocalZOrder(10);
521 _widget->addChild(button);
522
523 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
524 button2->setTouchEnabled(true);
525 button2->setTitleText("wrap mode");
526 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
527 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::switchWrapMode, this));
528 button2->setLocalZOrder(10);
529 _widget->addChild(button2);
530
531 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
532 button3->setTouchEnabled(true);
533 button3->setTitleText("alignment");
534 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
535 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::switchAlignment, this));
536 button3->setLocalZOrder(10);
537 _widget->addChild(button3);
538
539 // RichText
540 _richText = RichText::createWithXML("system font: <u>underline</u><i>italics</i><b>bold</b><del>strike-through</del>");
541 _richText->ignoreContentAdaptWithSize(false);
542 _richText->setContentSize(Size(100, 100));
543
544 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
545 _richText->setLocalZOrder(10);
546
547
548 _widget->addChild(_richText);
549
550 // test remove all children, this call won't effect the test
551 _richText->removeAllChildren();
552
553 return true;
554 }
555 return false;
556}
557
558void UIRichTextXMLSUIB::touchEvent(Ref *pSender, Widget::TouchEventType type)
559{
560 switch (type)
561 {
562 case Widget::TouchEventType::ENDED:
563 {
564 if (_richText->isIgnoreContentAdaptWithSize())
565 {
566 _richText->ignoreContentAdaptWithSize(false);
567 _richText->setContentSize(Size(100, 100));
568 }
569 else
570 {
571 _richText->ignoreContentAdaptWithSize(true);
572 }
573 }
574 break;
575
576 default:
577 break;
578 }
579}
580
581void UIRichTextXMLSUIB::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
582{
583 if (type == Widget::TouchEventType::ENDED)
584 {
585 auto wrapMode = _richText->getWrapMode();
586 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
587 _richText->setWrapMode(wrapMode);
588 }
589}
590
591void UIRichTextXMLSUIB::switchAlignment(Ref *sender, Widget::TouchEventType type) {
592 if (type == Widget::TouchEventType::ENDED)
593 {
594 auto alignment = _richText->getHorizontalAlignment();
595 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
596 _richText->setHorizontalAlignment(alignment);
597 }
598}
599
600//
601// UIRichTextXMLSUIB2
602//
604{
605 if (UIScene::init())
606 {
607 Size widgetSize = _widget->getContentSize();
608
609 // Add the alert
610 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
611 alert->setColor(Color3B(159, 168, 176));
612 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
613 _widget->addChild(alert);
614
615
616 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
617 button->setTouchEnabled(true);
618 button->setTitleText("switch");
619 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
620 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::touchEvent, this));
621 button->setLocalZOrder(10);
622 _widget->addChild(button);
623
624 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
625 button2->setTouchEnabled(true);
626 button2->setTitleText("wrap mode");
627 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
628 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::switchWrapMode, this));
629 button2->setLocalZOrder(10);
630 _widget->addChild(button2);
631
632 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
633 button3->setTouchEnabled(true);
634 button3->setTitleText("alignment");
635 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
636 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::switchAlignment, this));
637 button3->setLocalZOrder(10);
638 _widget->addChild(button3);
639
640 // RichText
641 _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>");
642 _richText->ignoreContentAdaptWithSize(false);
643 _richText->setContentSize(Size(100, 100));
644
645 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
646 _richText->setLocalZOrder(10);
647
648
649 _widget->addChild(_richText);
650
651 // test remove all children, this call won't effect the test
652 _richText->removeAllChildren();
653
654 return true;
655 }
656 return false;
657}
658
659void UIRichTextXMLSUIB2::touchEvent(Ref *pSender, Widget::TouchEventType type)
660{
661 switch (type)
662 {
663 case Widget::TouchEventType::ENDED:
664 {
665 if (_richText->isIgnoreContentAdaptWithSize())
666 {
667 _richText->ignoreContentAdaptWithSize(false);
668 _richText->setContentSize(Size(100, 100));
669 }
670 else
671 {
672 _richText->ignoreContentAdaptWithSize(true);
673 }
674 }
675 break;
676
677 default:
678 break;
679 }
680}
681
682void UIRichTextXMLSUIB2::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
683{
684 if (type == Widget::TouchEventType::ENDED)
685 {
686 auto wrapMode = _richText->getWrapMode();
687 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
688 _richText->setWrapMode(wrapMode);
689 }
690}
691
692void UIRichTextXMLSUIB2::switchAlignment(Ref *sender, Widget::TouchEventType type) {
693 if (type == Widget::TouchEventType::ENDED)
694 {
695 auto alignment = _richText->getHorizontalAlignment();
696 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
697 _richText->setHorizontalAlignment(alignment);
698 }
699}
700
701//
702// UIRichTextXMLSUIB3
703//
705{
706 if (UIScene::init())
707 {
708 Size widgetSize = _widget->getContentSize();
709
710 // Add the alert
711 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
712 alert->setColor(Color3B(159, 168, 176));
713 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
714 _widget->addChild(alert);
715
716
717 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
718 button->setTouchEnabled(true);
719 button->setTitleText("switch");
720 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
721 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::touchEvent, this));
722 button->setLocalZOrder(10);
723 _widget->addChild(button);
724
725 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
726 button2->setTouchEnabled(true);
727 button2->setTitleText("wrap mode");
728 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
729 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::switchWrapMode, this));
730 button2->setLocalZOrder(10);
731 _widget->addChild(button2);
732
733 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
734 button3->setTouchEnabled(true);
735 button3->setTitleText("alignment");
736 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
737 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::switchAlignment, this));
738 button3->setLocalZOrder(10);
739 _widget->addChild(button3);
740
741 // RichText
742 _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>");
743 _richText->ignoreContentAdaptWithSize(false);
744 _richText->setContentSize(Size(100, 100));
745
746 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
747 _richText->setLocalZOrder(10);
748
749
750 _widget->addChild(_richText);
751
752 // test remove all children, this call won't effect the test
753 _richText->removeAllChildren();
754
755 return true;
756 }
757 return false;
758}
759
760void UIRichTextXMLSUIB3::touchEvent(Ref *pSender, Widget::TouchEventType type)
761{
762 switch (type)
763 {
764 case Widget::TouchEventType::ENDED:
765 {
766 if (_richText->isIgnoreContentAdaptWithSize())
767 {
768 _richText->ignoreContentAdaptWithSize(false);
769 _richText->setContentSize(Size(100, 100));
770 }
771 else
772 {
773 _richText->ignoreContentAdaptWithSize(true);
774 }
775 }
776 break;
777
778 default:
779 break;
780 }
781}
782
783void UIRichTextXMLSUIB3::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
784{
785 if (type == Widget::TouchEventType::ENDED)
786 {
787 auto wrapMode = _richText->getWrapMode();
788 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
789 _richText->setWrapMode(wrapMode);
790 }
791}
792
793void UIRichTextXMLSUIB3::switchAlignment(Ref *sender, Widget::TouchEventType type) {
794 if (type == Widget::TouchEventType::ENDED)
795 {
796 auto alignment = _richText->getHorizontalAlignment();
797 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
798 _richText->setHorizontalAlignment(alignment);
799 }
800}
801
802//
803// UIRichTextXMLImg
804//
806{
807 if (UIScene::init())
808 {
809 Size widgetSize = _widget->getContentSize();
810
811 // Add the alert
812 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
813 alert->setColor(Color3B(159, 168, 176));
814 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
815 _widget->addChild(alert);
816
817
818 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
819 button->setTouchEnabled(true);
820 button->setTitleText("switch");
821 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
822 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::touchEvent, this));
823 button->setLocalZOrder(10);
824 _widget->addChild(button);
825
826 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
827 button2->setTouchEnabled(true);
828 button2->setTitleText("wrap mode");
829 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
830 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::switchWrapMode, this));
831 button2->setLocalZOrder(10);
832 _widget->addChild(button2);
833
834 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
835 button3->setTouchEnabled(true);
836 button3->setTitleText("alignment");
837 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
838 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::switchAlignment, this));
839 button3->setLocalZOrder(10);
840 _widget->addChild(button3);
841
842 // RichText
843 _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");
844 _richText->ignoreContentAdaptWithSize(false);
845 _richText->setContentSize(Size(100, 100));
846
847 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
848 _richText->setLocalZOrder(10);
849
850
851 _widget->addChild(_richText);
852
853 // test remove all children, this call won't effect the test
854 _richText->removeAllChildren();
855
856 return true;
857 }
858 return false;
859}
860
861void UIRichTextXMLImg::touchEvent(Ref *pSender, Widget::TouchEventType type)
862{
863 switch (type)
864 {
865 case Widget::TouchEventType::ENDED:
866 {
867 if (_richText->isIgnoreContentAdaptWithSize())
868 {
869 _richText->ignoreContentAdaptWithSize(false);
870 _richText->setContentSize(Size(100, 100));
871 }
872 else
873 {
874 _richText->ignoreContentAdaptWithSize(true);
875 }
876 }
877 break;
878
879 default:
880 break;
881 }
882}
883
884void UIRichTextXMLImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
885{
886 if (type == Widget::TouchEventType::ENDED)
887 {
888 auto wrapMode = _richText->getWrapMode();
889 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
890 _richText->setWrapMode(wrapMode);
891 }
892}
893
894void UIRichTextXMLImg::switchAlignment(Ref *sender, Widget::TouchEventType type) {
895 if (type == Widget::TouchEventType::ENDED)
896 {
897 auto alignment = _richText->getHorizontalAlignment();
898 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
899 _richText->setHorizontalAlignment(alignment);
900 }
901}
902
903//
904// UIRichTextXMLUrl
905//
907{
908 if (UIScene::init())
909 {
910 Size widgetSize = _widget->getContentSize();
911
912 // Add the alert
913 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
914 alert->setColor(Color3B(159, 168, 176));
915 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
916 _widget->addChild(alert);
917
918
919 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
920 button->setTouchEnabled(true);
921 button->setTitleText("switch");
922 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
923 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::touchEvent, this));
924 button->setLocalZOrder(10);
925 _widget->addChild(button);
926
927 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
928 button2->setTouchEnabled(true);
929 button2->setTitleText("wrap mode");
930 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
931 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::switchWrapMode, this));
932 button2->setLocalZOrder(10);
933 _widget->addChild(button2);
934
935 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
936 button3->setTouchEnabled(true);
937 button3->setTitleText("alignment");
938 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
939 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::switchAlignment, this));
940 button3->setLocalZOrder(10);
941 _widget->addChild(button3);
942
943 // RichText
944 _richText = RichText::createWithXML("This link will redirect you to google: <a href='http://www.google.com'>click me</a>");
945 _richText->ignoreContentAdaptWithSize(false);
946 _richText->setContentSize(Size(100, 100));
947
948 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
949 _richText->setLocalZOrder(10);
950
951
952 _widget->addChild(_richText);
953
954 // test remove all children, this call won't effect the test
955 _richText->removeAllChildren();
956
957 return true;
958 }
959 return false;
960}
961
962void UIRichTextXMLUrl::touchEvent(Ref *pSender, Widget::TouchEventType type)
963{
964 switch (type)
965 {
966 case Widget::TouchEventType::ENDED:
967 {
968 if (_richText->isIgnoreContentAdaptWithSize())
969 {
970 _richText->ignoreContentAdaptWithSize(false);
971 _richText->setContentSize(Size(100, 100));
972 }
973 else
974 {
975 _richText->ignoreContentAdaptWithSize(true);
976 }
977 }
978 break;
979
980 default:
981 break;
982 }
983}
984
985void UIRichTextXMLUrl::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
986{
987 if (type == Widget::TouchEventType::ENDED)
988 {
989 auto wrapMode = _richText->getWrapMode();
990 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
991 _richText->setWrapMode(wrapMode);
992 }
993}
994
995void UIRichTextXMLUrl::switchAlignment(Ref *sender, Widget::TouchEventType type) {
996 if (type == Widget::TouchEventType::ENDED)
997 {
998 auto alignment = _richText->getHorizontalAlignment();
999 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1000 _richText->setHorizontalAlignment(alignment);
1001 }
1002}
1003
1004//
1005// UIRichTextXMLUrlImg
1006//
1008{
1009 if (UIScene::init())
1010 {
1011 Size widgetSize = _widget->getContentSize();
1012
1013 // Add the alert
1014 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
1015 alert->setColor(Color3B(159, 168, 176));
1016 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1017 _widget->addChild(alert);
1018
1019
1020 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1021 button->setTouchEnabled(true);
1022 button->setTitleText("switch");
1023 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1024 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::touchEvent, this));
1025 button->setLocalZOrder(10);
1026 _widget->addChild(button);
1027
1028 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1029 button2->setTouchEnabled(true);
1030 button2->setTitleText("wrap mode");
1031 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1032 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::switchWrapMode, this));
1033 button2->setLocalZOrder(10);
1034 _widget->addChild(button2);
1035
1036 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1037 button3->setTouchEnabled(true);
1038 button3->setTitleText("alignment");
1039 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1040 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::switchAlignment, this));
1041 button3->setLocalZOrder(10);
1042 _widget->addChild(button3);
1043
1044 // RichText
1045 _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>");
1046 _richText->ignoreContentAdaptWithSize(false);
1047 _richText->setContentSize(Size(100, 100));
1048
1049 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1050 _richText->setLocalZOrder(10);
1051
1052
1053 _widget->addChild(_richText);
1054
1055 // test remove all children, this call won't effect the test
1056 _richText->removeAllChildren();
1057
1058 return true;
1059 }
1060 return false;
1061}
1062
1063void UIRichTextXMLUrlImg::touchEvent(Ref *pSender, Widget::TouchEventType type)
1064{
1065 switch (type)
1066 {
1067 case Widget::TouchEventType::ENDED:
1068 {
1069 if (_richText->isIgnoreContentAdaptWithSize())
1070 {
1071 _richText->ignoreContentAdaptWithSize(false);
1072 _richText->setContentSize(Size(100, 100));
1073 }
1074 else
1075 {
1076 _richText->ignoreContentAdaptWithSize(true);
1077 }
1078 }
1079 break;
1080
1081 default:
1082 break;
1083 }
1084}
1085
1086void UIRichTextXMLUrlImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1087{
1088 if (type == Widget::TouchEventType::ENDED)
1089 {
1090 auto wrapMode = _richText->getWrapMode();
1091 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1092 _richText->setWrapMode(wrapMode);
1093 }
1094}
1095
1096void UIRichTextXMLUrlImg::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1097 if (type == Widget::TouchEventType::ENDED)
1098 {
1099 auto alignment = _richText->getHorizontalAlignment();
1100 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1101 _richText->setHorizontalAlignment(alignment);
1102 }
1103}
1104
1105//
1106// UIRichTextXMLFace
1107//
1109{
1110 if (UIScene::init())
1111 {
1112 Size widgetSize = _widget->getContentSize();
1113
1114 // Add the alert
1115 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
1116 alert->setColor(Color3B(159, 168, 176));
1117 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1118 _widget->addChild(alert);
1119
1120
1121 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1122 button->setTouchEnabled(true);
1123 button->setTitleText("switch");
1124 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1125 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::touchEvent, this));
1126 button->setLocalZOrder(10);
1127 _widget->addChild(button);
1128
1129 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1130 button2->setTouchEnabled(true);
1131 button2->setTitleText("wrap mode");
1132 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1133 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::switchWrapMode, this));
1134 button2->setLocalZOrder(10);
1135 _widget->addChild(button2);
1136
1137 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1138 button3->setTouchEnabled(true);
1139 button3->setTitleText("alignment");
1140 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1141 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::switchAlignment, this));
1142 button3->setLocalZOrder(10);
1143 _widget->addChild(button3);
1144
1145 // RichText
1146 _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>");
1147 _richText->ignoreContentAdaptWithSize(false);
1148 _richText->setContentSize(Size(120, 100));
1149
1150 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1151 _richText->setLocalZOrder(10);
1152
1153
1154 _widget->addChild(_richText);
1155
1156 // test remove all children, this call won't effect the test
1157 _richText->removeAllChildren();
1158
1159 return true;
1160 }
1161 return false;
1162}
1163
1164void UIRichTextXMLFace::touchEvent(Ref *pSender, Widget::TouchEventType type)
1165{
1166 switch (type)
1167 {
1168 case Widget::TouchEventType::ENDED:
1169 {
1170 if (_richText->isIgnoreContentAdaptWithSize())
1171 {
1172 _richText->ignoreContentAdaptWithSize(false);
1173 _richText->setContentSize(Size(100, 100));
1174 }
1175 else
1176 {
1177 _richText->ignoreContentAdaptWithSize(true);
1178 }
1179 }
1180 break;
1181
1182 default:
1183 break;
1184 }
1185}
1186
1187void UIRichTextXMLFace::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1188{
1189 if (type == Widget::TouchEventType::ENDED)
1190 {
1191 auto wrapMode = _richText->getWrapMode();
1192 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1193 _richText->setWrapMode(wrapMode);
1194 }
1195}
1196
1197void UIRichTextXMLFace::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1198 if (type == Widget::TouchEventType::ENDED)
1199 {
1200 auto alignment = _richText->getHorizontalAlignment();
1201 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1202 _richText->setHorizontalAlignment(alignment);
1203 }
1204}
1205
1206//
1207// UIRichTextXMLBR
1208//
1210{
1211 if (UIScene::init())
1212 {
1213 Size widgetSize = _widget->getContentSize();
1214
1215 // Add the alert
1216 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
1217 alert->setColor(Color3B(159, 168, 176));
1218 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1219 _widget->addChild(alert);
1220
1221
1222 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1223 button->setTouchEnabled(true);
1224 button->setTitleText("switch");
1225 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1226 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::touchEvent, this));
1227 button->setLocalZOrder(10);
1228 _widget->addChild(button);
1229
1230 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1231 button2->setTouchEnabled(true);
1232 button2->setTitleText("wrap mode");
1233 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1234 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::switchWrapMode, this));
1235 button2->setLocalZOrder(10);
1236 _widget->addChild(button2);
1237
1238 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1239 button3->setTouchEnabled(true);
1240 button3->setTitleText("alignment");
1241 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1242 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::switchAlignment, this));
1243 button3->setLocalZOrder(10);
1244 _widget->addChild(button3);
1245
1246 // RichText
1247 _richText = RichText::createWithXML("this is one line.<br/>this should be in another line.<br/>and this is another line");
1248 _richText->ignoreContentAdaptWithSize(false);
1249 _richText->setContentSize(Size(100, 100));
1250
1251 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1252 _richText->setLocalZOrder(10);
1253
1254
1255 _widget->addChild(_richText);
1256
1257 // test remove all children, this call won't effect the test
1258 _richText->removeAllChildren();
1259
1260 return true;
1261 }
1262 return false;
1263}
1264
1265void UIRichTextXMLBR::touchEvent(Ref *pSender, Widget::TouchEventType type)
1266{
1267 switch (type)
1268 {
1269 case Widget::TouchEventType::ENDED:
1270 {
1271 if (_richText->isIgnoreContentAdaptWithSize())
1272 {
1273 _richText->ignoreContentAdaptWithSize(false);
1274 _richText->setContentSize(Size(100, 100));
1275 }
1276 else
1277 {
1278 _richText->ignoreContentAdaptWithSize(true);
1279 }
1280 }
1281 break;
1282
1283 default:
1284 break;
1285 }
1286}
1287
1288void UIRichTextXMLBR::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1289{
1290 if (type == Widget::TouchEventType::ENDED)
1291 {
1292 auto wrapMode = _richText->getWrapMode();
1293 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1294 _richText->setWrapMode(wrapMode);
1295 }
1296}
1297
1298void UIRichTextXMLBR::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1299 if (type == Widget::TouchEventType::ENDED)
1300 {
1301 auto alignment = _richText->getHorizontalAlignment();
1302 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1303 _richText->setHorizontalAlignment(alignment);
1304 }
1305}
1306
1307//
1308// UIRichTextXMLInvalid
1309//
1311{
1312 if (UIScene::init())
1313 {
1314 Size widgetSize = _widget->getContentSize();
1315
1316 // Add the alert
1317 Text *alert = Text::create("Invalid XML test", "fonts/Marker Felt.ttf", 30);
1318 alert->setColor(Color3B(159, 168, 176));
1319 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1320 _widget->addChild(alert);
1321
1322
1323 // RichText
1324 _richText = RichText::createWithXML("this is an invalid xml. <i>no closing tag");
1325 if (_richText)
1326 {
1327 _richText->ignoreContentAdaptWithSize(false);
1328 _richText->setContentSize(Size(100, 100));
1329
1330 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1331 _richText->setLocalZOrder(10);
1332
1333
1334 _widget->addChild(_richText);
1335
1336 // test remove all children, this call won't effect the test
1337 _richText->removeAllChildren();
1338 }
1339 return true;
1340 }
1341 return false;
1342}
1343
1344//
1345// UIRichTextXMLOutline
1346//
1348{
1349 if (UIScene::init())
1350 {
1351 Size widgetSize = _widget->getContentSize();
1352
1353 // Add the alert
1354 Text *alert = Text::create("Outline", "fonts/Marker Felt.ttf", 30);
1355 alert->setColor(Color3B(159, 168, 176));
1356 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1357 _widget->addChild(alert);
1358
1359
1360 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1361 button->setTouchEnabled(true);
1362 button->setTitleText("switch");
1363 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1364 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::touchEvent, this));
1365 button->setLocalZOrder(10);
1366 _widget->addChild(button);
1367
1368 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1369 button2->setTouchEnabled(true);
1370 button2->setTitleText("wrap mode");
1371 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1372 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::switchWrapMode, this));
1373 button2->setLocalZOrder(10);
1374 _widget->addChild(button2);
1375
1376 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1377 button3->setTouchEnabled(true);
1378 button3->setTitleText("alignment");
1379 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1380 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::switchAlignment, this));
1381 button3->setLocalZOrder(10);
1382 _widget->addChild(button3);
1383
1384 // RichText
1385 _richText = RichText::createWithXML("<font face='fonts/Marker Felt.ttf' size=\"24\"><outline color=\"#D2B48C\" size=\"2\">OUTLINE</outline></font>");
1386 _richText->ignoreContentAdaptWithSize(false);
1387 _richText->setContentSize(Size(100, 100));
1388
1389 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1390 _richText->setLocalZOrder(10);
1391
1392
1393 _widget->addChild(_richText);
1394
1395 // test remove all children, this call won't effect the test
1396 _richText->removeAllChildren();
1397
1398 return true;
1399 }
1400 return false;
1401}
1402
1403void UIRichTextXMLOutline::touchEvent(Ref *pSender, Widget::TouchEventType type)
1404{
1405 switch (type)
1406 {
1407 case Widget::TouchEventType::ENDED:
1408 {
1409 if (_richText->isIgnoreContentAdaptWithSize())
1410 {
1411 _richText->ignoreContentAdaptWithSize(false);
1412 _richText->setContentSize(Size(100, 100));
1413 }
1414 else
1415 {
1416 _richText->ignoreContentAdaptWithSize(true);
1417 }
1418 }
1419 break;
1420
1421 default:
1422 break;
1423 }
1424}
1425
1426void UIRichTextXMLOutline::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1427{
1428 if (type == Widget::TouchEventType::ENDED)
1429 {
1430 auto wrapMode = _richText->getWrapMode();
1431 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1432 _richText->setWrapMode(wrapMode);
1433 }
1434}
1435
1436void UIRichTextXMLOutline::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1437 if (type == Widget::TouchEventType::ENDED)
1438 {
1439 auto alignment = _richText->getHorizontalAlignment();
1440 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1441 _richText->setHorizontalAlignment(alignment);
1442 }
1443}
1444
1445//
1446// UIRichTextXMLShadow
1447//
1449{
1450 if (UIScene::init())
1451 {
1452 Size widgetSize = _widget->getContentSize();
1453
1454 // Add the alert
1455 Text *alert = Text::create("Shadow", "fonts/Marker Felt.ttf", 30);
1456 alert->setColor(Color3B(159, 168, 176));
1457 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1458 _widget->addChild(alert);
1459
1460
1461 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1462 button->setTouchEnabled(true);
1463 button->setTitleText("switch");
1464 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1465 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::touchEvent, this));
1466 button->setLocalZOrder(10);
1467 _widget->addChild(button);
1468
1469 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1470 button2->setTouchEnabled(true);
1471 button2->setTitleText("wrap mode");
1472 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1473 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::switchWrapMode, this));
1474 button2->setLocalZOrder(10);
1475 _widget->addChild(button2);
1476
1477 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1478 button3->setTouchEnabled(true);
1479 button3->setTitleText("alignment");
1480 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1481 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::switchAlignment, this));
1482 button3->setLocalZOrder(10);
1483 _widget->addChild(button3);
1484
1485 // RichText
1486 _richText = RichText::createWithXML("<font size=\"24\"><shadow color=\"#4169E1\" offsetWidth=\"8\" offsetHeight=\"-8\" blurRadius=\"2\">SHADOW</shadow></font>");
1487 _richText->ignoreContentAdaptWithSize(false);
1488 _richText->setContentSize(Size(150, 100));
1489
1490 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1491 _richText->setLocalZOrder(10);
1492
1493
1494 _widget->addChild(_richText);
1495
1496 // test remove all children, this call won't effect the test
1497 _richText->removeAllChildren();
1498
1499 return true;
1500 }
1501 return false;
1502}
1503
1504void UIRichTextXMLShadow::touchEvent(Ref *pSender, Widget::TouchEventType type)
1505{
1506 switch (type)
1507 {
1508 case Widget::TouchEventType::ENDED:
1509 {
1510 if (_richText->isIgnoreContentAdaptWithSize())
1511 {
1512 _richText->ignoreContentAdaptWithSize(false);
1513 _richText->setContentSize(Size(100, 100));
1514 }
1515 else
1516 {
1517 _richText->ignoreContentAdaptWithSize(true);
1518 }
1519 }
1520 break;
1521
1522 default:
1523 break;
1524 }
1525}
1526
1527void UIRichTextXMLShadow::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1528{
1529 if (type == Widget::TouchEventType::ENDED)
1530 {
1531 auto wrapMode = _richText->getWrapMode();
1532 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1533 _richText->setWrapMode(wrapMode);
1534 }
1535}
1536
1537void UIRichTextXMLShadow::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1538 if (type == Widget::TouchEventType::ENDED)
1539 {
1540 auto alignment = _richText->getHorizontalAlignment();
1541 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1542 _richText->setHorizontalAlignment(alignment);
1543 }
1544}
1545
1546//
1547// UIRichTextXMLGlow
1548//
1550{
1551 if (UIScene::init())
1552 {
1553 Size widgetSize = _widget->getContentSize();
1554
1555 // Add the alert
1556 Text *alert = Text::create("Glow", "fonts/Marker Felt.ttf", 30);
1557 alert->setColor(Color3B(159, 168, 176));
1558 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1559 _widget->addChild(alert);
1560
1561
1562 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1563 button->setTouchEnabled(true);
1564 button->setTitleText("switch");
1565 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1566 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::touchEvent, this));
1567 button->setLocalZOrder(10);
1568 _widget->addChild(button);
1569
1570 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1571 button2->setTouchEnabled(true);
1572 button2->setTitleText("wrap mode");
1573 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1574 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::switchWrapMode, this));
1575 button2->setLocalZOrder(10);
1576 _widget->addChild(button2);
1577
1578 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1579 button3->setTouchEnabled(true);
1580 button3->setTitleText("alignment");
1581 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1582 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::switchAlignment, this));
1583 button3->setLocalZOrder(10);
1584 _widget->addChild(button3);
1585
1586 // RichText
1587 _richText = RichText::createWithXML("<font face=\"fonts/Marker Felt.ttf\" size=\"24\"><glow color=\"#AFEEEE\">GLOW</glow></font>");
1588 _richText->ignoreContentAdaptWithSize(false);
1589 _richText->setContentSize(Size(100, 100));
1590
1591 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1592 _richText->setLocalZOrder(10);
1593
1594
1595 _widget->addChild(_richText);
1596
1597 // test remove all children, this call won't effect the test
1598 _richText->removeAllChildren();
1599
1600 return true;
1601 }
1602 return false;
1603}
1604
1605void UIRichTextXMLGlow::touchEvent(Ref *pSender, Widget::TouchEventType type)
1606{
1607 switch (type)
1608 {
1609 case Widget::TouchEventType::ENDED:
1610 {
1611 if (_richText->isIgnoreContentAdaptWithSize())
1612 {
1613 _richText->ignoreContentAdaptWithSize(false);
1614 _richText->setContentSize(Size(100, 100));
1615 }
1616 else
1617 {
1618 _richText->ignoreContentAdaptWithSize(true);
1619 }
1620 }
1621 break;
1622
1623 default:
1624 break;
1625 }
1626}
1627
1628void UIRichTextXMLGlow::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1629{
1630 if (type == Widget::TouchEventType::ENDED)
1631 {
1632 auto wrapMode = _richText->getWrapMode();
1633 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1634 _richText->setWrapMode(wrapMode);
1635 }
1636}
1637
1638void UIRichTextXMLGlow::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1639 if (type == Widget::TouchEventType::ENDED)
1640 {
1641 auto alignment = _richText->getHorizontalAlignment();
1642 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1643 _richText->setHorizontalAlignment(alignment);
1644 }
1645}
1646
1647//
1648// UIRichTextXMLExtend
1649//
1651{
1652 if (UIScene::init())
1653 {
1654 Size widgetSize = _widget->getContentSize();
1655
1656 // Add the alert
1657 Text *alert = Text::create("Extend", "fonts/Marker Felt.ttf", 30);
1658 alert->setColor(Color3B(159, 168, 176));
1659 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1660 _widget->addChild(alert);
1661
1662
1663 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1664 button->setTouchEnabled(true);
1665 button->setTitleText("switch");
1666 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1667 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::touchEvent, this));
1668 button->setLocalZOrder(10);
1669 _widget->addChild(button);
1670
1671 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1672 button2->setTouchEnabled(true);
1673 button2->setTitleText("wrap mode");
1674 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1675 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::switchWrapMode, this));
1676 button2->setLocalZOrder(10);
1677 _widget->addChild(button2);
1678
1679 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1680 button3->setTouchEnabled(true);
1681 button3->setTitleText("alignment");
1682 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1683 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::switchAlignment, this));
1684 button3->setLocalZOrder(10);
1685 _widget->addChild(button3);
1686
1687 /* Tag extension */
1688 RichText::setTagDescription("CloseNormal", false, [](const ValueMap& tagAttrValueMap) {
1689 RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseNormal.png");
1690 return make_pair(ValueMap(), richElement);
1691 });
1692 RichText::setTagDescription("CloseSelected", false, [](const ValueMap& tagAttrValueMap) {
1693 RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseSelected.png");
1694 return make_pair(ValueMap(), richElement);
1695 });
1696
1697 /* Defaults */
1698 ValueMap defaults;
1699 defaults[RichText::KEY_FONT_COLOR_STRING] = "#FFF";
1700 defaults[RichText::KEY_FONT_SIZE] = 12.0f;
1701 defaults[RichText::KEY_FONT_FACE] = "fonts/Marker Felt.ttf";
1702 defaults[RichText::KEY_ANCHOR_FONT_COLOR_STRING] = "#f0f8ff";
1703 defaults[RichText::KEY_ANCHOR_TEXT_BOLD] = false;
1704 defaults[RichText::KEY_ANCHOR_TEXT_ITALIC] = false;
1705 //defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_NONE;
1706 //defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_DEL;
1707 defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_UNDER;
1708 //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_NONE;
1709 //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_OUTLINE;
1710 //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_SHADOW;
1711 //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_GLOW;
1712 defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_COLOR] = "#D2B48C";
1713 defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_SIZE] = 4;
1714 defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_COLOR] = "#4169E1";
1715 defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH] = 4.0f;
1716 defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT] = -4.0f;
1717 defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS] = 0;
1718 defaults[RichText::KEY_ANCHOR_TEXT_GLOW_COLOR] = "#AFEEEE";
1719
1720 // RichText
1721 _richText = RichText::createWithXML("<span>CloseNormal-tag:<br /><CloseNormal /><br /><br />CloseSelected-tag:<br /><CloseSelected></CloseSelected></span>",
1722 defaults,
1723 [](const std::string& url) {
1724 Application::getInstance()->openURL(url);
1725 });
1726 _richText->ignoreContentAdaptWithSize(false);
1727 _richText->setContentSize(Size(100, 100));
1728
1729 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1730 _richText->setLocalZOrder(10);
1731
1732
1733 _widget->addChild(_richText);
1734
1735 // test remove all children, this call won't effect the test
1736 _richText->removeAllChildren();
1737
1738 return true;
1739 }
1740 return false;
1741}
1742
1743void UIRichTextXMLExtend::touchEvent(Ref *pSender, Widget::TouchEventType type)
1744{
1745 switch (type)
1746 {
1747 case Widget::TouchEventType::ENDED:
1748 {
1749 if (_richText->isIgnoreContentAdaptWithSize())
1750 {
1751 _richText->ignoreContentAdaptWithSize(false);
1752 _richText->setContentSize(Size(100, 100));
1753 }
1754 else
1755 {
1756 _richText->ignoreContentAdaptWithSize(true);
1757 }
1758 }
1759 break;
1760
1761 default:
1762 break;
1763 }
1764}
1765
1766void UIRichTextXMLExtend::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1767{
1768 if (type == Widget::TouchEventType::ENDED)
1769 {
1770 auto wrapMode = _richText->getWrapMode();
1771 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1772 _richText->setWrapMode(wrapMode);
1773 }
1774}
1775
1776void UIRichTextXMLExtend::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1777 if (type == Widget::TouchEventType::ENDED)
1778 {
1779 auto alignment = _richText->getHorizontalAlignment();
1780 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1781 _richText->setHorizontalAlignment(alignment);
1782 }
1783}
1784
1785//
1786// UIRichTextXMLSpace
1787//
1789{
1790 if (UIScene::init())
1791 {
1792 Size widgetSize = _widget->getContentSize();
1793
1794 // Add the alert
1795 Text *alert = Text::create("Space", "fonts/Marker Felt.ttf", 30);
1796 alert->setColor(Color3B(159, 168, 176));
1797 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
1798 _widget->addChild(alert);
1799
1800
1801 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1802 button->setTouchEnabled(true);
1803 button->setTitleText("switch");
1804 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
1805 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSpace::touchEvent, this));
1806 button->setLocalZOrder(10);
1807 _widget->addChild(button);
1808
1809 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1810 button2->setTouchEnabled(true);
1811 button2->setTitleText("wrap mode");
1812 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1813 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSpace::switchWrapMode, this));
1814 button2->setLocalZOrder(10);
1815 _widget->addChild(button2);
1816
1817 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
1818 button3->setTouchEnabled(true);
1819 button3->setTitleText("alignment");
1820 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
1821 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSpace::switchAlignment, this));
1822 button3->setLocalZOrder(10);
1823 _widget->addChild(button3);
1824
1825 // RichText
1826 _richText = RichText::createWithXML("words should be divided with space.<br /><br /><font face='fonts/Marker Felt.ttf' color='#ffff00'>HELLO </font><font color='#ffff00'>WORLD</font><br /><br /><font color='#ff00ff'>HELLO</font><font face='fonts/Marker Felt.ttf' color='#ff00ff'> WORLD</font>");
1827 _richText->ignoreContentAdaptWithSize(false);
1828 _richText->setContentSize(Size(50, 100));
1829 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
1830 _richText->setLocalZOrder(10);
1831
1832 _widget->addChild(_richText);
1833
1834 // test remove all children, this call won't effect the test
1835 _richText->removeAllChildren();
1836
1837 return true;
1838 }
1839 return false;
1840}
1841
1842void UIRichTextXMLSpace::touchEvent(Ref *pSender, Widget::TouchEventType type)
1843{
1844 switch (type)
1845 {
1846 case Widget::TouchEventType::ENDED:
1847 {
1848 if (_richText->isIgnoreContentAdaptWithSize())
1849 {
1850 _richText->ignoreContentAdaptWithSize(false);
1851 _richText->setContentSize(Size(50, 100));
1852 }
1853 else
1854 {
1855 _richText->ignoreContentAdaptWithSize(true);
1856 }
1857 }
1858 break;
1859
1860 default:
1861 break;
1862 }
1863}
1864
1865void UIRichTextXMLSpace::switchWrapMode(Ref *pSender, Widget::TouchEventType type)
1866{
1867 if (type == Widget::TouchEventType::ENDED)
1868 {
1869 auto wrapMode = _richText->getWrapMode();
1870 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
1871 _richText->setWrapMode(wrapMode);
1872 }
1873}
1874
1875void UIRichTextXMLSpace::switchAlignment(Ref *sender, Widget::TouchEventType type) {
1876 if (type == Widget::TouchEventType::ENDED)
1877 {
1878 auto alignment = _richText->getHorizontalAlignment();
1879 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
1880 _richText->setHorizontalAlignment(alignment);
1881 }
1882}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
cocos2d::ui::RichText * _richText
bool init() override
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
bool init() override
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
bool init() override
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
bool init() override
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
cocos2d::ui::RichText * _richText
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
cocos2d::ui::RichText * _richText
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
bool init() override
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45