Cocos2d-x源码分析之2d/ui/UILayout
_clippingRectDirty(true)。
const kmMat4 parentTransform。
0, clippingRect.origin.y, 如果颜色类型是固定的*/void setBackGroundColor(const Color3B color);const Color3B getBackGroundColor();/**设置背景颜色, parentTransform,//线性 垂直LAYOUT_LINEAR_HORIZONTAL, parentTransformUpdated);//专属自己的visitbreak;default:break;}}else//不可以裁切 基本的visit{ProtectedNode::visit(renderer, BACKGROUNDIMAGE_Z, this);renderer-addCommand(_beforeVisitCmdScissor);ProtectedNode::visit(renderer,_backGroundImageOpacity(255),_backGroundImageTextureSize(Size::ZERO),_clippingParent(nullptr), GL_KEEP。
const kmMat4 parentTransform, dirty);elsebreak;}//// draw self//this-draw(renderer, _currentStencilRef);glGetIntegerv(GL_STENCIL_VALUE_MASK,_backGroundImageColor(Color3B::WHITE), parentTransform。
finalPosY));layoutParameter-_put = true;unlayoutChildCount--;}}}widgetChildren.clear();}//渲染层Zorderstatic const int BACKGROUNDIMAGE_Z = (-1);static const int BCAKGROUNDCOLORRENDERER_Z = (-2);static GLint g_sStencilBits = -1;static GLint s_layer = -1;IMPLEMENT_CLASS_GUI_INFO(Layout)Layout::Layout():_clippingEnabled(false), Color4F(1。
_currentStencilPassDepthFail(GL_KEEP),_currentDepthWriteMask(GL_TRUE), BCAKGROUNDCOLORRENDERER_Z, BACKGROUNDIMAGE_Z,_backGroundImageFileName(), -1);}//位置居中_backGroundImage-setPosition(Point(_size.width/2.0f, this);renderer-addCommand(_beforeVisitCmdStencil);_clippingStencil-visit(renderer, VectorNode* container);};LayoutExecutant* LayoutExecutant::create(){LayoutExecutant* exe = new LayoutExecutant();if (exe){exe-autorelease();return exe;}CC_SAFE_DELETE(exe);return nullptr;}LinearVerticalLayoutExecutant* LinearVerticalLayoutExecutant::create(){LinearVerticalLayoutExecutant* exe = new LinearVerticalLayoutExecutant();if (exe){exe-autorelease();return exe;}CC_SAFE_DELETE(exe);return nullptr;}LinearHorizontalLayoutExecutant* LinearHorizontalLayoutExecutant::create(){LinearHorizontalLayoutExecutant* exe = new LinearHorizontalLayoutExecutant();if (exe){exe-autorelease();return exe;}CC_SAFE_DELETE(exe);return nullptr;}RelativeLayoutExecutant* RelativeLayoutExecutant::create(){RelativeLayoutExecutant* exe = new RelativeLayoutExecutant();if (exe){exe-autorelease();return exe;}CC_SAFE_DELETE(exe);return nullptr;}//线性垂直 布局执行者void LinearVerticalLayoutExecutant::doLayout(const cocos2d::Size layoutSize。
//线性 水平LAYOUT_RELATIVE// 平面}LayoutType;//容器类型typedef enum {LAYOUT_CLIPPING_STENCIL, Vectorcocos2d::Node * container){float leftBoundary = 0.0f;for (auto subWidget : container){Widget* child = dynamic_castWidget*(subWidget);if (child){LinearLayoutParameter* layoutParameter = dynamic_castLinearLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_LINEAR));if (layoutParameter){LinearGravity childGravity = layoutParameter-getGravity();Point ap = child-getAnchorPoint();Size cs = child-getSize();float finalPosX = leftBoundary + (ap.x * cs.width);float finalPosY = layoutSize.height - (1.0f - ap.y) * cs.height;switch (childGravity){case LINEAR_GRAVITY_NONE:case LINEAR_GRAVITY_TOP:break;case LINEAR_GRAVITY_BOTTOM:finalPosY = ap.y * cs.height;break;case LINEAR_GRAVITY_CENTER_VERTICAL:finalPosY = layoutSize.height / 2.0f - cs.height * (0.5f - ap.y);break;default:break;}Margin mg = layoutParameter-getMargin();finalPosX += mg.left;finalPosY -= mg.top;child-setPosition(Point(finalPosX,_currentStencilPassDepthPass(GL_KEEP), parentTransformUpdated);}}void Layout::sortAllChildren(){Widget::sortAllChildren();//排序子节点doLayout();//布局}//模板类型裁切void Layout::stencilClippingVisit(Renderer *renderer, tag);//添加child_doLayoutDirty = true;}void Layout::removeChild(Node *child, int tag) override;virtual void visit(Renderer *renderer, dirty);//// draw children and protectedChildren zOrder = 0//for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)(*it)-visit(renderer,_gEndColor(Color3B::WHITE),_backGroundImageCapInsets(Rect::ZERO)。
this);renderer-addCommand(_afterVisitCmdScissor);}void Layout::setClippingEnabled(bool able){if (able == _clippingEnabled)//默认不能裁切 若和当前值相同 说明设置过 不必再详加判断 防止外部调用多次出现 不必要的重复逻辑{return;}_clippingEnabled = able;//是否可以裁切switch (_clippingType){case LAYOUT_CLIPPING_STENCIL://裁切类型为 模板if (able)//若能裁切{static bool once = true;if (once){glGetIntegerv(GL_STENCIL_BITS,//绝对LAYOUT_LINEAR_VERTICAL, this);renderer-addCommand(_afterVisitCmdStencil);renderer-popGroup();kmGLPopMatrix();}void Layout::onBeforeVisitStencil(){s_layer++;GLint mask_layer = 0x1 s_layer;GLint mask_layer_l = mask_layer - 1;_mask_layer_le = mask_layer | mask_layer_l;_currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST);glGetIntegerv(GL_STENCIL_WRITEMASK, mask_layer);glStencilOp(GL_REPLACE,_clippingRect(Rect::ZERO), 1));kmGLMatrixMode(KM_GL_PROJECTION);kmGLPopMatrix();kmGLMatrixMode(KM_GL_MODELVIEW);kmGLPopMatrix();glStencilFunc(GL_NEVER。
(GLint *)_currentStencilPassDepthFail);glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS。
bool cleanup){Widget::removeChild(child, )){for (auto sWidget : widgetChildren){if (sWidget){RelativeLayoutParameter* rlayoutParameter = dynamic_castRelativeLayoutParameter*(sWidget-getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));if (rlayoutParameter strcmp(rlayoutParameter-getRelativeName()。
_modelViewTransform。
getChildren());}_doLayoutDirty = false;//布局完成}std::string Layout::getDescription() const{return Layout;}Widget* Layout::createCloneInstance(){return Layout::create();}void Layout::copyClonedWidgetChildren(Widget* model){Widget::copyClonedWidgetChildren(model);}//克隆属性void Layout::copySpecialProperties(Widget *widget){Layout* layout = dynamic_castLayout*(widget);if (layout){setBackGroundImageScale9Enabled(layout-_backGroundScale9Enabled);setBackGroundImage(layout-_backGroundImageFileName。
_backGroundScale9Enabled(false), (GLint *)_currentStencilFail);glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, Point(1, bool parentTransformUpdated);/**镂空类型的裁切渲染*/void scissorClippingVisit(Renderer *renderer, (GLint *)_currentStencilFunc);glGetIntegerv(GL_STENCIL_REF。
int zOrder,_currentStencilWriteMask(~0), -1);break;case LAYOUT_COLOR_GRADIENT:_gradientRender = LayerGradient::create();_gradientRender-setContentSize(_size);_gradientRender-setOpacity(_cOpacity);_gradientRender-setStartColor(_gStartColor);_gradientRender-setEndColor(_gEndColor);_gradientRender-setVector(_alongVector);addProtectedChild(_gradientRender, _size.height/2.0f));}void Layout::removeBackGroundImage(){if (!_backGroundImage){return;}//移除背景图 置空背景图及相关属性removeProtectedChild(_backGroundImage);_backGroundImage = nullptr;_backGroundImageFileName = ;_backGroundImageTextureSize = Size::ZERO;}void Layout::setBackGroundColorType(LayoutBackGroundColorType type){if (_colorType == type){return;}switch (_colorType)//移除渲染层{case LAYOUT_COLOR_NONE:if (_colorRender){removeProtectedChild(_colorRender);_colorRender = nullptr;}if (_gradientRender){removeProtectedChild(_gradientRender);_gradientRender = nullptr;}break;case LAYOUT_COLOR_SOLID:if (_colorRender){removeProtectedChild(_colorRender);_colorRender = nullptr;}break;case LAYOUT_COLOR_GRADIENT:if (_gradientRender){removeProtectedChild(_gradientRender);_gradientRender = nullptr;}break;default:break;}_colorType = type;//重置渲染层switch (_colorType){case LAYOUT_COLOR_NONE:break;case LAYOUT_COLOR_SOLID:_colorRender = LayerColor::create();_colorRender-setContentSize(_size);_colorRender-setOpacity(_cOpacity);_colorRender-setColor(_cColor);addProtectedChild(_colorRender, _size.height/2.0f));if (_backGroundScale9Enabled _backGroundImage){//若使用九宫格 设置透明度static_castextension::Scale9Sprite*(_backGroundImage)-setPreferredSize(_size);}}//设置渲染器的渲染区域大小if (_colorRender){_colorRender-setContentSize(_size);}if (_gradientRender){_gradientRender-setContentSize(_size);}}void Layout::setBackGroundImageScale9Enabled(bool able){if (_backGroundScale9Enabled == able){return;}removeProtectedChild(_backGroundImage);_backGroundImage = nullptr;//置空背景_backGroundScale9Enabled = able;addBackGroundImage();//添加背景 设置背景属性setBackGroundImage(_backGroundImageFileName, green);//花多边形}}//得到裁切的矩形const Rect Layout::getClippingRect(){if (_clippingRectDirty){Point worldPos = convertToWorldSpace(Point::ZERO);//世界坐标AffineTransform t = getNodeToWorldAffineTransform();//仿射旋转float scissorWidth = _size.width*t.a;//裁切宽度float scissorHeight = _size.height*t.d;//裁切高度Rect parentClippingRect;//父节点裁切矩形Layout* parent = this;//从自己开始while (parent){parent = dynamic_castLayout*(parent-getParent());if(parent)//存在layout的父节点{if (parent-isClippingEnabled())//若该节点可以裁切{_clippingParent = parent;//保存裁切节点break;}}}if (_clippingParent)//如果找到裁切父节点{parentClippingRect = _clippingParent-getClippingRect();//得到裁切矩形范围float finalX = worldPos.x - (scissorWidth * _anchorPoint.x);float finalY = worldPos.y - (scissorHeight * _anchorPoint.y);float finalWidth = scissorWidth;float finalHeight = scissorHeight;//计算得出裁切范围float leftOffset = worldPos.x - parentClippingRect.origin.x;if (leftOffset 0.0f){finalX = parentClippingRect.origin.x;finalWidth += leftOffset;}float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width);if (rightOffset 0.0f){finalWidth -= rightOffset;}float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height);if (topOffset 0.0f){finalHeight -= topOffset;}float bottomOffset = worldPos.y - parentClippingRect.origin.y;if (bottomOffset 0.0f){finalY = parentClippingRect.origin.x;finalHeight += bottomOffset;}if (finalWidth 0.0f){finalWidth = 0.0f;}if (finalHeight 0.0f){finalHeight = 0.0f;}_clippingRect.origin.x = finalX;_clippingRect.origin.y = finalY;_clippingRect.size.width = finalWidth;_clippingRect.size.height = finalHeight;}else{_clippingRect.origin.x = worldPos.x - (scissorWidth * _anchorPoint.x);_clippingRect.origin.y = worldPos.y - (scissorHeight * _anchorPoint.y);_clippingRect.size.width = scissorWidth;_clippingRect.size.height = scissorHeight;}_clippingRectDirty = false;//置为不可裁切}return _clippingRect;}void Layout::onSizeChanged(){Widget::onSizeChanged();setStencilClippingSize(_size);//设置裁切范围_doLayoutDirty = true;//开启布局_clippingRectDirty = true;//允许计算裁切区域if (_backGroundImage)//若背景存在{//设置背景位置居中_backGroundImage-setPosition(Point(_size.width/2.0f。
0,// but it is deprecated and your code should not rely on itkmGLPushMatrix();kmGLLoadMatrix(_modelViewTransform);//Add group command_groupCommand.init(_globalZOrder);renderer-addCommand(_groupCommand);renderer-pushGroup(_groupCommand.getRenderQueueID());_beforeVisitCmdStencil.init(_globalZOrder);_beforeVisitCmdStencil.func = CC_CALLBACK_0(Layout::onBeforeVisitStencil, GL_KEEP);}void Layout::onAfterVisitStencil(){glStencilFunc(_currentStencilFunc, parentTransformUpdated);//专属自己的visitbreak;case LAYOUT_CLIPPING_SCISSOR://镂空scissorClippingVisit(renderer。
this);renderer-addCommand(_afterDrawStencilCmd);int i = 0;// used by _childrenint j = 0;// used by _protectedChildrensortAllChildren();sortAllProtectedChildren();//// draw children and protectedChildren zOrder 0//for( ; i _children.size(); i++ ){auto node = _children.at(i);if ( node node-getLocalZOrder() 0 )node-visit(renderer,_cOpacity(255), bool cleanup = true) override;virtual void removeAllChildren() override;/*** Removes all children from the container, dirty);for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)(*it)-visit(renderer,_layoutType(LAYOUT_ABSOLUTE), parentTransformUpdated);_afterVisitCmdScissor.init(_globalZOrder);_afterVisitCmdScissor.func = CC_CALLBACK_0(Layout::onAfterVisitScissor,_currentStencilValueMask(~0)。
* @param clipping enabled.*/virtual void setClippingEnabled(bool enabled);/**设置裁切类型*/void setClippingType(LayoutClippingType type);LayoutClippingType getClippingType();/**是否可以裁切*/virtual bool isClippingEnabled();/*** Returns the class name of widget.*/virtual std::string getDescription() const override;/**设置容器类型*/virtual void setLayoutType(LayoutType type);/**得到容器类型*/virtual LayoutType getLayoutType() const;virtual void addChild(Node * child) override;virtual void addChild(Node * child。
-1.0f)), bool parentTransformUpdated){if(!_visible)return;bool dirty = parentTransformUpdated || _transformUpdated;if(dirty)_modelViewTransform = transform(parentTransform);_transformUpdated = false;// IMPORTANT:// To ease the migration to v3.0,_bgImageTexType);setBackGroundImageCapInsets(_backGroundImageCapInsets);}bool Layout::isBackGroundImageScale9Enabled(){return _backGroundScale9Enabled;}void Layout::setBackGroundImage(const std::string fileName, -1);static_castextension::Scale9Sprite*(_backGroundImage)-setPreferredSize(_size);}else{_backGroundImage = Sprite::create();addProtectedChild(_backGroundImage, int zOrder){Widget::addChild(child。
(GLint *)_currentStencilValueMask);glGetIntegerv(GL_STENCIL_FAIL。
1, mask_layer);glStencilOp(GL_ZERO。
GL_KEEP);}void Layout::onAfterDrawStencil(){glDepthMask(_currentDepthWriteMask);glStencilFunc(GL_EQUAL, 1);_clippingStencil-clear();_clippingStencil-drawPolygon(rect。
int tag){supplyTheLayoutParameterLackToChild(static_castWidget*(child));//设置布局参数Widget::addChild(child, 1, _currentStencilPassDepthPass);glStencilMask(_currentStencilWriteMask);if (!_currentStencilEnabled){glDisable(GL_STENCIL_TEST);}s_layer--;}void Layout::onBeforeVisitScissor(){Rect clippingRect = getClippingRect();glEnable(GL_SCISSOR_TEST);//裁切开始auto glview = Director::getInstance()-getOpenGLView();//得到OpenGL 窗口glview-setScissorInPoints(clippingRect.origin.x。
GL_KEEP,1), 4, green, _mask_layer_le,//模板LAYOUT_CLIPPING_SCISSOR//镂空}LayoutClippingType;//容器裁切类型/** * @js NA * @lua NA */class LayoutExecutant;class Layout : public Widget{DECLARE_CLASS_GUI_INFOpublic:Layout();virtual ~Layout();static Layout* create();//background/**设置背景图* @param fileName 图片路径* @param texType @see TextureResType.*/void setBackGroundImage(const std::string fileName, parentTransform,_bgImageTexType(UI_TEX_TYPE_LOCAL), const kmMat4 parentTransform, parentTransform, 0);rect[2] = Point(_size.width,#ifndef __LAYOUT_H__#define __LAYOUT_H__#include ui/UIWidget.hNS_CC_BEGINnamespace ui {typedef enum{LAYOUT_COLOR_NONE, const Color3B endColor){_gStartColor = startColor;if (_gradientRender){_gradientRender-setStartColor(startColor);//开始颜色}_gEndColor = endColor;if (_gradientRender){_gradientRender-setEndColor(endColor);//结束颜色}}const Color3B Layout::getBackGroundStartColor(){return _gStartColor;}const Color3B Layout::getBackGroundEndColor(){return _gEndColor;}void Layout::setBackGroundColorOpacity(GLubyte opacity){_cOpacity = opacity;switch (_colorType){case LAYOUT_COLOR_NONE:break;case LAYOUT_COLOR_SOLID://单一的颜色透明度_colorRender-setOpacity(opacity);break;case LAYOUT_COLOR_GRADIENT:_gradientRender-setOpacity(opacity);//渐变的颜色透明度break;default:break;}}GLubyte Layout::getBackGroundColorOpacity(){return _cOpacity;}void Layout::setBackGroundColorVector(const Point vector){_alongVector = vector;if (_gradientRender){_gradientRender-setVector(vector);//设置渐变方向}}const Point Layout::getBackGroundColorVector(){return _alongVector;}void Layout::setBackGroundImageColor(const Color3B color){_backGroundImageColor = color;updateBackGroundImageColor();}void Layout::setBackGroundImageOpacity(GLubyte opacity){_backGroundImageOpacity = opacity;updateBackGroundImageOpacity();}const Color3B Layout::getBackGroundImageColor(){return _backGroundImageColor;}GLubyte Layout::getBackGroundImageOpacity(){return _backGroundImageOpacity;}void Layout::updateBackGroundImageColor(){if (_backGroundImage){_backGroundImage-setColor(_backGroundImageColor);}}void Layout::updateBackGroundImageOpacity(){if (_backGroundImage){_backGroundImage-setOpacity(_backGroundImageOpacity);}}void Layout::updateBackGroundImageRGBA(){if (_backGroundImage){//设置背景color opacity_backGroundImage-setColor(_backGroundImageColor);_backGroundImage-setOpacity(_backGroundImageOpacity);}}const Size Layout::getBackGroundImageTextureSize() const{return _backGroundImageTextureSize;//背景资源size}void Layout::setLayoutType(LayoutType type){_layoutType = type;//设置布局类型CC_SAFE_RELEASE_NULL(_curLayoutExecutant);//释放布局执行者_curLayoutExecutant = createCurrentLayoutExecutant();//新建当前布局执行者CC_SAFE_RETAIN(_curLayoutExecutant);//引用次数++for (auto child : _children)//遍历所有孩子{Widget* widgetChild = dynamic_castWidget*(child);if (widgetChild){//提供布局参数supplyTheLayoutParameterLackToChild(static_castWidget*(child));}}_doLayoutDirty = true;//开启布局}LayoutExecutant* Layout::createCurrentLayoutExecutant(){LayoutExecutant* exe = nullptr;switch (_layoutType){case LAYOUT_LINEAR_VERTICAL://线性垂直exe = LinearVerticalLayoutExecutant::create();break;case LAYOUT_LINEAR_HORIZONTAL://线性水平exe = LinearHorizontalLayoutExecutant::create();break;case LAYOUT_RELATIVE://平面exe = RelativeLayoutExecutant::create();break;default:break;}return exe;}LayoutType Layout::getLayoutType() const{return _layoutType;//返回布局类型}//请求布局void Layout::requestDoLayout(){_doLayoutDirty = true;//开启布局}void Layout::doLayout(){if (!_doLayoutDirty)//没开启布局 直接return{return;}if (_curLayoutExecutant)//开启布局 有了布局数据{//布局吧_curLayoutExecutant-doLayout(getSize(), dirty);_afterVisitCmdStencil.init(_globalZOrder);_afterVisitCmdStencil.func = CC_CALLBACK_0(Layout::onAfterVisitStencil,_doLayoutDirty(true), -1);break;default:break;}}LayoutBackGroundColorType Layout::getBackGroundColorType(){return _colorType;}void Layout::setBackGroundColor(const Color3B color){_cColor = color;if (_colorRender){_colorRender-setColor(color);}}const Color3B Layout::getBackGroundColor(){return _cColor;}void Layout::setBackGroundColor(const Color3B startColor, Vectorcocos2d::Node * container){ssize_t unlayoutChildCount = 0;VectorWidget* widgetChildren;for (auto subWidget : container){Widget* child = dynamic_castWidget*(subWidget);if (child){RelativeLayoutParameter* layoutParameter = dynamic_castRelativeLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));layoutParameter-_put = false;unlayoutChildCount++;widgetChildren.pushBack(child);}}while (unlayoutChildCount 0){for (auto subWidget : widgetChildren){Widget* child = static_castWidget*(subWidget);RelativeLayoutParameter* layoutParameter = dynamic_castRelativeLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));if (layoutParameter){if (layoutParameter-_put){continue;}Point ap = child-getAnchorPoint();Size cs = child-getSize();RelativeAlign align = layoutParameter-getAlign();const char* relativeName = layoutParameter-getRelativeToWidgetName();Widget* relativeWidget = nullptr;RelativeLayoutParameter* relativeWidgetLP = nullptr;float finalPosX = 0.0f;float finalPosY = 0.0f;if (relativeName strcmp(relativeName, const kmMat4 parentTransform。
g_sStencilBits);//裁切if (g_sStencilBits = 0){CCLOG(Stencil buffer is not enabled.);}once = false;}_clippingStencil = DrawNode::create();//创建 绘制对象if (_running)//若该节点在运行{_clippingStencil-onEnter();//初始化绘制对象}_clippingStencil-retain();//绘制对象引用次数++setStencilClippingSize(_size);//设置裁切区域}else//若不能裁切{if (_running)//若该节点在运行{_clippingStencil-onExit();//绘制对象 退出}_clippingStencil-release();//计数--_clippingStencil = nullptr;//置空}break;default:break;}}void Layout::setClippingType(LayoutClippingType type){if (type == _clippingType){return;}bool clippingEnabled = isClippingEnabled();setClippingEnabled(false);_clippingType = type;//设置裁切类型setClippingEnabled(clippingEnabled);}LayoutClippingType Layout::getClippingType(){return _clippingType;}void Layout::setStencilClippingSize(const Size size){if (_clippingEnabled _clippingType == LAYOUT_CLIPPING_STENCIL){//若可以裁切 裁切类型为 模板Point rect[4];//设置裁切范围rect[0] = Point::ZERO;rect[1] = Point(_size.width,_currentStencilFunc(GL_ALWAYS),//空LAYOUT_COLOR_SOLID。
_gradientRender(nullptr)。
_currentStencilFail(GL_KEEP),_curLayoutExecutant(nullptr){_widgetType = WidgetTypeContainer;//默认 为容器类型}Layout::~Layout(){CC_SAFE_RELEASE(_clippingStencil);CC_SAFE_RELEASE(_curLayoutExecutant);}void Layout::onEnter(){Widget::onEnter();if (_clippingStencil){_clippingStencil-onEnter();}_doLayoutDirty = true;//可以布局_clippingRectDirty = true;//可以计算裁切矩形}void Layout::onExit(){Widget::onExit();if (_clippingStencil){_clippingStencil-onExit();}}Layout* Layout::create(){Layout* layout = new Layout();if (layout layout-init()){layout-autorelease();return layout;}CC_SAFE_DELETE(layout);return nullptr;}bool Layout::init(){if (ProtectedNode::init()){initRenderer();setBright(true);ignoreContentAdaptWithSize(false);setSize(Size::ZERO);setAnchorPoint(Point::ZERO);//锚点左下return true;}return false;}void Layout::addChild(Node *child){Widget::addChild(child);}void Layout::addChild(Node * child。
_currentStencilPassDepthFail,_alongVector(Point(0.0f, clippingRect.size.width。
_currentDepthWriteMask);glDepthMask(GL_FALSE);glStencilFunc(GL_NEVER, 1, 如果颜色类型是 渐变的* @param start color* @param end color*/void setBackGroundColor(const Color3B startColor,_colorRender(nullptr), VectorNode* container);};//相对 布局执行者class RelativeLayoutExecutant : public LayoutExecutant{public:RelativeLayoutExecutant(){};virtual ~RelativeLayoutExecutant(){};static RelativeLayoutExecutant* create();virtual void doLayout(const Size layoutSize,_currentAlphaTestFunc(GL_ALWAYS)。
finalPosY));leftBoundary = child-getRightInParent() + mg.right;}}}}//相对 布局执行者void RelativeLayoutExecutant::doLayout(const cocos2d::Size layoutSize, _size.height);Color4F green(0, we still support the kmGL stack,请启用该功能, _modelViewTransform,但它会降低渲染效率, GL_KEEP, cleanup);_doLayoutDirty = true;}void Layout::removeAllChildren(){Widget::removeAllChildren();}void Layout::removeAllChildrenWithCleanup(bool cleanup){Widget::removeAllChildrenWithCleanup(cleanup);_doLayoutDirty = true;}bool Layout::isClippingEnabled(){return _clippingEnabled;}void Layout::visit(Renderer *renderer, zOrder);}void Layout::addChild(Node *child, mask_layer,layout-_bgImageTexType);setBackGroundImageCapInsets(layout-_backGroundImageCapInsets);setBackGroundColorType(layout-_colorType);setBackGroundColor(layout-_cColor);setBackGroundColor(layout-_gStartColor,_clippingStencil(nullptr),_clippingType(LAYOUT_CLIPPING_STENCIL)。
dirty);elsebreak;}for( ; j _protectedChildren.size(); j++ ){auto node = _protectedChildren.at(j);if ( node node-getLocalZOrder() 0 )node-visit(renderer, dirty);_afterDrawStencilCmd.init(_globalZOrder);_afterDrawStencilCmd.func = CC_CALLBACK_0(Layout::onAfterDrawStencil, _size.height);rect[3] = Point(0, _currentStencilValueMask);glStencilOp(_currentStencilFail, layout-_gEndColor);setBackGroundColorOpacity(layout-_cOpacity);setBackGroundColorVector(layout-_alongVector);setLayoutType(layout-_layoutType);setClippingEnabled(layout-_clippingEnabled);setClippingType(layout-_clippingType);}}}NS_CC_END ,_gStartColor(Color3B::WHITE),TextureResType texType = UI_TEX_TYPE_LOCAL);/**如果背景图是9宫格 设置拉伸尺度* @param capinsets of background image.*/void setBackGroundImageCapInsets(const Rect capInsets);const Rect getBackGroundImageCapInsets();/**设置背景颜色类型*/void setBackGroundColorType(LayoutBackGroundColorType type);LayoutBackGroundColorType getBackGroundColorType();/**设置背景是否使用9宫格 默认不使用*/void setBackGroundImageScale9Enabled(bool enabled);bool isBackGroundImageScale9Enabled();/**设置背景颜色, const kmMat4 parentTransform,_backGroundImage(nullptr)。
_modelViewTransform, _modelViewTransform,_cColor(Color3B::WHITE), relativeName) == 0){relativeWidget = sWidget;relativeWidgetLP = rlayoutParameter;break;}}}}switch (align){case RELATIVE_ALIGN_NONE:case RELATIVE_ALIGN_PARENT_TOP_LEFT:finalPosX = ap.x * cs.width;finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);break;case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL:finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);break;case RELATIVE_ALIGN_PARENT_TOP_RIGHT:finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);finalPosY = layoutSize.height - ((1.0f - ap.y) * cs.height);break;case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL:finalPosX = ap.x * cs.width;finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);break;case RELATIVE_CENTER_IN_PARENT:finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);break;case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL:finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);finalPosY = layoutSize.height * 0.5f - cs.height * (0.5f - ap.y);break;case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM:finalPosX = ap.x * cs.width;finalPosY = ap.y * cs.height;break;case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL:finalPosX = layoutSize.width * 0.5f - cs.width * (0.5f - ap.x);finalPosY = ap.y * cs.height;break;case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM:finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);finalPosY = ap.y * cs.height;break;case RELATIVE_LOCATION_ABOVE_LEFTALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationBottom = relativeWidget-getTopInParent();float locationLeft = relativeWidget-getLeftInParent();finalPosY = locationBottom + ap.y * cs.height;finalPosX = locationLeft + ap.x * cs.width;}break;case RELATIVE_LOCATION_ABOVE_CENTER:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}Size rbs = relativeWidget-getSize();float locationBottom = relativeWidget-getTopInParent();finalPosY = locationBottom + ap.y * cs.height;finalPosX = relativeWidget-getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;}break;case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationBottom = relativeWidget-getTopInParent();float locationRight = relativeWidget-getRightInParent();finalPosY = locationBottom + ap.y * cs.height;finalPosX = locationRight - (1.0f - ap.x) * cs.width;}break;case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationTop = relativeWidget-getTopInParent();float locationRight = relativeWidget-getLeftInParent();finalPosY = locationTop - (1.0f - ap.y) * cs.height;finalPosX = locationRight - (1.0f - ap.x) * cs.width;}break;case RELATIVE_LOCATION_LEFT_OF_CENTER:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}Size rbs = relativeWidget-getSize();float locationRight = relativeWidget-getLeftInParent();finalPosX = locationRight - (1.0f - ap.x) * cs.width;finalPosY = relativeWidget-getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;}break;case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationBottom = relativeWidget-getBottomInParent();float locationRight = relativeWidget-getLeftInParent();finalPosY = locationBottom + ap.y * cs.height;finalPosX = locationRight - (1.0f - ap.x) * cs.width;}break;case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationTop = relativeWidget-getTopInParent();float locationLeft = relativeWidget-getRightInParent();finalPosY = locationTop - (1.0f - ap.y) * cs.height;finalPosX = locationLeft + ap.x * cs.width;}break;case RELATIVE_LOCATION_RIGHT_OF_CENTER:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}Size rbs = relativeWidget-getSize();float locationLeft = relativeWidget-getRightInParent();finalPosX = locationLeft + ap.x * cs.width;finalPosY = relativeWidget-getBottomInParent() + rbs.height * 0.5f + ap.y * cs.height - cs.height * 0.5f;}break;case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationBottom = relativeWidget-getBottomInParent();float locationLeft = relativeWidget-getRightInParent();finalPosY = locationBottom + ap.y * cs.height;finalPosX = locationLeft + ap.x * cs.width;}break;case RELATIVE_LOCATION_BELOW_LEFTALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationTop = relativeWidget-getBottomInParent();float locationLeft = relativeWidget-getLeftInParent();finalPosY = locationTop - (1.0f - ap.y) * cs.height;finalPosX = locationLeft + ap.x * cs.width;}break;case RELATIVE_LOCATION_BELOW_CENTER:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}Size rbs = relativeWidget-getSize();float locationTop = relativeWidget-getBottomInParent();finalPosY = locationTop - (1.0f - ap.y) * cs.height;finalPosX = relativeWidget-getLeftInParent() + rbs.width * 0.5f + ap.x * cs.width - cs.width * 0.5f;}break;case RELATIVE_LOCATION_BELOW_RIGHTALIGN:if (relativeWidget){if (relativeWidgetLP !relativeWidgetLP-_put){continue;}float locationTop = relativeWidget-getBottomInParent();float locationRight = relativeWidget-getRightInParent();finalPosY = locationTop - (1.0f - ap.y) * cs.height;finalPosX = locationRight - (1.0f - ap.x) * cs.width;}break;default:break;}Margin relativeWidgetMargin;Margin mg = layoutParameter-getMargin();if (relativeWidgetLP){relativeWidgetMargin = relativeWidgetLP-getMargin();}//handle marginswitch (align){case RELATIVE_ALIGN_NONE:case RELATIVE_ALIGN_PARENT_TOP_LEFT:finalPosX += mg.left;finalPosY -= mg.top;break;case RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL:finalPosY -= mg.top;break;case RELATIVE_ALIGN_PARENT_TOP_RIGHT:finalPosX -= mg.right;finalPosY -= mg.top;break;case RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL:finalPosX += mg.left;break;case RELATIVE_CENTER_IN_PARENT:break;case RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL:finalPosX -= mg.right;break;case RELATIVE_ALIGN_PARENT_LEFT_BOTTOM:finalPosX += mg.left;finalPosY += mg.bottom;break;case RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL:finalPosY += mg.bottom;break;case RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM:finalPosX -= mg.right;finalPosY += mg.bottom;break;case RELATIVE_LOCATION_ABOVE_LEFTALIGN:finalPosY += mg.bottom;finalPosX += mg.left;break;case RELATIVE_LOCATION_ABOVE_RIGHTALIGN:finalPosY += mg.bottom;finalPosX -= mg.right;break;case RELATIVE_LOCATION_ABOVE_CENTER:finalPosY += mg.bottom;break;case RELATIVE_LOCATION_LEFT_OF_TOPALIGN:finalPosX -= mg.right;finalPosY -= mg.top;break;case RELATIVE_LOCATION_LEFT_OF_BOTTOMALIGN:finalPosX -= mg.right;finalPosY += mg.bottom;break;case RELATIVE_LOCATION_LEFT_OF_CENTER:finalPosX -= mg.right;break;case RELATIVE_LOCATION_RIGHT_OF_TOPALIGN:finalPosX += mg.left;finalPosY -= mg.top;break;case RELATIVE_LOCATION_RIGHT_OF_BOTTOMALIGN:finalPosX += mg.left;finalPosY += mg.bottom;break;case RELATIVE_LOCATION_RIGHT_OF_CENTER:finalPosX += mg.left;break;case RELATIVE_LOCATION_BELOW_LEFTALIGN:finalPosY -= mg.top;finalPosX += mg.left;break;case RELATIVE_LOCATION_BELOW_RIGHTALIGN:finalPosY -= mg.top;finalPosX -= mg.right;break;case RELATIVE_LOCATION_BELOW_CENTER:finalPosY -= mg.top;break;default:break;}child-setPosition(Point(finalPosX,_currentStencilRef(0),_currentAlphaTestRef(1), int zOrder) override;virtual void addChild(Node* child, bool parentTransformUpdated){//模板裁切渲染_beforeVisitCmdScissor.init(_globalZOrder);_beforeVisitCmdScissor.func = CC_CALLBACK_0(Layout::onBeforeVisitScissor,-1), VectorNode* container);};//线性水平 布局执行者class LinearHorizontalLayoutExecutant : public LayoutExecutant{public:LinearHorizontalLayoutExecutant(){};virtual ~LinearHorizontalLayoutExecutant(){};static LinearHorizontalLayoutExecutant* create();virtual void doLayout(const Size layoutSize,_currentStencilEnabled(GL_FALSE), _modelViewTransform,并做了清理所有正在运行的动作*/virtual void removeAllChildrenWithCleanup(bool cleanup) override;virtual void sortAllChildren() override;void requestDoLayout();virtual void onEnter() override;virtual void onExit() override;CC_CONSTRUCTOR_ACCESS://override init method of widget.virtual bool init() override;protected://override onSizeChanged method of widget.virtual void onSizeChanged() override;//init background image renderer.void addBackGroundImage();void supplyTheLayoutParameterLackToChild(Widget* child);virtual Widget* createCloneInstance() override;virtual void copySpecialProperties(Widget* model) override;virtual void copyClonedWidgetChildren(Widget* model) override;/**模板类型的裁切渲染*/void stencilClippingVisit(Renderer *renderer, finalPosY));topBoundary = child-getBottomInParent() - mg.bottom;}}}}//线性水平 布局执行者 类似上void LinearHorizontalLayoutExecutant::doLayout(const cocos2d::Size layoutSize, int zOrder。
bool parentTransformUpdated){if (!_enabled)//不可用就直接return{return;}adaptRenderers();//对应各自的逻辑处理if (_clippingEnabled)//可以裁切{switch (_clippingType)//裁切类型{case LAYOUT_CLIPPING_STENCIL://模板stencilClippingVisit(renderer, (GLint *)_currentStencilPassDepthPass);glEnable(GL_STENCIL_TEST);CHECK_GL_ERROR_DEBUG();glStencilMask(mask_layer);glGetBooleanv(GL_DEPTH_WRITEMASK。
Vectorcocos2d::Node * container){float topBoundary = layoutSize.height;//布局高度for (auto subWidget : container)//遍历所有容器{Widget* child = dynamic_castWidget*(subWidget);if (child)//是widget类型{LinearLayoutParameter* layoutParameter = dynamic_castLinearLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_LINEAR));if (layoutParameter)//是线性布局参数{LinearGravity childGravity = layoutParameter-getGravity();//重力类型Point ap = child-getAnchorPoint();//锚点Size cs = child-getSize();//大小float finalPosX = ap.x * cs.width;//最终X位置float finalPosY = topBoundary - ((1.0f-ap.y) * cs.height);//最终Y位置switch (childGravity){case LINEAR_GRAVITY_NONE:case LINEAR_GRAVITY_LEFT:break;case LINEAR_GRAVITY_RIGHT:finalPosX = layoutSize.width - ((1.0f - ap.x) * cs.width);//最终X位置break;case LINEAR_GRAVITY_CENTER_HORIZONTAL:finalPosX = layoutSize.width / 2.0f - cs.width * (0.5f-ap.x);//最终Y位置break;default:break;}Margin mg = layoutParameter-getMargin();//得到间距finalPosX += mg.left;//加上左间距 右移finalPosY -= mg.top;//减去上间距 下移child-setPosition(Point(finalPosX,//单一固定颜色的LAYOUT_COLOR_GRADIENT//有梯度变化的}LayoutBackGroundColorType;//容器背景颜色类型typedef enum{LAYOUT_ABSOLUTE, bool parentTransformUpdated);/**设置裁切模板size*/void setStencilClippingSize(const Size size);const Rect getClippingRect();virtual void doLayout();//clippingvoid onBeforeVisitStencil();void onAfterDrawStencil();void onAfterVisitStencil();void onBeforeVisitScissor();void onAfterVisitScissor();void updateBackGroundImageColor();void updateBackGroundImageOpacity();void updateBackGroundImageRGBA();LayoutExecutant* createCurrentLayoutExecutant();protected:bool _clippingEnabled;//是否裁切//backgroundbool _backGroundScale9Enabled;//是否开启9宫格Node* _backGroundImage;//背景图std::string _backGroundImageFileName;//背景nameRect _backGroundImageCapInsets;//拉伸区域LayoutBackGroundColorType _colorType;//背景颜色类型TextureResType _bgImageTexType;//贴图类型LayerColor* _colorRender;//正常渲染层 当前只用一个 由类型决定LayerGradient* _gradientRender;//渐变渲染层Color3B _cColor;//正常模式颜色值Color3B _gStartColor;//渐变模式颜色的开始值Color3B _gEndColor;//渐变模式颜色的结束值Point _alongVector;//渐变颜色方向GLubyte _cOpacity;//透明度Size _backGroundImageTextureSize;//背景贴图sizeLayoutType _layoutType;//容器类型LayoutClippingType _clippingType;//裁切类型DrawNode* _clippingStencil;//绘制几何裁切区域bool _scissorRectDirty;//多余的变量Rect _clippingRect;//裁切的区域Layout* _clippingParent;//裁切布局bool _doLayoutDirty;//是否开启布局bool _clippingRectDirty;//是否计算裁切区域 默认true 由于计算裁切区域逻辑较复杂//所以计算一次之后就不计算了 _clippingRectDirty = false;//clippingGLboolean _currentStencilEnabled;GLuint _currentStencilWriteMask;GLenum _currentStencilFunc;GLint _currentStencilRef;GLuint _currentStencilValueMask;GLenum _currentStencilFail;GLenum _currentStencilPassDepthFail;GLenum _currentStencilPassDepthPass;GLboolean _currentDepthWriteMask;GLboolean _currentAlphaTestEnabled;GLenum _currentAlphaTestFunc;GLclampf _currentAlphaTestRef;Color3B _backGroundImageColor;GLubyte _backGroundImageOpacity;LayoutExecutant* _curLayoutExecutant;//布局执行者GLint _mask_layer_le;GroupCommand _groupCommand;CustomCommand _beforeVisitCmdStencil;CustomCommand _afterDrawStencilCmd;CustomCommand _afterVisitCmdStencil;CustomCommand _beforeVisitCmdScissor;CustomCommand _afterVisitCmdScissor;};}NS_CC_END#endif /* defined(__Layout__) */#include ui/UILayout.h#include ui/UIHelper.h#include extensions/GUI/CCControlExtension/CCScale9Sprite.h#include kazmath/GL/matrix.h#include CCGLProgram.h#include CCShaderCache.h#include CCDirector.h#include CCDrawingPrimitives.h#include renderer/CCRenderer.h#include renderer/CCGroupCommand.h#include renderer/CCCustomCommand.hNS_CC_BEGINnamespace ui {//布局执行者class LayoutExecutant : public Ref{public:LayoutExecutant(){};virtual ~LayoutExecutant(){};static LayoutExecutant* create();virtual void doLayout(const Size layoutSize, (GLint *)_currentStencilWriteMask);glGetIntegerv(GL_STENCIL_FUNC。
_colorType(LAYOUT_COLOR_NONE), _modelViewTransform, GL_KEEP);kmGLMatrixMode(KM_GL_MODELVIEW);kmGLPushMatrix();kmGLLoadIdentity();kmGLMatrixMode(KM_GL_PROJECTION);kmGLPushMatrix();kmGLLoadIdentity();DrawPrimitives::drawSolidRect(Point(-1, _mask_layer_le);glStencilOp(GL_KEEP, bool parentTransformUpdated) override;virtual void removeChild(Node* child, _currentStencilRef, const Color3B endColor);const Color3B getBackGroundStartColor();const Color3B getBackGroundEndColor();/** 设置透明度.*/void setBackGroundColorOpacity(GLubyte opacity);GLubyte getBackGroundColorOpacity();/** 如果背景颜色是渐变的 设置背景颜色渐变的向量* @param vector*/void setBackGroundColorVector(const Point vector);const Point getBackGroundColorVector();void setBackGroundImageColor(const Color3B color);void setBackGroundImageOpacity(GLubyte opacity);const Color3B getBackGroundImageColor();GLubyte getBackGroundImageOpacity();/*** 移除背景img*/void removeBackGroundImage();/**得到背景img size*/const Size getBackGroundImageTextureSize() const;/*** 设置布局可以裁切他的内荣和孩子 默认不裁切*如果你真的需要这个, BCAKGROUNDCOLORRENDERER_Z,_currentAlphaTestEnabled(GL_FALSE),TextureResType texType){if (fileName.empty()){return;}if (_backGroundImage == nullptr){addBackGroundImage();}_backGroundImageFileName = fileName;_bgImageTexType = texType;if (_backGroundScale9Enabled){//若使用九宫格 加载资源extension::Scale9Sprite* bgiScale9 = static_castextension::Scale9Sprite*(_backGroundImage);switch (_bgImageTexType){case UI_TEX_TYPE_LOCAL:bgiScale9-initWithFile(fileName);break;case UI_TEX_TYPE_PLIST:bgiScale9-initWithSpriteFrameName(fileName);break;default:break;}bgiScale9-setPreferredSize(_size);}else{//若没有使用九宫格 加载资源switch (_bgImageTexType){case UI_TEX_TYPE_LOCAL:static_castSprite*(_backGroundImage)-setTexture(fileName);break;case UI_TEX_TYPE_PLIST:static_castSprite*(_backGroundImage)-setSpriteFrame(fileName);break;default:break;}}//保存贴图size_backGroundImageTextureSize = _backGroundImage-getContentSize();//设置贴图位置居中_backGroundImage-setPosition(Point(_size.width/2.0f, const kmMat4 parentTransform,_scissorRectDirty(false), clippingRect.size.height);//根据裁切范围进行裁切}void Layout::onAfterVisitScissor(){glDisable(GL_SCISSOR_TEST);//裁切终止}void Layout::scissorClippingVisit(Renderer *renderer。
VectorNode* container){};};//线性垂直 布局执行者class LinearVerticalLayoutExecutant : public LayoutExecutant{public:LinearVerticalLayoutExecutant(){};virtual ~LinearVerticalLayoutExecutant(){};static LinearVerticalLayoutExecutant* create();virtual void doLayout(const Size layoutSize, zOrder, mask_layer, _size.height/2.0f));updateBackGroundImageRGBA();//更新贴图颜色}void Layout::setBackGroundImageCapInsets(const Rect capInsets){_backGroundImageCapInsets = capInsets;if (_backGroundScale9Enabled _backGroundImage){//若使用九宫格 设置区域static_castextension::Scale9Sprite*(_backGroundImage)-setCapInsets(capInsets);}}const Rect Layout::getBackGroundImageCapInsets(){return _backGroundImageCapInsets;}void Layout::supplyTheLayoutParameterLackToChild(Widget *child){if (!child){return;}switch (_layoutType){case LAYOUT_ABSOLUTE://绝对位置break;case LAYOUT_LINEAR_HORIZONTAL:case LAYOUT_LINEAR_VERTICAL://线性{LinearLayoutParameter* layoutParameter = dynamic_castLinearLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_LINEAR));if (!layoutParameter){child-setLayoutParameter(LinearLayoutParameter::create());//设置线性布局参数}break;}case LAYOUT_RELATIVE://平面{RelativeLayoutParameter* layoutParameter = dynamic_castRelativeLayoutParameter*(child-getLayoutParameter(LAYOUT_PARAMETER_RELATIVE));if (!layoutParameter){child-setLayoutParameter(RelativeLayoutParameter::create());//设置平面 布局参数}break;}default:break;}}void Layout::addBackGroundImage(){//背景图添加到节点树上if (_backGroundScale9Enabled){_backGroundImage = extension::Scale9Sprite::create();addProtectedChild(_backGroundImage,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://www.juheyunku.com/jiaob/yd/9971.shtml
热门TAG
命令 权重 外链 企业网站 白帽 php 织梦教程 dedecms修改内容 javascript 织梦 功能 标签 调用 详解 服务器 网站流量 实例解析 Dedecms 织梦cms HTML tags标签 python jquery教程 jquery windows SEO优化 蜘蛛 搜索引擎 网站收录 JSP最新文章
-
cocos2dxv3.2FlappyBird各个类对
时间:2020-12-28
-
来点不一样的:前端手指
时间:2020-12-28
-
Cocos2d-x3.2android平台新手开
时间:2020-12-28
-
模板中的TemplateBinding问题
时间:2020-12-28
-
从中间件的历史来看移动
时间:2020-12-28
-
web移动前端的click点透问题
时间:2020-12-28
-
微信小程序开发环境搭建
时间:2020-12-28
热门文章
-
从中间件的历史来看移动App开发的未来
时间:2020-12-28
-
模板中的TemplateBinding问题
时间:2020-12-28
-
cocos2dxv3.2FlappyBird各个类对象具体代码分析
时间:2020-12-28
-
来点不一样的:前端手指操
时间:2020-12-28
-
微信小程序开发环境搭建
时间:2020-12-28
-
web移动前端的click点透问题
时间:2020-12-28
-
Cocos2d-x3.2android平台新手开发环境配置教程
时间:2020-12-28
