JANITORIAL: Improve readability of code in drawWidget()

This commit is contained in:
av-dx 2021-07-28 00:01:06 +05:30 committed by Eugene Sandulenko
parent 8805365b59
commit 4ab39e81b1

View file

@ -76,36 +76,41 @@ void GridItemWidget::drawWidget() {
// selection border. This can break when the stroke width of // selection border. This can break when the stroke width of
// the border is comparable to 1/3 of grid item spacing. Also, // the border is comparable to 1/3 of grid item spacing. Also,
// border shadow is not considered. // border shadow is not considered.
const int kMarginX = _grid->_gridXSpacing / 3;
const int kMarginY = _grid->_gridYSpacing / 3;
if ((isHighlighted) || (_grid->getSelected() == _activeEntry->entryID)) { if ((isHighlighted) || (_grid->getSelected() == _activeEntry->entryID)) {
Common::Rect r(_x - kMarginX, _y - kMarginY,
_x + _w + kMarginX, _y + _h + kMarginY);
// Draw a highlighted BG on hover // Draw a highlighted BG on hover
g_gui.theme()->drawWidgetBackground(Common::Rect(_x - (_grid->_gridXSpacing / 3), _y - (_grid->_gridYSpacing / 3), g_gui.theme()->drawWidgetBackground(r, ThemeEngine::WidgetBackground::kGridItemHighlight);
_x + _w + (_grid->_gridXSpacing / 3), _y + _h + (_grid->_gridYSpacing / 3)),
ThemeEngine::WidgetBackground::kGridItemHighlight);
} else { } else {
Common::Rect r(_x - 2 * kMarginX, _y - 2 * kMarginY,
_x + _w + 2 * kMarginX, _y + _h + 2 * kMarginY);
// Draw a BG of the same color as grid area // Draw a BG of the same color as grid area
// when it is not highlighted to cover up // when it is not highlighted to cover up
// the highlight shadow // the highlight shadow
// FIXME: Find a way to redraw the area around the widget // FIXME: Find a way to redraw the area around the widget
// instead of just drawing a cover-up // instead of just drawing a cover-up
g_gui.theme()->drawWidgetBackground(Common::Rect(_x - 2 * (_grid->_gridXSpacing / 3), _y - 2 * (_grid->_gridYSpacing / 3), g_gui.theme()->drawWidgetBackground(r, ThemeEngine::WidgetBackground::kGridItemBackground);
_x + _w + 2 * (_grid->_gridXSpacing / 3), _y + _h + 2 * (_grid->_gridYSpacing / 3)),
ThemeEngine::WidgetBackground::kGridItemBackground);
} }
// Draw Thumbnail Background // Draw Thumbnail Background
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _grid->getThumbnailWidth(), _y + thumbHeight), g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + thumbWidth, _y + thumbHeight),
ThemeEngine::WidgetBackground::kThumbnailBackground); ThemeEngine::WidgetBackground::kThumbnailBackground);
// Draw Thumbnail // Draw Thumbnail
if (_thumbGfx.empty()) { if (_thumbGfx.empty()) {
// Draw Title when thumbnail is missing // Draw Title when thumbnail is missing
int linesInThumb = MIN(thumbHeight / kLineHeight, (int)titleLines.size()); int linesInThumb = MIN(thumbHeight / kLineHeight, (int)titleLines.size());
Common::Rect r(_x, _y + (thumbHeight - linesInThumb * kLineHeight) / 2,
_x + thumbWidth, _y + (thumbHeight - linesInThumb * kLineHeight) / 2 + kLineHeight);
for (int i = 0; i < linesInThumb; ++i) { for (int i = 0; i < linesInThumb; ++i) {
g_gui.theme()->drawText(Common::Rect(_x, _y + ((thumbHeight - (linesInThumb - 2 * i) * kLineHeight)) / 2, g_gui.theme()->drawText(r, titleLines[i], ThemeEngine::kStateEnabled,
_x + thumbWidth, _y + ((thumbHeight - (linesInThumb - 2 * i) * kLineHeight)) / 2 + kLineHeight), Graphics::kTextAlignCenter, ThemeEngine::kTextInversionNone,
titleLines[i], GUI::ThemeEngine::kStateEnabled, Graphics::kTextAlignCenter, 0, true, ThemeEngine::kFontStyleNormal,
ThemeEngine::kTextInversionNone, 0, true, ThemeEngine::kFontStyleNormal, ThemeEngine::kFontColorAlternate, false);
ThemeEngine::kFontColorAlternate, false); r.translate(0, kLineHeight);
} }
} else { } else {
g_gui.theme()->drawSurface(Common::Point(_x, _y), _thumbGfx, true); g_gui.theme()->drawSurface(Common::Point(_x, _y), _thumbGfx, true);
@ -114,15 +119,15 @@ void GridItemWidget::drawWidget() {
// Draw Platform Icon // Draw Platform Icon
const Graphics::ManagedSurface *platGfx = _grid->platformToSurface(_activeEntry->platform); const Graphics::ManagedSurface *platGfx = _grid->platformToSurface(_activeEntry->platform);
if (platGfx) { if (platGfx) {
g_gui.theme()->drawSurface(Common::Point(_x + thumbWidth - platGfx->w, _y + thumbHeight - platGfx->h), Common::Point p(_x + thumbWidth - platGfx->w, _y + thumbHeight - platGfx->h);
*platGfx, true); g_gui.theme()->drawSurface(p, *platGfx, true);
} }
// Draw Flag // Draw Flag
const Graphics::ManagedSurface *flagGfx = _grid->languageToSurface(_activeEntry->language); const Graphics::ManagedSurface *flagGfx = _grid->languageToSurface(_activeEntry->language);
if (flagGfx) { if (flagGfx) {
g_gui.theme()->drawSurface(Common::Point(_x + thumbWidth - flagGfx->w - 5, _y + 5), Common::Point p(_x + thumbWidth - flagGfx->w - 5, _y + 5);
*flagGfx, true); g_gui.theme()->drawSurface(p, *flagGfx, true);
} }
// Draw Title // Draw Title
@ -132,13 +137,16 @@ void GridItemWidget::drawWidget() {
if (titleLines.size() < 2) { if (titleLines.size() < 2) {
titleLines.push_back(U32String()); titleLines.push_back(U32String());
} else if (titleLines.size() > 2) { } else if (titleLines.size() > 2) {
titleLines[1].erase(titleLines[1].size() - 3); for (uint k = 0; (k < 3) && (titleLines[1].size() > 0); ++k)
titleLines[1].deleteLastChar();
titleLines[1] += U32String("..."); titleLines[1] += U32String("...");
} }
g_gui.theme()->drawText(Common::Rect(_x, _y + thumbHeight, _x + thumbWidth, _y + thumbHeight + kLineHeight), Common::Rect r(_x, _y + thumbHeight, _x + thumbWidth, _y + thumbHeight + kLineHeight);
titleLines[0], GUI::ThemeEngine::kStateEnabled, Graphics::kTextAlignCenter); for (uint k = 0; k < 2; ++k) {
g_gui.theme()->drawText(Common::Rect(_x, _y + thumbHeight + kLineHeight, _x + thumbWidth, _y + thumbHeight + 2 * kLineHeight), g_gui.theme()->drawText(Common::Rect(_x, _y + thumbHeight, _x + thumbWidth, _y + thumbHeight + kLineHeight),
titleLines[1], GUI::ThemeEngine::kStateEnabled, Graphics::kTextAlignCenter); titleLines[0], GUI::ThemeEngine::kStateEnabled, Graphics::kTextAlignCenter);
r.translate(0, kLineHeight);
}
} }
} }