本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-X 节点(UIButton.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
///cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/UIWidgets
#ifndef __UIBUTTON_H__
#define __UIBUTTON_H__
#include "../BaseClasses/UIWidget.h"
NS_CC_EXT_BEGIN
class UIButton : public UIWidget
{
public:
/**
* Default constructor
*/
UIButton();
/**
* Default destructor
*/
virtual ~UIButton();
/**
* Allocates and initializes.
*/
static UIButton* create();
/**
* Load textures for button. //为 button 加载 textures
*
* @param normal 正常状态下的 texture.
*
* @param selected 选择状态下的 texture.
*
* @param disabled dark state texture. //禁用状态下的 texture
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextures(const char* normal,const char* selected,const char* disabled,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load normal state texture for button. 为 button 加载正常状态下的 texture
*
* @param normal 正常状态下的 texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureNormal(const char* normal, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load selected state texture for button. 为button 加载选择状态下的 texture
*
* @param selected selected state texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTexturePressed(const char* selected, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* Load dark state texture for button. //为 button 加载 禁用状态下的 texture
*
* @param disabled dark state texture.
*
* @param texType @see UI_TEX_TYPE_LOCAL
*/
void loadTextureDisabled(const char* disabled, TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
* 如果 button使用 scale9 渲染, 设置 button 的 capinsets
*
* @param capInsets capinsets for button
*/
void setCapInsets(const Rect &capInsets);
/**
* 如果 button使用 scale9 渲染, 设置 button 的 capinsets
*
* @param capInsets capinsets for button
*/
void setCapInsetsNormalRenderer(const Rect &capInsets);
/**
* 如果 button使用 scale9 渲染, 设置 button 的 capinsets
*
* @param capInsets capinsets for button
*/
void setCapInsetsPressedRenderer(const Rect &capInsets);
/**
* 如果 button使用 scale9 渲染, 设置 button 的 capinsets
*
* @param capInsets capinsets for button
*/
void setCapInsetsDisabledRenderer(const Rect &capInsets);
//override "setAnchorPoint" of widget. 重载 widget 的 setAnchorPoint 方法
virtual void setAnchorPoint(const Point &pt);
/**
* 如果 button使用 scale9 渲染 那么就设置
*
* @param true 使用了 scale9 渲染, false otherwise.
*/
virtual void setScale9Enabled(bool able);
//override "setFlipX" of widget.
virtual void setFlipX(bool flipX);
//override "setFlipY" of widget.
virtual void setFlipY(bool flipY);
//override "isFlipX" of widget.
virtual bool isFlipX();
//override "isFlipY" of widget.
virtual bool isFlipY();
/**
* 如果 button 有点击放大效果,那么就使用该效果
*
* @param true 有 clicked 放大效果, false otherwise.
*/
void setPressedActionEnabled(bool enabled);
//override "ignoreContentAdaptWithSize" method of widget.
virtual void ignoreContentAdaptWithSize(bool ignore);
//override "getContentSize" method of widget.
virtual const Size& getContentSize() const;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer();
/**
* Sets color to widget 设置 widget 的颜色
* 默认情况下也改变 widget's children 的颜色
*
*
* @param color
*/
virtual void setColor(const Color3B &color);
void setTitleText(const char* text);
const char* getTitleText() const;
void setTitleColor(const Color3B& color);
const Color3B& getTitleColor() const;
void setTitleFontSize(float size);
float getTitleFontSize() const;
void setTitleFontName(const char* fontName);
const char* getTitleFontName() const;
/**
* Returns the "class name" of widget. //返回 widget的 名字
*/
virtual const char* getDescription() const;
protected:
virtual bool init();
virtual void initRenderer();
virtual void onPressStateChangedToNormal();
virtual void onPressStateChangedToPressed();
virtual void onPressStateChangedToDisabled();
virtual void onSizeChanged();
void normalTextureScaleChangedWithSize();
void pressedTextureScaleChangedWithSize();
void disabledTextureScaleChangedWithSize();
protected:
Node* _buttonNormalRenderer;
Node* _buttonClickedRenderer;
Node* _buttonDisableRenderer;
LabelTTF* _titleRenderer;
std::string _normalFileName;
std::string _clickedFileName;
std::string _disabledFileName;
bool _prevIgnoreSize;
bool _scale9Enabled;
Rect _capInsetsNormal;
Rect _capInsetsPressed;
Rect _capInsetsDisabled;
TextureResType _normalTexType;
TextureResType _pressedTexType;
TextureResType _disabledTexType;
Size _normalTextureSize;
Size _pressedTextureSize;
Size _disabledTextureSize;
bool _pressedActionEnabled;
Color3B _titleColor;
};
NS_CC_EXT_END
#endif /* defined(__CocoGUI__UIButton__) */