2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2014-03-11 17:13:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UICHECKBOX_H__
|
|
|
|
#define __UICHECKBOX_H__
|
|
|
|
|
2015-06-25 17:45:38 +08:00
|
|
|
#include "ui/UIAbstractCheckButton.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "ui/GUIExport.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-06-04 14:26:21 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-26 15:47:14 +08:00
|
|
|
* Checkbox is a specific type of two-states button that can be either checked or unchecked.
|
|
|
|
*/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_GUI_DLL CheckBox : public AbstractCheckButton
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
DECLARE_CLASS_GUI_INFO
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
public:
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* CheckBox event type, currently only "selected" and "unselected" event are cared.
|
|
|
|
*/
|
2014-05-09 16:04:55 +08:00
|
|
|
enum class EventType
|
|
|
|
{
|
|
|
|
SELECTED,
|
|
|
|
UNSELECTED
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which will be called after certain CheckBox event issue.
|
|
|
|
* @see `CheckBox::EventType`
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
typedef std::function<void(Ref*, CheckBox::EventType)> ccCheckBoxCallback;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Default constructor.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
CheckBox();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Default destructor.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
virtual ~CheckBox();
|
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create and return a empty CheckBox instance pointer.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
|
|
|
static CheckBox* create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-04-02 15:58:18 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Create an checkbox with various images.
|
2014-04-02 15:58:18 +08:00
|
|
|
*
|
|
|
|
* @param backGround backGround texture.
|
|
|
|
* @param backGroundSelected backGround selected state texture.
|
|
|
|
* @param cross cross texture.
|
2015-03-27 18:26:14 +08:00
|
|
|
* @param backGroundDisabled backGround disabled state texture.
|
2014-04-02 15:58:18 +08:00
|
|
|
* @param frontCrossDisabled cross dark state texture.
|
2015-03-25 18:17:58 +08:00
|
|
|
* @param texType @see `Widget::TextureResType`
|
2014-04-02 15:58:18 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @return A CheckBox instance pointer.
|
2014-04-02 15:58:18 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static CheckBox* create(std::string_view backGround,
|
|
|
|
std::string_view backGroundSelected,
|
|
|
|
std::string_view cross,
|
|
|
|
std::string_view backGroundDisabled,
|
|
|
|
std::string_view frontCrossDisabled,
|
2014-05-09 14:56:05 +08:00
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Another factory method to create a CheckBox instance.
|
|
|
|
* This method uses less resource to create a CheckBox.
|
|
|
|
* @param backGround The background image name in `std::string`.
|
|
|
|
* @param cross The cross image name in `std::string`.
|
|
|
|
* @param texType The texture's resource type in `Widget::TextureResType`.
|
|
|
|
* @return A CheckBox instance pointer
|
2014-12-23 15:03:31 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static CheckBox* create(std::string_view backGround,
|
|
|
|
std::string_view cross,
|
2015-06-30 19:31:31 +08:00
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
*Add a callback function which would be called when checkbox is selected or unselected.
|
|
|
|
*@param callback A std::function with type @see `ccCheckBoxCallback`
|
|
|
|
*/
|
2014-05-14 16:14:28 +08:00
|
|
|
void addEventListener(const ccCheckBoxCallback& callback);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// override functions
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
virtual void onTouchEnded(Touch* touch, Event* unusedEvent) override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2015-06-30 19:31:31 +08:00
|
|
|
virtual void dispatchSelectChangedEvent(bool selected) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
// if you use the old event callback, it will retain the _checkBoxEventListener
|
|
|
|
Ref* _checkBoxEventListener;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ccCheckBoxCallback _checkBoxEventCallback;
|
2014-03-11 17:13:54 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2015-03-25 18:17:58 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CocoGUI__CheckBox__) */
|