axmol/cocos/gui/UICheckBox.h

225 lines
7.3 KiB
C
Raw Normal View History

2013-09-13 22:20:20 +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.
****************************************************************************/
2013-09-13 22:20:20 +08:00
#ifndef __UICHECKBOX_H__
#define __UICHECKBOX_H__
#include "gui/UIWidget.h"
2013-09-13 22:20:20 +08:00
2013-12-23 15:02:52 +08:00
NS_CC_BEGIN
namespace ui {
2013-09-13 22:20:20 +08:00
typedef enum
{
CHECKBOX_STATE_EVENT_SELECTED,
CHECKBOX_STATE_EVENT_UNSELECTED
}CheckBoxEventType;
typedef void (Ref::*SEL_SelectedStateEvent)(Ref*,CheckBoxEventType);
#define checkboxselectedeventselector(_SELECTOR) (SEL_SelectedStateEvent)(&_SELECTOR)
2013-09-13 22:20:20 +08:00
2013-12-23 15:02:52 +08:00
/**
* @js NA
* @lua NA
*/
class CheckBox : public Widget
2013-09-13 22:20:20 +08:00
{
public:
/**
* Default constructor
*/
2013-12-23 15:02:52 +08:00
CheckBox();
2013-09-13 22:20:20 +08:00
/**
* Default destructor
*/
2013-12-23 15:02:52 +08:00
virtual ~CheckBox();
2013-09-13 22:20:20 +08:00
/**
* Allocates and initializes.
*/
2013-12-23 15:02:52 +08:00
static CheckBox* create();
2013-09-13 22:20:20 +08:00
/**
* Load textures for 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
*/
void loadTextures(const char* backGround,const char* backGroundSelected,const char* cross,const char* backGroundDisabled,const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Load backGround texture for checkbox.
*
* @param backGround backGround texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGround(const char* backGround,TextureResType type = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Load backGroundSelected texture for checkbox.
*
* @param backGroundSelected backGround selected state texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGroundSelected(const char* backGroundSelected,TextureResType texType = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Load cross texture for checkbox.
*
* @param cross cross texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureFrontCross(const char* cross,TextureResType texType = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Load backGroundDisabled texture for checkbox.
*
* @param backGroundDisabled backGroundDisabled texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureBackGroundDisabled(const char* backGroundDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Load frontCrossDisabled texture for checkbox.
*
* @param frontCrossDisabled frontCrossDisabled texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureFrontCrossDisabled(const char* frontCrossDisabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
2013-09-13 22:20:20 +08:00
/**
* Sets selcted state for checkbox.
*
* @param selected true that checkbox is selected, false otherwise.
*/
void setSelectedState(bool selected);
2013-09-13 22:20:20 +08:00
/**
* Gets selcted state of checkbox.
*
* @return selected true that checkbox is selected, false otherwise.
*/
bool getSelectedState();
2013-09-13 22:20:20 +08:00
//override "setAnchorPoint" method of widget.
2013-12-23 15:02:52 +08:00
virtual void setAnchorPoint(const Point &pt) override;
2013-09-13 22:20:20 +08:00
//add a call back function would called when checkbox is selected or unselected.
void addEventListenerCheckBox(Ref* target,SEL_SelectedStateEvent selector);
//override "setFlippedX" method of widget.
virtual void setFlippedX(bool flippedX) override;
//override "setFlippedY" method of widget.
virtual void setFlippedY(bool flippedY) override;
//override "isFlippedX" method of widget.
virtual bool isFlippedX() override;
//override "isFlippedY" method of widget.
virtual bool isFlippedY() override;
/** @deprecated Use isFlippedX() instead */
CC_DEPRECATED_ATTRIBUTE bool isFlipX() { return isFlippedX(); };
/** @deprecated Use setFlippedX() instead */
CC_DEPRECATED_ATTRIBUTE void setFlipX(bool flipX) { setFlippedX(flipX); };
/** @deprecated Use isFlippedY() instead */
CC_DEPRECATED_ATTRIBUTE bool isFlipY() { return isFlippedY(); };
/** @deprecated Use setFlippedY() instead */
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); };
2013-12-23 15:02:52 +08:00
//override "onTouchEnded" method of widget.
virtual void onTouchEnded(Touch *touch, Event *unusedEvent);
2013-09-13 22:20:20 +08:00
//override "getContentSize" method of widget.
2013-12-23 15:02:52 +08:00
virtual const Size& getContentSize() const override;
2013-09-13 22:20:20 +08:00
//override "getVirtualRenderer" method of widget.
2013-12-23 15:02:52 +08:00
virtual Node* getVirtualRenderer() override;
2013-09-17 17:59:20 +08:00
/**
* Returns the "class name" of widget.
*/
2013-12-23 15:02:52 +08:00
virtual std::string getDescription() const override;
2013-11-06 16:04:06 +08:00
2013-09-13 22:20:20 +08:00
protected:
2013-11-14 13:42:10 +08:00
virtual bool init() override;
virtual void initRenderer() override;
virtual void onPressStateChangedToNormal() override;
virtual void onPressStateChangedToPressed() override;
virtual void onPressStateChangedToDisabled() override;
2013-09-13 22:20:20 +08:00
void selectedEvent();
void unSelectedEvent();
2013-11-14 13:42:10 +08:00
virtual void onSizeChanged() override;
2013-09-13 22:20:20 +08:00
void backGroundTextureScaleChangedWithSize();
void backGroundSelectedTextureScaleChangedWithSize();
void frontCrossTextureScaleChangedWithSize();
void backGroundDisabledTextureScaleChangedWithSize();
void frontCrossDisabledTextureScaleChangedWithSize();
2013-12-23 15:02:52 +08:00
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
2013-09-13 22:20:20 +08:00
protected:
2013-12-23 15:02:52 +08:00
Sprite* _backGroundBoxRenderer;
Sprite* _backGroundSelectedBoxRenderer;
Sprite* _frontCrossRenderer;
Sprite* _backGroundBoxDisabledRenderer;
Sprite* _frontCrossDisabledRenderer;
2013-09-16 20:54:13 +08:00
bool _isSelected;
2013-09-13 22:20:20 +08:00
Ref* _checkBoxEventListener;
2013-11-08 18:43:06 +08:00
SEL_SelectedStateEvent _checkBoxEventSelector;
2013-09-16 20:54:13 +08:00
TextureResType _backGroundTexType;
TextureResType _backGroundSelectedTexType;
TextureResType _frontCrossTexType;
TextureResType _backGroundDisabledTexType;
TextureResType _frontCrossDisabledTexType;
2013-11-06 16:04:06 +08:00
std::string _backGroundFileName;
std::string _backGroundSelectedFileName;
std::string _frontCrossFileName;
std::string _backGroundDisabledFileName;
std::string _frontCrossDisabledFileName;
2013-09-13 22:20:20 +08:00
};
}
2013-09-13 22:20:20 +08:00
2013-12-23 15:02:52 +08:00
NS_CC_END
#endif /* defined(__CocoGUI__CheckBox__) */