2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "UIImageViewTest.h"
|
|
|
|
|
|
|
|
|
|
|
|
// UIImageViewTest
|
|
|
|
|
|
|
|
bool UIImageViewTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 10:42:30 +08:00
|
|
|
Text* alert = Text::create("ImageView", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-05-15 01:07:09 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2014-04-03 10:42:30 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the imageview
|
2014-04-02 16:37:09 +08:00
|
|
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-04-17 14:08:25 +08:00
|
|
|
widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
_uiLayer->addChild(imageView);
|
|
|
|
|
2014-04-03 10:42:30 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UIImageViewTest_Scale9
|
|
|
|
|
|
|
|
bool UIImageViewTest_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-03 10:42:30 +08:00
|
|
|
Text* alert = Text::create("ImageView scale9 render", "fonts/Marker Felt.ttf", 26);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-05-15 01:07:09 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
|
2014-04-03 10:42:30 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the imageview
|
2014-04-03 10:42:30 +08:00
|
|
|
ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
imageView->setScale9Enabled(true);
|
2014-06-20 14:03:33 +08:00
|
|
|
imageView->setContentSize(Size(300, 115));
|
2014-05-15 01:07:09 +08:00
|
|
|
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-04-17 14:08:25 +08:00
|
|
|
widgetSize.height / 2.0f));
|
2014-04-03 10:42:30 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(imageView);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-07-24 11:52:42 +08:00
|
|
|
|
|
|
|
// UIImageViewTest_ContentSize
|
|
|
|
|
|
|
|
bool UIImageViewTest_ContentSize::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
Text* alert = Text::create("ImageView ContentSize Change", "fonts/Marker Felt.ttf", 26);
|
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
|
|
|
|
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
Text *status = Text::create("child ImageView position percent", "fonts/Marker Felt.ttf", 16);
|
|
|
|
status->setColor(Color3B::RED);
|
|
|
|
status->setPosition(Vec2(widgetSize.width/2, widgetSize.height/2 + 80));
|
|
|
|
_uiLayer->addChild(status,20);
|
|
|
|
|
|
|
|
// Create the imageview
|
|
|
|
ImageView* imageView = ImageView::create("cocosui/buttonHighlighted.png");
|
|
|
|
imageView->setScale9Enabled(true);
|
|
|
|
imageView->setContentSize(Size(200, 80));
|
|
|
|
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f ));
|
|
|
|
|
|
|
|
|
|
|
|
ImageView* imageViewChild = ImageView::create("cocosui/buttonHighlighted.png");
|
|
|
|
imageViewChild->setScale9Enabled(true);
|
|
|
|
imageViewChild->setSizeType(Widget::SizeType::PERCENT);
|
|
|
|
imageViewChild->setPositionType(Widget::PositionType::PERCENT);
|
|
|
|
imageViewChild->setSizePercent(Vec2::ANCHOR_MIDDLE);
|
|
|
|
imageViewChild->setPositionPercent(Vec2::ANCHOR_MIDDLE);
|
|
|
|
imageViewChild->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f));
|
|
|
|
|
|
|
|
ImageView* imageViewChild2 = ImageView::create("cocosui/buttonHighlighted.png");
|
|
|
|
imageViewChild2->setScale9Enabled(true);
|
|
|
|
imageViewChild2->setSizeType(Widget::SizeType::PERCENT);
|
|
|
|
imageViewChild2->setPositionType(Widget::PositionType::PERCENT);
|
|
|
|
imageViewChild2->setSizePercent(Vec2::ANCHOR_MIDDLE);
|
|
|
|
imageViewChild2->setPositionPercent(Vec2::ANCHOR_MIDDLE);
|
|
|
|
imageViewChild->addChild(imageViewChild2);
|
|
|
|
|
|
|
|
|
|
|
|
imageView->addChild(imageViewChild);
|
|
|
|
|
|
|
|
imageView->setTouchEnabled(true);
|
|
|
|
imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
|
|
|
|
if (type == Widget::TouchEventType::ENDED) {
|
|
|
|
float width = CCRANDOM_0_1() * 200 + 50;
|
|
|
|
float height = CCRANDOM_0_1() * 80 + 30;
|
|
|
|
imageView->setContentSize(Size(width, height));
|
|
|
|
|
|
|
|
imageViewChild->setPositionPercent(Vec2(CCRANDOM_0_1(), CCRANDOM_0_1()));
|
|
|
|
status->setString(StringUtils::format("child ImageView position percent: %f, %f",
|
|
|
|
imageViewChild->getPositionPercent().x, imageViewChild->getPositionPercent().y));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_uiLayer->addChild(imageView);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|