2012-04-16 18:58:43 +08:00
|
|
|
/*
|
|
|
|
* CCControlColourPickerTest.m
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2012-04-17 11:12:05 +08:00
|
|
|
CCControlColourPickerTest::CCControlColourPickerTest()
|
|
|
|
{
|
2012-04-16 18:58:43 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCControlColourPickerTest::init()
|
|
|
|
{
|
|
|
|
if (CCControlScene::init())
|
|
|
|
{
|
|
|
|
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCNode *layer = CCNode::create();
|
2012-04-17 16:00:18 +08:00
|
|
|
layer->setPosition(ccp (screenSize.width / 2, screenSize.height / 2));
|
|
|
|
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
|
2012-06-14 15:13:16 +08:00
|
|
|
CCControlColourPicker *colourPicker = CCControlColourPicker::create();
|
2012-04-17 16:00:18 +08:00
|
|
|
colourPicker->setColor(ccc3(37, 46, 252));
|
|
|
|
colourPicker->setPosition(ccp (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
|
2012-06-12 05:57:30 +08:00
|
|
|
colourPicker->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlColourPickerTest::colourValueChanged), CCControlEventValueChanged);
|
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
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png");
|
2012-04-17 16:00:18 +08:00
|
|
|
background->setContentSize(CCSizeMake(150, 50));
|
|
|
|
background->setPosition(ccp(layer_width + background->getContentSize().width / 2.0f, 0));
|
|
|
|
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
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
m_pColorLabel = CCLabelTTF::create("#color", "Marker Felt", 30);
|
2012-04-17 16:00:18 +08:00
|
|
|
m_pColorLabel->retain();
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
m_pColorLabel->setPosition(background->getPosition());
|
|
|
|
layer->addChild(m_pColorLabel);
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Set the layer size
|
|
|
|
layer->setContentSize(CCSizeMake(layer_width, 0));
|
|
|
|
layer->setAnchorPoint(ccp (0.5f, 0.5f));
|
2012-04-17 11:12:05 +08:00
|
|
|
|
2012-04-17 16:00:18 +08:00
|
|
|
// Update the color text
|
2012-06-14 18:32:44 +08:00
|
|
|
colourValueChanged(colourPicker, CCControlEventValueChanged);
|
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
|
|
|
}
|
|
|
|
|
2012-04-17 11:12:05 +08:00
|
|
|
CCControlColourPickerTest::~CCControlColourPickerTest()
|
2012-04-16 18:58:43 +08:00
|
|
|
{
|
2012-04-17 11:12:05 +08:00
|
|
|
CC_SAFE_RELEASE(m_pColorLabel);
|
2012-04-16 18:58:43 +08:00
|
|
|
}
|
|
|
|
|
2012-06-14 18:32:44 +08:00
|
|
|
void CCControlColourPickerTest::colourValueChanged(CCObject *sender, CCControlEvent controlEvent)
|
2012-04-16 18:58:43 +08:00
|
|
|
{
|
2012-04-17 11:12:05 +08:00
|
|
|
CCControlColourPicker* pPicker = (CCControlColourPicker*)sender;
|
2012-06-14 16:05:58 +08:00
|
|
|
m_pColorLabel->setString(CCString::createWithFormat("#%02X%02X%02X",pPicker->getColorValue().r, pPicker->getColorValue().g, pPicker->getColorValue().b)->getCString());
|
2012-04-16 18:58:43 +08:00
|
|
|
}
|
|
|
|
|
2012-04-17 11:12:05 +08:00
|
|
|
|