mirror of https://github.com/axmolengine/axmol.git
Add RichText sample
This commit is contained in:
parent
03f5be47da
commit
8b7a5c3141
|
@ -1 +1 @@
|
||||||
d5bc7043083749a9bb33b41b6f902c251d4de747
|
d5aad52713bc25f053afa48235e48aae9155f328
|
|
@ -23,7 +23,8 @@ UITextAtlas.cpp \
|
||||||
UITextBMFont.cpp \
|
UITextBMFont.cpp \
|
||||||
UILoadingBar.cpp \
|
UILoadingBar.cpp \
|
||||||
UISlider.cpp \
|
UISlider.cpp \
|
||||||
UITextField.cpp
|
UITextField.cpp \
|
||||||
|
UIRichText.cpp
|
||||||
|
|
||||||
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \
|
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \
|
||||||
|
|
|
@ -17,6 +17,7 @@ set(GUI_SRC
|
||||||
UILoadingBar.cpp
|
UILoadingBar.cpp
|
||||||
UISlider.cpp
|
UISlider.cpp
|
||||||
UITextField.cpp
|
UITextField.cpp
|
||||||
|
UIRichText.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(gui STATIC
|
add_library(gui STATIC
|
||||||
|
|
|
@ -41,6 +41,7 @@ THE SOFTWARE.
|
||||||
#include "gui/UITextBMFont.h"
|
#include "gui/UITextBMFont.h"
|
||||||
#include "gui/UIPageView.h"
|
#include "gui/UIPageView.h"
|
||||||
#include "gui/UIHelper.h"
|
#include "gui/UIHelper.h"
|
||||||
|
#include "gui/UIRichText.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
|
@ -80,6 +80,7 @@ Classes/ExtensionsTest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp \
|
||||||
|
Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager_Editor.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager_Editor.cpp \
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp \
|
Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp \
|
||||||
|
|
|
@ -94,6 +94,7 @@ set(SAMPLE_SRC
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest.cpp
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest.cpp
|
||||||
|
Classes/ExtensionsTest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UIScene_Editor.cpp
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager_Editor.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager_Editor.cpp
|
||||||
Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp
|
Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp
|
||||||
|
|
|
@ -255,6 +255,18 @@ g_guisTests[] =
|
||||||
Director::getInstance()->replaceScene(pScene);
|
Director::getInstance()->replaceScene(pScene);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"gui RichTextTest",
|
||||||
|
[](Ref* sender)
|
||||||
|
{
|
||||||
|
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||||
|
pManager->setCurrentUISceneId(kUIRichTextTest);
|
||||||
|
pManager->setMinUISceneId(kUIRichTextTest);
|
||||||
|
pManager->setMaxUISceneId(kUIRichTextTest);
|
||||||
|
Scene* pScene = pManager->currentUIScene();
|
||||||
|
Director::getInstance()->replaceScene(pScene);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
|
||||||
|
|
||||||
|
#include "UIRichTextTest.h"
|
||||||
|
#include "cocostudio/CCArmatureDataManager.h"
|
||||||
|
#include "cocostudio/CCArmature.h"
|
||||||
|
|
||||||
|
UIRichTextTest::UIRichTextTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UIRichTextTest::~UIRichTextTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UIRichTextTest::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getSize();
|
||||||
|
|
||||||
|
// Add the alert
|
||||||
|
Text *alert = Text::create();
|
||||||
|
alert->setText("RichText");
|
||||||
|
alert->setFontName("Marker Felt");
|
||||||
|
alert->setFontSize(30);
|
||||||
|
alert->setColor(Color3B(159, 168, 176));
|
||||||
|
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.125));
|
||||||
|
_widget->addChild(alert);
|
||||||
|
|
||||||
|
|
||||||
|
Button* button = Button::create();
|
||||||
|
button->setTouchEnabled(true);
|
||||||
|
button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
|
||||||
|
button->setTitleText("switch");
|
||||||
|
button->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + button->getSize().height * 2.5));
|
||||||
|
button->addTouchEventListener(this, toucheventselector(UIRichTextTest::touchEvent));
|
||||||
|
button->setZOrder(10);
|
||||||
|
_widget->addChild(button);
|
||||||
|
|
||||||
|
|
||||||
|
// RichText
|
||||||
|
_richText = RichText::create();
|
||||||
|
_richText->ignoreContentAdaptWithSize(false);
|
||||||
|
_richText->setSize(Size(100, 100));
|
||||||
|
|
||||||
|
RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, "This color is white. ", "Helvetica", 10);
|
||||||
|
RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
|
||||||
|
RichElementText* re3 = RichElementText::create(3, Color3B::BLUE, 255, "This one is blue. ", "Helvetica", 10);
|
||||||
|
RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green. ", "Helvetica", 10);
|
||||||
|
RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10);
|
||||||
|
|
||||||
|
RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosgui/sliderballnormal.png");
|
||||||
|
|
||||||
|
cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosgui/100/100.ExportJson");
|
||||||
|
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);
|
||||||
|
|
||||||
|
_richText->setPosition(Point(widgetSize.width / 2, widgetSize.height / 2));
|
||||||
|
_richText->setZOrder(10);
|
||||||
|
|
||||||
|
|
||||||
|
_widget->addChild(_richText);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIRichTextTest::touchEvent(Ref *pSender, TouchEventType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case TOUCH_EVENT_ENDED:
|
||||||
|
{
|
||||||
|
if (_richText->isIgnoreContentAdaptWithSize())
|
||||||
|
{
|
||||||
|
_richText->ignoreContentAdaptWithSize(false);
|
||||||
|
_richText->setSize(Size(100, 100));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_richText->ignoreContentAdaptWithSize(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __TestCpp__UIRichTextTest__
|
||||||
|
#define __TestCpp__UIRichTextTest__
|
||||||
|
|
||||||
|
#include "../UIScene.h"
|
||||||
|
|
||||||
|
class UIRichTextTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIRichTextTest();
|
||||||
|
~UIRichTextTest();
|
||||||
|
bool init();
|
||||||
|
void touchEvent(Ref *pSender, TouchEventType type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIRichTextTest)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
RichText* _richText;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* defined(__TestCpp__UIRichTextTest__) */
|
|
@ -16,6 +16,7 @@
|
||||||
#include "UIPageViewTest/UIPageViewTest.h"
|
#include "UIPageViewTest/UIPageViewTest.h"
|
||||||
#include "UIListViewTest/UIListViewTest.h"
|
#include "UIListViewTest/UIListViewTest.h"
|
||||||
#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h"
|
#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h"
|
||||||
|
#include "UIRichTextTest/UIRichTextTest.h"
|
||||||
/*
|
/*
|
||||||
#include "UISwitchTest/UISwitchTest.h"
|
#include "UISwitchTest/UISwitchTest.h"
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +108,7 @@ static const char* s_testArray[] =
|
||||||
"UIPickerViewTest_Horizontal",
|
"UIPickerViewTest_Horizontal",
|
||||||
*/
|
*/
|
||||||
"UIWidgetAddNodeTest",
|
"UIWidgetAddNodeTest",
|
||||||
|
"UIRichTextTest",
|
||||||
};
|
};
|
||||||
|
|
||||||
static UISceneManager *sharedInstance = NULL;
|
static UISceneManager *sharedInstance = NULL;
|
||||||
|
@ -354,6 +356,9 @@ Scene *UISceneManager::currentUIScene()
|
||||||
|
|
||||||
case kUIWidgetAddNodeTest:
|
case kUIWidgetAddNodeTest:
|
||||||
return UIWidgetAddNodeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIWidgetAddNodeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
case kUIRichTextTest:
|
||||||
|
return UIRichTextTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
|
@ -100,6 +100,7 @@ enum
|
||||||
kUIPickerViewTest_Horizontal,
|
kUIPickerViewTest_Horizontal,
|
||||||
*/
|
*/
|
||||||
kUIWidgetAddNodeTest,
|
kUIWidgetAddNodeTest,
|
||||||
|
kUIRichTextTest,
|
||||||
kUITestMax
|
kUITestMax
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue