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

332 lines
15 KiB
C++
Raw Normal View History

2013-09-16 20:54:13 +08:00
#include "UIScrollViewTest.h"
// UIScrollViewTest_Vertical
UIScrollViewTest_Vertical::UIScrollViewTest_Vertical()
2013-12-23 15:35:35 +08:00
: _displayValueLabel(nullptr)
2013-09-16 20:54:13 +08:00
{
}
UIScrollViewTest_Vertical::~UIScrollViewTest_Vertical()
{
}
bool UIScrollViewTest_Vertical::init()
{
if (UIScene::init())
{
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
2013-09-16 20:54:13 +08:00
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = Text::create("Move by vertical direction", "fonts/Marker Felt.ttf", 32);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
2013-09-16 20:54:13 +08:00
// Add the alert
Text* alert = Text::create("ScrollView vertical", "fonts/Marker Felt.ttf", 30);
2013-09-16 20:54:13 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2013-09-16 20:54:13 +08:00
// Create the scrollview by vertical
ui::ScrollView* scrollView = ui::ScrollView::create();
2013-12-23 15:35:35 +08:00
scrollView->setSize(Size(280.0f, 150.0f));
2013-09-16 20:54:13 +08:00
Size backgroundSize = background->getContentSize();
scrollView->setPosition(Vector2((widgetSize.width - backgroundSize.width) / 2.0f +
2013-12-23 15:35:35 +08:00
(backgroundSize.width - scrollView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
_uiLayer->addChild(scrollView);
2013-09-16 20:54:13 +08:00
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
2013-09-16 20:54:13 +08:00
float innerWidth = scrollView->getSize().width;
float innerHeight = scrollView->getSize().height + imageView->getSize().height;
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Vector2(innerWidth / 2.0f, scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f));
2013-09-16 20:54:13 +08:00
scrollView->addChild(button);
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
titleButton->setPosition(Vector2(innerWidth / 2.0f, button->getBottomInParent() - button->getSize().height));
2013-12-23 15:35:35 +08:00
scrollView->addChild(titleButton);
2013-09-16 20:54:13 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-09-16 20:54:13 +08:00
button_scale9->setScale9Enabled(true);
2014-04-17 14:08:25 +08:00
button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vector2(innerWidth / 2.0f, titleButton->getBottomInParent() - titleButton->getSize().height));
2013-09-16 20:54:13 +08:00
scrollView->addChild(button_scale9);
imageView->setPosition(Vector2(innerWidth / 2.0f, imageView->getSize().height / 2.0f));
2013-12-23 15:35:35 +08:00
scrollView->addChild(imageView);
2013-09-16 20:54:13 +08:00
return true;
}
return false;
}
// UIScrollViewTest_Horizontal
UIScrollViewTest_Horizontal::UIScrollViewTest_Horizontal()
2013-12-23 15:35:35 +08:00
: _displayValueLabel(nullptr)
2013-09-16 20:54:13 +08:00
{
}
UIScrollViewTest_Horizontal::~UIScrollViewTest_Horizontal()
{
}
bool UIScrollViewTest_Horizontal::init()
{
if (UIScene::init())
{
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
2013-09-16 20:54:13 +08:00
// Add a label in which the scrollview alert will be displayed
_displayValueLabel = Text::create("Move by horizontal direction","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
Text* alert = Text::create("ScrollView horizontal","fonts/Marker Felt.ttf",30);
2013-09-16 20:54:13 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
2013-12-23 15:35:35 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
2013-09-16 20:54:13 +08:00
// Create the scrollview by horizontal
ui::ScrollView* scrollView = ui::ScrollView::create();
2013-11-06 16:04:06 +08:00
scrollView->setBounceEnabled(true);
2013-09-16 20:54:13 +08:00
scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
2013-12-23 15:35:35 +08:00
scrollView->setSize(Size(280.0f, 150.0f));
2013-09-16 20:54:13 +08:00
scrollView->setInnerContainerSize(scrollView->getSize());
Size backgroundSize = background->getContentSize();
scrollView->setPosition(Vector2((widgetSize.width - backgroundSize.width) / 2.0f +
2013-12-23 15:35:35 +08:00
(backgroundSize.width - scrollView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
_uiLayer->addChild(scrollView);
2013-09-16 20:54:13 +08:00
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
2013-09-16 20:54:13 +08:00
float innerWidth = scrollView->getSize().width + imageView->getSize().width;
float innerHeight = scrollView->getSize().height;
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
button->setPosition(Vector2(button->getSize().width / 2.0f,
2013-12-23 15:35:35 +08:00
scrollView->getInnerContainerSize().height - button->getSize().height / 2.0f));
2013-09-16 20:54:13 +08:00
scrollView->addChild(button);
Button* titleButton = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
2013-12-23 15:35:35 +08:00
titleButton->setTitleText("Title Button");
titleButton->setPosition(Vector2(button->getRightInParent() + button->getSize().width / 2.0f,
2013-12-23 15:35:35 +08:00
button->getBottomInParent() - button->getSize().height / 2.0f));
scrollView->addChild(titleButton);
2013-09-16 20:54:13 +08:00
Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
2013-09-16 20:54:13 +08:00
button_scale9->setScale9Enabled(true);
2014-04-17 14:08:25 +08:00
button_scale9->setSize(Size(100.0f, button_scale9->getVirtualRendererSize().height));
button_scale9->setPosition(Vector2(titleButton->getRightInParent() + titleButton->getSize().width / 2.0f,
2013-12-23 15:35:35 +08:00
titleButton->getBottomInParent() - titleButton->getSize().height / 2.0f));
2013-09-16 20:54:13 +08:00
scrollView->addChild(button_scale9);
imageView->setPosition(Vector2(innerWidth - imageView->getSize().width / 2.0f,
2013-12-23 15:35:35 +08:00
button_scale9->getBottomInParent() - button_scale9->getSize().height / 2.0f));
2013-09-16 20:54:13 +08:00
scrollView->addChild(imageView);
return true;
}
return false;
2013-12-23 15:35:35 +08:00
}
// UIScrollViewTest_Both
UIScrollViewTest_Both::UIScrollViewTest_Both()
: _displayValueLabel(nullptr)
{
}
UIScrollViewTest_Both::~UIScrollViewTest_Both()
{
}
bool UIScrollViewTest_Both::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();;
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create("Move by any direction","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("ScrollView both","fonts/Marker Felt.ttf",30);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
// Create the dragpanel
ui::ScrollView* scrollView = ui::ScrollView::create();
2013-12-23 15:35:35 +08:00
scrollView->setDirection(SCROLLVIEW_DIR_BOTH);
scrollView->setTouchEnabled(true);
scrollView->setBounceEnabled(true);
scrollView->setBackGroundImageScale9Enabled(true);
2014-03-11 17:13:54 +08:00
scrollView->setBackGroundImage("cocosui/green_edit.png");
2013-12-23 15:35:35 +08:00
scrollView->setSize(Size(210, 122.5));
Size backgroundSize = background->getContentSize();
scrollView->setPosition(Vector2((widgetSize.width - backgroundSize.width) / 2.0f +
2013-12-23 15:35:35 +08:00
(backgroundSize.width - scrollView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - scrollView->getSize().height) / 2.0f));
ImageView* imageView = ImageView::create("Hello.png");
2013-12-23 15:35:35 +08:00
scrollView->addChild(imageView);
scrollView->setInnerContainerSize(imageView->getContentSize());
Size innerSize = scrollView->getInnerContainerSize();
imageView->setPosition(Vector2(innerSize.width / 2.0f, innerSize.height / 2.0f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(scrollView);
return true;
}
return false;
}
// UIScrollViewTest_ScrollToPercentBothDirection
UIScrollViewTest_ScrollToPercentBothDirection::UIScrollViewTest_ScrollToPercentBothDirection()
: _displayValueLabel(nullptr)
{
}
UIScrollViewTest_ScrollToPercentBothDirection::~UIScrollViewTest_ScrollToPercentBothDirection()
{
}
bool UIScrollViewTest_ScrollToPercentBothDirection::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf",30);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("ScrollView scroll to percent both directrion","fonts/Marker Felt.ttf",20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
ui::ScrollView* sc = ui::ScrollView::create();
2013-12-23 15:35:35 +08:00
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
2013-12-23 15:35:35 +08:00
sc->setDirection(SCROLLVIEW_DIR_BOTH);
sc->setInnerContainerSize(Size(480, 320));
sc->setSize(Size(100,100));
Size backgroundSize = background->getContentSize();
sc->setPosition(Vector2((widgetSize.width - backgroundSize.width) / 2.0f +
2013-12-23 15:35:35 +08:00
(backgroundSize.width - sc->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - sc->getSize().height) / 2.0f));
sc->scrollToPercentBothDirection(Vector2(50, 50), 1, true);
ImageView* iv = ImageView::create("cocosui/Hello.png");
iv->setPosition(Vector2(240, 160));
2013-12-23 15:35:35 +08:00
sc->addChild(iv);
_uiLayer->addChild(sc);
return true;
}
return false;
}
// UIScrollViewTest_ScrollToPercentBothDirection_Bounce
UIScrollViewTest_ScrollToPercentBothDirection_Bounce::UIScrollViewTest_ScrollToPercentBothDirection_Bounce()
: _displayValueLabel(nullptr)
{
}
UIScrollViewTest_ScrollToPercentBothDirection_Bounce::~UIScrollViewTest_ScrollToPercentBothDirection_Bounce()
{
}
bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
// Add a label in which the dragpanel events will be displayed
_displayValueLabel = Text::create("No Event","fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vector2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getSize().height * 1.5f));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("ScrollView scroll to percent both directrion bounce","fonts/Marker Felt.ttf",20);
2013-12-23 15:35:35 +08:00
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vector2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
2013-12-23 15:35:35 +08:00
_uiLayer->addChild(alert);
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
ui::ScrollView* sc = ui::ScrollView::create();
2013-12-23 15:35:35 +08:00
sc->setBackGroundColor(Color3B::GREEN);
sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
2013-12-23 15:35:35 +08:00
sc->setBounceEnabled(true);
sc->setDirection(SCROLLVIEW_DIR_BOTH);
sc->setInnerContainerSize(Size(480, 320));
sc->setSize(Size(100,100));
Size backgroundSize = background->getContentSize();
sc->setPosition(Vector2((widgetSize.width - backgroundSize.width) / 2.0f +
2013-12-23 15:35:35 +08:00
(backgroundSize.width - sc->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - sc->getSize().height) / 2.0f));
sc->scrollToPercentBothDirection(Vector2(50, 50), 1, true);
ImageView* iv = ImageView::create("cocosui/Hello.png");
iv->setPosition(Vector2(240, 160));
2013-12-23 15:35:35 +08:00
sc->addChild(iv);
_uiLayer->addChild(sc);
return true;
}
return false;
}