1
0

UIWidget.cpp 36 KB

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