DIRECTOR: fix editableText both in D2/3 and in D4.

This commit is contained in:
ysj1173886760 2021-08-18 20:19:01 +08:00
parent b82735f0df
commit 8e8f640e69
5 changed files with 13 additions and 25 deletions

View File

@ -33,6 +33,7 @@
#include "director/sound.h"
#include "director/window.h"
#include "director/stxt.h"
#include "director/sprite.h"
namespace Director {
@ -780,11 +781,11 @@ Graphics::MacWidget *TextCastMember::createWidget(Common::Rect &bbox, Channel *c
}
widget = new Graphics::MacText(g_director->getCurrentWindow(), bbox.left, bbox.top, dims.width(), dims.height(), g_director->_wm, _ftext, macFont, getForeColor(), getBackColor(), _initialRect.width(), getAlignment(), _lineSpacing, _borderSize, _gutterSize, _boxShadow, _textShadow, _textType == kTextTypeFixed);
((Graphics::MacText *)widget)->setSelRange(g_director->getCurrentMovie()->_selStart, g_director->getCurrentMovie()->_selEnd);
((Graphics::MacText *)widget)->setEditable(_editable);
((Graphics::MacText *)widget)->setEditable(channel->_sprite->_editable);
((Graphics::MacText *)widget)->draw();
// since we disable the ability of setActive in setEdtiable, then we need to set active widget manually
if (_editable) {
if (channel->_sprite->_editable) {
Graphics::MacWidget *activeWidget = g_director->_wm->getActiveWidget();
if (activeWidget == nullptr || !activeWidget->isEditable())
g_director->_wm->setActiveWidget(widget);
@ -871,17 +872,6 @@ void TextCastMember::setTextSize(int textSize) {
}
}
bool TextCastMember::isEditable() {
return _editable;
}
void TextCastMember::setEditable(bool editable) {
_editable = editable;
// if we are linking to the widget, then we can modify it directly.
if (_widget)
((Graphics::MacText *)_widget)->setEditable(editable);
}
void TextCastMember::updateFromWidget(Graphics::MacWidget *widget) {
if (widget && _type == kCastText) {
_ptext = ((Graphics::MacText *)widget)->getEditedString();

View File

@ -224,8 +224,8 @@ public:
void setText(const Common::U32String &text);
virtual Graphics::MacWidget *createWidget(Common::Rect &bbox, Channel *channel, SpriteType spriteType) override;
virtual bool isEditable() override;
virtual void setEditable(bool editable) override;
virtual bool isEditable() override { return _editable; }
virtual void setEditable(bool editable) override { _editable = editable; }
virtual void updateFromWidget(Graphics::MacWidget *widget) override;
Graphics::TextAlign getAlignment();

View File

@ -59,7 +59,7 @@ Channel::Channel(Sprite *sp, int priority) {
_visible = true;
_dirty = true;
_sprite->updateCast();
_sprite->updateEditable();
}
Channel::~Channel() {
@ -357,7 +357,7 @@ void Channel::setClean(Sprite *nextSprite, int spriteId, bool partial) {
// for the dirty puppet sprites, we will always replaceWidget since previousCastId is 0, but we shouldn't replace the widget of there are only position changing
// e.g. we won't want a puppet editable text sprite changing because that will cause the loss of text.
if (replace) {
_sprite->updateCast();
_sprite->updateEditable();
replaceWidget(previousCastId, dimsChanged || spriteTypeChanged);
}
@ -376,6 +376,8 @@ void Channel::setClean(Sprite *nextSprite, int spriteId, bool partial) {
void Channel::updateTextCast() {
if (!_sprite->_cast || _sprite->_cast->_type != kCastText)
return;
_sprite->updateEditable();
setEditable(_sprite->_editable);
if (_widget) {
@ -394,9 +396,6 @@ void Channel::updateTextCast() {
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 (_sprite->_cast->isEditable() != editable)
_sprite->_cast->setEditable(editable);
if (_widget) {
((Graphics::MacText *)_widget)->setEditable(editable);
// we only set the first editable text member in score active

View File

@ -148,13 +148,12 @@ Graphics::Surface *Sprite::getQDMatte() {
return _matte ? _matte->getMask() : nullptr;
}
void Sprite::updateCast() {
void Sprite::updateEditable() {
if (!_cast)
return;
if (_cast->isEditable() != _editable && !_puppet)
_cast->setEditable(_editable);
if (!_puppet)
_editable = _editable || _cast->isEditable();
}
bool Sprite::respondsToMouse() {

View File

@ -65,7 +65,7 @@ public:
Frame *getFrame() const { return _frame; }
Score *getScore() const { return _score; }
void updateCast();
void updateEditable();
bool respondsToMouse();
bool isActive();