2015-06-25 17:45:38 +08:00
|
|
|
/****************************************************************************
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2015-06-25 17:45:38 +08:00
|
|
|
|
|
|
|
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/UIAbstractCheckButton.h"
|
|
|
|
#include "2d/CCSprite.h"
|
2015-12-04 10:43:39 +08:00
|
|
|
#include "editor-support/cocostudio/CocosStudioExtension.h"
|
2015-06-25 17:45:38 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
AbstractCheckButton::AbstractCheckButton():
|
|
|
|
_backGroundBoxRenderer(nullptr),
|
|
|
|
_backGroundSelectedBoxRenderer(nullptr),
|
|
|
|
_frontCrossRenderer(nullptr),
|
|
|
|
_backGroundBoxDisabledRenderer(nullptr),
|
|
|
|
_frontCrossDisabledRenderer(nullptr),
|
|
|
|
_isSelected(true),
|
|
|
|
_isBackgroundSelectedTextureLoaded(false),
|
|
|
|
_isBackgroundDisabledTextureLoaded(false),
|
|
|
|
_isFrontCrossDisabledTextureLoaded(false),
|
|
|
|
_backGroundTexType(TextureResType::LOCAL),
|
|
|
|
_backGroundSelectedTexType(TextureResType::LOCAL),
|
|
|
|
_frontCrossTexType(TextureResType::LOCAL),
|
|
|
|
_backGroundDisabledTexType(TextureResType::LOCAL),
|
|
|
|
_frontCrossDisabledTexType(TextureResType::LOCAL),
|
|
|
|
_zoomScale(0.1f),
|
|
|
|
_backgroundTextureScaleX(1.0),
|
|
|
|
_backgroundTextureScaleY(1.0),
|
2015-11-18 13:38:29 +08:00
|
|
|
_backGroundFileName(""),
|
|
|
|
_backGroundSelectedFileName(""),
|
|
|
|
_frontCrossFileName(""),
|
|
|
|
_backGroundDisabledFileName(""),
|
|
|
|
_frontCrossDisabledFileName(""),
|
2015-06-25 17:45:38 +08:00
|
|
|
_backGroundBoxRendererAdaptDirty(true),
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty(true),
|
|
|
|
_frontCrossRendererAdaptDirty(true),
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty(true),
|
|
|
|
_frontCrossDisabledRendererAdaptDirty(true)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
setTouchEnabled(true);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractCheckButton::~AbstractCheckButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractCheckButton::init(const std::string& backGround,
|
2017-01-19 09:40:35 +08:00
|
|
|
const std::string& backGroundSelected,
|
2015-06-30 19:31:31 +08:00
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
|
|
|
TextureResType texType)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!Widget::init())
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelected(false);
|
2017-01-19 09:40:35 +08:00
|
|
|
loadTextures(backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType);
|
2015-06-30 19:31:31 +08:00
|
|
|
} while (0);
|
|
|
|
return ret;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractCheckButton::init()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
if (Widget::init())
|
|
|
|
{
|
|
|
|
setSelected(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::initRenderer()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundBoxRenderer = Sprite::create();
|
|
|
|
_backGroundSelectedBoxRenderer = Sprite::create();
|
|
|
|
_frontCrossRenderer = Sprite::create();
|
|
|
|
_backGroundBoxDisabledRenderer = Sprite::create();
|
|
|
|
_frontCrossDisabledRenderer = Sprite::create();
|
|
|
|
|
|
|
|
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);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextures(const std::string& backGround,
|
2015-06-30 19:31:31 +08:00
|
|
|
const std::string& backGroundSelected,
|
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
|
|
|
TextureResType texType)
|
2015-06-25 17:45:38 +08:00
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
loadTextureBackGround(backGround,texType);
|
|
|
|
loadTextureBackGroundSelected(backGroundSelected,texType);
|
|
|
|
loadTextureFrontCross(cross,texType);
|
|
|
|
loadTextureBackGroundDisabled(backGroundDisabled,texType);
|
|
|
|
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGround(const std::string& backGround,TextureResType texType)
|
|
|
|
{
|
2015-11-18 13:38:29 +08:00
|
|
|
_backGroundFileName = backGround;
|
|
|
|
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundTexType = texType;
|
|
|
|
switch (_backGroundTexType)
|
|
|
|
{
|
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundBoxRenderer->setTexture(backGround);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundBoxRenderer->setSpriteFrame(backGround);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setupBackgroundTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundTexture()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
|
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
|
|
|
|
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
|
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGround(SpriteFrame* spriteFrame)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundBoxRenderer->setSpriteFrame(spriteFrame);
|
|
|
|
this->setupBackgroundTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType)
|
|
|
|
{
|
2015-11-18 13:38:29 +08:00
|
|
|
_backGroundSelectedFileName = backGroundSelected;
|
|
|
|
_isBackgroundSelectedTextureLoaded = !backGroundSelected.empty();
|
|
|
|
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundSelectedTexType = texType;
|
|
|
|
switch (_backGroundSelectedTexType)
|
|
|
|
{
|
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundSelectedBoxRenderer->setTexture(backGroundSelected);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->setupBackgroundSelectedTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundSelected(SpriteFrame* spriteframe)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->_backGroundSelectedBoxRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupBackgroundSelectedTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundSelectedTexture()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCross(const std::string& cross,TextureResType texType)
|
|
|
|
{
|
2015-11-18 13:38:29 +08:00
|
|
|
_frontCrossFileName = cross;
|
|
|
|
|
2015-06-30 19:31:31 +08:00
|
|
|
_frontCrossTexType = texType;
|
|
|
|
switch (_frontCrossTexType)
|
|
|
|
{
|
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_frontCrossRenderer->setTexture(cross);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_frontCrossRenderer->setSpriteFrame(cross);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->setupFrontCrossTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCross(SpriteFrame* spriteFrame)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->_frontCrossRenderer->setSpriteFrame(spriteFrame);
|
|
|
|
this->setupFrontCrossTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupFrontCrossTexture()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_frontCrossRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType)
|
|
|
|
{
|
2015-11-18 13:38:29 +08:00
|
|
|
_backGroundDisabledFileName = backGroundDisabled;
|
|
|
|
_isBackgroundDisabledTextureLoaded = !backGroundDisabled.empty();
|
|
|
|
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundDisabledTexType = texType;
|
|
|
|
switch (_backGroundDisabledTexType)
|
|
|
|
{
|
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundBoxDisabledRenderer->setTexture(backGroundDisabled);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->setupBackgroundDisable();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundDisabled(SpriteFrame* spriteframe)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->_backGroundBoxDisabledRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupBackgroundDisable();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundDisable()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType)
|
|
|
|
{
|
2015-11-18 13:38:29 +08:00
|
|
|
_frontCrossDisabledFileName = frontCrossDisabled;
|
|
|
|
_isFrontCrossDisabledTextureLoaded = !frontCrossDisabled.empty();
|
|
|
|
|
2015-06-30 19:31:31 +08:00
|
|
|
_frontCrossDisabledTexType = texType;
|
|
|
|
switch (_frontCrossDisabledTexType)
|
|
|
|
{
|
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_frontCrossDisabledRenderer->setTexture(frontCrossDisabled);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->setupFrontCrossDisableTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCrossDisabled(SpriteFrame* spriteframe)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->_frontCrossDisabledRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupFrontCrossDisableTexture();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupFrontCrossDisableTexture()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToNormal()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
_backGroundBoxRenderer->setVisible(true);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
|
|
|
|
2016-09-30 09:42:21 +08:00
|
|
|
_backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState(_backGroundBoxRenderer->getTexture()));
|
|
|
|
_frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState(_frontCrossRenderer->getTexture()));
|
2015-06-30 19:31:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
|
|
|
|
|
|
|
|
if (_isSelected)
|
|
|
|
{
|
|
|
|
_frontCrossRenderer->setVisible(true);
|
2015-07-03 10:23:49 +08:00
|
|
|
_frontCrossRendererAdaptDirty = true;
|
2015-06-30 19:31:31 +08:00
|
|
|
}
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToPressed()
|
|
|
|
{
|
2016-09-30 09:42:21 +08:00
|
|
|
_backGroundBoxRenderer->setGLProgramState(this->getNormalGLProgramState(_backGroundBoxRenderer->getTexture()));
|
|
|
|
_frontCrossRenderer->setGLProgramState(this->getNormalGLProgramState(_frontCrossRenderer->getTexture()));
|
2015-06-30 19:31:31 +08:00
|
|
|
|
|
|
|
if (!_isBackgroundSelectedTextureLoaded)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX + _zoomScale,
|
|
|
|
_backgroundTextureScaleY + _zoomScale);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX + _zoomScale,
|
|
|
|
_backgroundTextureScaleY + _zoomScale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(true);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
|
|
|
}
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToDisabled()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
if (!_isBackgroundDisabledTextureLoaded
|
|
|
|
|| !_isFrontCrossDisabledTextureLoaded)
|
|
|
|
{
|
2016-09-30 09:42:21 +08:00
|
|
|
_backGroundBoxRenderer->setGLProgramState(this->getGrayGLProgramState(_backGroundBoxRenderer->getTexture()));
|
|
|
|
_frontCrossRenderer->setGLProgramState(this->getGrayGLProgramState(_backGroundBoxRenderer->getTexture()));
|
2015-06-30 19:31:31 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_frontCrossRenderer->setVisible(false);
|
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
|
|
|
|
if (_isSelected)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setVisible(true);
|
2015-07-03 10:23:49 +08:00
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
2015-06-30 19:31:31 +08:00
|
|
|
}
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setZoomScale(float scale)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
_zoomScale = scale;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float AbstractCheckButton::getZoomScale()const
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
return _zoomScale;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setSelected(bool selected)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
if (selected == _isSelected)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_isSelected = selected;
|
|
|
|
_frontCrossRenderer->setVisible(_isSelected);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractCheckButton::isSelected()const
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
return _isSelected;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onSizeChanged()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
Widget::onSizeChanged();
|
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
|
|
|
_frontCrossRendererAdaptDirty = true;
|
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::adaptRenderers()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
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;
|
|
|
|
}
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Size AbstractCheckButton::getVirtualRendererSize() const
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
return _backGroundBoxRenderer->getContentSize();
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* AbstractCheckButton::getVirtualRenderer()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
return _backGroundBoxRenderer;
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundTextureScaleChangedWithSize()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
_backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Size textureSize = _backGroundBoxRenderer->getContentSize();
|
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
_backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float scaleX = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
|
|
|
_backgroundTextureScaleX = scaleX;
|
|
|
|
_backgroundTextureScaleY = scaleY;
|
|
|
|
_backGroundBoxRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundBoxRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_backGroundBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
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 = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
|
|
|
_backGroundSelectedBoxRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundSelectedBoxRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_backGroundSelectedBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::frontCrossTextureScaleChangedWithSize()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
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 = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
|
|
|
_frontCrossRenderer->setScaleX(scaleX);
|
|
|
|
_frontCrossRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_frontCrossRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
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 = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
|
|
|
_backGroundBoxDisabledRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundBoxDisabledRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_backGroundBoxDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
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 = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
|
|
|
_frontCrossDisabledRenderer->setScaleX(scaleX);
|
|
|
|
_frontCrossDisabledRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_frontCrossDisabledRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::copySpecialProperties(Widget *widget)
|
|
|
|
{
|
2015-06-30 19:31:31 +08:00
|
|
|
AbstractCheckButton* abstractCheckButton = dynamic_cast<AbstractCheckButton*>(widget);
|
|
|
|
if (abstractCheckButton)
|
|
|
|
{
|
|
|
|
loadTextureBackGround(abstractCheckButton->_backGroundBoxRenderer->getSpriteFrame());
|
|
|
|
loadTextureBackGroundSelected(abstractCheckButton->_backGroundSelectedBoxRenderer->getSpriteFrame());
|
|
|
|
loadTextureFrontCross(abstractCheckButton->_frontCrossRenderer->getSpriteFrame());
|
|
|
|
loadTextureBackGroundDisabled(abstractCheckButton->_backGroundBoxDisabledRenderer->getSpriteFrame());
|
|
|
|
loadTextureFrontCrossDisabled(abstractCheckButton->_frontCrossDisabledRenderer->getSpriteFrame());
|
|
|
|
setSelected(abstractCheckButton->_isSelected);
|
|
|
|
_zoomScale = abstractCheckButton->_zoomScale;
|
|
|
|
_backgroundTextureScaleX = abstractCheckButton->_backgroundTextureScaleX;
|
|
|
|
_backgroundTextureScaleY = abstractCheckButton->_backgroundTextureScaleY;
|
|
|
|
_isBackgroundSelectedTextureLoaded = abstractCheckButton->_isBackgroundSelectedTextureLoaded;
|
|
|
|
_isBackgroundDisabledTextureLoaded = abstractCheckButton->_isBackgroundDisabledTextureLoaded;
|
|
|
|
_isFrontCrossDisabledTextureLoaded = abstractCheckButton->_isFrontCrossDisabledTextureLoaded;
|
|
|
|
}
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
2015-11-18 13:38:29 +08:00
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData AbstractCheckButton::getBackNormalFile()
|
2015-11-18 13:38:29 +08:00
|
|
|
{
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData rData;
|
2015-11-18 13:38:29 +08:00
|
|
|
rData.type = (int)_backGroundTexType;
|
|
|
|
rData.file = _backGroundFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData AbstractCheckButton::getBackPressedFile()
|
2015-11-18 13:38:29 +08:00
|
|
|
{
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData rData;
|
2015-11-18 13:38:29 +08:00
|
|
|
rData.type = (int)_backGroundSelectedTexType;
|
|
|
|
rData.file = _backGroundSelectedFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData AbstractCheckButton::getBackDisabledFile()
|
2015-11-18 13:38:29 +08:00
|
|
|
{
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData rData;
|
2015-11-18 13:38:29 +08:00
|
|
|
rData.type = (int)_backGroundDisabledTexType;
|
|
|
|
rData.file = _backGroundDisabledFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData AbstractCheckButton::getCrossNormalFile()
|
2015-11-18 13:38:29 +08:00
|
|
|
{
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData rData;
|
2015-11-18 13:38:29 +08:00
|
|
|
rData.type = (int)_frontCrossTexType;
|
|
|
|
rData.file = _frontCrossFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData AbstractCheckButton::getCrossDisabledFile()
|
2015-11-18 13:38:29 +08:00
|
|
|
{
|
2015-12-05 00:26:07 +08:00
|
|
|
ResourceData rData;
|
2015-11-18 13:38:29 +08:00
|
|
|
rData.type = (int)_frontCrossDisabledTexType;
|
|
|
|
rData.file = _frontCrossDisabledFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2015-06-25 17:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|