DIRECTOR: add _originalSprite pointing to the original sprite.

We still need it to change the size of button sprites.
This commit is contained in:
ysj1173886760 2021-06-21 21:17:44 +08:00 committed by Eugene Sandulenko
parent 2255b11139
commit 8b9d72d181
2 changed files with 9 additions and 1 deletions

View File

@ -40,6 +40,7 @@ Channel::Channel(Sprite *sp, int priority) {
else
_sprite = new Sprite(*sp);
_originalSprite = sp;
_widget = nullptr;
_currentPoint = sp->_startPoint;
_delta = Common::Point(0, 0);
@ -359,12 +360,13 @@ void Channel::replaceSprite(Sprite *nextSprite) {
bool newSprite = (_sprite->_spriteType == kInactiveSprite && nextSprite->_spriteType != kInactiveSprite);
// update the _sprite we stored in channel
// update the _sprite we stored in channel, and point the originalSprite to the new one
// release the widget, because we may having the new one, we may optimize this by adding it to dtor?
if (_sprite->_cast)
_sprite->_cast->releaseWidget();
delete _sprite;
_sprite = new Sprite(*nextSprite);
_originalSprite = nextSprite;
// Sprites marked moveable are constrained to the same bounding box until
// the moveable is disabled
@ -423,6 +425,11 @@ void Channel::replaceWidget() {
if (_sprite->_cast->_type == kCastText || _sprite->_cast->_type == kCastButton) {
_sprite->_width = _widget->_dims.width();
_sprite->_height = _widget->_dims.height();
// TODO: originalSprite should not be modified. We shall amend it when we get the correct way to deal with button size.
if (_originalSprite) {
_originalSprite->_width = _sprite->_width;
_originalSprite->_height = _sprite->_height;
}
_width = _sprite->_width;
_height = _sprite->_height;
}

View File

@ -71,6 +71,7 @@ public:
public:
Sprite *_sprite;
Sprite *_originalSprite;
Cursor _cursor;
Graphics::MacWidget *_widget;