/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp

https://bitbucket.org/Tsiannian/cocos2d-x · C++ · 669 lines · 496 code · 98 blank · 75 comment · 48 complexity · 733f057c1944277328fe0b7a72454121 MD5 · raw file

  1. //
  2. // CCScale9Sprite.cpp
  3. // PlantCaring
  4. //
  5. // Created by Jung Sang-Taik on 12. 3. 16..
  6. // Copyright (c) 2012 Neofect. All rights reserved.
  7. //
  8. #include "CCScale9Sprite.h"
  9. #include "sprite_nodes/CCSpriteBatchNode.h"
  10. #include "sprite_nodes/CCSpriteFrame.h"
  11. #include "sprite_nodes/CCSpriteFrameCache.h"
  12. #include "sprite_nodes/CCSprite.h"
  13. #include "support/CCPointExtension.h"
  14. NS_CC_EXT_BEGIN
  15. CCScale9Sprite::CCScale9Sprite()
  16. : m_insetLeft(0)
  17. , m_insetTop(0)
  18. , m_insetRight(0)
  19. , m_insetBottom(0)
  20. {
  21. }
  22. CCScale9Sprite::~CCScale9Sprite()
  23. {
  24. }
  25. bool CCScale9Sprite::init()
  26. {
  27. return this->initWithBatchNode(NULL, CCRectZero, CCRectZero);
  28. }
  29. bool CCScale9Sprite::initWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, CCRect capInsets)
  30. {
  31. if(batchnode)
  32. {
  33. this->updateWithBatchNode(batchnode, rect, capInsets);
  34. this->setAnchorPoint(ccp(0.5f, 0.5f));
  35. }
  36. this->m_positionsAreDirty = true;
  37. return true;
  38. }
  39. bool CCScale9Sprite::updateWithBatchNode(CCSpriteBatchNode* batchnode, CCRect rect, CCRect capInsets)
  40. {
  41. // Release old sprites
  42. this->removeAllChildrenWithCleanup(true);
  43. // TODO Is this needed?
  44. /*
  45. if(this->topLeft != NULL)
  46. {
  47. CC_SAFE_RELEASE(this->topLeft);
  48. CC_SAFE_RELEASE(this->top);
  49. CC_SAFE_RELEASE(this->topRight);
  50. CC_SAFE_RELEASE(this->left);
  51. CC_SAFE_RELEASE(this->centre);
  52. CC_SAFE_RELEASE(this->right);
  53. CC_SAFE_RELEASE(this->bottomLeft);
  54. CC_SAFE_RELEASE(this->bottom);
  55. CC_SAFE_RELEASE(this->bottomRight);
  56. }
  57. */
  58. if(this->scale9Image != batchnode)
  59. {
  60. // TODO Is this needed?
  61. /*
  62. if(this->scale9Image != NULL)
  63. {
  64. CC_SAFE_RELEASE(this->scale9Image);
  65. }
  66. */
  67. scale9Image = batchnode; // TODO No retain on purpose?
  68. }
  69. scale9Image->removeAllChildrenWithCleanup(true);
  70. m_capInsets = capInsets;
  71. // If there is no given rect
  72. if ( rect.equals(CCRectZero) )
  73. {
  74. // Get the texture size as original
  75. CCSize textureSize = scale9Image->getTextureAtlas()->getTexture()->getContentSize();
  76. rect = CCRectMake(0, 0, textureSize.width, textureSize.height);
  77. }
  78. // Set the given rect's size as original size
  79. m_spriteRect = rect;
  80. m_originalSize = rect.size;
  81. m_preferredSize = m_originalSize;
  82. m_capInsetsInternal = capInsets;
  83. // If there is no specified center region
  84. if ( m_capInsetsInternal.equals(CCRectZero) )
  85. {
  86. // Apply the 3x3 grid format
  87. m_capInsetsInternal = CCRectMake(
  88. rect.origin.x + m_originalSize.width / 3,
  89. rect.origin.y + m_originalSize.height / 3,
  90. m_originalSize.width / 3,
  91. m_originalSize.height / 3);
  92. }
  93. // Get the image edges
  94. float l = rect.origin.x;
  95. float t = rect.origin.y;
  96. float h = rect.size.height;
  97. float w = rect.size.width;
  98. //
  99. // Set up the image
  100. //
  101. // Centre
  102. centre = CCSprite::createWithTexture(scale9Image->getTexture(), m_capInsetsInternal);
  103. scale9Image->addChild(centre, 0, pCentre);
  104. // Top
  105. top = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(m_capInsetsInternal.origin.x,
  106. t,
  107. m_capInsetsInternal.size.width,
  108. m_capInsetsInternal.origin.y - t));
  109. scale9Image->addChild(top, 1, pTop);
  110. // Bottom
  111. bottom = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake( m_capInsetsInternal.origin.x,
  112. m_capInsetsInternal.origin.y + m_capInsetsInternal.size.height,
  113. m_capInsetsInternal.size.width,
  114. h - (m_capInsetsInternal.origin.y - t + m_capInsetsInternal.size.height) ));
  115. scale9Image->addChild(bottom, 1, pBottom);
  116. // Left
  117. left = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  118. l,
  119. m_capInsetsInternal.origin.y,
  120. m_capInsetsInternal.origin.x - l,
  121. m_capInsetsInternal.size.height) );
  122. scale9Image->addChild(left, 1, pLeft);
  123. // Right
  124. right = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  125. m_capInsetsInternal.origin.x + m_capInsetsInternal.size.width,
  126. m_capInsetsInternal.origin.y,
  127. w - (m_capInsetsInternal.origin.x - l + m_capInsetsInternal.size.width),
  128. m_capInsetsInternal.size.height));
  129. scale9Image->addChild(right, 1, pRight);
  130. // Top left
  131. topLeft = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  132. l,
  133. t,
  134. m_capInsetsInternal.origin.x - l,
  135. m_capInsetsInternal.origin.y - t));
  136. scale9Image->addChild(topLeft, 2, pTopLeft);
  137. // Top right
  138. topRight = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  139. m_capInsetsInternal.origin.x + m_capInsetsInternal.size.width,
  140. t,
  141. w - (m_capInsetsInternal.origin.x - l + m_capInsetsInternal.size.width),
  142. m_capInsetsInternal.origin.y - t));
  143. scale9Image->addChild(topRight, 2, pTopRight);
  144. // Bottom left
  145. bottomLeft = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  146. l,
  147. m_capInsetsInternal.origin.y + m_capInsetsInternal.size.height,
  148. m_capInsetsInternal.origin.x - l,
  149. h - (m_capInsetsInternal.origin.y - t + m_capInsetsInternal.size.height)) );
  150. scale9Image->addChild(bottomLeft, 2, pBottomLeft);
  151. // Bottom right
  152. bottomRight = CCSprite::createWithTexture(scale9Image->getTexture(), CCRectMake(
  153. m_capInsetsInternal.origin.x + m_capInsetsInternal.size.width,
  154. m_capInsetsInternal.origin.y + m_capInsetsInternal.size.height,
  155. w - (m_capInsetsInternal.origin.x - l + m_capInsetsInternal.size.width),
  156. h - (m_capInsetsInternal.origin.y - t + m_capInsetsInternal.size.height)) );
  157. scale9Image->addChild(bottomRight, 2, pBottomRight);
  158. this->setContentSize(rect.size);
  159. this->addChild(scale9Image);
  160. return true;
  161. }
  162. void CCScale9Sprite::setContentSize(const CCSize &size)
  163. {
  164. CCNode::setContentSize(size);
  165. this->m_positionsAreDirty = true;
  166. }
  167. void CCScale9Sprite::updatePositions()
  168. {
  169. CCSize size = this->m_tContentSize;
  170. float sizableWidth = size.width - topLeft->getContentSize().width - topRight->getContentSize().width;
  171. float sizableHeight = size.height - topLeft->getContentSize().height - bottomRight->getContentSize().height;
  172. float horizontalScale = sizableWidth/centre->getContentSize().width;
  173. float verticalScale = sizableHeight/centre->getContentSize().height;
  174. centre->setScaleX(horizontalScale);
  175. centre->setScaleY(verticalScale);
  176. float rescaledWidth = centre->getContentSize().width * horizontalScale;
  177. float rescaledHeight = centre->getContentSize().height * verticalScale;
  178. float leftWidth = bottomLeft->getContentSize().width;
  179. float bottomHeight = bottomLeft->getContentSize().height;
  180. bottomLeft->setAnchorPoint(ccp(0,0));
  181. bottomRight->setAnchorPoint(ccp(0,0));
  182. topLeft->setAnchorPoint(ccp(0,0));
  183. topRight->setAnchorPoint(ccp(0,0));
  184. left->setAnchorPoint(ccp(0,0));
  185. right->setAnchorPoint(ccp(0,0));
  186. top->setAnchorPoint(ccp(0,0));
  187. bottom->setAnchorPoint(ccp(0,0));
  188. centre->setAnchorPoint(ccp(0,0));
  189. // Position corners
  190. bottomLeft->setPosition(ccp(0,0));
  191. bottomRight->setPosition(ccp(leftWidth+rescaledWidth,0));
  192. topLeft->setPosition(ccp(0, bottomHeight+rescaledHeight));
  193. topRight->setPosition(ccp(leftWidth+rescaledWidth, bottomHeight+rescaledHeight));
  194. // Scale and position borders
  195. left->setPosition(ccp(0, bottomHeight));
  196. left->setScaleY(verticalScale);
  197. right->setPosition(ccp(leftWidth+rescaledWidth,bottomHeight));
  198. right->setScaleY(verticalScale);
  199. bottom->setPosition(ccp(leftWidth,0));
  200. bottom->setScaleX(horizontalScale);
  201. top->setPosition(ccp(leftWidth,bottomHeight+rescaledHeight));
  202. top->setScaleX(horizontalScale);
  203. // Position centre
  204. centre->setPosition(ccp(leftWidth, bottomHeight));
  205. }
  206. bool CCScale9Sprite::initWithFile(const char* file, CCRect rect, CCRect capInsets)
  207. {
  208. CCAssert(file != NULL, "Invalid file for sprite");
  209. CCSpriteBatchNode *batchnode = CCSpriteBatchNode::create(file, 9);
  210. bool pReturn = this->initWithBatchNode(batchnode, rect, capInsets);
  211. return pReturn;
  212. }
  213. CCScale9Sprite* CCScale9Sprite::spriteWithFile(const char* file, CCRect rect, CCRect capInsets)
  214. {
  215. return CCScale9Sprite::create(file, rect, capInsets);
  216. }
  217. CCScale9Sprite* CCScale9Sprite::create(const char* file, CCRect rect, CCRect capInsets)
  218. {
  219. CCScale9Sprite* pReturn = new CCScale9Sprite();
  220. if ( pReturn && pReturn->initWithFile(file, rect, capInsets) )
  221. {
  222. pReturn->autorelease();
  223. return pReturn;
  224. }
  225. CC_SAFE_DELETE(pReturn);
  226. return NULL;
  227. }
  228. bool CCScale9Sprite::initWithFile(const char* file, CCRect rect)
  229. {
  230. bool pReturn = this->initWithFile(file, rect, CCRectZero);
  231. return pReturn;
  232. }
  233. CCScale9Sprite* CCScale9Sprite::spriteWithFile(const char* file, CCRect rect)
  234. {
  235. return CCScale9Sprite::create(file, rect);
  236. }
  237. CCScale9Sprite* CCScale9Sprite::create(const char* file, CCRect rect)
  238. {
  239. CCScale9Sprite* pReturn = new CCScale9Sprite();
  240. if ( pReturn && pReturn->initWithFile(file, rect) )
  241. {
  242. pReturn->autorelease();
  243. return pReturn;
  244. }
  245. CC_SAFE_DELETE(pReturn);
  246. return NULL;
  247. }
  248. bool CCScale9Sprite::initWithFile(CCRect capInsets, const char* file)
  249. {
  250. bool pReturn = this->initWithFile(file, CCRectZero, capInsets);
  251. return pReturn;
  252. }
  253. CCScale9Sprite* CCScale9Sprite::spriteWithFile(CCRect capInsets, const char* file)
  254. {
  255. return CCScale9Sprite::create(capInsets, file);
  256. }
  257. CCScale9Sprite* CCScale9Sprite::create(CCRect capInsets, const char* file)
  258. {
  259. CCScale9Sprite* pReturn = new CCScale9Sprite();
  260. if ( pReturn && pReturn->initWithFile(file, capInsets) )
  261. {
  262. pReturn->autorelease();
  263. return pReturn;
  264. }
  265. CC_SAFE_DELETE(pReturn);
  266. return NULL;
  267. }
  268. bool CCScale9Sprite::initWithFile(const char* file)
  269. {
  270. bool pReturn = this->initWithFile(file, CCRectZero);
  271. return pReturn;
  272. }
  273. CCScale9Sprite* CCScale9Sprite::spriteWithFile(const char* file)
  274. {
  275. return CCScale9Sprite::create(file);
  276. }
  277. CCScale9Sprite* CCScale9Sprite::create(const char* file)
  278. {
  279. CCScale9Sprite* pReturn = new CCScale9Sprite();
  280. if ( pReturn && pReturn->initWithFile(file) )
  281. {
  282. pReturn->autorelease();
  283. return pReturn;
  284. }
  285. CC_SAFE_DELETE(pReturn);
  286. return NULL;
  287. }
  288. bool CCScale9Sprite::initWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets)
  289. {
  290. CCAssert(spriteFrame != NULL, "Sprite frame must be not nil");
  291. CCSpriteBatchNode *batchnode = CCSpriteBatchNode::createWithTexture(spriteFrame->getTexture(), 9);
  292. bool pReturn = this->initWithBatchNode(batchnode, spriteFrame->getRect(), capInsets);
  293. return pReturn;
  294. }
  295. CCScale9Sprite* CCScale9Sprite::spriteWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets)
  296. {
  297. return CCScale9Sprite::createWithSpriteFrame(spriteFrame, capInsets);
  298. }
  299. CCScale9Sprite* CCScale9Sprite::createWithSpriteFrame(CCSpriteFrame* spriteFrame, CCRect capInsets)
  300. {
  301. CCScale9Sprite* pReturn = new CCScale9Sprite();
  302. if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame, capInsets) )
  303. {
  304. pReturn->autorelease();
  305. return pReturn;
  306. }
  307. CC_SAFE_DELETE(pReturn);
  308. return NULL;
  309. }
  310. bool CCScale9Sprite::initWithSpriteFrame(CCSpriteFrame* spriteFrame)
  311. {
  312. bool pReturn = this->initWithSpriteFrame(spriteFrame, CCRectZero);
  313. return pReturn;
  314. }
  315. CCScale9Sprite* CCScale9Sprite::spriteWithSpriteFrame(CCSpriteFrame* spriteFrame)
  316. {
  317. return CCScale9Sprite::createWithSpriteFrame(spriteFrame);
  318. }
  319. CCScale9Sprite* CCScale9Sprite::createWithSpriteFrame(CCSpriteFrame* spriteFrame)
  320. {
  321. CCScale9Sprite* pReturn = new CCScale9Sprite();
  322. if ( pReturn && pReturn->initWithSpriteFrame(spriteFrame) )
  323. {
  324. pReturn->autorelease();
  325. return pReturn;
  326. }
  327. CC_SAFE_DELETE(pReturn);
  328. return NULL;
  329. }
  330. bool CCScale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, CCRect capInsets)
  331. {
  332. CCAssert(spriteFrameName != NULL, "Invalid spriteFrameName for sprite");
  333. CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName);
  334. bool pReturn = this->initWithSpriteFrame(frame, capInsets);
  335. return pReturn;
  336. }
  337. CCScale9Sprite* CCScale9Sprite::spriteWithSpriteFrameName(const char* spriteFrameName, CCRect capInsets)
  338. {
  339. return CCScale9Sprite::createWithSpriteFrameName(spriteFrameName, capInsets);
  340. }
  341. CCScale9Sprite* CCScale9Sprite::createWithSpriteFrameName(const char* spriteFrameName, CCRect capInsets)
  342. {
  343. CCScale9Sprite* pReturn = new CCScale9Sprite();
  344. if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName, capInsets) )
  345. {
  346. pReturn->autorelease();
  347. return pReturn;
  348. }
  349. CC_SAFE_DELETE(pReturn);
  350. return NULL;
  351. }
  352. bool CCScale9Sprite::initWithSpriteFrameName(const char* spriteFrameName)
  353. {
  354. bool pReturn = this->initWithSpriteFrameName(spriteFrameName, CCRectZero);
  355. return pReturn;
  356. }
  357. CCScale9Sprite* CCScale9Sprite::spriteWithSpriteFrameName(const char* spriteFrameName)
  358. {
  359. return CCScale9Sprite::createWithSpriteFrameName(spriteFrameName);
  360. }
  361. CCScale9Sprite* CCScale9Sprite::createWithSpriteFrameName(const char* spriteFrameName)
  362. {
  363. CCScale9Sprite* pReturn = new CCScale9Sprite();
  364. if ( pReturn && pReturn->initWithSpriteFrameName(spriteFrameName) )
  365. {
  366. pReturn->autorelease();
  367. return pReturn;
  368. }
  369. CC_SAFE_DELETE(pReturn);
  370. return NULL;
  371. }
  372. CCScale9Sprite* CCScale9Sprite::resizableSpriteWithCapInsets(CCRect capInsets)
  373. {
  374. CCScale9Sprite* pReturn = new CCScale9Sprite();
  375. if ( pReturn && pReturn->initWithBatchNode(scale9Image, m_spriteRect, capInsets) )
  376. {
  377. pReturn->autorelease();
  378. return pReturn;
  379. }
  380. CC_SAFE_DELETE(pReturn);
  381. return NULL;
  382. }
  383. CCScale9Sprite* CCScale9Sprite::node()
  384. {
  385. return CCScale9Sprite::create();
  386. }
  387. CCScale9Sprite* CCScale9Sprite::create()
  388. {
  389. CCScale9Sprite *pReturn = new CCScale9Sprite();
  390. if (pReturn)
  391. {
  392. pReturn->autorelease();
  393. return pReturn;
  394. }
  395. CC_SAFE_DELETE(pReturn);
  396. return NULL;
  397. }
  398. //LabelBMFont - CCRGBAProtocol protocol
  399. void CCScale9Sprite::setColor(const ccColor3B& color3)
  400. {
  401. m_tColor = color3;
  402. if (scale9Image->getChildren() && scale9Image->getChildren()->count() != 0)
  403. {
  404. CCObject* child;
  405. CCARRAY_FOREACH(scale9Image->getChildren(), child)
  406. {
  407. CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);
  408. if (pNode)
  409. {
  410. pNode->setColor(m_tColor);
  411. }
  412. }
  413. }
  414. }
  415. const ccColor3B& CCScale9Sprite::getColor(void)
  416. {
  417. return m_tColor;
  418. }
  419. void CCScale9Sprite::setOpacity(GLubyte var)
  420. {
  421. m_cOpacity = var;
  422. if (scale9Image->getChildren() && scale9Image->getChildren()->count() != 0)
  423. {
  424. CCObject* child;
  425. CCARRAY_FOREACH(scale9Image->getChildren(), child)
  426. {
  427. CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);
  428. if (pNode)
  429. {
  430. pNode->setOpacity(m_cOpacity);
  431. }
  432. //CCNode* pNode = (CCNode*) child;
  433. //if (pNode)
  434. //{
  435. // CCRGBAProtocol *pRGBAProtocol = (CCRGBAProtocol *)pNode;
  436. // if (pRGBAProtocol)
  437. // {
  438. // pRGBAProtocol->setOpacity(m_cOpacity);
  439. // }
  440. //}
  441. }
  442. }
  443. }
  444. /** sets the opacity.
  445. @warning If the the texture has premultiplied alpha then, the R, G and B channels will be modifed.
  446. Values goes from 0 to 255, where 255 means fully opaque.
  447. */
  448. GLubyte CCScale9Sprite::getOpacity()
  449. {
  450. return m_cOpacity;
  451. }
  452. void CCScale9Sprite::setPreferredSize(CCSize preferedSize)
  453. {
  454. this->setContentSize(preferedSize);
  455. this->m_preferredSize = preferedSize;
  456. }
  457. CCSize CCScale9Sprite::getPreferredSize()
  458. {
  459. return this->m_preferredSize;
  460. }
  461. void CCScale9Sprite::setCapInsets(CCRect capInsets)
  462. {
  463. CCSize contentSize = this->m_tContentSize;
  464. this->updateWithBatchNode(this->scale9Image, this->m_spriteRect, capInsets);
  465. this->setContentSize(contentSize);
  466. }
  467. CCRect CCScale9Sprite::getCapInsets()
  468. {
  469. return m_capInsets;
  470. }
  471. void CCScale9Sprite::updateCapInset()
  472. {
  473. CCRect insets;
  474. if (this->m_insetLeft == 0 && this->m_insetTop == 0 && this->m_insetRight == 0 && this->m_insetBottom == 0)
  475. {
  476. insets = CCRectZero;
  477. }
  478. else
  479. {
  480. insets = CCRectMake(this->m_insetLeft,
  481. this->m_insetTop,
  482. this->m_spriteRect.size.width-this->m_insetLeft-this->m_insetRight,
  483. this->m_spriteRect.size.height-this->m_insetTop-this->m_insetBottom);
  484. }
  485. this->setCapInsets(insets);
  486. }
  487. void CCScale9Sprite::setOpacityModifyRGB(bool var)
  488. {
  489. m_bIsOpacityModifyRGB = var;
  490. if (scale9Image->getChildren() && scale9Image->getChildren()->count() != 0)
  491. {
  492. CCObject* child;
  493. CCARRAY_FOREACH(scale9Image->getChildren(), child)
  494. {
  495. CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);
  496. if (pNode)
  497. {
  498. pNode->setOpacityModifyRGB(m_bIsOpacityModifyRGB);
  499. }
  500. //CCNode* pNode = (CCNode*) child;
  501. //if (pNode)
  502. //{
  503. // CCRGBAProtocol *pRGBAProtocol = (CCRGBAProtocol *)pNode;
  504. // if (pRGBAProtocol)
  505. // {
  506. // pRGBAProtocol->setOpacityModifyRGB(m_bIsOpacityModifyRGB);
  507. // }
  508. //}
  509. }
  510. }
  511. }
  512. bool CCScale9Sprite::isOpacityModifyRGB()
  513. {
  514. return m_bIsOpacityModifyRGB;
  515. }
  516. void CCScale9Sprite::setSpriteFrame(CCSpriteFrame * spriteFrame)
  517. {
  518. CCSpriteBatchNode * batchnode = CCSpriteBatchNode::createWithTexture(spriteFrame->getTexture(), 9);
  519. this->updateWithBatchNode(batchnode, spriteFrame->getRect(), CCRectZero);
  520. // Reset insets
  521. this->m_insetLeft = 0;
  522. this->m_insetTop = 0;
  523. this->m_insetRight = 0;
  524. this->m_insetBottom = 0;
  525. }
  526. float CCScale9Sprite::getInsetLeft()
  527. {
  528. return this->m_insetLeft;
  529. }
  530. float CCScale9Sprite::getInsetTop()
  531. {
  532. return this->m_insetTop;
  533. }
  534. float CCScale9Sprite::getInsetRight()
  535. {
  536. return this->m_insetRight;
  537. }
  538. float CCScale9Sprite::getInsetBottom()
  539. {
  540. return this->m_insetBottom;
  541. }
  542. void CCScale9Sprite::setInsetLeft(float insetLeft)
  543. {
  544. this->m_insetLeft = insetLeft;
  545. this->updateCapInset();
  546. }
  547. void CCScale9Sprite::setInsetTop(float insetTop)
  548. {
  549. this->m_insetTop = insetTop;
  550. this->updateCapInset();
  551. }
  552. void CCScale9Sprite::setInsetRight(float insetRight)
  553. {
  554. this->m_insetRight = insetRight;
  555. this->updateCapInset();
  556. }
  557. void CCScale9Sprite::setInsetBottom(float insetBottom)
  558. {
  559. this->m_insetBottom = insetBottom;
  560. this->updateCapInset();
  561. }
  562. void CCScale9Sprite::visit()
  563. {
  564. if(this->m_positionsAreDirty)
  565. {
  566. this->updatePositions();
  567. this->m_positionsAreDirty = false;
  568. }
  569. CCNode::visit();
  570. }
  571. NS_CC_EXT_END