| 251 | } |
| 252 | |
| 253 | void ButtonSprite::updateSpriteBGSize() |
| 254 | { |
| 255 | // Update content size |
| 256 | Vec2 newContentSize; |
| 257 | |
| 258 | if (_subBGSprite) |
| 259 | { |
| 260 | newContentSize = _subBGSprite->getContentSize(); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | if (_absoluteWidth) |
| 265 | { |
| 266 | newContentSize.width = _width; |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | float labelWidth = _subSprite->getContentSize().width; |
| 271 | |
| 272 | if (_minWidth < (labelWidth * _subSprite->getScale())) |
| 273 | { |
| 274 | newContentSize.width = labelWidth * _subSprite->getScale(); |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | newContentSize.width = _minWidth; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if (_buttonTexture) |
| 283 | { |
| 284 | Rect defaultRect = { 0,0,40,40 }; |
| 285 | |
| 286 | newContentSize.width += 8; |
| 287 | |
| 288 | if (defaultRect.size.height >= (_subSprite->getContentSize().height * _subSprite->getScale()) + 8) |
| 289 | newContentSize.height = defaultRect.size.height; |
| 290 | else |
| 291 | newContentSize.height = (_subSprite->getContentSize().height * _subSprite->getScale()) + 8; |
| 292 | |
| 293 | _buttonTexture->setContentSize(newContentSize); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | this->setContentSize(newContentSize); |
| 298 | |
| 299 | // Update positions |
| 300 | _subSprite->setPosition( |
| 301 | (this->getContentSize().width / 2) + _spriteOffset.x, |
| 302 | ((this->getContentSize().height / 2) + 2) + _spriteOffset.y |
| 303 | ); |
| 304 | |
| 305 | if (_buttonTexture) |
| 306 | { |
| 307 | _buttonTexture->setPosition(this->getContentSize() / 2); |
| 308 | } |
| 309 | else if (_subBGSprite) |
| 310 | { |
no test coverage detected