DIRECTOR: wrap updating global attributes to function updateGlobalAttr, handle button cast member attributes.

updateGlobalAttr will handle selEnd and selStart for text, and checkBoxType for button
This commit is contained in:
ysj1173886760 2021-06-13 22:05:11 +08:00 committed by Eugene Sandulenko
parent efe872b8c0
commit 9cc29dac61
3 changed files with 18 additions and 2 deletions

View File

@ -728,6 +728,7 @@ Graphics::MacWidget *TextCastMember::createWidget(Common::Rect &bbox, Channel *c
widget->_focusable = true;
((Graphics::MacButton *)widget)->setHilite(_hilite);
((Graphics::MacButton *)widget)->setCheckBoxType(g_director->getCurrentMovie()->_checkBoxType);
((Graphics::MacButton *)widget)->draw();
break;

View File

@ -30,6 +30,7 @@
#include "director/castmember.h"
#include "graphics/macgui/mactext.h"
#include "graphics/macgui/macbutton.h"
namespace Director {
@ -308,6 +309,7 @@ void Channel::setClean(Sprite *nextSprite, int spriteId, bool partial) {
}
setEditable(_sprite->_editable);
updateGlobalAttr();
_dirty = false;
}
@ -315,8 +317,6 @@ void Channel::setClean(Sprite *nextSprite, int spriteId, bool partial) {
void Channel::setEditable(bool editable) {
if (_sprite->_cast && _sprite->_cast->_type == kCastText) {
// if the sprite is editable, then we refresh the selEnd and setStart
if (editable && _widget)
((Graphics::MacText *)_widget)->setSelRange(g_director->getCurrentMovie()->_selStart, g_director->getCurrentMovie()->_selEnd);
if (_sprite->_cast->isEditable() == editable)
return;
_sprite->_cast->setEditable(editable);
@ -337,6 +337,19 @@ void Channel::setEditable(bool editable) {
}
}
// we may optimize this by only update those attributes when we are changing them
// but not to pass them to widgets everytime
void Channel::updateGlobalAttr() {
if (!_sprite->_cast)
return;
// update text info, including selEnd and selStart
if (_sprite->_cast->_type == kCastText && _sprite->_editable && _widget)
((Graphics::MacText *)_widget)->setSelRange(g_director->getCurrentMovie()->_selStart, g_director->getCurrentMovie()->_selEnd);
// update button info, including checkBoxType
if (_sprite->_cast->_type == kCastButton && _widget)
((Graphics::MacButton *)_widget)->setCheckBoxType(g_director->getCurrentMovie()->_checkBoxType);
}
void Channel::replaceSprite(Sprite *nextSprite) {
if (!nextSprite)
return;

View File

@ -65,6 +65,8 @@ public:
void replaceWidget();
bool updateWidget();
void updateGlobalAttr();
void addDelta(Common::Point pos);
public: