2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dnode.h"
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::ButtonToggle::ButtonToggle()
|
|
|
|
|
|
: Button()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
, _bState(true)
|
|
|
|
|
|
, _pNormalOn(nullptr)
|
|
|
|
|
|
, _pMouseoverOn(nullptr)
|
|
|
|
|
|
, _pSelectedOn(nullptr)
|
|
|
|
|
|
, _pDisabledOn(nullptr)
|
|
|
|
|
|
, _pNormalOff(nullptr)
|
|
|
|
|
|
, _pMouseoverOff(nullptr)
|
|
|
|
|
|
, _pSelectedOff(nullptr)
|
|
|
|
|
|
, _pDisabledOff(nullptr)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 11:37:11 +08:00
|
|
|
|
e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, const Function& func)
|
2018-02-07 16:37:12 +08:00
|
|
|
|
: Button()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
, _bState(true)
|
|
|
|
|
|
, _pNormalOn(nullptr)
|
|
|
|
|
|
, _pMouseoverOn(nullptr)
|
|
|
|
|
|
, _pSelectedOn(nullptr)
|
|
|
|
|
|
, _pDisabledOn(nullptr)
|
|
|
|
|
|
, _pNormalOff(nullptr)
|
|
|
|
|
|
, _pMouseoverOff(nullptr)
|
|
|
|
|
|
, _pSelectedOff(nullptr)
|
|
|
|
|
|
, _pDisabledOff(nullptr)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->setNormal(toggleOnNormal);
|
|
|
|
|
|
this->setNormalOff(toggleOffNormal);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
this->setClickFunc(func);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 11:37:11 +08:00
|
|
|
|
e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
|
2018-02-07 16:37:12 +08:00
|
|
|
|
: Button()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
, _bState(true)
|
|
|
|
|
|
, _pNormalOn(nullptr)
|
|
|
|
|
|
, _pMouseoverOn(nullptr)
|
|
|
|
|
|
, _pSelectedOn(nullptr)
|
|
|
|
|
|
, _pDisabledOn(nullptr)
|
|
|
|
|
|
, _pNormalOff(nullptr)
|
|
|
|
|
|
, _pMouseoverOff(nullptr)
|
|
|
|
|
|
, _pSelectedOff(nullptr)
|
|
|
|
|
|
, _pDisabledOff(nullptr)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->setNormal(toggleOnNormal);
|
|
|
|
|
|
this->setNormalOff(toggleOffNormal);
|
|
|
|
|
|
this->setSelected(toggleOnSelected);
|
|
|
|
|
|
this->setSelectedOff(toggleOffSelected);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
this->setClickFunc(func);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 11:37:11 +08:00
|
|
|
|
e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, const Function& func)
|
2018-02-07 16:37:12 +08:00
|
|
|
|
: Button()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
, _bState(true)
|
|
|
|
|
|
, _pNormalOn(nullptr)
|
|
|
|
|
|
, _pMouseoverOn(nullptr)
|
|
|
|
|
|
, _pSelectedOn(nullptr)
|
|
|
|
|
|
, _pDisabledOn(nullptr)
|
|
|
|
|
|
, _pNormalOff(nullptr)
|
|
|
|
|
|
, _pMouseoverOff(nullptr)
|
|
|
|
|
|
, _pSelectedOff(nullptr)
|
|
|
|
|
|
, _pDisabledOff(nullptr)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->setNormal(toggleOnNormal);
|
|
|
|
|
|
this->setNormalOff(toggleOffNormal);
|
|
|
|
|
|
this->setMouseOver(toggleOnMouseOver);
|
|
|
|
|
|
this->setMouseOverOff(toggleOffMouseOver);
|
|
|
|
|
|
this->setSelected(toggleOnSelected);
|
|
|
|
|
|
this->setSelectedOff(toggleOffSelected);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
this->setClickFunc(func);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 11:37:11 +08:00
|
|
|
|
e2d::ButtonToggle::ButtonToggle(Node * toggleOnNormal, Node * toggleOffNormal, Node * toggleOnMouseOver, Node * toggleOffMouseOver, Node * toggleOnSelected, Node * toggleOffSelected, Node * toggleOnDisabled, Node * toggleOffDisabled, const Function& func)
|
2018-02-07 16:37:12 +08:00
|
|
|
|
: Button()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
, _bState(true)
|
|
|
|
|
|
, _pNormalOn(nullptr)
|
|
|
|
|
|
, _pMouseoverOn(nullptr)
|
|
|
|
|
|
, _pSelectedOn(nullptr)
|
|
|
|
|
|
, _pDisabledOn(nullptr)
|
|
|
|
|
|
, _pNormalOff(nullptr)
|
|
|
|
|
|
, _pMouseoverOff(nullptr)
|
|
|
|
|
|
, _pSelectedOff(nullptr)
|
|
|
|
|
|
, _pDisabledOff(nullptr)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->setNormal(toggleOnNormal);
|
|
|
|
|
|
this->setNormalOff(toggleOffNormal);
|
|
|
|
|
|
this->setMouseOver(toggleOnMouseOver);
|
|
|
|
|
|
this->setMouseOverOff(toggleOffMouseOver);
|
|
|
|
|
|
this->setSelected(toggleOnSelected);
|
|
|
|
|
|
this->setSelectedOff(toggleOffSelected);
|
|
|
|
|
|
this->setDisabled(toggleOnDisabled);
|
|
|
|
|
|
this->setDisabledOff(toggleOffDisabled);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
this->setClickFunc(func);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool e2d::ButtonToggle::getState() const
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
return _bState;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setState(bool bState)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_bState != bState)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_bState = bState;
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-09 18:22:41 +08:00
|
|
|
|
_updateVisiable();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setNormal(Node * normal)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (normal != _pNormalOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pNormalOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pNormalOn);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(normal);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
this->setSize(normal->getWidth(), normal->getHeight());
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pNormalOn = normal;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setMouseOver(Node * mouseover)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (mouseover != _pMouseoverOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pMouseoverOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pMouseoverOn);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (mouseover)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(mouseover);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pMouseoverOn = mouseover;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setSelected(Node * selected)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (selected != _pSelectedOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pSelectedOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pSelectedOn);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (selected)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(selected);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pSelectedOn = selected;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setDisabled(Node * disabled)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (disabled != _pDisabledOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pDisabledOn)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pDisabledOn);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (disabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(disabled);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pDisabledOn = disabled;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setNormalOff(Node * normal)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (normal != _pNormalOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pNormalOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pNormalOff);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(normal);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pNormalOff = normal;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setMouseOverOff(Node * mouseover)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (mouseover != _pMouseoverOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pMouseoverOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pMouseoverOff);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (mouseover)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(mouseover);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pMouseoverOff = mouseover;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setSelectedOff(Node * selected)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (selected != _pSelectedOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pSelectedOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pSelectedOff);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (selected)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(selected);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pSelectedOff = selected;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::setDisabledOff(Node * disabled)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (disabled != _pDisabledOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ɵ<EFBFBD>
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pDisabledOff)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
this->removeChild(_pDisabledOff);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>
|
|
|
|
|
|
if (disabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->addChild(disabled);
|
|
|
|
|
|
}
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pDisabledOff = disabled;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
_updateVisiable();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::_updateState()
|
2018-02-04 21:24:27 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_bState)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pNormal = _pNormalOn;
|
|
|
|
|
|
_pMouseover = _pMouseoverOn;
|
|
|
|
|
|
_pSelected = _pSelectedOn;
|
|
|
|
|
|
_pDisabled = _pDisabledOn;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pNormalOff) _pNormalOff->setVisiable(false);
|
|
|
|
|
|
if (_pMouseoverOff) _pMouseoverOff->setVisiable(false);
|
|
|
|
|
|
if (_pSelectedOff) _pSelectedOff->setVisiable(false);
|
|
|
|
|
|
if (_pDisabledOff) _pDisabledOff->setVisiable(false);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_pNormal = _pNormalOff;
|
|
|
|
|
|
_pMouseover = _pMouseoverOff;
|
|
|
|
|
|
_pSelected = _pSelectedOff;
|
|
|
|
|
|
_pDisabled = _pDisabledOff;
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_pNormalOn) _pNormalOn->setVisiable(false);
|
|
|
|
|
|
if (_pMouseoverOn) _pMouseoverOn->setVisiable(false);
|
|
|
|
|
|
if (_pSelectedOn) _pSelectedOn->setVisiable(false);
|
|
|
|
|
|
if (_pDisabledOn) _pDisabledOn->setVisiable(false);
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::ButtonToggle::_runCallback()
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_bState = !_bState;
|
2018-02-04 21:24:27 +08:00
|
|
|
|
_updateState();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
|
2018-05-08 17:40:36 +08:00
|
|
|
|
if (_Callback)
|
2017-11-07 22:20:46 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_Callback();
|
2017-11-07 22:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|