本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-X 节点(Layout.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
获取 widget 的尺寸,添加移除背景尺寸
///cocos2d-x-3.0alpha0/extensions/CocoStudio/GUI/Layouts
// 获取 widget 的尺寸,添加移除背景尺寸
#ifndef __LAYOUT_H__
#define __LAYOUT_H__
#include "../BaseClasses/UIWidget.h"
#include "LayoutExecutant.h"
NS_CC_EXT_BEGIN
typedef enum
{
LAYOUT_COLOR_NONE,
LAYOUT_COLOR_SOLID,
LAYOUT_COLOR_GRADIENT
}LayoutBackGroundColorType;
class Layout : public UIWidget
{
public:
/**
* Default constructor
*/
Layout();
/**
* Default destructor
*/
virtual ~Layout();
/**
* 分配并初始化一个 layout.
*/
static Layout* create();
/**
* 设置一个LayoutExecutant做布局。 //布局执行者
*
* @see LayoutExecutant
*
* @param LayoutExecutant pointer.
*/
virtual void setLayoutExecutant(LayoutExecutant* exe);
virtual LayoutExecutant* getLayoutExecutant() const;
//覆盖 widget 的 "hitTest" 方法.
virtual bool hitTest(const Point &pt);
//background 后台
/**
* 设置布局的背景图像
*
* @param fileName image 文件路径.
*
* @param texType @see TextureResType. UI_TEX_TYPE_LOCAL 意味着本地文件, UI_TEX_TYPE_PLIST 意味着 sprite 帧.
*/
void setBackGroundImage(const char* fileName,TextureResType texType = UI_TEX_TYPE_LOCAL);
/**
*
* 如果背景图像是一个scale9渲染,设置布局的背景图像(capinsets)
* @param capinsets of background image.
*
*/
void setBackGroundImageCapInsets(const Rect& capInsets);
/**
* 为 layout 设置颜色类型.
*
* @param type @see LayoutBackGroundColorType.
*/
void setBackGroundColorType(LayoutBackGroundColorType type);
/**
* 设置背景图片使用 scale9 渲染.
*
* @param enabled true that use scale9 renderer(渲染), false otherwise.
*/
void setBackGroundImageScale9Enabled(bool enabled);
/**
*
* 如果颜色类型是 LAYOUT_COLOR_SOLID, 为 layout 设置颜色类型.
* @param color
*/
void setBackGroundColor(const Color3B &color);
/**如果颜色类型是 LAYOUT_COLOR_GRADIENT 为 layout 设置颜色类型.
*
*
* @param start color
*
* @param end color
*/
void setBackGroundColor(const Color3B &startColor, const Color3B &endColor);
/**
* Sets background opacity layout.
*
* @param opacity
*/
void setBackGroundColorOpacity(int opacity);
/** 如果颜色类型是 LAYOUT_COLOR_GRADIENT 为 layout 设置颜色矢量.
*
*
* @param vector
*/
void setBackGroundColorVector(const Point &vector);
//override "setColor" method of widget. //覆盖
virtual void setColor(const Color3B &color);
//override "setOpacity" method of widget.. //覆盖
virtual void setOpacity(int opacity);
/**
* 移除 layout 的背景图片.
*/
void removeBackGroundImage();
/**
* Gets 背景图片的texture 尺寸.
*
* @return background image texture size.
*/
const Size& getBackGroundImageTextureSize() const;
/**
*
* 如果 layout 可以 CLIP(剪辑)也就是说它包含 child 那么就改变它
* 如果你真的需要这个,请启用该功能。但它会降低渲染效率。
*
* @param clipping enabled.
*/
virtual void setClippingEnabled(bool able);
/**
* layout clipping(剪辑)是否启用了.
*
* @return if layout is clipping enabled.
*/
virtual bool isClippingEnabled();
/**
* 获取这个 widget 内容尺寸.
*
* Content size is widget's texture size.
*/
virtual const Size& getContentSize() const;
/**
* Returns the "class name" of widget.
*/
virtual const char* getDescription() const;
protected:
//override "init" method of widget. //覆盖
virtual bool init();
//override "initRenderer" method of widget. //覆盖
virtual void initRenderer();
//override "onSizeChanged" method of widget. //覆盖
virtual void onSizeChanged();
//init background image renderer.
void addBackGroundImage();
protected:
bool _clippingEnabled;
LayoutExecutant* _layoutExecutant;
//background
bool _backGroundScale9Enabled;
Node* _backGroundImage;
std::string _backGroundImageFileName;
Rect _backGroundImageCapInsets;
LayoutBackGroundColorType _colorType;
TextureResType _bgImageTexType;
LayerColor* _colorRender;
LayerGradient* _gradientRender;
Color3B _cColor;
Color3B _gStartColor;
Color3B _gEndColor;
Point _alongVector;
int _cOpacity;
Size _backGroundImageTextureSize;
};
class RectClippingNode : public ClippingNode
{
public:
virtual ~RectClippingNode();
virtual bool init();
static RectClippingNode* create();
void setClippingSize(const Size& size);
void setClippingEnabled(bool enabled);
virtual void visit();
void setEnabled(bool enabled);
bool isEnabled() const;
protected:
DrawNode* m_pInnerStencil;
bool _enabled;
private:
RectClippingNode();
Point rect[4];
Size _clippingSize;
bool _clippingEnabled;
};
NS_CC_EXT_END
#endif /* defined(__Layout__) */