From dc41917a74cb5b872a8169edfd2d5191ba1afc9c Mon Sep 17 00:00:00 2001 From: ysj1173886760 <1173886760@qq.com> Date: Tue, 6 Jul 2021 18:05:42 +0800 Subject: [PATCH] DIRECTOR: implement text chunk fields operations --- engines/director/lingo/lingo-object.cpp | 58 +++++++++++++++++-------- graphics/macgui/mactext.cpp | 4 +- graphics/macgui/mactext.h | 4 +- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/engines/director/lingo/lingo-object.cpp b/engines/director/lingo/lingo-object.cpp index b7a9f148901..7064440a188 100644 --- a/engines/director/lingo/lingo-object.cpp +++ b/engines/director/lingo/lingo-object.cpp @@ -36,6 +36,7 @@ #include "director/lingo/xlibs/palxobj.h" #include "director/lingo/xlibs/flushxobj.h" #include "director/lingo/xlibs/winxobj.h" +#include "graphics/macgui/mactext.h" namespace Director { @@ -999,21 +1000,38 @@ bool TextCastMember::hasChunkField(int field) { Datum TextCastMember::getChunkField(int field, int start, int end) { Datum d; + Graphics::MacText *macText = ((Graphics::MacText *)_widget); + if (!_widget) + warning("TextCastMember::getChunkField getting chunk field when there is no linked widget, returning the default value"); + switch (field) { case kTheForeColor: - d.u.i = getForeColor(); + if (_widget) + d.u.i = macText->getTextColor(start, end); + else + d.u.i = getForeColor(); break; case kTheTextFont: - d.u.i = _fontId; + if (_widget) + d.u.i = macText->getTextFont(start, end); + else + d.u.i = _fontId; break; case kTheTextHeight: + warning("TextCastMember::getChunkField getting text height(line spacing) is not implemented yet, returning the default one"); d.u.i = _lineSpacing; break; case kTheTextSize: - d.u.i = _fontSize; + if (_widget) + d.u.i = macText->getTextSize(start, end); + else + d.u.i = _fontSize; break; case kTheTextStyle: - d.u.i = _textSlant; + if (_widget) + d.u.i = macText->getTextSlant(start, end); + else + d.u.i = _textSlant; break; default: break; @@ -1023,28 +1041,30 @@ Datum TextCastMember::getChunkField(int field, int start, int end) { } bool TextCastMember::setChunkField(int field, int start, int end, const Datum &d) { - uint color = 0; + Graphics::MacText *macText = ((Graphics::MacText *)_widget); + if (!_widget) + warning("TextCastMember::setChunkField setting chunk field when there is no linked widget"); + switch (field) { case kTheForeColor: - color = d.asInt(); - setColors(&color, nullptr); - return false; + if (_widget) + macText->setTextColor(d.asInt(), start, end); + return true; case kTheTextFont: - _fontId = d.asInt(); - _modified = true; - return false; + if (_widget) + macText->setTextFont(d.asInt(), start, end); + return true; case kTheTextHeight: - _lineSpacing = d.asInt(); - _modified = true; + warning("TextCastMember::setChunkField setting text height(line spacing) is not implemented yet"); return false; case kTheTextSize: - _fontSize = d.asInt(); - _modified = true; - return false; + if (_widget) + macText->setTextSize(d.asInt(), start, end); + return true; case kTheTextStyle: - _textSlant = d.asInt(); - _modified = true; - return false; + if (_widget) + macText->setTextSlant(d.asInt(), start, end); + return true; default: break; } diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 3c0f1eed0ca..f4c361cf71d 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -472,7 +472,7 @@ void setTextFontCallback(MacFontRun &macFontRun, int fontId) { macFontRun.fontId = fontId; } -void MacText::setTextFont(int start, int end, int fontId) { +void MacText::setTextFont(int fontId, int start, int end) { setTextChunks(start, end, fontId, setTextFontCallback); } @@ -480,7 +480,7 @@ void setTextSlantCallback(MacFontRun &macFontRun, int textSlant) { macFontRun.textSlant = textSlant; } -void MacText::setTextSlant(int start, int end, int textSlant) { +void MacText::setTextSlant(int textSlant, int start, int end) { setTextChunks(start, end, textSlant, setTextSlantCallback); } diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h index dd2906264e9..4733131ebfb 100644 --- a/graphics/macgui/mactext.h +++ b/graphics/macgui/mactext.h @@ -206,10 +206,10 @@ public: uint getTextColor(int start, int end); int getTextFont(int start, int end); - void setTextFont(int start, int end, int fontId); + void setTextFont(int fontId, int start, int end); int getTextSlant(int start, int end); - void setTextSlant(int start, int end, int textSlant); + void setTextSlant(int textSlant, int start, int end); private: MacFontRun getTextChunks(int start, int end);