mirror of https://github.com/axmolengine/axmol.git
issue #4636, add parameter create method to UICheckBox
This commit is contained in:
parent
1b0583214b
commit
ba9a605568
|
@ -76,6 +76,49 @@ CheckBox* CheckBox::create()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
bool bRet = true;
|
||||||
|
do {
|
||||||
|
if (!Widget::init()) {
|
||||||
|
bRet = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedState(false);
|
||||||
|
setTouchEnabled(true);
|
||||||
|
loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled,texType);
|
||||||
|
} while (0);
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
bool CheckBox::init()
|
bool CheckBox::init()
|
||||||
{
|
{
|
||||||
if (Widget::init())
|
if (Widget::init())
|
||||||
|
@ -102,7 +145,12 @@ void CheckBox::initRenderer()
|
||||||
addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1);
|
addProtectedChild(_frontCrossDisabledRenderer, FRONTCROSSDISABLED_RENDERER_Z, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextures(const char *backGround, const char *backGroundSelected, const char *cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType)
|
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)
|
||||||
{
|
{
|
||||||
loadTextureBackGround(backGround,texType);
|
loadTextureBackGround(backGround,texType);
|
||||||
loadTextureBackGroundSelected(backGroundSelected,texType);
|
loadTextureBackGroundSelected(backGroundSelected,texType);
|
||||||
|
@ -111,9 +159,9 @@ void CheckBox::loadTextures(const char *backGround, const char *backGroundSelect
|
||||||
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
|
loadTextureFrontCrossDisabled(frontCrossDisabled,texType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texType)
|
void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResType texType)
|
||||||
{
|
{
|
||||||
if (!backGround || strcmp(backGround, "") == 0)
|
if (backGround.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -137,9 +185,9 @@ void CheckBox::loadTextureBackGround(const char *backGround,TextureResType texTy
|
||||||
updateRGBAToRenderer(_backGroundBoxRenderer);
|
updateRGBAToRenderer(_backGroundBoxRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,TextureResType texType)
|
void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType)
|
||||||
{
|
{
|
||||||
if (!backGroundSelected || strcmp(backGroundSelected, "") == 0)
|
if (backGroundSelected.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -163,9 +211,9 @@ void CheckBox::loadTextureBackGroundSelected(const char *backGroundSelected,Text
|
||||||
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
|
updateRGBAToRenderer(_backGroundSelectedBoxRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
|
void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType texType)
|
||||||
{
|
{
|
||||||
if (!cross || strcmp(cross, "") == 0)
|
if (cross.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -189,9 +237,9 @@ void CheckBox::loadTextureFrontCross(const char *cross,TextureResType texType)
|
||||||
updateRGBAToRenderer(_frontCrossRenderer);
|
updateRGBAToRenderer(_frontCrossRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,TextureResType texType)
|
void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType)
|
||||||
{
|
{
|
||||||
if (!backGroundDisabled || strcmp(backGroundDisabled, "") == 0)
|
if (backGroundDisabled.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -215,9 +263,9 @@ void CheckBox::loadTextureBackGroundDisabled(const char *backGroundDisabled,Text
|
||||||
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
|
updateRGBAToRenderer(_backGroundBoxDisabledRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::loadTextureFrontCrossDisabled(const char *frontCrossDisabled,TextureResType texType)
|
void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType)
|
||||||
{
|
{
|
||||||
if (!frontCrossDisabled || strcmp(frontCrossDisabled, "") == 0)
|
if (frontCrossDisabled.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,26 @@ public:
|
||||||
*/
|
*/
|
||||||
static CheckBox* create();
|
static CheckBox* create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create an checkbox
|
||||||
|
*
|
||||||
|
* @param backGround backGround texture.
|
||||||
|
*
|
||||||
|
* @param backGroundSelected backGround selected state texture.
|
||||||
|
*
|
||||||
|
* @param cross cross texture.
|
||||||
|
*
|
||||||
|
* @param frontCrossDisabled cross dark state texture.
|
||||||
|
*
|
||||||
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
|
*/
|
||||||
|
static CheckBox* create(const std::string& backGround,
|
||||||
|
const std::string& backGroundSeleted,
|
||||||
|
const std::string& cross,
|
||||||
|
const std::string& backGroundDisabled,
|
||||||
|
const std::string& frontCrossDisabled,
|
||||||
|
TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load textures for checkbox.
|
* Load textures for checkbox.
|
||||||
*
|
*
|
||||||
|
@ -78,7 +98,12 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
void loadTextures(const std::string& backGround,
|
||||||
|
const std::string& backGroundSelected,
|
||||||
|
const std::string& cross,
|
||||||
|
const std::string& backGroundDisabled,
|
||||||
|
const std::string& frontCrossDisabled,
|
||||||
|
TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load backGround texture for checkbox.
|
* Load backGround texture for checkbox.
|
||||||
|
@ -87,7 +112,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL);
|
void loadTextureBackGround(const std::string& backGround,TextureResType type = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load backGroundSelected texture for checkbox.
|
* Load backGroundSelected texture for checkbox.
|
||||||
|
@ -96,7 +121,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
void loadTextureBackGroundSelected(const std::string& backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load cross texture for checkbox.
|
* Load cross texture for checkbox.
|
||||||
|
@ -105,7 +130,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
void loadTextureFrontCross(const std::string&,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load backGroundDisabled texture for checkbox.
|
* Load backGroundDisabled texture for checkbox.
|
||||||
|
@ -114,7 +139,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
void loadTextureBackGroundDisabled(const std::string& backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load frontCrossDisabled texture for checkbox.
|
* Load frontCrossDisabled texture for checkbox.
|
||||||
|
@ -123,7 +148,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param texType @see UI_TEX_TYPE_LOCAL
|
* @param texType @see UI_TEX_TYPE_LOCAL
|
||||||
*/
|
*/
|
||||||
void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
void loadTextureFrontCrossDisabled(const std::string& frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets selcted state for checkbox.
|
* Sets selcted state for checkbox.
|
||||||
|
@ -161,6 +186,12 @@ public:
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
virtual bool init() override;
|
virtual bool init() override;
|
||||||
|
virtual bool init(const std::string& backGround,
|
||||||
|
const std::string& backGroundSeleted,
|
||||||
|
const std::string& cross,
|
||||||
|
const std::string& backGroundDisabled,
|
||||||
|
const std::string& frontCrossDisabled,
|
||||||
|
TextureResType texType = UI_TEX_TYPE_LOCAL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void initRenderer() override;
|
virtual void initRenderer() override;
|
||||||
|
|
|
@ -39,13 +39,17 @@ bool UICheckBoxTest::init()
|
||||||
_uiLayer->addChild(alert);
|
_uiLayer->addChild(alert);
|
||||||
|
|
||||||
// Create the checkbox
|
// Create the checkbox
|
||||||
CheckBox* checkBox = CheckBox::create();
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png",
|
||||||
checkBox->setTouchEnabled(true);
|
|
||||||
checkBox->loadTextures("cocosui/check_box_normal.png",
|
|
||||||
"cocosui/check_box_normal_press.png",
|
"cocosui/check_box_normal_press.png",
|
||||||
"cocosui/check_box_active.png",
|
"cocosui/check_box_active.png",
|
||||||
"cocosui/check_box_normal_disable.png",
|
"cocosui/check_box_normal_disable.png",
|
||||||
"cocosui/check_box_active_disable.png");
|
"cocosui/check_box_active_disable.png");
|
||||||
|
checkBox->setTouchEnabled(true);
|
||||||
|
// checkBox->loadTextures("cocosui/check_box_normal.png",
|
||||||
|
// "cocosui/check_box_normal_press.png",
|
||||||
|
// "cocosui/check_box_active.png",
|
||||||
|
// "cocosui/check_box_normal_disable.png",
|
||||||
|
// "cocosui/check_box_active_disable.png");
|
||||||
checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||||
|
|
||||||
checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));
|
checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent));
|
||||||
|
|
Loading…
Reference in New Issue