2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "ui/UICheckBox.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
static const int BACKGROUNDBOX_RENDERER_Z = (-1);
|
|
|
|
static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1);
|
|
|
|
static const int FRONTCROSS_RENDERER_Z = (-1);
|
|
|
|
static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1);
|
|
|
|
static const int FRONTCROSSDISABLED_RENDERER_Z = (-1);
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_GUI_INFO(CheckBox)
|
|
|
|
|
|
|
|
CheckBox::CheckBox():
|
|
|
|
_backGroundBoxRenderer(nullptr),
|
|
|
|
_backGroundSelectedBoxRenderer(nullptr),
|
|
|
|
_frontCrossRenderer(nullptr),
|
|
|
|
_backGroundBoxDisabledRenderer(nullptr),
|
|
|
|
_frontCrossDisabledRenderer(nullptr),
|
|
|
|
_isSelected(true),
|
|
|
|
_checkBoxEventListener(nullptr),
|
|
|
|
_checkBoxEventSelector(nullptr),
|
2014-05-09 14:56:05 +08:00
|
|
|
_backGroundTexType(TextureResType::LOCAL),
|
|
|
|
_backGroundSelectedTexType(TextureResType::LOCAL),
|
|
|
|
_frontCrossTexType(TextureResType::LOCAL),
|
|
|
|
_backGroundDisabledTexType(TextureResType::LOCAL),
|
|
|
|
_frontCrossDisabledTexType(TextureResType::LOCAL),
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundFileName(""),
|
|
|
|
_backGroundSelectedFileName(""),
|
|
|
|
_frontCrossFileName(""),
|
|
|
|
_backGroundDisabledFileName(""),
|
2014-04-17 14:08:25 +08:00
|
|
|
_frontCrossDisabledFileName(""),
|
|
|
|
_backGroundBoxRendererAdaptDirty(true),
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty(true),
|
|
|
|
_frontCrossRendererAdaptDirty(true),
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty(true),
|
|
|
|
_frontCrossDisabledRendererAdaptDirty(true)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBox::~CheckBox()
|
|
|
|
{
|
|
|
|
_checkBoxEventSelector = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBox* CheckBox::create()
|
|
|
|
{
|
|
|
|
CheckBox* widget = new CheckBox();
|
|
|
|
if (widget && widget->init())
|
|
|
|
{
|
|
|
|
widget->autorelease();
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(widget);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-02 15:58:18 +08:00
|
|
|
|
|
|
|
CheckBox* CheckBox::create(const std::string& backGround,
|
|
|
|
const std::string& backGroundSeleted,
|
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
|
|
|
TextureResType texType)
|
|
|
|
{
|
|
|
|
CheckBox *pWidget = new CheckBox;
|
|
|
|
if (pWidget && pWidget->init(backGround,
|
|
|
|
backGroundSeleted,
|
|
|
|
cross,
|
|
|
|
backGroundDisabled,
|
|
|
|
frontCrossDisabled,
|
|
|
|
texType))
|
|
|
|
{
|
|
|
|
pWidget->autorelease();
|
|
|
|
return pWidget;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pWidget);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckBox::init(const std::string& backGround,
|
|
|
|
const std::string& backGroundSeleted,
|
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
|
|
|
TextureResType texType)
|
|
|
|
{
|
2014-04-04 18:26:53 +08:00
|
|
|
bool ret = true;
|
2014-04-02 15:58:18 +08:00
|
|
|
do {
|
|
|
|
if (!Widget::init()) {
|
2014-04-04 18:26:53 +08:00
|
|
|
ret = false;
|
2014-04-02 15:58:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelectedState(false);
|
|
|
|
loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType);
|
|
|
|
} while (0);
|
2014-04-04 18:26:53 +08:00
|
|
|
return ret;
|
2014-04-02 15:58:18 +08:00
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
bool CheckBox::init()
|
|
|
|
{
|
|
|
|
if (Widget::init())
|
|
|
|
{
|
|
|
|
setSelectedState(false);
|
|
|
|
setTouchEnabled(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::initRenderer()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer = Sprite::create();
|
|
|
|
_backGroundSelectedBoxRenderer = Sprite::create();
|
|
|
|
_frontCrossRenderer = Sprite::create();
|
|
|
|
_backGroundBoxDisabledRenderer = Sprite::create();
|
|
|
|
_frontCrossDisabledRenderer = Sprite::create();
|
|
|
|
|
2014-03-24 15:25:44 +08:00
|
|
|
addProtectedChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1);
|
|
|
|
addProtectedChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1);
|
|
|
|
addProtectedChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1);
|
|
|
|
addProtectedChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1);
|
|
|
|
addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextures(const std::string& backGround,
|
|
|
|
const std::string& backGroundSelected,
|
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
|
|
|
TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
loadTextureBackGround(backGround,texType);
|
|
|
|
loadTextureBackGroundSelected(backGroundSelected,texType);
|
|
|
|
loadTextureFrontCross(cross,texType);
|
|
|
|
loadTextureBackGroundDisabled(backGroundDisabled,texType);
|
|
|
|
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
|
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-04-02 15:58:18 +08:00
|
|
|
if (backGround.empty())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_backGroundFileName = backGround;
|
|
|
|
_backGroundTexType = texType;
|
|
|
|
switch (_backGroundTexType)
|
|
|
|
{
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::LOCAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundBoxRenderer->setTexture(backGround);
|
|
|
|
break;
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::PLIST:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundBoxRenderer->setSpriteFrame(backGround);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateFlippedX();
|
|
|
|
updateFlippedY();
|
|
|
|
updateRGBAToRenderer(_backGroundBoxRenderer);
|
2014-04-17 14:08:25 +08:00
|
|
|
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
|
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-04-02 15:58:18 +08:00
|
|
|
if (backGroundSelected.empty())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_backGroundSelectedFileName = backGroundSelected;
|
|
|
|
_backGroundSelectedTexType = texType;
|
|
|
|
switch (_backGroundSelectedTexType)
|
|
|
|
{
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::LOCAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundSelectedBoxRenderer->setTexture(backGroundSelected);
|
|
|
|
break;
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::PLIST:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateFlippedX();
|
|
|
|
updateFlippedY();
|
|
|
|
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
|
2014-04-17 14:08:25 +08:00
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-04-02 15:58:18 +08:00
|
|
|
if (cross.empty())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_frontCrossFileName = cross;
|
|
|
|
_frontCrossTexType = texType;
|
|
|
|
switch (_frontCrossTexType)
|
|
|
|
{
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::LOCAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
_frontCrossRenderer->setTexture(cross);
|
|
|
|
break;
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::PLIST:
|
2014-03-11 17:13:54 +08:00
|
|
|
_frontCrossRenderer->setSpriteFrame(cross);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateFlippedX();
|
|
|
|
updateFlippedY();
|
|
|
|
updateRGBAToRenderer(_frontCrossRenderer);
|
2014-04-17 14:08:25 +08:00
|
|
|
_frontCrossRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-04-02 15:58:18 +08:00
|
|
|
if (backGroundDisabled.empty())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_backGroundDisabledFileName = backGroundDisabled;
|
|
|
|
_backGroundDisabledTexType = texType;
|
|
|
|
switch (_backGroundDisabledTexType)
|
|
|
|
{
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::LOCAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundBoxDisabledRenderer->setTexture(backGroundDisabled);
|
|
|
|
break;
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::PLIST:
|
2014-03-11 17:13:54 +08:00
|
|
|
_backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateFlippedX();
|
|
|
|
updateFlippedY();
|
|
|
|
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
|
2014-04-17 14:08:25 +08:00
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-04-02 15:58:18 +08:00
|
|
|
if (frontCrossDisabled.empty())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_frontCrossDisabledFileName = frontCrossDisabled;
|
|
|
|
_frontCrossDisabledTexType = texType;
|
|
|
|
switch (_frontCrossDisabledTexType)
|
|
|
|
{
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::LOCAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
_frontCrossDisabledRenderer->setTexture(frontCrossDisabled);
|
|
|
|
break;
|
2014-05-09 14:56:05 +08:00
|
|
|
case TextureResType::PLIST:
|
2014-03-11 17:13:54 +08:00
|
|
|
_frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateFlippedX();
|
|
|
|
updateFlippedY();
|
|
|
|
updateRGBAToRenderer(_frontCrossDisabledRenderer);
|
2014-04-17 14:08:25 +08:00
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent)
|
|
|
|
{
|
|
|
|
_touchEndPos = touch->getLocation();
|
2014-05-04 10:19:11 +08:00
|
|
|
if (_highlight)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
releaseUpEvent();
|
|
|
|
if (_isSelected){
|
|
|
|
setSelectedState(false);
|
|
|
|
unSelectedEvent();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setSelectedState(true);
|
|
|
|
selectedEvent();
|
|
|
|
}
|
|
|
|
}
|
2014-05-06 12:04:52 +08:00
|
|
|
setHighlighted(false);
|
2014-03-11 17:13:54 +08:00
|
|
|
Widget* widgetParent = getWidgetParent();
|
|
|
|
if (widgetParent)
|
|
|
|
{
|
|
|
|
widgetParent->checkChildInfo(2,this,_touchEndPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::onPressStateChangedToNormal()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(true);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::onPressStateChangedToPressed()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(true);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::onPressStateChangedToDisabled()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(true);
|
|
|
|
_frontCrossRenderer->setVisible(false);
|
|
|
|
if (_isSelected)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::setSelectedState(bool selected)
|
|
|
|
{
|
|
|
|
if (selected == _isSelected)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_isSelected = selected;
|
|
|
|
_frontCrossRenderer->setVisible(_isSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckBox::getSelectedState()
|
|
|
|
{
|
|
|
|
return _isSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::selectedEvent()
|
|
|
|
{
|
2014-05-09 16:04:55 +08:00
|
|
|
if (_checkBoxEventCallback)
|
|
|
|
{
|
|
|
|
_checkBoxEventCallback(this, EventType::SELECTED);
|
|
|
|
}
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
if (_checkBoxEventListener && _checkBoxEventSelector)
|
|
|
|
{
|
|
|
|
(_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_SELECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::unSelectedEvent()
|
|
|
|
{
|
2014-05-09 16:04:55 +08:00
|
|
|
if (_checkBoxEventCallback) {
|
|
|
|
_checkBoxEventCallback(this, EventType::UNSELECTED);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
if (_checkBoxEventListener && _checkBoxEventSelector)
|
|
|
|
{
|
|
|
|
(_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_UNSELECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::addEventListenerCheckBox(Ref *target, SEL_SelectedStateEvent selector)
|
|
|
|
{
|
|
|
|
_checkBoxEventListener = target;
|
|
|
|
_checkBoxEventSelector = selector;
|
|
|
|
}
|
2014-05-09 16:04:55 +08:00
|
|
|
|
2014-05-14 16:14:28 +08:00
|
|
|
void CheckBox::addEventListener(const ccCheckBoxCallback& callback)
|
2014-05-09 16:04:55 +08:00
|
|
|
{
|
|
|
|
_checkBoxEventCallback = callback;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
void CheckBox::updateFlippedX()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setFlippedX(_flippedX);
|
|
|
|
_backGroundSelectedBoxRenderer->setFlippedX(_flippedX);
|
|
|
|
_frontCrossRenderer->setFlippedX(_flippedX);
|
|
|
|
_backGroundBoxDisabledRenderer->setFlippedX(_flippedX);
|
|
|
|
_frontCrossDisabledRenderer->setFlippedX(_flippedX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::updateFlippedY()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setFlippedY(_flippedY);
|
|
|
|
_backGroundSelectedBoxRenderer->setFlippedY(_flippedY);
|
|
|
|
_frontCrossRenderer->setFlippedY(_flippedY);
|
|
|
|
_backGroundBoxDisabledRenderer->setFlippedY(_flippedY);
|
|
|
|
_frontCrossDisabledRenderer->setFlippedY(_flippedY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::onSizeChanged()
|
|
|
|
{
|
|
|
|
Widget::onSizeChanged();
|
2014-04-17 14:08:25 +08:00
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
|
|
|
_frontCrossRendererAdaptDirty = true;
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::adaptRenderers()
|
|
|
|
{
|
|
|
|
if (_backGroundBoxRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
backGroundTextureScaleChangedWithSize();
|
|
|
|
_backGroundBoxRendererAdaptDirty = false;
|
|
|
|
}
|
|
|
|
if (_backGroundSelectedBoxRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
backGroundSelectedTextureScaleChangedWithSize();
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = false;
|
|
|
|
}
|
|
|
|
if (_frontCrossRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
frontCrossTextureScaleChangedWithSize();
|
|
|
|
_frontCrossRendererAdaptDirty = false;
|
|
|
|
}
|
|
|
|
if (_backGroundBoxDisabledRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
backGroundDisabledTextureScaleChangedWithSize();
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = false;
|
|
|
|
}
|
|
|
|
if (_frontCrossDisabledRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
frontCrossDisabledTextureScaleChangedWithSize();
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = false;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-04-17 14:08:25 +08:00
|
|
|
const Size& CheckBox::getVirtualRendererSize() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _backGroundBoxRenderer->getContentSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* CheckBox::getVirtualRenderer()
|
|
|
|
{
|
|
|
|
return _backGroundBoxRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::backGroundTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _backGroundBoxRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _size.width / textureSize.width;
|
|
|
|
float scaleY = _size.height / textureSize.height;
|
|
|
|
_backGroundBoxRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundBoxRenderer->setScaleY(scaleY);
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_backGroundBoxRenderer->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::backGroundSelectedTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundSelectedBoxRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _backGroundSelectedBoxRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_backGroundSelectedBoxRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _size.width / textureSize.width;
|
|
|
|
float scaleY = _size.height / textureSize.height;
|
|
|
|
_backGroundSelectedBoxRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundSelectedBoxRenderer->setScaleY(scaleY);
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_backGroundSelectedBoxRenderer->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::frontCrossTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_frontCrossRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _frontCrossRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_frontCrossRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _size.width / textureSize.width;
|
|
|
|
float scaleY = _size.height / textureSize.height;
|
|
|
|
_frontCrossRenderer->setScaleX(scaleX);
|
|
|
|
_frontCrossRenderer->setScaleY(scaleY);
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_frontCrossRenderer->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::backGroundDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundBoxDisabledRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _backGroundBoxDisabledRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_backGroundBoxDisabledRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _size.width / textureSize.width;
|
|
|
|
float scaleY = _size.height / textureSize.height;
|
|
|
|
_backGroundBoxDisabledRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundBoxDisabledRenderer->setScaleY(scaleY);
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_backGroundBoxDisabledRenderer->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::frontCrossDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _frontCrossDisabledRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _size.width / textureSize.width;
|
|
|
|
float scaleY = _size.height / textureSize.height;
|
|
|
|
_frontCrossDisabledRenderer->setScaleX(scaleX);
|
|
|
|
_frontCrossDisabledRenderer->setScaleY(scaleY);
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_frontCrossDisabledRenderer->setPosition(Vec2(_contentSize.width / 2, _contentSize.height / 2));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CheckBox::getDescription() const
|
|
|
|
{
|
|
|
|
return "CheckBox";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::updateTextureColor()
|
|
|
|
{
|
|
|
|
updateColorToRenderer(_backGroundBoxRenderer);
|
|
|
|
updateColorToRenderer(_backGroundSelectedBoxRenderer);
|
|
|
|
updateColorToRenderer(_frontCrossRenderer);
|
|
|
|
updateColorToRenderer(_backGroundBoxDisabledRenderer);
|
|
|
|
updateColorToRenderer(_frontCrossDisabledRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::updateTextureOpacity()
|
|
|
|
{
|
|
|
|
updateOpacityToRenderer(_backGroundBoxRenderer);
|
|
|
|
updateOpacityToRenderer(_backGroundSelectedBoxRenderer);
|
|
|
|
updateOpacityToRenderer(_frontCrossRenderer);
|
|
|
|
updateOpacityToRenderer(_backGroundBoxDisabledRenderer);
|
|
|
|
updateOpacityToRenderer(_frontCrossDisabledRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::updateTextureRGBA()
|
|
|
|
{
|
|
|
|
updateRGBAToRenderer(_backGroundBoxRenderer);
|
|
|
|
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
|
|
|
|
updateRGBAToRenderer(_frontCrossRenderer);
|
|
|
|
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
|
|
|
|
updateRGBAToRenderer(_frontCrossDisabledRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* CheckBox::createCloneInstance()
|
|
|
|
{
|
|
|
|
return CheckBox::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBox::copySpecialProperties(Widget *widget)
|
|
|
|
{
|
|
|
|
CheckBox* checkBox = dynamic_cast<CheckBox*>(widget);
|
|
|
|
if (checkBox)
|
|
|
|
{
|
2014-04-03 10:34:20 +08:00
|
|
|
loadTextureBackGround(checkBox->_backGroundFileName, checkBox->_backGroundTexType);
|
|
|
|
loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName, checkBox->_backGroundSelectedTexType);
|
|
|
|
loadTextureFrontCross(checkBox->_frontCrossFileName, checkBox->_frontCrossTexType);
|
|
|
|
loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName, checkBox->_backGroundDisabledTexType);
|
|
|
|
loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName, checkBox->_frontCrossDisabledTexType);
|
2014-03-11 17:13:54 +08:00
|
|
|
setSelectedState(checkBox->_isSelected);
|
2014-05-23 15:03:46 +08:00
|
|
|
_checkBoxEventListener = checkBox->_checkBoxEventListener;
|
|
|
|
_checkBoxEventSelector = checkBox->_checkBoxEventSelector;
|
|
|
|
_checkBoxEventCallback = checkBox->_checkBoxEventCallback;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|