UIWidget.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "ui/UIWidget.h"
  22. #include "ui/UILayout.h"
  23. #include "ui/UIHelper.h"
  24. #include "base/CCEventListenerTouch.h"
  25. #include "base/CCEventListenerKeyboard.h"
  26. #include "base/CCDirector.h"
  27. #include "base/CCEventFocus.h"
  28. #include "base/CCEventDispatcher.h"
  29. #include "ui/UILayoutComponent.h"
  30. #include "renderer/CCGLProgram.h"
  31. #include "renderer/CCGLProgramState.h"
  32. #include "renderer/ccShaders.h"
  33. #include "2d/CCCamera.h"
  34. #include "2d/CCSprite.h"
  35. #include "ui/UIScale9Sprite.h"
  36. NS_CC_BEGIN
  37. namespace ui {
  38. class Widget::FocusNavigationController
  39. {
  40. void enableFocusNavigation(bool flag);
  41. FocusNavigationController():
  42. _keyboardListener(nullptr),
  43. _firstFocusedWidget(nullptr),
  44. _enableFocusNavigation(false),
  45. _keyboardEventPriority(1)
  46. {
  47. //no-op
  48. }
  49. ~FocusNavigationController();
  50. protected:
  51. void setFirstFocusedWidget(Widget* widget);
  52. void onKeypadKeyPressed(EventKeyboard::KeyCode, Event*);
  53. void addKeyboardEventListener();
  54. void removeKeyboardEventListener();
  55. friend class Widget;
  56. private:
  57. EventListenerKeyboard* _keyboardListener ;
  58. Widget* _firstFocusedWidget ;
  59. bool _enableFocusNavigation ;
  60. const int _keyboardEventPriority;
  61. };
  62. Widget::FocusNavigationController::~FocusNavigationController()
  63. {
  64. this->removeKeyboardEventListener();
  65. }
  66. void Widget::FocusNavigationController::onKeypadKeyPressed(EventKeyboard::KeyCode keyCode, Event* /*event*/)
  67. {
  68. if (_enableFocusNavigation && _firstFocusedWidget)
  69. {
  70. if (keyCode == EventKeyboard::KeyCode::KEY_DPAD_DOWN)
  71. {
  72. _firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::DOWN, _firstFocusedWidget);
  73. }
  74. if (keyCode == EventKeyboard::KeyCode::KEY_DPAD_UP)
  75. {
  76. _firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::UP, _firstFocusedWidget);
  77. }
  78. if (keyCode == EventKeyboard::KeyCode::KEY_DPAD_LEFT)
  79. {
  80. _firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::LEFT, _firstFocusedWidget);
  81. }
  82. if (keyCode == EventKeyboard::KeyCode::KEY_DPAD_RIGHT)
  83. {
  84. _firstFocusedWidget = _firstFocusedWidget->findNextFocusedWidget(Widget::FocusDirection::RIGHT, _firstFocusedWidget);
  85. }
  86. }
  87. }
  88. void Widget::FocusNavigationController::enableFocusNavigation(bool flag)
  89. {
  90. if (_enableFocusNavigation == flag)
  91. return;
  92. _enableFocusNavigation = flag;
  93. if (flag)
  94. this->addKeyboardEventListener();
  95. else
  96. this->removeKeyboardEventListener();
  97. }
  98. void Widget::FocusNavigationController::setFirstFocusedWidget(Widget* widget)
  99. {
  100. _firstFocusedWidget = widget;
  101. }
  102. void Widget::FocusNavigationController::addKeyboardEventListener()
  103. {
  104. if (nullptr == _keyboardListener)
  105. {
  106. _keyboardListener = EventListenerKeyboard::create();
  107. _keyboardListener->onKeyReleased = CC_CALLBACK_2(Widget::FocusNavigationController::onKeypadKeyPressed, this);
  108. EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
  109. dispatcher->addEventListenerWithFixedPriority(_keyboardListener, _keyboardEventPriority);
  110. }
  111. }
  112. void Widget::FocusNavigationController::removeKeyboardEventListener()
  113. {
  114. if (nullptr != _keyboardListener)
  115. {
  116. EventDispatcher* dispatcher = Director::getInstance()->getEventDispatcher();
  117. dispatcher->removeEventListener(_keyboardListener);
  118. _keyboardListener = nullptr;
  119. }
  120. }
  121. Widget* Widget::_focusedWidget = nullptr;
  122. Widget::FocusNavigationController* Widget::_focusNavigationController = nullptr;
  123. Widget::Widget():
  124. _usingLayoutComponent(false),
  125. _unifySize(false),
  126. _enabled(true),
  127. _bright(true),
  128. _touchEnabled(false),
  129. _highlight(false),
  130. _affectByClipping(false),
  131. _ignoreSize(false),
  132. _propagateTouchEvents(true),
  133. _brightStyle(BrightStyle::NONE),
  134. _sizeType(SizeType::ABSOLUTE),
  135. _positionType(PositionType::ABSOLUTE),
  136. _actionTag(0),
  137. _customSize(Size::ZERO),
  138. _hitted(false),
  139. _hittedByCamera(nullptr),
  140. _touchListener(nullptr),
  141. _flippedX(false),
  142. _flippedY(false),
  143. _layoutParameterType(LayoutParameter::Type::NONE),
  144. _focused(false),
  145. _focusEnabled(true),
  146. _touchEventListener(nullptr),
  147. _touchEventSelector(nullptr),
  148. _ccEventCallback(nullptr),
  149. _callbackType(""),
  150. _callbackName("")
  151. {
  152. }
  153. Widget::~Widget()
  154. {
  155. this->cleanupWidget();
  156. }
  157. void Widget::cleanupWidget()
  158. {
  159. //clean up _touchListener
  160. _eventDispatcher->removeEventListener(_touchListener);
  161. CC_SAFE_RELEASE_NULL(_touchListener);
  162. //cleanup focused widget and focus navigation controller
  163. if (_focusedWidget == this)
  164. {
  165. //delete
  166. CC_SAFE_DELETE(_focusNavigationController);
  167. _focusedWidget = nullptr;
  168. }
  169. }
  170. Widget* Widget::create()
  171. {
  172. Widget* widget = new (std::nothrow) Widget();
  173. if (widget && widget->init())
  174. {
  175. widget->autorelease();
  176. return widget;
  177. }
  178. CC_SAFE_DELETE(widget);
  179. return nullptr;
  180. }
  181. bool Widget::init()
  182. {
  183. if (ProtectedNode::init())
  184. {
  185. initRenderer();
  186. setBright(true);
  187. onFocusChanged = CC_CALLBACK_2(Widget::onFocusChange,this);
  188. onNextFocusedWidget = nullptr;
  189. this->setAnchorPoint(Vec2(0.5f, 0.5f));
  190. ignoreContentAdaptWithSize(true);
  191. return true;
  192. }
  193. return false;
  194. }
  195. void Widget::onEnter()
  196. {
  197. #if CC_ENABLE_SCRIPT_BINDING
  198. if (_scriptType == kScriptTypeJavascript)
  199. {
  200. if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
  201. return;
  202. }
  203. #endif
  204. if (!_usingLayoutComponent)
  205. updateSizeAndPosition();
  206. ProtectedNode::onEnter();
  207. }
  208. void Widget::onExit()
  209. {
  210. #if CC_ENABLE_SCRIPT_BINDING
  211. if (_scriptType == kScriptTypeJavascript)
  212. {
  213. if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit))
  214. return;
  215. }
  216. #endif
  217. unscheduleUpdate();
  218. ProtectedNode::onExit();
  219. }
  220. void Widget::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
  221. {
  222. if (_visible)
  223. {
  224. adaptRenderers();
  225. ProtectedNode::visit(renderer, parentTransform, parentFlags);
  226. }
  227. }
  228. Widget* Widget::getWidgetParent()
  229. {
  230. return dynamic_cast<Widget*>(getParent());
  231. }
  232. void Widget::setEnabled(bool enabled)
  233. {
  234. _enabled = enabled;
  235. setBright(enabled);
  236. }
  237. void Widget::initRenderer()
  238. {
  239. }
  240. LayoutComponent* Widget::getOrCreateLayoutComponent()
  241. {
  242. auto layoutComponent = this->getComponent(__LAYOUT_COMPONENT_NAME);
  243. if (nullptr == layoutComponent)
  244. {
  245. LayoutComponent *component = LayoutComponent::create();
  246. this->addComponent(component);
  247. layoutComponent = component;
  248. }
  249. return (LayoutComponent*)layoutComponent;
  250. }
  251. void Widget::setContentSize(const cocos2d::Size &contentSize)
  252. {
  253. Size previousSize = ProtectedNode::getContentSize();
  254. if(previousSize.equals(contentSize))
  255. {
  256. return;
  257. }
  258. ProtectedNode::setContentSize(contentSize);
  259. _customSize = contentSize;
  260. if (_unifySize)
  261. {
  262. //unify Size logic
  263. }
  264. else if (_ignoreSize)
  265. {
  266. ProtectedNode::setContentSize(getVirtualRendererSize());
  267. }
  268. if (!_usingLayoutComponent && _running)
  269. {
  270. Widget* widgetParent = getWidgetParent();
  271. Size pSize;
  272. if (widgetParent)
  273. {
  274. pSize = widgetParent->getContentSize();
  275. }
  276. else
  277. {
  278. pSize = _parent->getContentSize();
  279. }
  280. float spx = 0.0f;
  281. float spy = 0.0f;
  282. if (pSize.width > 0.0f)
  283. {
  284. spx = _customSize.width / pSize.width;
  285. }
  286. if (pSize.height > 0.0f)
  287. {
  288. spy = _customSize.height / pSize.height;
  289. }
  290. _sizePercent.set(spx, spy);
  291. }
  292. onSizeChanged();
  293. }
  294. void Widget::setSize(const Size &size)
  295. {
  296. this->setContentSize(size);
  297. }
  298. void Widget::setSizePercent(const Vec2 &percent)
  299. {
  300. if (_usingLayoutComponent)
  301. {
  302. auto component = this->getOrCreateLayoutComponent();
  303. component->setUsingPercentContentSize(true);
  304. component->setPercentContentSize(percent);
  305. component->refreshLayout();
  306. }
  307. else
  308. {
  309. _sizePercent = percent;
  310. Size cSize = _customSize;
  311. if (_running)
  312. {
  313. Widget* widgetParent = getWidgetParent();
  314. if (widgetParent)
  315. {
  316. cSize = Size(widgetParent->getContentSize().width * percent.x, widgetParent->getContentSize().height * percent.y);
  317. }
  318. else
  319. {
  320. cSize = Size(_parent->getContentSize().width * percent.x, _parent->getContentSize().height * percent.y);
  321. }
  322. }
  323. if (_ignoreSize)
  324. {
  325. this->setContentSize(getVirtualRendererSize());
  326. }
  327. else
  328. {
  329. this->setContentSize(cSize);
  330. }
  331. _customSize = cSize;
  332. }
  333. }
  334. void Widget::updateSizeAndPosition()
  335. {
  336. Size pSize = _parent->getContentSize();
  337. updateSizeAndPosition(pSize);
  338. }
  339. void Widget::updateSizeAndPosition(const cocos2d::Size &parentSize)
  340. {
  341. switch (_sizeType)
  342. {
  343. case SizeType::ABSOLUTE:
  344. {
  345. if (_ignoreSize)
  346. {
  347. this->setContentSize(getVirtualRendererSize());
  348. }
  349. else
  350. {
  351. this->setContentSize(_customSize);
  352. }
  353. float spx = 0.0f;
  354. float spy = 0.0f;
  355. if (parentSize.width > 0.0f)
  356. {
  357. spx = _customSize.width / parentSize.width;
  358. }
  359. if (parentSize.height > 0.0f)
  360. {
  361. spy = _customSize.height / parentSize.height;
  362. }
  363. _sizePercent.set(spx, spy);
  364. break;
  365. }
  366. case SizeType::PERCENT:
  367. {
  368. Size cSize = Size(parentSize.width * _sizePercent.x , parentSize.height * _sizePercent.y);
  369. if (_ignoreSize)
  370. {
  371. this->setContentSize(getVirtualRendererSize());
  372. }
  373. else
  374. {
  375. this->setContentSize(cSize);
  376. }
  377. _customSize = cSize;
  378. break;
  379. }
  380. default:
  381. break;
  382. }
  383. //update position & position percent
  384. Vec2 absPos = getPosition();
  385. switch (_positionType)
  386. {
  387. case PositionType::ABSOLUTE:
  388. {
  389. if (parentSize.width <= 0.0f || parentSize.height <= 0.0f)
  390. {
  391. _positionPercent.setZero();
  392. }
  393. else
  394. {
  395. _positionPercent.set(absPos.x / parentSize.width, absPos.y / parentSize.height);
  396. }
  397. break;
  398. }
  399. case PositionType::PERCENT:
  400. {
  401. absPos.set(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
  402. break;
  403. }
  404. default:
  405. break;
  406. }
  407. setPosition(absPos);
  408. }
  409. void Widget::setSizeType(SizeType type)
  410. {
  411. _sizeType = type;
  412. if (_usingLayoutComponent)
  413. {
  414. auto component = this->getOrCreateLayoutComponent();
  415. if (_sizeType == Widget::SizeType::PERCENT)
  416. {
  417. component->setUsingPercentContentSize(true);
  418. }
  419. else
  420. {
  421. component->setUsingPercentContentSize(false);
  422. }
  423. }
  424. }
  425. Widget::SizeType Widget::getSizeType() const
  426. {
  427. return _sizeType;
  428. }
  429. void Widget::ignoreContentAdaptWithSize(bool ignore)
  430. {
  431. if (_unifySize)
  432. {
  433. this->setContentSize(_customSize);
  434. return;
  435. }
  436. if (_ignoreSize == ignore)
  437. {
  438. return;
  439. }
  440. _ignoreSize = ignore;
  441. if (_ignoreSize)
  442. {
  443. Size s = getVirtualRendererSize();
  444. this->setContentSize(s);
  445. }
  446. else
  447. {
  448. this->setContentSize(_customSize);
  449. }
  450. }
  451. bool Widget::isIgnoreContentAdaptWithSize() const
  452. {
  453. return _ignoreSize;
  454. }
  455. const Size& Widget::getSize() const
  456. {
  457. return this->getContentSize();
  458. }
  459. const Size& Widget::getCustomSize() const
  460. {
  461. return _customSize;
  462. }
  463. const Vec2& Widget::getSizePercent()
  464. {
  465. if (_usingLayoutComponent)
  466. {
  467. auto component = this->getOrCreateLayoutComponent();
  468. _sizePercent = component->getPercentContentSize();
  469. }
  470. return _sizePercent;
  471. }
  472. Vec2 Widget::getWorldPosition()const
  473. {
  474. return convertToWorldSpace(Vec2(_anchorPoint.x * _contentSize.width, _anchorPoint.y * _contentSize.height));
  475. }
  476. Node* Widget::getVirtualRenderer()
  477. {
  478. return this;
  479. }
  480. void Widget::onSizeChanged()
  481. {
  482. if (!_usingLayoutComponent)
  483. {
  484. for (auto& child : getChildren())
  485. {
  486. Widget* widgetChild = dynamic_cast<Widget*>(child);
  487. if (widgetChild)
  488. {
  489. widgetChild->updateSizeAndPosition();
  490. }
  491. }
  492. }
  493. }
  494. Size Widget::getVirtualRendererSize() const
  495. {
  496. return _contentSize;
  497. }
  498. void Widget::updateContentSizeWithTextureSize(const cocos2d::Size &size)
  499. {
  500. if (_unifySize)
  501. {
  502. this->setContentSize(size);
  503. return;
  504. }
  505. if (_ignoreSize)
  506. {
  507. this->setContentSize(size);
  508. }
  509. else
  510. {
  511. this->setContentSize(_customSize);
  512. }
  513. }
  514. void Widget::setTouchEnabled(bool enable)
  515. {
  516. if (enable == _touchEnabled)
  517. {
  518. return;
  519. }
  520. _touchEnabled = enable;
  521. if (_touchEnabled)
  522. {
  523. _touchListener = EventListenerTouchOneByOne::create();
  524. CC_SAFE_RETAIN(_touchListener);
  525. _touchListener->setSwallowTouches(true);
  526. _touchListener->onTouchBegan = CC_CALLBACK_2(Widget::onTouchBegan, this);
  527. _touchListener->onTouchMoved = CC_CALLBACK_2(Widget::onTouchMoved, this);
  528. _touchListener->onTouchEnded = CC_CALLBACK_2(Widget::onTouchEnded, this);
  529. _touchListener->onTouchCancelled = CC_CALLBACK_2(Widget::onTouchCancelled, this);
  530. _eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this);
  531. }
  532. else
  533. {
  534. _eventDispatcher->removeEventListener(_touchListener);
  535. CC_SAFE_RELEASE_NULL(_touchListener);
  536. }
  537. }
  538. bool Widget::isTouchEnabled() const
  539. {
  540. return _touchEnabled;
  541. }
  542. bool Widget::isHighlighted() const
  543. {
  544. return _highlight;
  545. }
  546. void Widget::setHighlighted(bool highlight)
  547. {
  548. if (highlight == _highlight)
  549. {
  550. return;
  551. }
  552. _highlight = highlight;
  553. if (_bright)
  554. {
  555. if (_highlight)
  556. {
  557. setBrightStyle(BrightStyle::HIGHLIGHT);
  558. }
  559. else
  560. {
  561. setBrightStyle(BrightStyle::NORMAL);
  562. }
  563. }
  564. else
  565. {
  566. onPressStateChangedToDisabled();
  567. }
  568. }
  569. void Widget::setBright(bool bright)
  570. {
  571. _bright = bright;
  572. if (_bright)
  573. {
  574. _brightStyle = BrightStyle::NONE;
  575. setBrightStyle(BrightStyle::NORMAL);
  576. }
  577. else
  578. {
  579. onPressStateChangedToDisabled();
  580. }
  581. }
  582. void Widget::setBrightStyle(BrightStyle style)
  583. {
  584. if (_brightStyle == style)
  585. {
  586. return;
  587. }
  588. _brightStyle = style;
  589. switch (_brightStyle)
  590. {
  591. case BrightStyle::NORMAL:
  592. onPressStateChangedToNormal();
  593. break;
  594. case BrightStyle::HIGHLIGHT:
  595. onPressStateChangedToPressed();
  596. break;
  597. default:
  598. break;
  599. }
  600. }
  601. void Widget::onPressStateChangedToNormal()
  602. {
  603. }
  604. void Widget::onPressStateChangedToPressed()
  605. {
  606. }
  607. void Widget::onPressStateChangedToDisabled()
  608. {
  609. }
  610. void Widget::updateChildrenDisplayedRGBA()
  611. {
  612. this->setColor(this->getColor());
  613. this->setOpacity(this->getOpacity());
  614. }
  615. Widget* Widget::getAncestorWidget(Node* node)
  616. {
  617. if (nullptr == node)
  618. {
  619. return nullptr;
  620. }
  621. Node* parent = node->getParent();
  622. if (nullptr == parent)
  623. {
  624. return nullptr;
  625. }
  626. Widget* parentWidget = dynamic_cast<Widget*>(parent);
  627. if (parentWidget)
  628. {
  629. return parentWidget;
  630. }
  631. else
  632. {
  633. return this->getAncestorWidget(parent->getParent());
  634. }
  635. }
  636. Widget* Widget::getAncensterWidget(Node* node)
  637. {
  638. return getAncestorWidget(node);
  639. }
  640. bool Widget::isAncestorsVisible(Node* node)
  641. {
  642. if (nullptr == node)
  643. {
  644. return true;
  645. }
  646. Node* parent = node->getParent();
  647. if (parent && !parent->isVisible())
  648. {
  649. return false;
  650. }
  651. return this->isAncestorsVisible(parent);
  652. }
  653. bool Widget::isAncestorsEnabled()
  654. {
  655. Widget* parentWidget = this->getAncestorWidget(this);
  656. if (parentWidget == nullptr)
  657. {
  658. return true;
  659. }
  660. if (parentWidget && !parentWidget->isEnabled())
  661. {
  662. return false;
  663. }
  664. return parentWidget->isAncestorsEnabled();
  665. }
  666. void Widget::setPropagateTouchEvents(bool isPropagate)
  667. {
  668. _propagateTouchEvents = isPropagate;
  669. }
  670. bool Widget::isPropagateTouchEvents()const
  671. {
  672. return _propagateTouchEvents;
  673. }
  674. void Widget::setSwallowTouches(bool swallow)
  675. {
  676. if (_touchListener)
  677. {
  678. _touchListener->setSwallowTouches(swallow);
  679. }
  680. }
  681. bool Widget::isSwallowTouches()const
  682. {
  683. if (_touchListener)
  684. {
  685. return _touchListener->isSwallowTouches();
  686. }
  687. return false;
  688. }
  689. bool Widget::onTouchBegan(Touch *touch, Event* /*unusedEvent*/)
  690. {
  691. _hitted = false;
  692. if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) )
  693. {
  694. _touchBeganPosition = touch->getLocation();
  695. auto camera = Camera::getVisitingCamera();
  696. if(hitTest(_touchBeganPosition, camera, nullptr))
  697. {
  698. if (isClippingParentContainsPoint(_touchBeganPosition)) {
  699. _hittedByCamera = camera;
  700. _hitted = true;
  701. }
  702. }
  703. }
  704. if (!_hitted)
  705. {
  706. return false;
  707. }
  708. setHighlighted(true);
  709. /*
  710. * Propagate touch events to its parents
  711. */
  712. if (_propagateTouchEvents)
  713. {
  714. this->propagateTouchEvent(TouchEventType::BEGAN, this, touch);
  715. }
  716. pushDownEvent(touch);
  717. return true;
  718. }
  719. void Widget::propagateTouchEvent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, cocos2d::Touch *touch)
  720. {
  721. Widget* widgetParent = getWidgetParent();
  722. if (widgetParent)
  723. {
  724. widgetParent->_hittedByCamera = _hittedByCamera;
  725. widgetParent->interceptTouchEvent(event, sender, touch);
  726. widgetParent->_hittedByCamera = nullptr;
  727. }
  728. }
  729. void Widget::onTouchMoved(Touch *touch, Event* /*unusedEvent*/)
  730. {
  731. _touchMovePosition = touch->getLocation();
  732. setHighlighted(hitTest(_touchMovePosition, _hittedByCamera, nullptr));
  733. /*
  734. * Propagate touch events to its parents
  735. */
  736. if (_propagateTouchEvents)
  737. {
  738. this->propagateTouchEvent(TouchEventType::MOVED, this, touch);
  739. }
  740. moveEvent(touch);
  741. }
  742. void Widget::onTouchEnded(Touch *touch, Event* /*unusedEvent*/)
  743. {
  744. _touchEndPosition = touch->getLocation();
  745. /*
  746. * Propagate touch events to its parents
  747. */
  748. if (_propagateTouchEvents)
  749. {
  750. this->propagateTouchEvent(TouchEventType::ENDED, this, touch);
  751. }
  752. bool highlight = _highlight;
  753. setHighlighted(false);
  754. if (highlight)
  755. {
  756. releaseUpEvent(touch);
  757. }
  758. else
  759. {
  760. cancelUpEvent(touch);
  761. }
  762. }
  763. void Widget::onTouchCancelled(Touch* touch, Event* /*unusedEvent*/)
  764. {
  765. /*
  766. * Propagate touch events to its parents
  767. */
  768. if (_propagateTouchEvents)
  769. {
  770. this->propagateTouchEvent(TouchEventType::CANCELED, this, touch);
  771. }
  772. setHighlighted(false);
  773. cancelUpEvent(touch);
  774. }
  775. void Widget::pushDownEvent(Touch* touch)
  776. {
  777. this->retain();
  778. if (_touchEventCallback)
  779. {
  780. _touchEventCallback(this, TouchEventType::BEGAN,touch);
  781. }
  782. if (_touchEventListener && _touchEventSelector)
  783. {
  784. (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_BEGAN);
  785. }
  786. this->release();
  787. }
  788. void Widget::moveEvent(Touch* touch)
  789. {
  790. this->retain();
  791. if (_touchEventCallback)
  792. {
  793. _touchEventCallback(this, TouchEventType::MOVED,touch);
  794. }
  795. if (_touchEventListener && _touchEventSelector)
  796. {
  797. (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_MOVED);
  798. }
  799. this->release();
  800. }
  801. void Widget::releaseUpEvent(Touch* touch)
  802. {
  803. this->retain();
  804. if (isFocusEnabled())
  805. {
  806. requestFocus();
  807. }
  808. if (_touchEventCallback)
  809. {
  810. _touchEventCallback(this, TouchEventType::ENDED,touch);
  811. }
  812. if (_touchEventListener && _touchEventSelector)
  813. {
  814. (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_ENDED);
  815. }
  816. if (_clickEventListener) {
  817. _clickEventListener(this);
  818. }
  819. this->release();
  820. }
  821. void Widget::cancelUpEvent(Touch* touch)
  822. {
  823. this->retain();
  824. if (_touchEventCallback)
  825. {
  826. _touchEventCallback(this, TouchEventType::CANCELED,touch);
  827. }
  828. if (_touchEventListener && _touchEventSelector)
  829. {
  830. (_touchEventListener->*_touchEventSelector)(this,TOUCH_EVENT_CANCELED);
  831. }
  832. this->release();
  833. }
  834. void Widget::addTouchEventListener(Ref *target, SEL_TouchEvent selector)
  835. {
  836. _touchEventListener = target;
  837. _touchEventSelector = selector;
  838. }
  839. void Widget::addTouchEventListener(const ccWidgetTouchCallback& callback)
  840. {
  841. this->_touchEventCallback = callback;
  842. }
  843. void Widget::addClickEventListener(const ccWidgetClickCallback &callback)
  844. {
  845. this->_clickEventListener = callback;
  846. }
  847. void Widget::addCCSEventListener(const ccWidgetEventCallback &callback)
  848. {
  849. this->_ccEventCallback = callback;
  850. }
  851. bool Widget::hitTest(const Vec2 &pt, const Camera* camera, Vec3 *p) const
  852. {
  853. Rect rect;
  854. rect.size = getContentSize();
  855. return isScreenPointInRect(pt, camera, getWorldToNodeTransform(), rect, p);
  856. }
  857. bool Widget::isClippingParentContainsPoint(const Vec2 &pt)
  858. {
  859. _affectByClipping = false;
  860. Node* parent = getParent();
  861. Widget* clippingParent = nullptr;
  862. while (parent)
  863. {
  864. Layout* layoutParent = dynamic_cast<Layout*>(parent);
  865. if (layoutParent)
  866. {
  867. if (layoutParent->isClippingEnabled())
  868. {
  869. _affectByClipping = true;
  870. clippingParent = layoutParent;
  871. break;
  872. }
  873. }
  874. parent = parent->getParent();
  875. }
  876. if (!_affectByClipping)
  877. {
  878. return true;
  879. }
  880. if (clippingParent)
  881. {
  882. bool bRet = false;
  883. auto camera = Camera::getVisitingCamera();
  884. // Camera isn't null means in touch begin process, otherwise use _hittedByCamera instead.
  885. if (clippingParent->hitTest(pt, (camera ? camera : _hittedByCamera), nullptr))
  886. {
  887. bRet = true;
  888. }
  889. if (bRet)
  890. {
  891. return clippingParent->isClippingParentContainsPoint(pt);
  892. }
  893. return false;
  894. }
  895. return true;
  896. }
  897. void Widget::interceptTouchEvent(cocos2d::ui::Widget::TouchEventType event, cocos2d::ui::Widget *sender, Touch *touch)
  898. {
  899. Widget* widgetParent = getWidgetParent();
  900. if (widgetParent)
  901. {
  902. widgetParent->_hittedByCamera = _hittedByCamera;
  903. widgetParent->interceptTouchEvent(event,sender,touch);
  904. widgetParent->_hittedByCamera = nullptr;
  905. }
  906. }
  907. void Widget::setPosition(const Vec2 &pos)
  908. {
  909. if (!_usingLayoutComponent && _running)
  910. {
  911. Widget* widgetParent = getWidgetParent();
  912. if (widgetParent)
  913. {
  914. Size pSize = widgetParent->getContentSize();
  915. if (pSize.width <= 0.0f || pSize.height <= 0.0f)
  916. {
  917. _positionPercent.setZero();
  918. }
  919. else
  920. {
  921. _positionPercent.set(pos.x / pSize.width, pos.y / pSize.height);
  922. }
  923. }
  924. }
  925. ProtectedNode::setPosition(pos);
  926. }
  927. void Widget::setPositionPercent(const Vec2 &percent)
  928. {
  929. if (_usingLayoutComponent)
  930. {
  931. auto component = this->getOrCreateLayoutComponent();
  932. component->setPositionPercentX(percent.x);
  933. component->setPositionPercentY(percent.y);
  934. component->refreshLayout();
  935. }
  936. else
  937. {
  938. _positionPercent = percent;
  939. if (_running)
  940. {
  941. Widget* widgetParent = getWidgetParent();
  942. if (widgetParent)
  943. {
  944. Size parentSize = widgetParent->getContentSize();
  945. Vec2 absPos(parentSize.width * _positionPercent.x, parentSize.height * _positionPercent.y);
  946. setPosition(absPos);
  947. }
  948. }
  949. }
  950. }
  951. const Vec2& Widget::getPositionPercent(){
  952. if (_usingLayoutComponent)
  953. {
  954. auto component = this->getOrCreateLayoutComponent();
  955. float percentX = component->getPositionPercentX();
  956. float percentY = component->getPositionPercentY();
  957. _positionPercent.set(percentX, percentY);
  958. }
  959. return _positionPercent;
  960. }
  961. void Widget::setPositionType(PositionType type)
  962. {
  963. _positionType = type;
  964. if (_usingLayoutComponent)
  965. {
  966. auto component = this->getOrCreateLayoutComponent();
  967. if (type == Widget::PositionType::ABSOLUTE)
  968. {
  969. component->setPositionPercentXEnabled(false);
  970. component->setPositionPercentYEnabled(false);
  971. }
  972. else
  973. {
  974. component->setPositionPercentXEnabled(true);
  975. component->setPositionPercentYEnabled(true);
  976. }
  977. }
  978. }
  979. Widget::PositionType Widget::getPositionType() const
  980. {
  981. return _positionType;
  982. }
  983. bool Widget::isBright() const
  984. {
  985. return _bright;
  986. }
  987. bool Widget::isEnabled() const
  988. {
  989. return _enabled;
  990. }
  991. float Widget::getLeftBoundary() const
  992. {
  993. return getBoundingBox().origin.x;
  994. }
  995. float Widget::getBottomBoundary() const
  996. {
  997. return getBoundingBox().origin.y;
  998. }
  999. float Widget::getRightBoundary() const
  1000. {
  1001. return getLeftBoundary() + getBoundingBox().size.width;
  1002. }
  1003. float Widget::getTopBoundary() const
  1004. {
  1005. return getBottomBoundary() + getBoundingBox().size.height;
  1006. }
  1007. const Vec2& Widget::getTouchBeganPosition()const
  1008. {
  1009. return _touchBeganPosition;
  1010. }
  1011. const Vec2& Widget::getTouchMovePosition()const
  1012. {
  1013. return _touchMovePosition;
  1014. }
  1015. const Vec2& Widget::getTouchEndPosition()const
  1016. {
  1017. return _touchEndPosition;
  1018. }
  1019. void Widget::setLayoutParameter(LayoutParameter *parameter)
  1020. {
  1021. if (!parameter)
  1022. {
  1023. return;
  1024. }
  1025. _layoutParameterDictionary.insert((int)parameter->getLayoutType(), parameter);
  1026. _layoutParameterType = parameter->getLayoutType();
  1027. }
  1028. LayoutParameter* Widget::getLayoutParameter()const
  1029. {
  1030. return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at((int)_layoutParameterType));
  1031. }
  1032. LayoutParameter* Widget::getLayoutParameter(LayoutParameter::Type type)
  1033. {
  1034. return dynamic_cast<LayoutParameter*>(_layoutParameterDictionary.at((int)type));
  1035. }
  1036. std::string Widget::getDescription() const
  1037. {
  1038. return "Widget";
  1039. }
  1040. Widget* Widget::clone()
  1041. {
  1042. Widget* clonedWidget = createCloneInstance();
  1043. clonedWidget->copyProperties(this);
  1044. clonedWidget->copyClonedWidgetChildren(this);
  1045. return clonedWidget;
  1046. }
  1047. Widget* Widget::createCloneInstance()
  1048. {
  1049. return Widget::create();
  1050. }
  1051. void Widget::copyClonedWidgetChildren(Widget* model)
  1052. {
  1053. auto& modelChildren = model->getChildren();
  1054. for (auto& subWidget : modelChildren)
  1055. {
  1056. Widget* child = dynamic_cast<Widget*>(subWidget);
  1057. if (child)
  1058. {
  1059. addChild(child->clone());
  1060. }
  1061. }
  1062. }
  1063. GLProgramState* Widget::getNormalGLProgramState(Texture2D* texture)const
  1064. {
  1065. return GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture);
  1066. }
  1067. GLProgramState* Widget::getGrayGLProgramState(Texture2D* texture)const
  1068. {
  1069. return GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_GRAYSCALE, texture);
  1070. }
  1071. void Widget::copySpecialProperties(Widget* /*model*/)
  1072. {
  1073. }
  1074. void Widget::copyProperties(Widget *widget)
  1075. {
  1076. setEnabled(widget->isEnabled());
  1077. setVisible(widget->isVisible());
  1078. setBright(widget->isBright());
  1079. setTouchEnabled(widget->isTouchEnabled());
  1080. setLocalZOrder(widget->getLocalZOrder());
  1081. setTag(widget->getTag());
  1082. setName(widget->getName());
  1083. setActionTag(widget->getActionTag());
  1084. _ignoreSize = widget->_ignoreSize;
  1085. this->setContentSize(widget->_contentSize);
  1086. _customSize = widget->_customSize;
  1087. _sizeType = widget->getSizeType();
  1088. _sizePercent = widget->_sizePercent;
  1089. _positionType = widget->_positionType;
  1090. _positionPercent = widget->_positionPercent;
  1091. setPosition(widget->getPosition());
  1092. setAnchorPoint(widget->getAnchorPoint());
  1093. setScaleX(widget->getScaleX());
  1094. setScaleY(widget->getScaleY());
  1095. setRotation(widget->getRotation());
  1096. setRotationSkewX(widget->getRotationSkewX());
  1097. setRotationSkewY(widget->getRotationSkewY());
  1098. setFlippedX(widget->isFlippedX());
  1099. setFlippedY(widget->isFlippedY());
  1100. setColor(widget->getColor());
  1101. setOpacity(widget->getOpacity());
  1102. setCascadeColorEnabled(widget->isCascadeColorEnabled());
  1103. setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled());
  1104. _touchEventCallback = widget->_touchEventCallback;
  1105. _touchEventListener = widget->_touchEventListener;
  1106. _touchEventSelector = widget->_touchEventSelector;
  1107. _clickEventListener = widget->_clickEventListener;
  1108. _focused = widget->_focused;
  1109. _focusEnabled = widget->_focusEnabled;
  1110. _propagateTouchEvents = widget->_propagateTouchEvents;
  1111. copySpecialProperties(widget);
  1112. Map<int, LayoutParameter*>& layoutParameterDic = widget->_layoutParameterDictionary;
  1113. for (auto& iter : layoutParameterDic)
  1114. {
  1115. setLayoutParameter(iter.second->clone());
  1116. }
  1117. }
  1118. void Widget::setFlippedX(bool flippedX)
  1119. {
  1120. float realScale = this->getScaleX();
  1121. _flippedX = flippedX;
  1122. this->setScaleX(realScale);
  1123. }
  1124. void Widget::setFlippedY(bool flippedY)
  1125. {
  1126. float realScale = this->getScaleY();
  1127. _flippedY = flippedY;
  1128. this->setScaleY(realScale);
  1129. }
  1130. void Widget::setScaleX(float scaleX)
  1131. {
  1132. if (_flippedX) {
  1133. scaleX = scaleX * -1;
  1134. }
  1135. Node::setScaleX(scaleX);
  1136. }
  1137. void Widget::setScaleY(float scaleY)
  1138. {
  1139. if (_flippedY) {
  1140. scaleY = scaleY * -1;
  1141. }
  1142. Node::setScaleY(scaleY);
  1143. }
  1144. void Widget::setScale(float scale)
  1145. {
  1146. this->setScaleX(scale);
  1147. this->setScaleY(scale);
  1148. this->setScaleZ(scale);
  1149. }
  1150. void Widget::setScale(float scaleX, float scaleY)
  1151. {
  1152. this->setScaleX(scaleX);
  1153. this->setScaleY(scaleY);
  1154. }
  1155. float Widget::getScaleX()const
  1156. {
  1157. float originalScale = Node::getScaleX();
  1158. if (_flippedX)
  1159. {
  1160. originalScale = originalScale * -1.0f;
  1161. }
  1162. return originalScale;
  1163. }
  1164. float Widget::getScaleY()const
  1165. {
  1166. float originalScale = Node::getScaleY();
  1167. if (_flippedY)
  1168. {
  1169. originalScale = originalScale * -1.0f;
  1170. }
  1171. return originalScale;
  1172. }
  1173. float Widget::getScale()const
  1174. {
  1175. CCASSERT(this->getScaleX() == this->getScaleY(), "scaleX should be equal to scaleY.");
  1176. return this->getScaleX();
  1177. }
  1178. /*temp action*/
  1179. void Widget::setActionTag(int tag)
  1180. {
  1181. _actionTag = tag;
  1182. }
  1183. int Widget::getActionTag()const
  1184. {
  1185. return _actionTag;
  1186. }
  1187. void Widget::setFocused(bool focus)
  1188. {
  1189. _focused = focus;
  1190. //make sure there is only one focusedWidget
  1191. if (focus) {
  1192. _focusedWidget = this;
  1193. if (_focusNavigationController) {
  1194. _focusNavigationController->setFirstFocusedWidget(this);
  1195. }
  1196. }
  1197. }
  1198. bool Widget::isFocused()const
  1199. {
  1200. return _focused;
  1201. }
  1202. void Widget::setFocusEnabled(bool enable)
  1203. {
  1204. _focusEnabled = enable;
  1205. }
  1206. bool Widget::isFocusEnabled()const
  1207. {
  1208. return _focusEnabled;
  1209. }
  1210. Widget* Widget::findNextFocusedWidget(FocusDirection direction, Widget* current)
  1211. {
  1212. if (nullptr == onNextFocusedWidget || nullptr == onNextFocusedWidget(direction) ) {
  1213. if (this->isFocused() || dynamic_cast<Layout*>(current))
  1214. {
  1215. Node* parent = this->getParent();
  1216. Layout* layout = dynamic_cast<Layout*>(parent);
  1217. if (nullptr == layout)
  1218. {
  1219. //the outer layout's default behaviour is : loop focus
  1220. if (dynamic_cast<Layout*>(current))
  1221. {
  1222. return current->findNextFocusedWidget(direction, current);
  1223. }
  1224. return current;
  1225. }
  1226. else
  1227. {
  1228. Widget *nextWidget = layout->findNextFocusedWidget(direction, current);
  1229. return nextWidget;
  1230. }
  1231. }
  1232. else
  1233. {
  1234. return current;
  1235. }
  1236. }
  1237. else
  1238. {
  1239. Widget *getFocusWidget = onNextFocusedWidget(direction);
  1240. this->dispatchFocusEvent(this, getFocusWidget);
  1241. return getFocusWidget;
  1242. }
  1243. }
  1244. void Widget::dispatchFocusEvent(cocos2d::ui::Widget *widgetLoseFocus, cocos2d::ui::Widget *widgetGetFocus)
  1245. {
  1246. //if the widgetLoseFocus doesn't get focus, it will use the previous focused widget instead
  1247. if (widgetLoseFocus && !widgetLoseFocus->isFocused())
  1248. {
  1249. widgetLoseFocus = _focusedWidget;
  1250. }
  1251. if (widgetGetFocus != widgetLoseFocus)
  1252. {
  1253. if (widgetGetFocus)
  1254. {
  1255. widgetGetFocus->onFocusChanged(widgetLoseFocus, widgetGetFocus);
  1256. }
  1257. if (widgetLoseFocus)
  1258. {
  1259. widgetLoseFocus->onFocusChanged(widgetLoseFocus, widgetGetFocus);
  1260. }
  1261. EventFocus event(widgetLoseFocus, widgetGetFocus);
  1262. auto dispatcher = cocos2d::Director::getInstance()->getEventDispatcher();
  1263. dispatcher->dispatchEvent(&event);
  1264. }
  1265. }
  1266. void Widget::requestFocus()
  1267. {
  1268. if (this == _focusedWidget)
  1269. {
  1270. return;
  1271. }
  1272. this->dispatchFocusEvent(_focusedWidget, this);
  1273. }
  1274. void Widget::onFocusChange(Widget* widgetLostFocus, Widget* widgetGetFocus)
  1275. {
  1276. //only change focus when there is indeed a get&lose happens
  1277. if (widgetLostFocus)
  1278. {
  1279. widgetLostFocus->setFocused(false);
  1280. }
  1281. if (widgetGetFocus)
  1282. {
  1283. widgetGetFocus->setFocused(true);
  1284. }
  1285. }
  1286. Widget* Widget::getCurrentFocusedWidget(bool /*isWidget*/){
  1287. return getCurrentFocusedWidget();
  1288. }
  1289. Widget* Widget::getCurrentFocusedWidget()
  1290. {
  1291. return _focusedWidget;
  1292. }
  1293. void Widget::enableDpadNavigation(bool enable)
  1294. {
  1295. if (enable)
  1296. {
  1297. if (nullptr == _focusNavigationController)
  1298. {
  1299. _focusNavigationController = new (std::nothrow) FocusNavigationController;
  1300. if (_focusedWidget)
  1301. {
  1302. _focusNavigationController->setFirstFocusedWidget(_focusedWidget);
  1303. }
  1304. }
  1305. }
  1306. else
  1307. {
  1308. CC_SAFE_DELETE(_focusNavigationController);
  1309. }
  1310. if (nullptr != _focusNavigationController)
  1311. {
  1312. _focusNavigationController->enableFocusNavigation(enable);
  1313. }
  1314. }
  1315. bool Widget::isUnifySizeEnabled()const
  1316. {
  1317. return _unifySize;
  1318. }
  1319. void Widget::setUnifySizeEnabled(bool enable)
  1320. {
  1321. _unifySize = enable;
  1322. }
  1323. void Widget::setLayoutComponentEnabled(bool enable)
  1324. {
  1325. _usingLayoutComponent = enable;
  1326. }
  1327. bool Widget::isLayoutComponentEnabled()const
  1328. {
  1329. return _usingLayoutComponent;
  1330. }
  1331. }
  1332. NS_CC_END