2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#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
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_BEGIN
|
2014-06-04 14:26:21 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
namespace ui {
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* Checkbox event type, there are two type here:
|
|
|
|
* - selected state
|
|
|
|
* - unselected state
|
|
|
|
* @deprecated use `CheckBox::EventType` instead
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef enum
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CHECKBOX_STATE_EVENT_SELECTED,
|
|
|
|
CHECKBOX_STATE_EVENT_UNSELECTED
|
2015-06-25 17:45:38 +08:00
|
|
|
} CheckBoxEventType;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which will be called after checkbox event happens.
|
|
|
|
* @deprecated use `CheckBox::ccCheckBoxCallback` instead.
|
|
|
|
*/
|
2014-07-10 00:45:27 +08:00
|
|
|
typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType);
|
2014-03-11 17:13:54 +08:00
|
|
|
#define checkboxselectedeventselector(_SELECTOR) (SEL_SelectedStateEvent)(&_SELECTOR)
|
|
|
|
|
|
|
|
/**
|
2015-03-26 15:47:14 +08:00
|
|
|
* Checkbox is a specific type of two-states button that can be either checked or unchecked.
|
|
|
|
*/
|
2015-06-25 17:45:38 +08:00
|
|
|
class CC_GUI_DLL CheckBox : public AbstractCheckButton
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
DECLARE_CLASS_GUI_INFO
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**
|
|
|
|
* A callback which will be called after certain CheckBox event issue.
|
|
|
|
* @see `CheckBox::EventType`
|
|
|
|
*/
|
2014-05-09 16:04:55 +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.
|
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.
|
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();
|
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
|
|
|
*/
|
|
|
|
static CheckBox* create(const std::string& backGround,
|
2015-03-27 17:09:54 +08:00
|
|
|
const std::string& backGroundSelected,
|
2014-04-02 15:58:18 +08:00
|
|
|
const std::string& cross,
|
|
|
|
const std::string& backGroundDisabled,
|
|
|
|
const std::string& frontCrossDisabled,
|
2014-05-09 14:56:05 +08:00
|
|
|
TextureResType texType = TextureResType::LOCAL);
|
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
|
|
|
*/
|
|
|
|
static CheckBox* create(const std::string& backGround,
|
|
|
|
const std::string& 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
|
|
|
* Change Checkbox state to selected.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `isSelected()` instead
|
|
|
|
* @param selected True means the Checkbox will be selected, false means unselected.
|
2014-03-11 17:13:54 +08:00
|
|
|
*/
|
2014-08-15 15:26:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void setSelectedState(bool selected){this->setSelected(selected);}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-25 18:17:58 +08:00
|
|
|
* Query whether the CheckBox is selected or not.
|
2014-03-11 17:13:54 +08:00
|
|
|
*
|
2015-03-25 18:17:58 +08:00
|
|
|
* @deprecated use `setSelected(bool)` instead.
|
2014-03-11 17:13:54 +08:00
|
|
|
* @return selected true that checkbox is selected, false otherwise.
|
|
|
|
*/
|
2014-08-15 15:26:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE bool getSelectedState()const{return this->isSelected();}
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
/**Add a callback function which would be called when checkbox is selected or unselected.
|
|
|
|
*@deprecated use `addEventListener(const ccCheckBoxCallback&)` instead
|
|
|
|
*@param target A pointer type in Ref*.
|
|
|
|
*@param selector A member function pointer in SEL_SelectedStateEvent.
|
|
|
|
*/
|
2014-05-09 16:04:55 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector);
|
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
|
|
|
|
|
|
|
|
2015-03-25 18:17:58 +08:00
|
|
|
//override functions
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual std::string getDescription() const override;
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2015-06-30 19:31:31 +08:00
|
|
|
virtual void releaseUpEvent() override;
|
|
|
|
|
|
|
|
virtual void dispatchSelectChangedEvent(bool selected) override;
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
virtual Widget* createCloneInstance() override;
|
|
|
|
virtual void copySpecialProperties(Widget* model) override;
|
2015-06-30 19:31:31 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
protected:
|
2014-05-09 16:04:55 +08:00
|
|
|
//if you use the old event callback, it will retain the _checkBoxEventListener
|
2014-03-11 17:13:54 +08:00
|
|
|
Ref* _checkBoxEventListener;
|
2014-05-09 18:37:22 +08:00
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
2014-03-11 17:13:54 +08:00
|
|
|
SEL_SelectedStateEvent _checkBoxEventSelector;
|
2014-05-09 18:37:22 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
|
2014-05-09 16:04:55 +08:00
|
|
|
ccCheckBoxCallback _checkBoxEventCallback;
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-26 15:47:14 +08:00
|
|
|
NS_CC_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__) */
|