GRAPHICS: MACGUI: Do not use hardcoded colors

This commit is contained in:
Eugene Sandulenko 2018-07-12 00:34:04 +02:00
parent 000d5fcba8
commit 5684134ef6
6 changed files with 100 additions and 40 deletions

View file

@ -700,7 +700,7 @@ void Frame::renderButton(Graphics::ManagedSurface &surface, uint16 spriteId) {
break; break;
case kTypeButton: { case kTypeButton: {
_rect = Common::Rect(x, y, x + width, y + height + 3); _rect = Common::Rect(x, y, x + width, y + height + 3);
Graphics::MacPlotData pd(&surface, &_vm->getMacWindowManager()->getPatterns(), Graphics::MacGUIConstants::kPatternSolid, 1); Graphics::MacPlotData pd(&surface, &_vm->getMacWindowManager()->getPatterns(), Graphics::MacGUIConstants::kPatternSolid, 1, Graphics::kColorWhite);
Graphics::drawRoundRect(_rect, 4, 0, false, Graphics::macDrawPixel, &pd); Graphics::drawRoundRect(_rect, 4, 0, false, Graphics::macDrawPixel, &pd);
addDrawRect(spriteId, _rect); addDrawRect(spriteId, _rect);
} }

View file

@ -362,17 +362,17 @@ bool MacMenu::draw(ManagedSurface *g, bool forceRedraw) {
_screen.clear(kColorGreen); _screen.clear(kColorGreen);
drawFilledRoundRect(&_screen, r, kDesktopArc, kColorWhite); drawFilledRoundRect(&_screen, r, kDesktopArc, _wm->_colorWhite);
r.top = 7; r.top = 7;
_screen.fillRect(r, kColorWhite); _screen.fillRect(r, _wm->_colorWhite);
r.top = kMenuHeight - 1; r.top = kMenuHeight - 1;
r.bottom++; r.bottom++;
_screen.fillRect(r, kColorGreen); _screen.fillRect(r, kColorGreen);
r.bottom--; r.bottom--;
_screen.fillRect(r, kColorBlack); _screen.fillRect(r, _wm->_colorBlack);
for (uint i = 0; i < _items.size(); i++) { for (uint i = 0; i < _items.size(); i++) {
int color = kColorBlack; int color = _wm->_colorBlack;
MacMenuItem *it = _items[i]; MacMenuItem *it = _items[i];
if ((uint)_activeItem == i) { if ((uint)_activeItem == i) {
@ -382,8 +382,8 @@ bool MacMenu::draw(ManagedSurface *g, bool forceRedraw) {
hbox.right += 3; hbox.right += 3;
hbox.bottom += 1; hbox.bottom += 1;
_screen.fillRect(hbox, kColorBlack); _screen.fillRect(hbox, _wm->_colorBlack);
color = kColorWhite; color = _wm->_colorWhite;
if (!it->subitems.empty()) if (!it->subitems.empty())
renderSubmenu(it); renderSubmenu(it);
@ -405,12 +405,12 @@ void MacMenu::renderSubmenu(MacMenuItem *menu) {
if (r->width() == 0 || r->height() == 0) if (r->width() == 0 || r->height() == 0)
return; return;
_screen.fillRect(*r, kColorWhite); _screen.fillRect(*r, _wm->_colorWhite);
_screen.frameRect(*r, kColorBlack); _screen.frameRect(*r, _wm->_colorBlack);
_screen.vLine(r->right, r->top + 3, r->bottom + 1, kColorBlack); _screen.vLine(r->right, r->top + 3, r->bottom + 1, _wm->_colorBlack);
_screen.vLine(r->right + 1, r->top + 3, r->bottom + 1, kColorBlack); _screen.vLine(r->right + 1, r->top + 3, r->bottom + 1, _wm->_colorBlack);
_screen.hLine(r->left + 3, r->bottom, r->right + 1, kColorBlack); _screen.hLine(r->left + 3, r->bottom, r->right + 1, _wm->_colorBlack);
_screen.hLine(r->left + 3, r->bottom + 1, r->right + 1, kColorBlack); _screen.hLine(r->left + 3, r->bottom + 1, r->right + 1, _wm->_colorBlack);
int x = r->left + kMenuDropdownPadding; int x = r->left + kMenuDropdownPadding;
int y = r->top + 1; int y = r->top + 1;
@ -419,12 +419,12 @@ void MacMenu::renderSubmenu(MacMenuItem *menu) {
Common::String acceleratorText(getAcceleratorString(menu->subitems[i], "")); Common::String acceleratorText(getAcceleratorString(menu->subitems[i], ""));
int accelX = r->right - 25; int accelX = r->right - 25;
int color = kColorBlack; int color = _wm->_colorBlack;
if (i == (uint)_activeSubItem && !text.empty() && menu->subitems[i]->enabled) { if (i == (uint)_activeSubItem && !text.empty() && menu->subitems[i]->enabled) {
color = kColorWhite; color = _wm->_colorWhite;
Common::Rect trect(r->left, y - (_wm->_fontMan->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight()); Common::Rect trect(r->left, y - (_wm->_fontMan->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());
_screen.fillRect(trect, kColorBlack); _screen.fillRect(trect, _wm->_colorBlack);
} }
if (!text.empty()) { if (!text.empty()) {
@ -464,7 +464,7 @@ void MacMenu::renderSubmenu(MacMenuItem *menu) {
bool flip = r->left & 2; bool flip = r->left & 2;
byte *ptr = (byte *)_screen.getBasePtr(r->left + 1, y + kMenuDropdownItemHeight / 2); byte *ptr = (byte *)_screen.getBasePtr(r->left + 1, y + kMenuDropdownItemHeight / 2);
for (int xx = r->left + 1; xx <= r->right - 1; xx++, ptr++) { for (int xx = r->left + 1; xx <= r->right - 1; xx++, ptr++) {
*ptr = flip ? kColorBlack : kColorWhite; *ptr = flip ? _wm->_colorBlack : _wm->_colorWhite;
flip = !flip; flip = !flip;
} }
} }

View file

@ -70,7 +70,7 @@ MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgco
_cursorRect = new Common::Rect(0, 0, 1, kCursorHeight); _cursorRect = new Common::Rect(0, 0, 1, kCursorHeight);
_cursorSurface = new ManagedSurface(1, kCursorHeight); _cursorSurface = new ManagedSurface(1, kCursorHeight);
_cursorSurface->fillRect(*_cursorRect, kColorBlack); _cursorSurface->fillRect(*_cursorRect, _wm->_colorBlack);
g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "textWindowCursor"); g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "textWindowCursor");
} }
@ -131,7 +131,7 @@ bool MacTextWindow::draw(ManagedSurface *g, bool forceRedraw) {
if (_borderIsDirty || forceRedraw) { if (_borderIsDirty || forceRedraw) {
drawBorder(); drawBorder();
_composeSurface.clear(kColorWhite); _composeSurface.clear(_wm->_colorWhite);
} }
if (_inputIsDirty || forceRedraw) { if (_inputIsDirty || forceRedraw) {
@ -209,10 +209,10 @@ void MacTextWindow::drawSelection() {
byte *ptr = (byte *)_composeSurface.getBasePtr(x1 + kConWOverlap - 2, y + kConWOverlap - 2); byte *ptr = (byte *)_composeSurface.getBasePtr(x1 + kConWOverlap - 2, y + kConWOverlap - 2);
for (int x = x1; x < x2; x++, ptr++) for (int x = x1; x < x2; x++, ptr++)
if (*ptr == kColorBlack) if (*ptr == _wm->_colorBlack)
*ptr = kColorWhite; *ptr = _wm->_colorWhite;
else else
*ptr = kColorBlack; *ptr = _wm->_colorBlack;
} }
} }

View file

@ -159,13 +159,15 @@ const int arrowPixels[ARROW_H][ARROW_W] = {
{0,1,1,1,1,1,1,1,1,1,1,0}, {0,1,1,1,1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,1,1,1,1,1,1}}; {1,1,1,1,1,1,1,1,1,1,1,1}};
int localColorWhite, localColorBlack;
static void drawPixelInverted(int x, int y, int color, void *data) { static void drawPixelInverted(int x, int y, int color, void *data) {
ManagedSurface *surface = (ManagedSurface *)data; ManagedSurface *surface = (ManagedSurface *)data;
if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) { if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
byte *p = (byte *)surface->getBasePtr(x, y); byte *p = (byte *)surface->getBasePtr(x, y);
*p = *p == kColorWhite ? kColorBlack : kColorWhite; *p = *p == localColorWhite ? localColorBlack : localColorWhite;
} }
} }
@ -234,26 +236,26 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
drawBox(g, x + width - size + 1, y + size, size - 4, height - 2 * size - 1); drawBox(g, x + width - size + 1, y + size, size - 4, height - 2 * size - 1);
if (active) { if (active) {
fillRect(g, x + size, y + 5, width - 2 * size - 1, 8, kColorBlack); fillRect(g, x + size, y + 5, width - 2 * size - 1, 8, _wm->_colorBlack);
fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack); fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, _wm->_colorBlack);
fillRect(g, x + 5, y + size, 8, height - 2 * size - 1, kColorBlack); fillRect(g, x + 5, y + size, 8, height - 2 * size - 1, _wm->_colorBlack);
if (!scrollable) { if (!scrollable) {
fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1, kColorBlack); fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1, _wm->_colorBlack);
} else { } else {
int x1 = x + width - 15; int x1 = x + width - 15;
int y1 = y + size + 1; int y1 = y + size + 1;
for (int yy = 0; yy < ARROW_H; yy++) { for (int yy = 0; yy < ARROW_H; yy++) {
for (int xx = 0; xx < ARROW_W; xx++) for (int xx = 0; xx < ARROW_W; xx++)
g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite)); g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? _wm->_colorBlack : _wm->_colorWhite));
} }
fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2, kColorBlack); fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2, _wm->_colorBlack);
y1 += height - 2 * size - ARROW_H - 2; y1 += height - 2 * size - ARROW_H - 2;
for (int yy = 0; yy < ARROW_H; yy++) { for (int yy = 0; yy < ARROW_H; yy++) {
for (int xx = 0; xx < ARROW_W; xx++) for (int xx = 0; xx < ARROW_W; xx++)
g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? kColorBlack : kColorWhite)); g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? _wm->_colorBlack : _wm->_colorWhite));
} }
if (_highlightedPart == kBorderScrollUp || _highlightedPart == kBorderScrollDown) { if (_highlightedPart == kBorderScrollUp || _highlightedPart == kBorderScrollDown) {
@ -263,12 +265,15 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
int ry2 = ry1 + _dims.height() * _scrollSize; int ry2 = ry1 + _dims.height() * _scrollSize;
Common::Rect rr(rx1, ry1, rx2, ry2); Common::Rect rr(rx1, ry1, rx2, ry2);
Graphics::drawFilledRect(rr, kColorBlack, drawPixelInverted, g); localColorWhite = _wm->_colorWhite;
localColorBlack = _wm->_colorBlack;
Graphics::drawFilledRect(rr, _wm->_colorBlack, drawPixelInverted, g);
} }
} }
if (closeable) { if (closeable) {
if (_highlightedPart == kBorderCloseButton) { if (_highlightedPart == kBorderCloseButton) {
fillRect(g, x + 6, y + 6, 6, 6, kColorBlack); fillRect(g, x + 6, y + 6, 6, 6, _wm->_colorBlack);
} else { } else {
drawBox(g, x + 5, y + 5, 7, 7); drawBox(g, x + 5, y + 5, 7, 7);
} }
@ -284,7 +289,7 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
if (w > maxWidth) if (w > maxWidth)
w = maxWidth; w = maxWidth;
drawBox(g, x + (width - w) / 2, y, w, size); drawBox(g, x + (width - w) / 2, y, w, size);
font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack); font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, _wm->_colorBlack);
} }
} }
@ -294,9 +299,9 @@ void MacWindow::drawPattern() {
for (int x = 0; x < _surface.w; x++) { for (int x = 0; x < _surface.w; x++) {
byte *dst = (byte *)_surface.getBasePtr(x, y); byte *dst = (byte *)_surface.getBasePtr(x, y);
if (pat[y % 8] & (1 << (7 - (x % 8)))) if (pat[y % 8] & (1 << (7 - (x % 8))))
*dst = kColorBlack; *dst = _wm->_colorBlack;
else else
*dst = kColorWhite; *dst = _wm->_colorWhite;
} }
} }
} }
@ -350,8 +355,8 @@ void MacWindow::setCloseable(bool closeable) {
void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) { void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
Common::Rect r(x, y, x + w + 1, y + h + 1); Common::Rect r(x, y, x + w + 1, y + h + 1);
g->fillRect(r, kColorWhite); g->fillRect(r, _wm->_colorWhite);
g->frameRect(r, kColorBlack); g->frameRect(r, _wm->_colorBlack);
} }
void MacWindow::fillRect(ManagedSurface *g, int x, int y, int w, int h, int color) { void MacWindow::fillRect(ManagedSurface *g, int x, int y, int w, int h, int color) {

View file

@ -158,6 +158,9 @@ MacWindowManager::MacWindowManager() {
_menuDelay = 0; _menuDelay = 0;
_menuTimerActive = false; _menuTimerActive = false;
_colorBlack = 0;
_colorWhite = 2;
_fullRefresh = true; _fullRefresh = true;
for (int i = 0; i < ARRAYSIZE(fillPatterns); i++) for (int i = 0; i < ARRAYSIZE(fillPatterns); i++)
@ -290,9 +293,9 @@ void macDrawPixel(int x, int y, int color, void *data) {
void MacWindowManager::drawDesktop() { void MacWindowManager::drawDesktop() {
Common::Rect r(_screen->getBounds()); Common::Rect r(_screen->getBounds());
MacPlotData pd(_screen, &_patterns, kPatternCheckers, 1); MacPlotData pd(_screen, &_patterns, kPatternCheckers, 1, _colorWhite);
Graphics::drawRoundRect(r, kDesktopArc, kColorBlack, true, macDrawPixel, &pd); Graphics::drawRoundRect(r, kDesktopArc, _colorBlack, true, macDrawPixel, &pd);
g_system->copyRectToScreen(_screen->getPixels(), _screen->pitch, 0, 0, _screen->w, _screen->h); g_system->copyRectToScreen(_screen->getPixels(), _screen->pitch, 0, 0, _screen->w, _screen->h);
} }
@ -450,5 +453,53 @@ void MacWindowManager::popCursor() {
CursorMan.popCursor(); CursorMan.popCursor();
} }
///////////////////
// Palette stuff
///////////////////
void MacWindowManager::passPalette(const byte *pal, uint size) {
const byte *p = pal;
_colorWhite = -1;
_colorBlack = -1;
// Search pure white and black colors
for (uint i = 0; i < size; i++) {
if (_colorWhite == -1 && p[0] == 0xff && p[1] == 0xff && p[2] == 0xff)
_colorWhite = i;
if (_colorBlack == -1 && p[0] == 0x00 && p[1] == 0x00 && p[2] == 0x00)
_colorBlack = i;
p += 3;
}
if (_colorWhite != -1 && _colorBlack != -1)
return;
// We did not find some color. Let's find closest approximations
float darkest = 1000.0f, brightest = -1.0f;
int di = -1, bi = -1;
p = pal;
for (uint i = 0; i < size; i++) {
float gray = p[0] * 0.3f + p[1] * 0.59f + p[2] * 0.11f;
if (darkest > gray) {
darkest = gray;
di = i;
}
if (brightest < gray) {
brightest = gray;
bi = i;
}
p += 3;
}
_colorWhite = brightest;
_colorBlack = darkest;
}
} // End of namespace Graphics } // End of namespace Graphics

View file

@ -83,7 +83,7 @@ struct MacPlotData {
int thickness; int thickness;
uint bgColor; uint bgColor;
MacPlotData(Graphics::ManagedSurface *s, MacPatterns *p, int f, int t, uint bg = kColorWhite) : MacPlotData(Graphics::ManagedSurface *s, MacPatterns *p, int f, int t, uint bg) :
surface(s), patterns(p), fillType(f), thickness(t), bgColor(bg) { surface(s), patterns(p), fillType(f), thickness(t), bgColor(bg) {
} }
}; };
@ -210,6 +210,8 @@ public:
void setMode(uint32 mode) { _mode = mode; } void setMode(uint32 mode) { _mode = mode; }
void passPalette(const byte *palette, uint size);
public: public:
MacFontManager *_fontMan; MacFontManager *_fontMan;
uint32 _mode; uint32 _mode;
@ -219,6 +221,8 @@ public:
bool _menuTimerActive; bool _menuTimerActive;
int _colorBlack, _colorWhite;
private: private:
void drawDesktop(); void drawDesktop();