2014-03-06 20:52:29 +08:00
# include "UIRichTextTest.h"
# include "cocostudio/CCArmatureDataManager.h"
# include "cocostudio/CCArmature.h"
2015-04-09 12:23:47 +08:00
USING_NS_CC ;
using namespace cocos2d : : ui ;
2015-04-03 14:31:03 +08:00
UIRichTextTests : : UIRichTextTests ( )
{
ADD_TEST_CASE ( UIRichTextTest ) ;
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 ) ;
ADD_TEST_CASE ( UIRichTextXMLFace ) ;
ADD_TEST_CASE ( UIRichTextXMLBR ) ;
2016-01-20 13:16:53 +08:00
ADD_TEST_CASE ( UIRichTextXMLInvalid ) ;
2015-04-03 14:31:03 +08:00
}
2014-03-06 20:52:29 +08:00
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
2014-08-01 21:20:27 +08:00
auto config = Configuration : : getInstance ( ) ;
config - > loadConfigFile ( " configs/config-test-ok.plist " ) ;
std : : string str1 = config - > getValue ( " Chinese " ) . asString ( ) ;
std : : string str2 = config - > getValue ( " Japanese " ) . asString ( ) ;
2014-07-28 17:24:37 +08:00
CCLOG ( " str1:%s ascii length = %ld, utf8 length = %ld, substr = %s " ,
str1 . c_str ( ) ,
str1 . length ( ) ,
StringUtils : : getCharacterCountInUTF8String ( str1 ) ,
2014-07-30 10:45:35 +08:00
Helper : : getSubStringOfUTF8String ( str1 , 0 , 5 ) . c_str ( ) ) ;
2014-07-28 17:24:37 +08:00
CCLOG ( " str2:%s ascii length = %ld, utf8 length = %ld, substr = %s " ,
str2 . c_str ( ) ,
str2 . length ( ) ,
StringUtils : : getCharacterCountInUTF8String ( str2 ) ,
2014-07-30 10:45:35 +08:00
Helper : : getSubStringOfUTF8String ( str2 , 0 , 2 ) . c_str ( ) ) ;
2014-07-28 17:24:37 +08:00
2014-03-06 20:52:29 +08:00
// Add the alert
2014-04-03 15:22:23 +08:00
Text * alert = Text : : create ( " RichText " , " fonts/Marker Felt.ttf " , 30 ) ;
2014-03-06 20:52:29 +08:00
alert - > setColor ( Color3B ( 159 , 168 , 176 ) ) ;
2014-06-20 11:18:53 +08:00
alert - > setPosition ( Vec2 ( widgetSize . width / 2.0f , widgetSize . height / 2.0f - alert - > getContentSize ( ) . height * 3.125 ) ) ;
2014-03-06 20:52:29 +08:00
_widget - > addChild ( alert ) ;
2014-04-03 15:22:23 +08:00
Button * button = Button : : create ( " cocosui/animationbuttonnormal.png " , " cocosui/animationbuttonpressed.png " ) ;
2014-03-06 20:52:29 +08:00
button - > setTouchEnabled ( true ) ;
button - > setTitleText ( " switch " ) ;
2014-06-20 11:18:53 +08:00
button - > setPosition ( Vec2 ( widgetSize . width / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
2014-05-09 14:30:39 +08:00
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextTest : : touchEvent , this ) ) ;
2014-03-24 10:12:40 +08:00
button - > setLocalZOrder ( 10 ) ;
2014-03-06 20:52:29 +08:00
_widget - > addChild ( button ) ;
// RichText
_richText = RichText : : create ( ) ;
_richText - > ignoreContentAdaptWithSize ( false ) ;
2014-06-20 14:03:33 +08:00
_richText - > setContentSize ( Size ( 100 , 100 ) ) ;
2014-03-06 20:52:29 +08:00
2015-06-20 17:07:11 +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 ) ;
2015-06-20 17:07:11 +08:00
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 ) ;
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 ;
}
2014-05-09 14:30:39 +08:00
void UIRichTextTest : : touchEvent ( Ref * pSender , Widget : : TouchEventType type )
2014-03-06 20:52:29 +08:00
{
switch ( type )
{
2014-05-09 14:30:39 +08:00
case Widget : : TouchEventType : : ENDED :
2014-03-06 20:52:29 +08:00
{
if ( _richText - > isIgnoreContentAdaptWithSize ( ) )
{
_richText - > ignoreContentAdaptWithSize ( false ) ;
2014-06-20 14:03:33 +08:00
_richText - > setContentSize ( Size ( 100 , 100 ) ) ;
2014-03-06 20:52:29 +08:00
}
else
{
_richText - > ignoreContentAdaptWithSize ( true ) ;
}
}
break ;
default :
break ;
}
2014-03-11 17:13:54 +08:00
}
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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLBasic : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLSmallBig : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLColor : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// RichText
_richText = RichText : : createWithXML ( " Defaul color.<font color='#ff0000'>red.<font color='#00ff00'>green</font>red again.</font>default 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 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLSUIB : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLSUIB2 : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLSUIB3 : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLImg : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLUrl : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// RichText
_richText = RichText : : createWithXML ( " And this link will redirect you to google: <a href='http://www.google.com'>click me</a> " ) ;
_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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLFace : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ( 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 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 ;
}
}
//
// 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 / 2.0f , widgetSize . height / 2.0f + button - > getContentSize ( ) . height * 2.5 ) ) ;
button - > addTouchEventListener ( CC_CALLBACK_2 ( UIRichTextXMLBR : : touchEvent , this ) ) ;
button - > setLocalZOrder ( 10 ) ;
_widget - > addChild ( button ) ;
// 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 ;
}
}
2016-01-20 13:16:53 +08:00
//
// 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 ;
}