2012-04-16 18:58:43 +08:00
|
|
|
/*
|
2013-06-20 14:17:10 +08:00
|
|
|
* ControlColourPickerTest.m
|
2012-04-16 18:58:43 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Yannick Loriot
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-04-17 11:12:05 +08:00
|
|
|
#include "CCControlColourPickerTest.h"
|
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-07-12 06:24:23 +08:00
|
|
|
Size screenSize = Director::getInstance()->getWinSize();
|
2012-04-17 16:00:18 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Node *layer = Node::create();
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setPosition(Point (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));
|
2013-07-12 14:11:55 +08:00
|
|
|
colourPicker->setPosition(Point (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-06-20 14:17:10 +08:00
|
|
|
colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(ControlColourPickerTest::colourValueChanged), ControlEventValueChanged);
|
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-06-20 14:17:10 +08:00
|
|
|
Scale9Sprite *background = Scale9Sprite::create("extensions/buttonBackground.png");
|
2013-07-12 14:30:26 +08:00
|
|
|
background->setContentSize(Size(150, 50));
|
2013-07-12 14:11:55 +08:00
|
|
|
background->setPosition(Point(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
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_colorLabel = LabelTTF::create("#color", "Marker Felt", 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));
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setAnchorPoint(Point (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-06-20 14:17:10 +08:00
|
|
|
colourValueChanged(colourPicker, ControlEventValueChanged);
|
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
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ControlColourPickerTest::colourValueChanged(Object *sender, ControlEvent 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
|
|
|
|