2012-04-17 11:12:05 +08:00
|
|
|
#include "CCControlColourPickerTest.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
2012-07-19 17:22:36 +08:00
|
|
|
USING_NS_CC_EXT;
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlColourPickerTest::ControlColourPickerTest()
|
2012-04-17 11:12:05 +08:00
|
|
|
{
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool ControlColourPickerTest::init()
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
if (ControlScene::init())
|
2012-04-17 16:00:18 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto screenSize = Director::getInstance()->getWinSize();
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = Node::create();
|
2014-08-28 13:59:56 +08:00
|
|
|
layer->setPosition(screenSize.width / 2, screenSize.height / 2);
|
2012-04-17 16:00:18 +08:00
|
|
|
addChild(layer, 1);
|
|
|
|
|
|
|
|
double layer_width = 0;
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Create the colour picker
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlColourPicker *colourPicker = ControlColourPicker::create();
|
2013-07-05 16:49:22 +08:00
|
|
|
colourPicker->setColor(Color3B(37, 46, 252));
|
2014-08-28 11:41:18 +08:00
|
|
|
colourPicker->setPosition(colourPicker->getContentSize().width / 2, 0);
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Add it to the layer
|
|
|
|
layer->addChild(colourPicker);
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Add the target-action pair
|
2013-07-26 14:37:26 +08:00
|
|
|
colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlColourPickerTest::colourValueChanged), Control::EventType::VALUE_CHANGED);
|
2012-04-17 11:12:05 +08:00
|
|
|
|
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
layer_width += colourPicker->getContentSize().width;
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Add the black background for the text
|
2013-08-16 16:05:27 +08:00
|
|
|
auto background = Scale9Sprite::create("extensions/buttonBackground.png");
|
2013-07-12 14:30:26 +08:00
|
|
|
background->setContentSize(Size(150, 50));
|
2014-08-28 11:41:18 +08:00
|
|
|
background->setPosition(layer_width + background->getContentSize().width / 2.0f, 0);
|
2012-04-17 16:00:18 +08:00
|
|
|
layer->addChild(background);
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
layer_width += background->getContentSize().width;
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
_colorLabel = Label::createWithTTF("#color", "fonts/Marker Felt.ttf", 30);
|
2013-06-15 14:03:30 +08:00
|
|
|
_colorLabel->retain();
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_colorLabel->setPosition(background->getPosition());
|
|
|
|
layer->addChild(_colorLabel);
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Set the layer size
|
2013-07-12 14:30:26 +08:00
|
|
|
layer->setContentSize(Size(layer_width, 0));
|
2014-05-15 01:07:09 +08:00
|
|
|
layer->setAnchorPoint(Vec2 (0.5f, 0.5f));
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Update the color text
|
2013-07-26 14:37:26 +08:00
|
|
|
colourValueChanged(colourPicker, Control::EventType::VALUE_CHANGED);
|
2012-04-17 16:00:18 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-16 18:58:43 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlColourPickerTest::~ControlColourPickerTest()
|
2012-04-16 18:58:43 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_colorLabel);
|
2012-04-16 18:58:43 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ControlColourPickerTest::colourValueChanged(Ref *sender, Control::EventType controlEvent)
|
2012-04-16 18:58:43 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlColourPicker* pPicker = (ControlColourPicker*)sender;
|
|
|
|
_colorLabel->setString(String::createWithFormat("#%02X%02X%02X",pPicker->getColor().r, pPicker->getColor().g, pPicker->getColor().b)->getCString());
|
2012-04-16 18:58:43 +08:00
|
|
|
}
|
|
|
|
|
2012-04-17 11:12:05 +08:00
|
|
|
|