2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2024-07-11 23:28:31 +08:00
|
|
|
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2024-06-10 02:25:43 +08:00
|
|
|
https://axmol.dev/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "2d/Sprite.h"
|
|
|
|
#include "renderer/Shaders.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "renderer/backend/ProgramStateRegistry.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static const int BACKGROUNDBOX_RENDERER_Z = (-1);
|
2019-11-23 20:27:39 +08:00
|
|
|
static const int BACKGROUNDSELECTEDBOX_RENDERER_Z = (-1);
|
2021-12-25 10:04:45 +08:00
|
|
|
static const int FRONTCROSS_RENDERER_Z = (-1);
|
2019-11-23 20:27:39 +08:00
|
|
|
static const int BACKGROUNDBOXDISABLED_RENDERER_Z = (-1);
|
2021-12-25 10:04:45 +08:00
|
|
|
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)
|
|
|
|
, _backGroundBoxRendererAdaptDirty(true)
|
|
|
|
, _backGroundSelectedBoxRendererAdaptDirty(true)
|
|
|
|
, _frontCrossRendererAdaptDirty(true)
|
|
|
|
, _backGroundBoxDisabledRendererAdaptDirty(true)
|
|
|
|
, _frontCrossDisabledRendererAdaptDirty(true)
|
|
|
|
, _backGroundFileName("")
|
|
|
|
, _backGroundSelectedFileName("")
|
|
|
|
, _frontCrossFileName("")
|
|
|
|
, _backGroundDisabledFileName("")
|
|
|
|
, _frontCrossDisabledFileName("")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
setTouchEnabled(true);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AbstractCheckButton::~AbstractCheckButton() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool AbstractCheckButton::init(std::string_view backGround,
|
|
|
|
std::string_view backGroundSelected,
|
|
|
|
std::string_view cross,
|
|
|
|
std::string_view backGroundDisabled,
|
|
|
|
std::string_view frontCrossDisabled,
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!Widget::init())
|
|
|
|
{
|
|
|
|
ret = false;
|
|
|
|
break;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
setSelected(false);
|
|
|
|
loadTextures(backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType);
|
|
|
|
} while (0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractCheckButton::init()
|
|
|
|
{
|
|
|
|
if (Widget::init())
|
|
|
|
{
|
|
|
|
setSelected(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::initRenderer()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_backGroundBoxRenderer = Sprite::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundSelectedBoxRenderer = Sprite::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
_frontCrossRenderer = Sprite::create();
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundBoxDisabledRenderer = Sprite::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
_frontCrossDisabledRenderer = Sprite::create();
|
|
|
|
|
2019-11-23 20:27:39 +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);
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextures(std::string_view backGround,
|
|
|
|
std::string_view backGroundSelected,
|
|
|
|
std::string_view cross,
|
|
|
|
std::string_view backGroundDisabled,
|
|
|
|
std::string_view frontCrossDisabled,
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
loadTextureBackGround(backGround, texType);
|
|
|
|
loadTextureBackGroundSelected(backGroundSelected, texType);
|
|
|
|
loadTextureFrontCross(cross, texType);
|
|
|
|
loadTextureBackGroundDisabled(backGroundDisabled, texType);
|
|
|
|
loadTextureFrontCrossDisabled(frontCrossDisabled, texType);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextureBackGround(std::string_view backGround, TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_backGroundFileName = backGround;
|
|
|
|
|
|
|
|
_backGroundTexType = texType;
|
|
|
|
switch (_backGroundTexType)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundBoxRenderer->setTexture(backGround);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundBoxRenderer->setSpriteFrame(backGround);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
this->setupBackgroundTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundTexture()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
this->updateChildrenDisplayedRGBA();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
|
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGround(SpriteFrame* spriteFrame)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setSpriteFrame(spriteFrame);
|
|
|
|
this->setupBackgroundTexture();
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextureBackGroundSelected(std::string_view backGroundSelected, TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_backGroundSelectedFileName = backGroundSelected;
|
2019-11-23 20:27:39 +08:00
|
|
|
_isBackgroundSelectedTextureLoaded = !backGroundSelected.empty();
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isBackgroundSelectedTextureLoaded)
|
|
|
|
return;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundSelectedTexType = texType;
|
|
|
|
switch (_backGroundSelectedTexType)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundSelectedBoxRenderer->setTexture(backGroundSelected);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundSelectedBoxRenderer->setSpriteFrame(backGroundSelected);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
this->setupBackgroundSelectedTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundSelected(SpriteFrame* spriteframe)
|
|
|
|
{
|
|
|
|
this->_backGroundSelectedBoxRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupBackgroundSelectedTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundSelectedTexture()
|
|
|
|
{
|
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextureFrontCross(std::string_view cross, TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_frontCrossFileName = cross;
|
|
|
|
|
|
|
|
_frontCrossTexType = texType;
|
|
|
|
switch (_frontCrossTexType)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_frontCrossRenderer->setTexture(cross);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_frontCrossRenderer->setSpriteFrame(cross);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
this->setupFrontCrossTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCross(SpriteFrame* spriteFrame)
|
|
|
|
{
|
|
|
|
this->_frontCrossRenderer->setSpriteFrame(spriteFrame);
|
|
|
|
this->setupFrontCrossTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupFrontCrossTexture()
|
|
|
|
{
|
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_frontCrossRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextureBackGroundDisabled(std::string_view backGroundDisabled, TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_backGroundDisabledFileName = backGroundDisabled;
|
2019-11-23 20:27:39 +08:00
|
|
|
_isBackgroundDisabledTextureLoaded = !backGroundDisabled.empty();
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isBackgroundDisabledTextureLoaded)
|
|
|
|
return;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_backGroundDisabledTexType = texType;
|
|
|
|
switch (_backGroundDisabledTexType)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_backGroundBoxDisabledRenderer->setTexture(backGroundDisabled);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_backGroundBoxDisabledRenderer->setSpriteFrame(backGroundDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
this->setupBackgroundDisable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureBackGroundDisabled(SpriteFrame* spriteframe)
|
|
|
|
{
|
|
|
|
this->_backGroundBoxDisabledRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupBackgroundDisable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupBackgroundDisable()
|
|
|
|
{
|
|
|
|
this->updateChildrenDisplayedRGBA();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void AbstractCheckButton::loadTextureFrontCrossDisabled(std::string_view frontCrossDisabled, TextureResType texType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_frontCrossDisabledFileName = frontCrossDisabled;
|
2019-11-23 20:27:39 +08:00
|
|
|
_isFrontCrossDisabledTextureLoaded = !frontCrossDisabled.empty();
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isFrontCrossDisabledTextureLoaded)
|
|
|
|
return;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_frontCrossDisabledTexType = texType;
|
|
|
|
switch (_frontCrossDisabledTexType)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case TextureResType::LOCAL:
|
|
|
|
_frontCrossDisabledRenderer->setTexture(frontCrossDisabled);
|
|
|
|
break;
|
|
|
|
case TextureResType::PLIST:
|
|
|
|
_frontCrossDisabledRenderer->setSpriteFrame(frontCrossDisabled);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
this->setupFrontCrossDisableTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::loadTextureFrontCrossDisabled(SpriteFrame* spriteframe)
|
|
|
|
{
|
|
|
|
this->_frontCrossDisabledRenderer->setSpriteFrame(spriteframe);
|
|
|
|
this->setupFrontCrossDisableTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setupFrontCrossDisableTexture()
|
|
|
|
{
|
|
|
|
this->updateChildrenDisplayedRGBA();
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToNormal()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(true);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundBoxRenderer->setProgramState(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
|
|
|
_frontCrossRenderer->setProgramState(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (_isSelected)
|
|
|
|
{
|
|
|
|
_frontCrossRenderer->setVisible(true);
|
|
|
|
_frontCrossRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToPressed()
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setProgramState(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
|
|
|
_frontCrossRenderer->setProgramState(backend::ProgramType::POSITION_TEXTURE_COLOR);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!_isBackgroundSelectedTextureLoaded)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX + _zoomScale, _backgroundTextureScaleY + _zoomScale);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX + _zoomScale, _backgroundTextureScaleY + _zoomScale);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundSelectedBoxRenderer->setVisible(true);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(false);
|
|
|
|
_frontCrossDisabledRenderer->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onPressStateChangedToDisabled()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isBackgroundDisabledTextureLoaded || !_isFrontCrossDisabledTextureLoaded)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setProgramState(backend::ProgramType::GRAY_SCALE);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_frontCrossRenderer->setProgramState(backend::ProgramType::GRAY_SCALE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setVisible(false);
|
|
|
|
_backGroundBoxDisabledRenderer->setVisible(true);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundSelectedBoxRenderer->setVisible(false);
|
|
|
|
_frontCrossRenderer->setVisible(false);
|
|
|
|
_backGroundBoxRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
|
|
|
_frontCrossRenderer->setScale(_backgroundTextureScaleX, _backgroundTextureScaleY);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (_isSelected)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setVisible(true);
|
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setZoomScale(float scale)
|
|
|
|
{
|
|
|
|
_zoomScale = scale;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float AbstractCheckButton::getZoomScale() const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return _zoomScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::setSelected(bool selected)
|
|
|
|
{
|
|
|
|
if (selected == _isSelected)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_isSelected = selected;
|
|
|
|
_frontCrossRenderer->setVisible(_isSelected);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool AbstractCheckButton::isSelected() const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return _isSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::onSizeChanged()
|
|
|
|
{
|
|
|
|
Widget::onSizeChanged();
|
2021-12-25 10:04:45 +08:00
|
|
|
_backGroundBoxRendererAdaptDirty = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
_frontCrossRendererAdaptDirty = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
_frontCrossDisabledRendererAdaptDirty = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 AbstractCheckButton::getVirtualRendererSize() const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return _backGroundBoxRenderer->getContentSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* AbstractCheckButton::getVirtualRenderer()
|
|
|
|
{
|
|
|
|
return _backGroundBoxRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
_backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _backGroundBoxRenderer->getContentSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_backGroundBoxRenderer->setScale(1.0f);
|
|
|
|
_backgroundTextureScaleX = _backgroundTextureScaleY = 1.0f;
|
|
|
|
return;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
float scaleX = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
2019-11-23 20:27:39 +08:00
|
|
|
_backgroundTextureScaleX = scaleX;
|
|
|
|
_backgroundTextureScaleY = scaleY;
|
|
|
|
_backGroundBoxRenderer->setScaleX(scaleX);
|
|
|
|
_backGroundBoxRenderer->setScaleY(scaleY);
|
|
|
|
}
|
|
|
|
_backGroundBoxRenderer->setPosition(_contentSize.width / 2, _contentSize.height / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundSelectedTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundSelectedBoxRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _backGroundSelectedBoxRenderer->getContentSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::frontCrossTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_frontCrossRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _frontCrossRenderer->getContentSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::backGroundDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_backGroundBoxDisabledRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _backGroundBoxDisabledRenderer->getContentSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCheckButton::frontCrossDisabledTextureScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_frontCrossDisabledRenderer->setScale(1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _frontCrossDisabledRenderer->getContentSize();
|
2019-11-23 20:27:39 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void AbstractCheckButton::copySpecialProperties(Widget* widget)
|
2019-11-23 20:27:39 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
_zoomScale = abstractCheckButton->_zoomScale;
|
|
|
|
_backgroundTextureScaleX = abstractCheckButton->_backgroundTextureScaleX;
|
|
|
|
_backgroundTextureScaleY = abstractCheckButton->_backgroundTextureScaleY;
|
2019-11-23 20:27:39 +08:00
|
|
|
_isBackgroundSelectedTextureLoaded = abstractCheckButton->_isBackgroundSelectedTextureLoaded;
|
|
|
|
_isBackgroundDisabledTextureLoaded = abstractCheckButton->_isBackgroundDisabledTextureLoaded;
|
|
|
|
_isFrontCrossDisabledTextureLoaded = abstractCheckButton->_isFrontCrossDisabledTextureLoaded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceData AbstractCheckButton::getBackNormalFile()
|
|
|
|
{
|
|
|
|
ResourceData rData;
|
|
|
|
rData.type = (int)_backGroundTexType;
|
|
|
|
rData.file = _backGroundFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceData AbstractCheckButton::getBackPressedFile()
|
|
|
|
{
|
|
|
|
ResourceData rData;
|
|
|
|
rData.type = (int)_backGroundSelectedTexType;
|
|
|
|
rData.file = _backGroundSelectedFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceData AbstractCheckButton::getBackDisabledFile()
|
|
|
|
{
|
|
|
|
ResourceData rData;
|
|
|
|
rData.type = (int)_backGroundDisabledTexType;
|
|
|
|
rData.file = _backGroundDisabledFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceData AbstractCheckButton::getCrossNormalFile()
|
|
|
|
{
|
|
|
|
ResourceData rData;
|
|
|
|
rData.type = (int)_frontCrossTexType;
|
|
|
|
rData.file = _frontCrossFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceData AbstractCheckButton::getCrossDisabledFile()
|
|
|
|
{
|
|
|
|
ResourceData rData;
|
|
|
|
rData.type = (int)_frontCrossDisabledTexType;
|
|
|
|
rData.file = _frontCrossDisabledFileName;
|
|
|
|
return rData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|