GRAPHICS: MACGUI: Render table cells in MacText

This commit is contained in:
Eugene Sandulenko 2023-10-09 00:18:22 +02:00
parent b2a7bad618
commit 4fba78c13d
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 46 additions and 25 deletions

View File

@ -119,7 +119,7 @@ uint MacTextLine::getChunkNum(int *col) {
MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims) :
MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
_macFont(macFont), _interLinear(interlinear) {
_macFont(macFont) {
D(6, "MacText::MacText(): fgcolor: %d, bgcolor: %d s: \"%s\"", fgcolor, bgcolor, Common::toPrintable(s.encode()).c_str());
@ -134,6 +134,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = textShadow;
_canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@ -155,7 +156,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
// NOTE: This constructor and the one afterward are for MacText engines that don't use widgets. This is the classic was MacText was constructed.
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *macFont, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
_macFont(macFont), _interLinear(interlinear) {
_macFont(macFont) {
_str = s;
@ -167,6 +168,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = 0;
_canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = true;
@ -188,7 +190,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
// Working with plain Font
MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, uint32 fgcolor, uint32 bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, bool fixedDims) :
MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
_macFont(nullptr), _interLinear(interlinear) {
_macFont(nullptr) {
_str = s;
@ -200,6 +202,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
_canvas._maxWidth = maxWidth;
_canvas._textAlignment = textAlignment;
_canvas._textShadow = 0;
_canvas._interLinear = interlinear;
_canvas._wm = wm;
_canvas._bgcolor = bgcolor;
_canvas._macFontMode = false;
@ -1318,7 +1321,7 @@ int MacTextCanvas::getLineHeight(int line) {
}
void MacText::setInterLinear(int interLinear) {
_interLinear = interLinear;
_canvas._interLinear = interLinear;
recalcDims();
_fullRefresh = true;
@ -1327,22 +1330,7 @@ void MacText::setInterLinear(int interLinear) {
}
void MacText::recalcDims() {
if (_canvas._text.empty())
return;
int y = 0;
_canvas._textMaxWidth = 0;
for (uint i = 0; i < _canvas._text.size(); i++) {
_canvas._text[i].y = y;
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
_canvas._textMaxWidth = MAX(_canvas._textMaxWidth, _canvas.getLineWidth(i, true));
y += MAX(getLineHeight(i), _interLinear);
}
_canvas._textMaxHeight = y;
_canvas.recalcDims();
if (!_fixedDims) {
int newBottom = _dims.top + _canvas._textMaxHeight + (2 * _border) + _gutter + _shadow;
@ -1361,6 +1349,25 @@ void MacText::recalcDims() {
}
}
void MacTextCanvas::recalcDims() {
if (_text.empty())
return;
int y = 0;
_textMaxWidth = 0;
for (uint i = 0; i < _text.size(); i++) {
_text[i].y = y;
// We must calculate width first, because it enforces
// the computation. Calling Height() will return cached value!
_textMaxWidth = MAX(_textMaxWidth, getLineWidth(i, true));
y += MAX(getLineHeight(i), _interLinear);
}
_textMaxHeight = y;
}
void MacText::setAlignOffset(TextAlign align) {
if (_canvas._textAlignment == align)
return;
@ -1547,7 +1554,7 @@ void MacText::removeLastLine() {
if (!_canvas._text.size())
return;
int h = getLineHeight(_canvas._text.size() - 1) + _interLinear;
int h = getLineHeight(_canvas._text.size() - 1) + _canvas._interLinear;
_canvas._surface->fillRect(Common::Rect(0, _canvas._textMaxHeight - h, _canvas._surface->w, _canvas._textMaxHeight), _bgcolor);
@ -2975,6 +2982,20 @@ void MacText::processTable(int line) {
for (uint i = 0; i < numCols; i++) {
warning("%d: %d", i, colW[i]);
}
for (auto &row : *table) {
int i = 0;
for (auto &cell : row.cells) {
cell._maxWidth = colW[i];
cell.recalcDims();
cell.reallocSurface();
cell._surface->clear(_bgcolor);
cell.render(0, cell._text.size());
i++;
}
}
}
} // End of namespace Graphics

View File

@ -128,6 +128,7 @@ public:
int _textMaxWidth = 0;
int _textMaxHeight = 0;
TextAlign _textAlignment = kTextAlignRight;
int _interLinear = 0;
int _textShadow = 0;
MacWindowManager *_wm = nullptr;
uint32 _bgcolor = 0;
@ -140,6 +141,7 @@ public:
delete _shadowSurface;
}
void recalcDims();
void reallocSurface();
void render(int from, int to);
void render(int from, int to, int shadow);
@ -237,7 +239,7 @@ public:
void drawToPoint(ManagedSurface *g, Common::Point dstPoint);
ManagedSurface *getSurface() { return _canvas._surface; }
int getInterLinear() { return _interLinear; }
int getInterLinear() { return _canvas._interLinear; }
void setInterLinear(int interLinear);
void setMaxWidth(int maxWidth);
void setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
@ -329,7 +331,7 @@ public:
Common::U32String cutSelection();
const SelectedText *getSelectedText() { return &_selectedText; }
int getLineSpacing() { return _interLinear; }
int getLineSpacing() { return _canvas._interLinear; }
/**
* set the selection of mactext
@ -392,8 +394,6 @@ protected:
Common::U32String _str;
const MacFont *_macFont;
int _interLinear;
bool _fixedDims;
int _selEnd;