axmol/cocos/gui/UICheckBox.cpp

540 lines
16 KiB
C++
Raw Normal View History

2013-09-13 22:20:20 +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.
****************************************************************************/
2013-09-13 22:20:20 +08:00
#include "gui/UICheckBox.h"
2013-09-13 22:20:20 +08:00
2013-12-23 15:02:52 +08:00
NS_CC_BEGIN
namespace ui {
2013-12-24 20:22:14 +08:00
2014-01-03 15:46:42 +08:00
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);
2014-03-04 16:51:35 +08:00
IMPLEMENT_CLASS_GUI_INFO(CheckBox)
2013-11-06 16:04:06 +08:00
2013-12-23 15:02:52 +08:00
CheckBox::CheckBox():
2013-11-14 11:37:46 +08:00
_backGroundBoxRenderer(nullptr),
_backGroundSelectedBoxRenderer(nullptr),
_frontCrossRenderer(nullptr),
_backGroundBoxDisabledRenderer(nullptr),
_frontCrossDisabledRenderer(nullptr),
2013-09-16 20:54:13 +08:00
_isSelected(true),
2013-11-14 11:37:46 +08:00
_checkBoxEventListener(nullptr),
_checkBoxEventSelector(nullptr),
2013-09-16 20:54:13 +08:00
_backGroundTexType(UI_TEX_TYPE_LOCAL),
_backGroundSelectedTexType(UI_TEX_TYPE_LOCAL),
_frontCrossTexType(UI_TEX_TYPE_LOCAL),
_backGroundDisabledTexType(UI_TEX_TYPE_LOCAL),
2013-11-06 16:04:06 +08:00
_frontCrossDisabledTexType(UI_TEX_TYPE_LOCAL),
_backGroundFileName(""),
_backGroundSelectedFileName(""),
_frontCrossFileName(""),
_backGroundDisabledFileName(""),
_frontCrossDisabledFileName("")
2013-09-13 22:20:20 +08:00
{
}
2013-12-23 15:02:52 +08:00
CheckBox::~CheckBox()
2013-09-13 22:20:20 +08:00
{
2013-11-14 11:37:46 +08:00
_checkBoxEventListener = nullptr;
_checkBoxEventSelector = nullptr;
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
CheckBox* CheckBox::create()
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
CheckBox* widget = new CheckBox();
2013-09-13 22:20:20 +08:00
if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
2013-11-14 11:37:46 +08:00
return nullptr;
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
bool CheckBox::init()
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
if (Widget::init())
2013-09-13 22:20:20 +08:00
{
setSelectedState(false);
return true;
}
return false;
}
2013-12-23 15:02:52 +08:00
void CheckBox::initRenderer()
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
_backGroundBoxRenderer = Sprite::create();
_backGroundSelectedBoxRenderer = Sprite::create();
_frontCrossRenderer = Sprite::create();
_backGroundBoxDisabledRenderer = Sprite::create();
_frontCrossDisabledRenderer = Sprite::create();
2013-12-24 20:22:14 +08:00
2014-01-03 15:46:42 +08:00
Node::addChild(_backGroundBoxRenderer, BACKGROUNDBOX_RENDERER_Z, -1);
Node::addChild(_backGroundSelectedBoxRenderer, BACKGROUNDSELECTEDBOX_RENDERER_Z, -1);
Node::addChild(_frontCrossRenderer, FRONTCROSS_RENDERER_Z, -1);
Node::addChild(_backGroundBoxDisabledRenderer, BACKGROUNDBOXDISABLED_RENDERER_Z, -1);
Node::addChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
loadTextureBackGround(backGround,texType);
loadTextureBackGroundSelected(backGroundSelected,texType);
loadTextureFrontCross(cross,texType);
loadTextureBackGroundDisabled(backGroundDisabled,texType);
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
if (!backGround || strcmp(backGround, "") == 0)
{
return;
}
2013-11-06 16:04:06 +08:00
_backGroundFileName = backGround;
2013-09-16 20:54:13 +08:00
_backGroundTexType = texType;
switch (_backGroundTexType)
2013-09-13 22:20:20 +08:00
{
case UI_TEX_TYPE_LOCAL:
2013-11-14 07:55:36 +08:00
_backGroundBoxRenderer->setTexture(backGround);
2013-09-13 22:20:20 +08:00
break;
case UI_TEX_TYPE_PLIST:
2013-11-14 07:55:36 +08:00
_backGroundBoxRenderer->setSpriteFrame(backGround);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
2013-12-25 18:30:21 +08:00
updateAnchorPoint();
2014-03-06 13:40:46 +08:00
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundBoxRenderer);
2013-09-13 22:20:20 +08:00
backGroundTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
if (!backGroundSelected || strcmp(backGroundSelected, "") == 0)
{
return;
}
2013-11-06 16:04:06 +08:00
_backGroundSelectedFileName = backGroundSelected;
2013-09-16 20:54:13 +08:00
_backGroundSelectedTexType = texType;
switch (_backGroundSelectedTexType)
2013-09-13 22:20:20 +08:00
{
case UI_TEX_TYPE_LOCAL:
2013-11-14 07:55:36 +08:00
_backGroundSelectedBoxRenderer->setTexture(backGroundSelected);
2013-09-13 22:20:20 +08:00
break;
case UI_TEX_TYPE_PLIST:
2013-11-14 07:55:36 +08:00
_backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
2013-12-25 18:30:21 +08:00
updateAnchorPoint();
2014-03-06 13:40:46 +08:00
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
2013-09-13 22:20:20 +08:00
backGroundSelectedTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
if (!cross || strcmp(cross, "") == 0)
{
return;
}
2013-11-06 16:04:06 +08:00
_frontCrossFileName = cross;
2013-09-16 20:54:13 +08:00
_frontCrossTexType = texType;
switch (_frontCrossTexType)
2013-09-13 22:20:20 +08:00
{
case UI_TEX_TYPE_LOCAL:
2013-11-14 07:55:36 +08:00
_frontCrossRenderer->setTexture(cross);
2013-09-13 22:20:20 +08:00
break;
case UI_TEX_TYPE_PLIST:
2013-11-14 07:55:36 +08:00
_frontCrossRenderer->setSpriteFrame(cross);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
2013-12-25 18:30:21 +08:00
updateAnchorPoint();
2014-03-06 13:40:46 +08:00
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_frontCrossRenderer);
2013-09-13 22:20:20 +08:00
frontCrossTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0)
{
return;
}
2013-11-06 16:04:06 +08:00
_backGroundDisabledFileName = backGroundDisabled;
2013-09-16 20:54:13 +08:00
_backGroundDisabledTexType = texType;
switch (_backGroundDisabledTexType)
2013-09-13 22:20:20 +08:00
{
case UI_TEX_TYPE_LOCAL:
2013-11-14 07:55:36 +08:00
_backGroundBoxDisabledRenderer->setTexture(backGroundDisabled);
2013-09-13 22:20:20 +08:00
break;
case UI_TEX_TYPE_PLIST:
2013-11-14 07:55:36 +08:00
_backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
2013-12-25 18:30:21 +08:00
updateAnchorPoint();
2014-03-06 13:40:46 +08:00
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
2013-09-13 22:20:20 +08:00
backGroundDisabledTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType)
2013-09-13 22:20:20 +08:00
{
if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0)
{
return;
}
2013-11-06 16:04:06 +08:00
_frontCrossDisabledFileName = frontCrossDisabled;
2013-09-16 20:54:13 +08:00
_frontCrossDisabledTexType = texType;
switch (_frontCrossDisabledTexType)
2013-09-13 22:20:20 +08:00
{
case UI_TEX_TYPE_LOCAL:
2013-11-14 07:55:36 +08:00
_frontCrossDisabledRenderer->setTexture(frontCrossDisabled);
2013-09-13 22:20:20 +08:00
break;
case UI_TEX_TYPE_PLIST:
2013-11-14 07:55:36 +08:00
_frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
2013-12-25 18:30:21 +08:00
updateAnchorPoint();
2014-03-06 13:40:46 +08:00
updateFlippedX();
updateFlippedY();
updateRGBAToRenderer(_frontCrossDisabledRenderer);
2013-09-13 22:20:20 +08:00
frontCrossDisabledTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
void CheckBox::onTouchEnded(Touch *touch, Event *unusedEvent)
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
_touchEndPos = touch->getLocation();
2013-09-16 15:32:52 +08:00
if (_focus)
2013-09-13 22:20:20 +08:00
{
releaseUpEvent();
2013-09-16 20:54:13 +08:00
if (_isSelected){
2013-09-13 22:20:20 +08:00
setSelectedState(false);
unSelectedEvent();
}
else
{
setSelectedState(true);
selectedEvent();
}
}
setFocused(false);
2013-12-23 15:02:52 +08:00
Widget* widgetParent = getWidgetParent();
if (widgetParent)
{
widgetParent->checkChildInfo(2,this,_touchEndPos);
}
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::onPressStateChangedToNormal()
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setVisible(true);
_backGroundSelectedBoxRenderer->setVisible(false);
_backGroundBoxDisabledRenderer->setVisible(false);
_frontCrossDisabledRenderer->setVisible(false);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::onPressStateChangedToPressed()
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setVisible(false);
_backGroundSelectedBoxRenderer->setVisible(true);
_backGroundBoxDisabledRenderer->setVisible(false);
_frontCrossDisabledRenderer->setVisible(false);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::onPressStateChangedToDisabled()
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setVisible(false);
_backGroundSelectedBoxRenderer->setVisible(false);
_backGroundBoxDisabledRenderer->setVisible(true);
_frontCrossRenderer->setVisible(false);
if (_isSelected)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_frontCrossDisabledRenderer->setVisible(true);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::setSelectedState(bool selected)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
if (selected == _isSelected)
2013-09-13 22:20:20 +08:00
{
return;
}
2013-09-16 20:54:13 +08:00
_isSelected = selected;
_frontCrossRenderer->setVisible(_isSelected);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
bool CheckBox::getSelectedState()
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
return _isSelected;
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::selectedEvent()
2013-09-13 22:20:20 +08:00
{
2013-11-08 18:43:06 +08:00
if (_checkBoxEventListener && _checkBoxEventSelector)
2013-09-13 22:20:20 +08:00
{
2013-11-08 18:43:06 +08:00
(_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_SELECTED);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::unSelectedEvent()
2013-09-13 22:20:20 +08:00
{
2013-11-08 18:43:06 +08:00
if (_checkBoxEventListener && _checkBoxEventSelector)
2013-09-13 22:20:20 +08:00
{
2013-11-08 18:43:06 +08:00
(_checkBoxEventListener->*_checkBoxEventSelector)(this,CHECKBOX_STATE_EVENT_UNSELECTED);
2013-09-13 22:20:20 +08:00
}
}
void CheckBox::addEventListenerCheckBox(Ref *target, SEL_SelectedStateEvent selector)
2013-09-13 22:20:20 +08:00
{
2013-11-08 18:43:06 +08:00
_checkBoxEventListener = target;
_checkBoxEventSelector = selector;
2013-09-13 22:20:20 +08:00
}
2014-03-06 13:40:46 +08:00
void CheckBox::updateFlippedX()
2013-09-13 22:20:20 +08:00
{
2014-03-06 13:40:46 +08:00
_backGroundBoxRenderer->setFlippedX(_flippedX);
_backGroundSelectedBoxRenderer->setFlippedX(_flippedX);
_frontCrossRenderer->setFlippedX(_flippedX);
_backGroundBoxDisabledRenderer->setFlippedX(_flippedX);
_frontCrossDisabledRenderer->setFlippedX(_flippedX);
2013-09-13 22:20:20 +08:00
}
2014-03-06 13:40:46 +08:00
void CheckBox::updateFlippedY()
2013-09-13 22:20:20 +08:00
{
2014-03-06 13:40:46 +08:00
_backGroundBoxRenderer->setFlippedY(_flippedY);
_backGroundSelectedBoxRenderer->setFlippedY(_flippedY);
_frontCrossRenderer->setFlippedY(_flippedY);
_backGroundBoxDisabledRenderer->setFlippedY(_flippedY);
_frontCrossDisabledRenderer->setFlippedY(_flippedY);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::setAnchorPoint(const Point &pt)
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
Widget::setAnchorPoint(pt);
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setAnchorPoint(pt);
_backGroundSelectedBoxRenderer->setAnchorPoint(pt);
_backGroundBoxDisabledRenderer->setAnchorPoint(pt);
_frontCrossRenderer->setAnchorPoint(pt);
_frontCrossDisabledRenderer->setAnchorPoint(pt);
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::onSizeChanged()
2013-09-13 22:20:20 +08:00
{
2013-12-23 15:02:52 +08:00
Widget::onSizeChanged();
2013-09-13 22:20:20 +08:00
backGroundTextureScaleChangedWithSize();
backGroundSelectedTextureScaleChangedWithSize();
frontCrossTextureScaleChangedWithSize();
backGroundDisabledTextureScaleChangedWithSize();
frontCrossDisabledTextureScaleChangedWithSize();
}
2013-12-23 15:02:52 +08:00
const Size& CheckBox::getContentSize() const
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
return _backGroundBoxRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
Node* CheckBox::getVirtualRenderer()
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
return _backGroundBoxRenderer;
2013-09-13 22:20:20 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::backGroundTextureScaleChangedWithSize()
2013-09-13 22:20:20 +08:00
{
2013-09-16 15:32:52 +08:00
if (_ignoreSize)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setScale(1.0f);
_size = _backGroundBoxRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
}
else
{
2013-12-23 15:02:52 +08:00
Size textureSize = _backGroundBoxRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 15:32:52 +08:00
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
2013-09-16 20:54:13 +08:00
_backGroundBoxRenderer->setScaleX(scaleX);
_backGroundBoxRenderer->setScaleY(scaleY);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::backGroundSelectedTextureScaleChangedWithSize()
2013-09-13 22:20:20 +08:00
{
2013-09-16 15:32:52 +08:00
if (_ignoreSize)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundSelectedBoxRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
}
else
{
2013-12-23 15:02:52 +08:00
Size textureSize = _backGroundSelectedBoxRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
2013-09-16 20:54:13 +08:00
_backGroundSelectedBoxRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 15:32:52 +08:00
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
2013-09-16 20:54:13 +08:00
_backGroundSelectedBoxRenderer->setScaleX(scaleX);
_backGroundSelectedBoxRenderer->setScaleY(scaleY);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::frontCrossTextureScaleChangedWithSize()
2013-09-13 22:20:20 +08:00
{
2013-09-16 15:32:52 +08:00
if (_ignoreSize)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_frontCrossRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
}
else
{
2013-12-23 15:02:52 +08:00
Size textureSize = _frontCrossRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
2013-09-16 20:54:13 +08:00
_frontCrossRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 15:32:52 +08:00
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
2013-09-16 20:54:13 +08:00
_frontCrossRenderer->setScaleX(scaleX);
_frontCrossRenderer->setScaleY(scaleY);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::backGroundDisabledTextureScaleChangedWithSize()
2013-09-13 22:20:20 +08:00
{
2013-09-16 15:32:52 +08:00
if (_ignoreSize)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_backGroundBoxDisabledRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
}
else
{
2013-12-23 15:02:52 +08:00
Size textureSize = _backGroundBoxDisabledRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
2013-09-16 20:54:13 +08:00
_backGroundBoxDisabledRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 15:32:52 +08:00
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
2013-09-16 20:54:13 +08:00
_backGroundBoxDisabledRenderer->setScaleX(scaleX);
_backGroundBoxDisabledRenderer->setScaleY(scaleY);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
void CheckBox::frontCrossDisabledTextureScaleChangedWithSize()
2013-09-13 22:20:20 +08:00
{
2013-09-16 15:32:52 +08:00
if (_ignoreSize)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_frontCrossDisabledRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
}
else
{
2013-12-23 15:02:52 +08:00
Size textureSize = _frontCrossDisabledRenderer->getContentSize();
2013-09-13 22:20:20 +08:00
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
{
2013-09-16 20:54:13 +08:00
_frontCrossDisabledRenderer->setScale(1.0f);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 15:32:52 +08:00
float scaleX = _size.width / textureSize.width;
float scaleY = _size.height / textureSize.height;
2013-09-16 20:54:13 +08:00
_frontCrossDisabledRenderer->setScaleX(scaleX);
_frontCrossDisabledRenderer->setScaleY(scaleY);
2013-09-13 22:20:20 +08:00
}
}
2013-12-23 15:02:52 +08:00
std::string CheckBox::getDescription() const
2013-09-17 17:59:20 +08:00
{
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);
}
2013-09-17 17:59:20 +08:00
2013-12-23 15:02:52 +08:00
Widget* CheckBox::createCloneInstance()
2013-11-06 16:04:06 +08:00
{
2013-12-23 15:02:52 +08:00
return CheckBox::create();
2013-11-06 16:04:06 +08:00
}
2013-12-23 15:02:52 +08:00
void CheckBox::copySpecialProperties(Widget *widget)
2013-11-06 16:04:06 +08:00
{
2013-12-23 15:02:52 +08:00
CheckBox* checkBox = dynamic_cast<CheckBox*>(widget);
2013-11-06 16:04:06 +08:00
if (checkBox)
{
loadTextureBackGround(checkBox->_backGroundFileName.c_str(), checkBox->_backGroundTexType);
loadTextureBackGroundSelected(checkBox->_backGroundSelectedFileName.c_str(), checkBox->_backGroundSelectedTexType);
loadTextureFrontCross(checkBox->_frontCrossFileName.c_str(), checkBox->_frontCrossTexType);
loadTextureBackGroundDisabled(checkBox->_backGroundDisabledFileName.c_str(), checkBox->_backGroundDisabledTexType);
loadTextureFrontCrossDisabled(checkBox->_frontCrossDisabledFileName.c_str(), checkBox->_frontCrossDisabledTexType);
setSelectedState(checkBox->_isSelected);
}
}
2013-12-23 15:02:52 +08:00
}
NS_CC_END