【Cocos2d-x】源码分析之 2d/ui/Widget

前端之家收集整理的这篇文章主要介绍了【Cocos2d-x】源码分析之 2d/ui/Widget前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

【Cocos2d-x】源码分析之 2d/ui/Widget


转自:http://blog.csdn.net/yhhwatl/article/details/26487731

从今天开始 咱也模仿 红孩儿这些大牛分析源码 ,由于水平有限 不对之处欢迎狂喷。哈哈。

  1. #ifndef__UIWIDGET_H__
  2. @H_403_46@ #define__UIWIDGET_H__
  3. @H_403_46@ #include"ui/CCProtectedNode.h"
  4. #include"ui/UILayoutDefine.h"
  5. @H_403_46@ #include"ui/UILayoutParameter.h"
  6. #include"ui/GUIDefine.h"
  7. @H_403_46@
  8. NS_CC_BEGIN
  9. @H_403_46@
  10. namespaceui{
  11. @H_403_46@
  12. typedefenum
  13. @H_403_46@ {
  14. BRIGHT_NONE=-1,
  15. @H_403_46@ BRIGHT_NORMAL,//正常
  16. BRIGHT_HIGHLIGHT//高亮按钮点击之后
  17. @H_403_46@ }BrightStyle;//明亮的风格
  18. @H_403_46@ enum
  19. {
  20. @H_403_46@ WidgetTypeWidget,119)">//control基本UIWidget默认
  21. WidgetTypeContainer//container容器layout实例化
  22. @H_403_46@ }WidgetType;//ui类型
  23. @H_403_46@ enum
  24. {
  25. @H_403_46@ UI_TEX_TYPE_LOCAL=0,119)">//meanslocalfile
  26. UI_TEX_TYPE_PLIST=1//meansspriteframe
  27. @H_403_46@ }TextureResType;//贴图类型
  28. @H_403_46@ enumclassTouchEventType
  29. {
  30. @H_403_46@ TOUCH_EVENT_BEGAN,119)">//开始
  31. TOUCH_EVENT_MOVED,119)">//移动
  32. @H_403_46@ TOUCH_EVENT_ENDED,119)">//结束
  33. TOUCH_EVENT_CANCELED//取消
  34. @H_403_46@ };//触摸事件类型
  35. @H_403_46@ enum
  36. {
  37. @H_403_46@ SIZE_ABSOLUTE,119)">//绝对值
  38. SIZE_PERCENT//百分比值
  39. @H_403_46@ }SizeType;//size值类型
  40. @H_403_46@ enum
  41. {
  42. @H_403_46@ POSITION_ABSOLUTE,119)">//绝对真实位置
  43. POSITION_PERCENT//相对父节点位置百分比
  44. @H_403_46@ }PositionType;//位置类型
  45. @H_403_46@ enum
  46. {
  47. @H_403_46@ WIDGET_SIZE,119)">//size
  48. WIDGET_POSITION//position
  49. @H_403_46@
  50. }WidgetInfoType;//位置类型
  51. @H_403_46@ //哦这里说明一下回调函数被我修改了下主要是这样修改之后可以用到C++11的lambda表达式
copy
  1. //不必在使用的时候多声明一个回调函数了比较方便希望引擎组可以采用这种方式。
  2. @H_403_46@ typedefstd::function<void(Ref*,TouchEventType)>SEL_TouchEvent;
  3. @H_403_46@ //函数指针指向返回值void参数列表(Ref*,TouchEventType)类型的函数
  4. //typedefvoid(Ref::*SEL_TouchEvent)(Ref*,TouchEventType);
  5. @H_403_46@ //宏定义给函数指针SEL_TouchEvent取别名为toucheventselector
  6. #definetoucheventselector(_SELECTOR)(SEL_TouchEvent)(&_SELECTOR)
  7. @H_403_46@
  8. classWidget:publicProtectedNode
  9. @H_403_46@ {
  10. public:
  11. @H_403_46@ Widget(void);
  12. virtual~Widget();
  13. @H_403_46@ staticWidget*create();
  14. /**设置是否触摸&&可见默认true*/
  15. @H_403_46@ virtualvoidsetEnabled(boolenabled);
  16. boolisEnabled()const;
  17. @H_403_46@ /**设置是否明亮默认true*/
  18. voidsetBright(boolbright);
  19. @H_403_46@ /**是否明亮*/
  20. boolisBright()/**是否可以触摸(响应事件)默认true*/
  21. voidsetTouchEnabled(boolenabled);
  22. @H_403_46@ /**设置明亮风格正常or明亮默认正常*/
  23. voidsetBrightStyle(BrightStylestyle);
  24. @H_403_46@ /**是否可以触摸*/
  25. boolisTouchEnabled()/**是否被选中默认false*/
  26. boolisFocused()/**是否被选中默认false*/
  27. voidsetFocused(boolfucosed);
  28. @H_403_46@ /**获取此控件距离左节点的下边界长度*/
  29. floatgetLeftInParent();
  30. @H_403_46@ /**获取此控件距离父节点的下边界长度*/
  31. floatgetBottomInParent();
  32. @H_403_46@ /**获取此控件距离父节点的右边界长度*/
  33. floatgetRightInParent();
  34. @H_403_46@ /**获取此控件距离父节点的上边界长度*/
  35. floatgetTopInParent();
  36. @H_403_46@
  37. /**获取一个孩子从容器根据它的名字*/
  38. @H_403_46@ virtualWidget*getChildByName(constchar*name);
  39. /**渲染重载*/
  40. @H_403_46@ voidvisit(cocos2d::Renderer*renderer,constkmMat4&parentTransform,boolparentTransformUpdated)override;
  41. @H_403_46@ /**添加回调事件*/
  42. voidaddTouchEventListener(SEL_TouchEventselector);
  43. @H_403_46@ /**打印属性debug*/
  44. voidlogInfo(WidgetInfoType_type);
  45. @H_403_46@
  46. //cocos2d属性
  47. @H_403_46@ /**
  48. 基类有的函数为virtual有的不是
  49. @H_403_46@ 不带virtual的是所有子类都拥有这个函数功能
  50. 带virtual的是拥有上述功能之外重载父类函数想拓展功能用的。
  51. @H_403_46@ 带virtual的函数可以使用多态即父类指针指向子类成员
  52. */
  53. @H_403_46@
  54. /**
  55. @H_403_46@ *更改在OpenGL坐标系中widget的位置(X,Y)
  56. *原来的点(0,0)是在屏幕的左下角。
  57. @H_403_46@ *@参数位置在OpenGL坐标widget的位置(X,Y)
  58. */
  59. @H_403_46@ voidsetPosition(constPoint&pos)override;
  60. /**同上绝对位置变为百分比*/
  61. @H_403_46@ voidsetPositionPercent(constPoint&percent);
  62. /**得到在OpenGL坐标系中widget的百分比位置(X,Y)*/
  63. @H_403_46@ constPoint&getPositionPercent();
  64. @H_403_46@ /**设置位置类型*/
  65. voidsetPositionType(PositionTypetype);
  66. @H_403_46@
  67. /**得到位置类型*/
  68. @H_403_46@ PositionTypegetPositionType()const;
  69. @H_403_46@ /**设置该widget是否水平翻转*/
  70. voidsetFlippedX(boolflippedX);
  71. @H_403_46@
  72. /**该widget是否水平翻转*/
  73. @H_403_46@ virtualboolisFlippedX(){return_flippedX;};
  74. @H_403_46@ /**该widget是否垂直翻转*/
  75. voidsetFlippedY(boolflippedY);
  76. @H_403_46@
  77. /**该widget是否垂直翻转*/
  78. @H_403_46@ boolisFlippedY(){return_flippedY;};
  79. /**设置颜色*/
  80. @H_403_46@ voidsetColor(constColor3B&color)override;
  81. /**设置透明度*/
  82. @H_403_46@ voidsetOpacity(GLubyteopacity)override;
  83. /**得到颜色值*/
  84. @H_403_46@ constColor3B&getColor()constoverride{return_color;};
  85. /**得到透明度*/
  86. @H_403_46@ GLubytegetOpacity()return_opacity;};
  87. /**弃用的属性*/
  88. @H_403_46@ /**@deprecatedUseisFlippedX()instead*/
  89. CC_DEPRECATED_ATTRIBUTEboolisFlipX(){returnisFlippedX();};
  90. @H_403_46@ /**@deprecatedUsesetFlippedX()instead*/
  91. CC_DEPRECATED_ATTRIBUTEvoidsetFlipX(boolflipX){setFlippedX(flipX);};
  92. @H_403_46@ /**@deprecatedUseisFlippedY()instead*/
  93. CC_DEPRECATED_ATTRIBUTEboolisFlipY(){returnisFlippedY();};
  94. @H_403_46@ /**@deprecatedUsesetFlippedY()instead*/
  95. CC_DEPRECATED_ATTRIBUTEvoidsetFlipY(boolflipY){setFlippedY(flipY);};
  96. @H_403_46@
  97. /**当该widget失去焦点会调用*/
  98. @H_403_46@ voiddidNotSelectSelf();
  99. @H_403_46@ /**检查一个点是否在父节点区域*/
  100. boolclippingParentAreaContainPoint(constPoint&pt);
  101. @H_403_46@
  102. /**发送触摸事件到widget的父节点*/
  103. @H_403_46@ voidcheckChildInfo(inthandleState,Widget*sender,255); font-weight:bold">constPoint&touchPoint);
  104. @H_403_46@ /**Getsthetouchbeganpointofwidgetwhenwidgetisselected.*/
  105. constPoint&getTouchStartPos();
  106. @H_403_46@
  107. /**Getsthetouchmovepointofwidgetwhenwidgetisselected*/
  108. @H_403_46@ constPoint&getTouchMovePos();
  109. @H_403_46@ /**Getsthetouchendpointofwidgetwhenwidgetisselected.*/
  110. constPoint&getTouchEndPos();
  111. @H_403_46@
  112. /**设置name*/
  113. @H_403_46@ voidsetName(char*name);
  114. @H_403_46@ /**得到name*/
  115. char*getName()const;
  116. @H_403_46@
  117. /**得到控件类型*/
  118. @H_403_46@ WidgetTypegetWidgetType()/**设置控件大小*/
  119. voidsetSize(constSize&size);
  120. @H_403_46@ voidsetSizeW(int&sizeW);
  121. voidsetSizeH(int&sizeH);
  122. @H_403_46@ /**设置size百分比*/
  123. voidsetSizePercent(constPoint&percent);
  124. @H_403_46@
  125. /**size类型*/
  126. @H_403_46@ voidsetSizeType(SizeTypetype);
  127. @H_403_46@ /**得到size类型*/
  128. SizeTypegetSizeType()/**得到size*/
  129. @H_403_46@ constSize&getSize()/**得到Customsize*/
  130. constSize&getCustomSize()/**得到layoutsize*/
  131. constSize&getLayoutSize(){return_size;};//虚函数供子类重写?
  132. @H_403_46@
  133. /**得到size百分比*/
  134. @H_403_46@ constPoint&getSizePercent()/***/
  135. boolhitTest(constPoint&pt);
  136. @H_403_46@ /**触摸事件*/
  137. boolonTouchBegan(Touch*touch,Event*unusedEvent);
  138. @H_403_46@ voidonTouchMoved(Touch*touch,Event*unusedEvent);
  139. voidonTouchEnded(Touch*touch,255); font-weight:bold">voidonTouchCancelled(Touch*touch,Event*unusedEvent);
  140. @H_403_46@ /**设置布局参数*/
  141. voidsetLayoutParameter(LayoutParameter*parameter);
  142. @H_403_46@
  143. /**得到布局参数*/
  144. @H_403_46@ LayoutParameter*getLayoutParameter(LayoutParameterTypetype);
  145. @H_403_46@ /**是否忽略size使用texturesize默认true*/
  146. voidignoreContentAdaptWithSize(boolignore);
  147. @H_403_46@
  148. /**是否忽略size使用texturesize*/
  149. @H_403_46@ boolisIgnoreContentAdaptWithSize()/**得到世界位置*/
  150. PointgetWorldPosition();
  151. @H_403_46@
  152. /**得到虚拟渲染器例如一个button的虚拟渲染器是他的texturerenderer贴图渲染器*/
  153. @H_403_46@ virtualNode*getVirtualRenderer();
  154. @H_403_46@ /**得到虚拟渲染器的size默认是_contentSize不同的子类有自己的重载*/
  155. constSize&getVirtualRendererSize()const;
  156. @H_403_46@
  157. @H_403_46@
  158. *得到改控件对应的"classname".
  159. virtualstd::stringgetDescription()constoverride;
  160. /**克隆替身*/
  161. @H_403_46@ Widget*clone();
  162. @H_403_46@ voidonEnter()override;
  163. voidonExit()override;
  164. @H_403_46@ /**更新size和position*/
  165. voidupdateSizeAndPosition();
  166. @H_403_46@
  167. voidupdateSizeAndPosition(constSize&parentSize);
  168. @H_403_46@
  169. /*tempaction*/
  170. @H_403_46@ voidsetActionTag(inttag);
  171. intgetActionTag();
  172. @H_403_46@
  173. CC_CONSTRUCTOR_ACCESS:
  174. @H_403_46@ //initializesstateofwidget.
  175. boolinit()override;
  176. @H_403_46@
  177. protected:
  178. @H_403_46@ //callbackfunctioncalledwhensizechanged.
  179. voidonSizeChanged();
  180. @H_403_46@
  181. //initializesrendererofwidget.
  182. @H_403_46@ voidinitRenderer();
  183. @H_403_46@ //回复正常调用.
  184. voidonPressStateChangedToNormal();
  185. @H_403_46@
  186. //选中会调用
  187. @H_403_46@ voidonPressStateChangedToPressed();
  188. @H_403_46@ //变暗会调用
  189. voidonPressStateChangedToDisabled();
  190. @H_403_46@ //不同的事件
  191. voidpushDownEvent();
  192. @H_403_46@ voidmoveEvent();
  193. voidreleaseUpEvent();
  194. @H_403_46@ voidcancelUpEvent();
  195. //空的虚函数为了多态
  196. @H_403_46@ voidupdateTextureColor(){};
  197. voidupdateTextureOpacity(){};
  198. @H_403_46@ voidupdateTextureRGBA(){};
  199. voidupdateFlippedX(){};
  200. @H_403_46@ voidupdateFlippedY(){};
  201. @H_403_46@ voidupdateColorToRenderer(Node*renderer);
  202. voidupdateOpacityToRenderer(Node*renderer);
  203. @H_403_46@ voidupdateRGBAToRenderer(Node*renderer);
  204. voidcopyProperties(Widget*model);
  205. @H_403_46@
  206. virtualWidget*createCloneInstance();
  207. @H_403_46@ voidcopySpecialProperties(Widget*model);
  208. voidcopyClonedWidgetChildren(Widget*model);
  209. @H_403_46@ Widget*getWidgetParent();
  210. voidupdateContentSizeWithTextureSize(constSize&size);
  211. @H_403_46@ /**多态适用于所有的子类重载实现自己的逻辑*/
  212. voidadaptRenderers(){};
  213. @H_403_46@ protected:
  214. bool_enabled;///<是否可见&&可触摸最高属性
  215. @H_403_46@ bool_bright;///<是否光亮
  216. bool_touchEnabled;///<是否响应触摸
  217. @H_403_46@ bool_touchPassedEnabled;///<触摸时间是不是按下
  218. bool_focus;///<是不是焦点
  219. @H_403_46@ BrightStyle_brightStyle;///<明亮风格
  220. Point_touchStartPos;///<touchbeganpoint
  221. @H_403_46@ Point_touchMovePos;///<touchmovedpoint
  222. Point_touchEndPos;///<touchendedpoint
  223. @H_403_46@
  224. SEL_TouchEvent_touchEventSelector;///回调函数类型
  225. @H_403_46@ std::string_name;///类名
  226. WidgetType_widgetType;///控件类型
  227. @H_403_46@ int_actionTag;///执行动作的tag
  228. Size_size;///untransformedsize
  229. @H_403_46@ Size_customSize;///自定义size
  230. bool_ignoreSize;///是否忽略自定义的大小而取资源原本的大小untransformedimgsize默认_size=_customSize
  231. @H_403_46@ bool_affectByClipping;
  232. SizeType_sizeType;///size类型
  233. @H_403_46@ Point_sizePercent;///相对父节点size百分比
  234. PositionType_positionType;///位置类型
  235. @H_403_46@ Point_positionPercent;///相对父节点的位置百分比
  236. bool_reorderWidgetChildDirty;
  237. @H_403_46@ bool_hitted;
  238. EventListenerTouchOneByOne*_touchListener;///单点触摸
  239. @H_403_46@ Color3B_color;///颜色值
  240. GLubyte_opacity;///透明度
  241. @H_403_46@ bool_flippedX;//是否镜像X轴
  242. bool_flippedY;//是否镜像Y轴
  243. @H_403_46@ Map<int,LayoutParameter*>_layoutParameterDictionary;//布局参数Map
  244. @H_403_46@ };
  245. }
  246. @H_403_46@
  247. NS_CC_END
  248. @H_403_46@
  249. #endif/*defined(__Widget__)*/

copy
/**************************************************************************** @H_403_46@ Copyright(c)2013-2014ChukongTechnologiesInc.
  • @H_403_46@ http://www.cocos2d-x.org
  • Permissionisherebygranted,freeofcharge,toanypersonobtainingacopy
  • ofthissoftwareandassociateddocumentationfiles(the"Software"),todeal
  • @H_403_46@ intheSoftwarewithoutrestriction,includingwithoutlimitationtherights
  • touse,copy,modify,merge,publish,distribute,sublicense,and/orsell
  • @H_403_46@ copiesoftheSoftware,andtopermitpersonstowhomtheSoftwareis
  • furnishedtodoso,subjecttothefollowingconditions:
  • @H_403_46@
  • Theabovecopyrightnoticeandthispermissionnoticeshallbeincludedin
  • @H_403_46@ allcopiesorsubstantialportionsoftheSoftware.
  • THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND,EXPRESSOR
  • IMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOFMERCHANTABILITY,
  • @H_403_46@ FITNESSFORAPARTICULARPURPOSEANDNONINFRINGEMENT.INNOEVENTSHALLTHE
  • AUTHORSORCOPYRIGHTHOLDERSBELIABLEFORANYCLAIM,DAMAGESOROTHER
  • @H_403_46@ LIABILITY,WHETHERINANACTIONOFCONTRACT,TORTOROTHERWISE,ARISINGFROM,
  • OUTOFORINCONNECTIONWITHTHESOFTWAREORTHEUSEOROTHERDEALINGSIN
  • @H_403_46@ THESOFTWARE.
  • ****************************************************************************/
  • @H_403_46@
  • #include"ui/UIWidget.h"
  • @H_403_46@ #include"ui/UILayout.h"
  • #include"ui/UIHelper.h"
  • @H_403_46@
  • NS_CC_BEGIN
  • @H_403_46@
  • namespaceui{
  • @H_403_46@
  • Widget::Widget():
  • @H_403_46@ _enabled(true),
  • _bright(403_46@ _touchEnabled(false),
  • _touchPassedEnabled(403_46@ _focus( _brightStyle(BRIGHT_NONE),
  • @H_403_46@ _touchStartPos(Point::ZERO),
  • _touchMovePos(Point::ZERO),
  • @H_403_46@ _touchEndPos(Point::ZERO),
  • _touchEventSelector(nullptr),
  • @H_403_46@ _name("default"),
  • _widgetType(WidgetTypeWidget),
  • @H_403_46@ _actionTag(0),
  • _size(Size::ZERO),
  • @H_403_46@ _customSize(Size::ZERO),
  • _ignoreSize(403_46@ _affectByClipping( _sizeType(SIZE_ABSOLUTE),
  • @H_403_46@ _sizePercent(Point::ZERO),
  • _positionType(POSITION_ABSOLUTE),
  • @H_403_46@ _positionPercent(Point::ZERO),
  • _reorderWidgetChildDirty(403_46@ _hitted( _touchListener(nullptr),
  • @H_403_46@ _color(Color3B::WHITE),
  • _opacity(255),
  • @H_403_46@ _flippedX( _flippedY(false) @H_403_46@ {
  • @H_403_46@ }
  • @H_403_46@ Widget::~Widget()
  • {
  • @H_403_46@ _touchEventSelector=nullptr;
  • setTouchEnabled(false);
  • @H_403_46@ }
  • @H_403_46@ Widget*Widget::create()
  • {
  • @H_403_46@ Widget*widget=newWidget();
  • if(widget&&widget->init())
  • @H_403_46@ {
  • widget->autorelease();
  • @H_403_46@ returnwidget;
  • }
  • @H_403_46@ CC_SAFE_DELETE(widget);
  • returnnullptr;
  • @H_403_46@ }
  • @H_403_46@ boolWidget::init()
  • {
  • @H_403_46@ if(ProtectedNode::init())
  • {
  • @H_403_46@ initRenderer();//初始化渲染器多态
  • setBright(true);//设置明亮
  • @H_403_46@ ignoreContentAdaptWithSize(//默认内容不适应size大小
  • setAnchorPoint(Point(0.5f,0.5f));//默认锚点在中心
  • @H_403_46@ returntrue;
  • }
  • @H_403_46@ false;
  • }
  • @H_403_46@
  • voidWidget::onEnter()
  • @H_403_46@ {
  • updateSizeAndPosition();
  • @H_403_46@ ProtectedNode::onEnter();
  • }
  • @H_403_46@
  • voidWidget::onExit()
  • @H_403_46@ {
  • unscheduleUpdate();
  • @H_403_46@ ProtectedNode::onExit();
  • }
  • @H_403_46@
  • voidWidget::visit(Renderer*renderer,51); font-weight:bold">boolparentTransformUpdated)
  • @H_403_46@ {
  • if(_enabled)
  • @H_403_46@ {
  • adaptRenderers();
  • @H_403_46@ ProtectedNode::visit(renderer,parentTransform,parentTransformUpdated);
  • }
  • @H_403_46@ }
  • @H_403_46@ Widget*Widget::getWidgetParent()
  • {
  • @H_403_46@ //得到父节点
  • dynamic_cast<Widget*>(getParent());
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setEnabled(boolenabled)
  • {
  • @H_403_46@ _enabled=enabled;
  • for(auto&child:_children)
  • @H_403_46@ {
  • if(child)
  • @H_403_46@ {
  • Widget*widgetChild=dynamic_cast<Widget*>(child);
  • @H_403_46@ if(widgetChild)
  • {
  • @H_403_46@ widgetChild->setEnabled(enabled);
  • }
  • @H_403_46@ }
  • }
  • @H_403_46@
  • for(auto&child:_protectedChildren)
  • @H_403_46@ {
  • if(widgetChild)
  • {
  • @H_403_46@ widgetChild->setEnabled(enabled);
  • }
  • @H_403_46@ }
  • }
  • @H_403_46@ }
  • @H_403_46@ Widget*Widget::getChildByName(char*name)
  • {
  • @H_403_46@ for(auto&child:_children)
  • {
  • @H_403_46@ if(child)
  • {
  • @H_403_46@ Widget*widgetChild=dynamic_cast<Widget*>(child);
  • if(widgetChild)
  • @H_403_46@ {
  • if(strcmp(widgetChild->getName(),name)==0)
  • @H_403_46@ {
  • returnwidgetChild;
  • @H_403_46@ }
  • }
  • @H_403_46@ }
  • }
  • @H_403_46@ returnnullptr;
  • }
  • @H_403_46@
  • voidWidget::initRenderer()
  • @H_403_46@ {
  • //多态不同的控件有自己的初始化渲染方式
  • @H_403_46@
  • }
  • @H_403_46@
  • voidWidget::setSizeW(int&sizeW)
  • @H_403_46@ {
  • _customSize.width=sizeW;
  • @H_403_46@ if(_ignoreSize)
  • {
  • @H_403_46@ _size=getVirtualRendererSize();
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ _size.width=sizeW;
  • }
  • @H_403_46@ if(_running)
  • {
  • @H_403_46@ Widget*widgetParent=getWidgetParent();
  • SizepSize;
  • @H_403_46@ if(widgetParent)
  • {
  • @H_403_46@ pSize=widgetParent->getSize();
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ pSize=_parent->getContentSize();
  • }
  • @H_403_46@ floatspx=0.0f;
  • floatspy=0.0f;
  • @H_403_46@ if(pSize.width>0.0f)
  • {
  • @H_403_46@ spx=_customSize.width/pSize.width;
  • }
  • @H_403_46@ if(pSize.height>0.0f)
  • {
  • @H_403_46@ spy=_customSize.height/pSize.height;
  • }
  • @H_403_46@ _sizePercent=Point(spx,spy);
  • }
  • @H_403_46@ onSizeChanged();
  • }
  • @H_403_46@ voidWidget::setSizeH(int&sizeH)
  • {
  • @H_403_46@ _customSize.height=sizeH;
  • if(_ignoreSize)
  • @H_403_46@ {
  • _size=getVirtualRendererSize();
  • @H_403_46@ }
  • else
  • @H_403_46@ {
  • _size.height=sizeH;
  • @H_403_46@ }
  • if(_running)
  • @H_403_46@ {
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ SizepSize;
  • if(widgetParent)
  • @H_403_46@ {
  • pSize=widgetParent->getSize();
  • @H_403_46@ }
  • else
  • @H_403_46@ {
  • pSize=_parent->getContentSize();
  • @H_403_46@ }
  • floatspx=0.0f;
  • @H_403_46@ floatspy=0.0f;
  • if(pSize.width>0.0f)
  • @H_403_46@ {
  • spx=_customSize.width/pSize.width;
  • @H_403_46@ }
  • if(pSize.height>0.0f)
  • @H_403_46@ {
  • spy=_customSize.height/pSize.height;
  • @H_403_46@ }
  • _sizePercent=Point(spx,spy);
  • @H_403_46@ }
  • onSizeChanged();
  • @H_403_46@ }
  • voidWidget::setSize(constSize&size)
  • @H_403_46@ {
  • _customSize=size;
  • @H_403_46@ else
  • {
  • @H_403_46@ _size=size;
  • }
  • @H_403_46@ } @H_403_46@ onSizeChanged();
  • }
  • @H_403_46@
  • voidWidget::setSizePercent(constPoint&percent)
  • @H_403_46@ {
  • _sizePercent=percent;
  • @H_403_46@ SizecSize=_customSize;
  • if(_running)
  • @H_403_46@ {
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ if(widgetParent)
  • {
  • @H_403_46@ cSize=Size(widgetParent->getSize().width*percent.x,widgetParent->getSize().height*percent.y);
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ cSize=Size(_parent->getContentSize().width*percent.x,_parent->getContentSize().height*percent.y);
  • }
  • @H_403_46@ }
  • else
  • @H_403_46@ {
  • _size=cSize;
  • @H_403_46@ }
  • _customSize=cSize;
  • @H_403_46@ onSizeChanged();
  • }
  • @H_403_46@
  • voidWidget::updateSizeAndPosition()
  • @H_403_46@ {
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ SizepSize;
  • if(widgetParent)
  • @H_403_46@ {//如果有父节点是控件基类widget保存父节点的容器大小
  • pSize=widgetParent->getLayoutSize();
  • @H_403_46@ }
  • else
  • @H_403_46@ {//如果父节点不是控件基类widget得到绑定贴图大小
  • pSize=_parent->getContentSize();
  • @H_403_46@ }
  • updateSizeAndPosition(pSize);
  • @H_403_46@ }
  • @H_403_46@ voidWidget::updateSizeAndPosition(constcocos2d::Size&parentSize)
  • {
  • @H_403_46@ switch(_sizeType)
  • {
  • @H_403_46@ caseSIZE_ABSOLUTE://绝对大小真实大小
  • {
  • @H_403_46@ if(_ignoreSize)//忽略设置的大小
  • {
  • @H_403_46@ _size=getVirtualRendererSize();//size取untransformedimgsize
  • }
  • @H_403_46@ else//不忽略自定义大小
  • {
  • @H_403_46@ _size=_customSize;//size取自定义大小
  • }
  • @H_403_46@ if(parentSize.width>0.0f)
  • {
  • @H_403_46@ spx=_customSize.width/parentSize.width;
  • }
  • @H_403_46@ if(parentSize.height>0.0f)
  • {
  • @H_403_46@ spy=_customSize.height/parentSize.height;
  • }
  • @H_403_46@ _sizePercent=Point(spx,spy);//计算得到相对父节点的size百分比
  • break;
  • @H_403_46@ }
  • caseSIZE_PERCENT://百分比size
  • @H_403_46@ {
  • SizecSize=Size(parentSize.width*_sizePercent.x,parentSize.height*_sizePercent.y);//计算得到自定义大小
  • @H_403_46@ //不忽略自定义大小
  • {
  • @H_403_46@ _size=cSize;//size取计算得到自定义大小
  • }
  • @H_403_46@ _customSize=cSize;//计算得到自定义大小
  • default:
  • @H_403_46@ break;
  • }
  • @H_403_46@ onSizeChanged();
  • PointabsPos=getPosition();
  • @H_403_46@ switch(_positionType)
  • {
  • @H_403_46@ casePOSITION_ABSOLUTE://真实位置
  • {
  • @H_403_46@ if(parentSize.width<=0.0f||parentSize.height<=0.0f)
  • {//父节点size=0
  • @H_403_46@ _positionPercent=Point::ZERO;//相对父节点的位置百分比为0
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ _positionPercent=Point(absPos.x/parentSize.width,absPos.y/parentSize.height);//相对父节点的位置百分比
  • }
  • @H_403_46@ break;
  • }
  • @H_403_46@ casePOSITION_PERCENT://相对位置
  • {
  • @H_403_46@ absPos=Point(parentSize.width*_positionPercent.x,parentSize.height*_positionPercent.y);//得到真实位置
  • break;
  • }
  • @H_403_46@ setPosition(absPos);//更新真实位置
  • }
  • @H_403_46@
  • voidWidget::setSizeType(SizeTypetype)
  • @H_403_46@ {
  • _sizeType=type;//设置size类型
  • @H_403_46@ }
  • @H_403_46@ SizeTypeWidget::getSizeType()const//返回值不可改
  • {
  • @H_403_46@ return_sizeType;//得到sizetype返回值不可改
  • }
  • @H_403_46@
  • voidWidget::ignoreContentAdaptWithSize(boolignore)
  • @H_403_46@ {
  • if(_ignoreSize==ignore)
  • @H_403_46@ {
  • return;//和当前值一样没必要更新处理了直接返回
  • @H_403_46@ }
  • _ignoreSize=ignore;
  • @H_403_46@ //忽略自定义size
  • {
  • @H_403_46@ Sizes=getVirtualRendererSize();//取原本大小的size
  • _size=s;
  • @H_403_46@ }
  • //不忽略自定义size
  • @H_403_46@ {
  • _size=_customSize;//取自定义size
  • @H_403_46@ }
  • onSizeChanged();//更新size
  • @H_403_46@ }
  • @H_403_46@ boolWidget::isIgnoreContentAdaptWithSize()const
  • {
  • @H_403_46@ return_ignoreSize;
  • }
  • @H_403_46@
  • constSize&Widget::getSize()const
  • @H_403_46@ {
  • return_size;
  • @H_403_46@ }
  • @H_403_46@ constSize&Widget::getCustomSize()return_customSize;
  • }
  • @H_403_46@
  • constPoint&Widget::getSizePercent()return_sizePercent;
  • @H_403_46@ }
  • @H_403_46@ PointWidget::getWorldPosition()
  • {
  • @H_403_46@ returnconvertToWorldSpace(Point(_anchorPoint.x*_contentSize.width,_anchorPoint.y*_contentSize.height));//得到世界坐标
  • }
  • @H_403_46@
  • Node*Widget::getVirtualRenderer()
  • @H_403_46@ {
  • this;//得到虚拟渲染器默认是自己不同的子类有自己的重载
  • @H_403_46@ }
  • @H_403_46@ voidWidget::onSizeChanged()
  • {
  • @H_403_46@ setContentSize(_size);//设置untransformedsize
  • for(auto&child:getChildren())
  • @H_403_46@ {
  • Widget*widgetChild=if(widgetChild)
  • {
  • @H_403_46@ widgetChild->updateSizeAndPosition();//递归更新所有子节点sizeposition
  • }
  • @H_403_46@ }
  • }
  • @H_403_46@
  • constSize&Widget::getVirtualRendererSize()return_contentSize;//得到虚拟渲染器zise默认是_contentSize不同的子类有自己的重载
  • @H_403_46@ }
  • @H_403_46@ voidWidget::updateContentSizeWithTextureSize(constcocos2d::Size&size)
  • {
  • @H_403_46@ if(_ignoreSize)
  • {
  • @H_403_46@ _size=size;
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ _size=_customSize;
  • }
  • @H_403_46@ onSizeChanged();
  • }
  • @H_403_46@
  • voidWidget::setTouchEnabled(boolenable)
  • @H_403_46@ {
  • if(enable==_touchEnabled)
  • @H_403_46@ {
  • return;
  • @H_403_46@ }
  • _touchEnabled=enable;
  • @H_403_46@ if(_touchEnabled)//如果开启触摸
  • {
  • @H_403_46@ _touchListener=EventListenerTouchOneByOne::create();
  • CC_SAFE_RETAIN(_touchListener);//创建单点触摸
  • @H_403_46@ _touchListener->setSwallowTouches(//不向下触摸,简单点来说,比如有两个sprite,A和B,A在上B在下(位置重叠),触摸A的时候,B不会受到影响
  • //绑定四个回调函数
  • @H_403_46@ _touchListener->onTouchBegan=CC_CALLBACK_2(Widget::onTouchBegan,this);
  • _touchListener->onTouchMoved=CC_CALLBACK_2(Widget::onTouchMoved,255); font-weight:bold">this);
  • @H_403_46@ _touchListener->onTouchEnded=CC_CALLBACK_2(Widget::onTouchEnded,255); font-weight:bold">this);
  • _touchListener->onTouchCancelled=CC_CALLBACK_2(Widget::onTouchCancelled,255); font-weight:bold">this);
  • @H_403_46@ _eventDispatcher->addEventListenerWithSceneGraPHPriority(_touchListener,255); font-weight:bold">this);
  • }
  • @H_403_46@ else//如果不开启触摸
  • {
  • @H_403_46@ _eventDispatcher->removeEventListener(_touchListener);//移除
  • CC_SAFE_RELEASE_NULL(_touchListener);//释放
  • @H_403_46@ }
  • }
  • @H_403_46@
  • boolWidget::isTouchEnabled()return_touchEnabled;
  • @H_403_46@ }
  • @H_403_46@ boolWidget::isFocused()return_focus;
  • }
  • @H_403_46@
  • voidWidget::setFocused(boolfucos)
  • @H_403_46@ {
  • if(fucos==_focus)
  • @H_403_46@ {
  • return;
  • @H_403_46@ }
  • _focus=fucos;
  • @H_403_46@ if(_bright)//如果亮
  • {
  • @H_403_46@ if(_focus)//如果选中
  • {
  • @H_403_46@ setBrightStyle(BRIGHT_HIGHLIGHT);//高亮
  • }
  • @H_403_46@ //如果没有选中
  • {
  • @H_403_46@ setBrightStyle(BRIGHT_NORMAL);//正常
  • }
  • @H_403_46@ }
  • //如果不亮
  • @H_403_46@ {
  • onPressStateChangedToDisabled();//变暗
  • @H_403_46@ }
  • }
  • @H_403_46@
  • voidWidget::setBright(boolbright)
  • @H_403_46@ {
  • _bright=bright;
  • @H_403_46@ //如果亮
  • {
  • @H_403_46@ _brightStyle=BRIGHT_NONE;
  • setBrightStyle(BRIGHT_NORMAL);//正常亮
  • @H_403_46@ }
  • voidWidget::setBrightStyle(BrightStylestyle)
  • @H_403_46@ {
  • if(_brightStyle==style)
  • @H_403_46@ {
  • return;
  • @H_403_46@ }
  • _brightStyle=style;
  • @H_403_46@ switch(_brightStyle)
  • {
  • @H_403_46@ caseBRIGHT_NORMAL:
  • onPressStateChangedToNormal();
  • @H_403_46@ break;
  • caseBRIGHT_HIGHLIGHT:
  • @H_403_46@ onPressStateChangedToPressed();
  • break;
  • @H_403_46@ default:
  • break;
  • @H_403_46@ }
  • }
  • @H_403_46@
  • voidWidget::onPressStateChangedToNormal()
  • @H_403_46@ {
  • @H_403_46@ }
  • @H_403_46@ voidWidget::onPressStateChangedToPressed()
  • {
  • @H_403_46@
  • }
  • @H_403_46@
  • voidWidget::onPressStateChangedToDisabled()
  • @H_403_46@ {
  • @H_403_46@ }
  • @H_403_46@ voidWidget::didNotSelectSelf()
  • {
  • @H_403_46@
  • }
  • @H_403_46@ voidWidget::logInfo(WidgetInfoType_type)
  • {
  • @H_403_46@ log("widgetanchorx=%f,y=%f",getAnchorPoint().x,getAnchorPoint().y);
  • if(_type==WIDGET_SIZE){
  • @H_403_46@ log("widgetsizewidth=%f,height=%f",_size.width,_size.height);
  • }
  • @H_403_46@ if(_type==WIDGET_POSITION){
  • log("widgetpositionx=%f,getPositionX(),getPositionY());
  • @H_403_46@ }
  • }
  • @H_403_46@ boolWidget::onTouchBegan(Touch*touch,Event*unusedEvent)
  • {
  • @H_403_46@ _hitted=false;//刚开始触摸没有碰到
  • if(isEnabled()&&isTouchEnabled())//节点可以使用可以点击
  • @H_403_46@ {
  • _touchStartPos=touch->getLocation();//得到点击位置
  • @H_403_46@ //触摸点在到图像区域并且触摸点在裁切区域
  • if(hitTest(_touchStartPos)&&clippingParentAreaContainPoint(_touchStartPos))
  • @H_403_46@ {
  • _hitted=true;//触摸到了
  • @H_403_46@ }
  • }
  • @H_403_46@ if(!_hitted)//没有触摸到
  • {
  • @H_403_46@ //停止
  • }
  • @H_403_46@ setFocused(//得到焦点
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ if(widgetParent)//有父节点
  • {
  • @H_403_46@ widgetParent->checkChildInfo(0,255); font-weight:bold">this,_touchStartPos);//检查孩子属性
  • }
  • @H_403_46@ pushDownEvent();//按下回调响应
  • return!_touchPassedEnabled;
  • @H_403_46@ }
  • @H_403_46@ voidWidget::onTouchMoved(Touch*touch,Event*unusedEvent)
  • {
  • @H_403_46@ _touchMovePos=touch->getLocation();
  • setFocused(hitTest(_touchMovePos));
  • @H_403_46@ Widget*widgetParent=getWidgetParent();
  • if(widgetParent)
  • @H_403_46@ {
  • widgetParent->checkChildInfo(1,_touchMovePos);
  • @H_403_46@ }
  • moveEvent();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::onTouchEnded(Touch*touch,Event*unusedEvent)
  • {
  • @H_403_46@ _touchEndPos=touch->getLocation();
  • boolfocus=_focus;
  • @H_403_46@ setFocused(false);
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ if(widgetParent)
  • {
  • @H_403_46@ widgetParent->checkChildInfo(2,_touchEndPos);
  • }
  • @H_403_46@ if(focus)
  • {
  • @H_403_46@ releaseUpEvent();
  • }
  • @H_403_46@ else
  • {
  • @H_403_46@ cancelUpEvent();
  • }
  • @H_403_46@ }
  • @H_403_46@ voidWidget::onTouchCancelled(Touch*touch,Event*unusedEvent)
  • {
  • @H_403_46@ setFocused(false);
  • cancelUpEvent();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::pushDownEvent()
  • {
  • @H_403_46@ if(_touchEventSelector)
  • {
  • @H_403_46@ //(->*_touchEventSelector)(this,TouchEventType::TOUCH_EVENT_BEGAN);//响应开始按下的回调
  • _touchEventSelector(//响应开始按下的回调
  • @H_403_46@ }
  • }
  • @H_403_46@
  • voidWidget::moveEvent()
  • @H_403_46@ {
  • if(_touchEventSelector)
  • @H_403_46@ {
  • @H_403_46@ _touchEventSelector(//响应移动的回调
  • }
  • @H_403_46@ }
  • @H_403_46@ voidWidget::releaseUpEvent()
  • {
  • @H_403_46@
  • _touchEventSelector(//响应结束的回调
  • @H_403_46@ }
  • }
  • @H_403_46@
  • voidWidget::cancelUpEvent()
  • @H_403_46@ {
  • if(_touchEventSelector)
  • @H_403_46@ {
  • _touchEventSelector(//响应取消按下的回调
  • @H_403_46@
  • }
  • @H_403_46@ }
  • //共外部注册回调
  • @H_403_46@ voidWidget::addTouchEventListener(SEL_TouchEventselector)
  • {
  • @H_403_46@ _touchEventSelector=selector;
  • }
  • @H_403_46@
  • boolWidget::hitTest(constPoint&pt)
  • @H_403_46@ {
  • Pointnsp=convertToNodeSpace(pt);//相对this的点
  • @H_403_46@ Rectbb;
  • bb.size=_contentSize;
  • @H_403_46@ if(bb.containsPoint(nsp))
  • {
  • @H_403_46@ //点在size内hit~!
  • }
  • @H_403_46@ false;
  • }
  • @H_403_46@
  • boolWidget::clippingParentAreaContainPoint(constPoint&pt)
  • @H_403_46@ {
  • _affectByClipping=false;
  • @H_403_46@ Widget*parent=getWidgetParent();
  • Widget*clippingParent=nullptr;
  • @H_403_46@ while(parent)//有父节点
  • {
  • @H_403_46@ Layout*layoutParent=dynamic_cast<Layout*>(parent);
  • if(layoutParent)//父节点是层容器
  • @H_403_46@ {
  • if(layoutParent->isClippingEnabled())//父节点是可以裁切的
  • @H_403_46@ {
  • _affectByClipping=//受裁切的影响
  • @H_403_46@ clippingParent=layoutParent;//取到已经裁切的父节点
  • break;//跳出循环
  • @H_403_46@ }
  • }
  • @H_403_46@ parent=parent->getWidgetParent();//向上遍历父节点
  • }
  • @H_403_46@
  • if(!_affectByClipping)//没有可以裁切的层容器
  • @H_403_46@ {
  • true;
  • @H_403_46@ }
  • @H_403_46@
  • if(clippingParent)//存在裁切的父节点
  • @H_403_46@ {
  • boolbRet=false;
  • @H_403_46@ if(clippingParent->hitTest(pt))//点在裁切裁切范围内
  • {
  • @H_403_46@ bRet=if(bRet)
  • {
  • @H_403_46@ returnclippingParent->clippingParentAreaContainPoint(pt);//递归裁切父节点
  • }
  • @H_403_46@ false;
  • }
  • @H_403_46@ true;
  • }
  • @H_403_46@
  • voidWidget::checkChildInfo(constPoint&touchPoint)
  • @H_403_46@ {
  • Widget*widgetParent=getWidgetParent();
  • @H_403_46@ if(widgetParent)
  • {
  • @H_403_46@ widgetParent->checkChildInfo(handleState,sender,touchPoint);//递归检查孩子的info
  • }
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setPosition(constPoint&pos)
  • {
  • @H_403_46@ if(_running)//若在运行状态
  • {
  • @H_403_46@ Widget*widgetParent=getWidgetParent();
  • //若有父节点
  • @H_403_46@ {
  • SizepSize=widgetParent->getSize();//父节点大小
  • @H_403_46@ if(pSize.width<=0.0f||pSize.height<=0.0f)
  • {
  • @H_403_46@ _positionPercent=Point::ZERO;//百分比为0
  • }
  • @H_403_46@ else
  • {//计算相对父节点百分比
  • @H_403_46@ _positionPercent=Point(pos.x/pSize.width,pos.y/pSize.height);
  • }
  • @H_403_46@ }
  • }
  • @H_403_46@ //因为widget对于position的表示除了世界坐标之外还新加了百分比坐标
  • //所以需要额外处理计算百分比坐标
  • @H_403_46@ ProtectedNode::setPosition(pos);
  • }
  • @H_403_46@
  • voidWidget::setPositionPercent(constPoint&percent)
  • @H_403_46@ {
  • _positionPercent=percent;
  • @H_403_46@ if(_running)
  • {
  • @H_403_46@ Widget*widgetParent=getWidgetParent();
  • if(widgetParent)
  • @H_403_46@ {
  • SizeparentSize=widgetParent->getSize();
  • @H_403_46@ PointabsPos=Point(parentSize.width*_positionPercent.x,119)">//绝对坐标
  • setPosition(absPos);
  • @H_403_46@ }
  • }
  • @H_403_46@ }
  • @H_403_46@ constPoint&Widget::getPositionPercent()
  • {
  • @H_403_46@ return_positionPercent;
  • }
  • @H_403_46@
  • voidWidget::setPositionType(PositionTypetype)
  • @H_403_46@ {
  • _positionType=type;
  • @H_403_46@ }
  • @H_403_46@ PositionTypeWidget::getPositionType()return_positionType;
  • }
  • @H_403_46@
  • boolWidget::isBright()return_bright;
  • @H_403_46@ }
  • @H_403_46@ boolWidget::isEnabled()return_enabled;
  • }
  • @H_403_46@
  • floatWidget::getLeftInParent()
  • @H_403_46@ {
  • returngetPosition().x-getAnchorPoint().x*_size.width;;
  • @H_403_46@ }
  • //得到距离父节点底部的距离
  • @H_403_46@ floatWidget::getBottomInParent()
  • {
  • @H_403_46@ returngetPosition().y-getAnchorPoint().y*_size.height;;
  • }
  • @H_403_46@
  • floatWidget::getRightInParent()
  • @H_403_46@ {
  • returngetLeftInParent()+_size.width;
  • @H_403_46@ }
  • @H_403_46@ floatWidget::getTopInParent()
  • {
  • @H_403_46@ returngetBottomInParent()+_size.height;
  • }
  • @H_403_46@
  • constPoint&Widget::getTouchStartPos()
  • @H_403_46@ {
  • return_touchStartPos;
  • @H_403_46@ }
  • @H_403_46@ constPoint&Widget::getTouchMovePos()
  • {
  • @H_403_46@ return_touchMovePos;
  • }
  • @H_403_46@
  • constPoint&Widget::getTouchEndPos()
  • @H_403_46@ {
  • return_touchEndPos;
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setName(char*name)
  • {
  • @H_403_46@ _name=name;
  • }
  • @H_403_46@
  • char*Widget::getName()return_name.c_str();
  • @H_403_46@ }
  • @H_403_46@ WidgetTypeWidget::getWidgetType()return_widgetType;
  • }
  • @H_403_46@ //设置布局参数
  • voidWidget::setLayoutParameter(LayoutParameter*parameter)
  • @H_403_46@ {
  • if(!parameter)
  • @H_403_46@ {
  • return;
  • @H_403_46@ }
  • _layoutParameterDictionary.insert(parameter->getLayoutType(),parameter);
  • @H_403_46@ }
  • //得到所有布局参数
  • @H_403_46@ LayoutParameter*Widget::getLayoutParameter(LayoutParameterTypetype)
  • {
  • @H_403_46@ dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at(type));
  • }
  • @H_403_46@
  • std::stringWidget::getDescription()return"Widget";
  • @H_403_46@ }
  • //克隆
  • @H_403_46@ Widget*Widget::clone()
  • {
  • @H_403_46@ Widget*clonedWidget=createCloneInstance();
  • clonedWidget->copyProperties(this);//拷贝基础属性
  • @H_403_46@ clonedWidget->copyClonedWidgetChildren(//拷贝所有孩子
  • returnclonedWidget;
  • @H_403_46@ }
  • @H_403_46@ Widget*Widget::createCloneInstance()
  • {
  • @H_403_46@ returnWidget::create();
  • }
  • @H_403_46@
  • voidWidget::copyClonedWidgetChildren(Widget*model)
  • @H_403_46@ {
  • //引用类型auto&
  • @H_403_46@ auto&modelChildren=model->getChildren();
  • @H_403_46@ for(auto&subWidget:modelChildren)
  • {
  • @H_403_46@ Widget*child=dynamic_cast<Widget*>(subWidget);
  • if(child)
  • @H_403_46@ {
  • addChild(child->clone());
  • @H_403_46@ }
  • }
  • @H_403_46@ }
  • @H_403_46@ voidWidget::copySpecialProperties(Widget*model)
  • {
  • @H_403_46@
  • }
  • @H_403_46@ //拷贝属性
  • voidWidget::copyProperties(Widget*widget)
  • @H_403_46@ {
  • setEnabled(widget->isEnabled());
  • @H_403_46@ setVisible(widget->isVisible());
  • setBright(widget->isBright());
  • @H_403_46@ setTouchEnabled(widget->isTouchEnabled());
  • _touchPassedEnabled=false;
  • @H_403_46@ setLocalZOrder(widget->getLocalZOrder());
  • setTag(widget->getTag());
  • @H_403_46@ setName(widget->getName());
  • setActionTag(widget->getActionTag());
  • @H_403_46@ _ignoreSize=widget->_ignoreSize;
  • _size=widget->_size;
  • @H_403_46@ _customSize=widget->_customSize;
  • copySpecialProperties(widget);
  • @H_403_46@ _sizeType=widget->getSizeType();
  • _sizePercent=widget->_sizePercent;
  • @H_403_46@ _positionType=widget->_positionType;
  • _positionPercent=widget->_positionPercent;
  • @H_403_46@ setPosition(widget->getPosition());
  • setAnchorPoint(widget->getAnchorPoint());
  • @H_403_46@ setScaleX(widget->getScaleX());
  • setScaleY(widget->getScaleY());
  • @H_403_46@ setRotation(widget->getRotation());
  • setRotationSkewX(widget->getRotationSkewX());
  • @H_403_46@ setRotationSkewY(widget->getRotationSkewY());
  • setFlippedX(widget->isFlippedX());
  • @H_403_46@ setFlippedY(widget->isFlippedY());
  • setColor(widget->getColor());
  • @H_403_46@ setOpacity(widget->getOpacity());
  • //遍历布局参数容器拷贝
  • @H_403_46@ Map< for(autoiter=layoutParameterDic.begin();iter!=layoutParameterDic.end();++iter) @H_403_46@ {
  • setLayoutParameter(iter->second->clone());
  • @H_403_46@ }
  • onSizeChanged();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setColor(constColor3B&color)
  • {
  • @H_403_46@ _color=color;
  • updateTextureColor();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setOpacity(GLubyteopacity)
  • {
  • @H_403_46@ _opacity=opacity;
  • updateTextureOpacity();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setFlippedX(boolflippedX)
  • {
  • @H_403_46@ _flippedX=flippedX;
  • updateFlippedX();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::setFlippedY(boolflippedY)
  • {
  • @H_403_46@ _flippedY=flippedY;
  • updateFlippedY();
  • @H_403_46@ }
  • @H_403_46@ voidWidget::updateColorToRenderer(Node*renderer)
  • {
  • @H_403_46@ renderer->setColor(_color);
  • }
  • @H_403_46@
  • voidWidget::updateOpacityToRenderer(Node*renderer)
  • @H_403_46@ {
  • renderer->setOpacity(_opacity);
  • @H_403_46@ }
  • @H_403_46@ voidWidget::updateRGBAToRenderer(Node*renderer)
  • {
  • @H_403_46@ renderer->setColor(_color);
  • renderer->setOpacity(_opacity);
  • @H_403_46@ }
  • @H_403_46@ /*tempaction*/
  • voidWidget::setActionTag(inttag)
  • @H_403_46@ {
  • _actionTag=tag;
  • @H_403_46@ }
  • @H_403_46@ intWidget::getActionTag()
  • {
  • @H_403_46@ return_actionTag;
  • }
  • @H_403_46@
  • }
  • @H_403_46@
  • NS_CC_END
  • 原文链接:https://www.f2er.com/cocos2dx/340301.html

    猜你在找的Cocos2d-x相关文章