Fixed inconsistency in passing color data to parameters.

- Now uses 'ColorId' as the datatype; this is currently mapped to uInt32, but can change in the future if required
- Eliminates needless and annoying casts in various places; all colors are now 'ColorId' type
This commit is contained in:
Stephen Anthony 2018-08-08 13:09:10 -02:30
parent f7d09c772d
commit 8298ad4d26
28 changed files with 134 additions and 132 deletions

View File

@ -46,7 +46,7 @@ FBSurfaceSDL2::~FBSurfaceSDL2()
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color) void FBSurfaceSDL2::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, ColorId color)
{ {
// Fill the rectangle // Fill the rectangle
SDL_Rect tmp; SDL_Rect tmp;

View File

@ -38,7 +38,7 @@ class FBSurfaceSDL2 : public FBSurface
// Most of the surface drawing primitives are implemented in FBSurface; // Most of the surface drawing primitives are implemented in FBSurface;
// the ones implemented here use SDL-specific code for extra performance // the ones implemented here use SDL-specific code for extra performance
// //
void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color) override; void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, ColorId color) override;
// With hardware surfaces, it's faster to just update the entire surface // With hardware surfaces, it's faster to just update the entire surface
void setDirty() override { mySurfaceIsDirty = true; } void setDirty() override { mySurfaceIsDirty = true; }

View File

@ -615,7 +615,7 @@ void DataGridWidget::drawWidget(bool hilite)
int x = _x + 4 + (col * _colWidth); int x = _x + 4 + (col * _colWidth);
int y = _y + 2 + (row * _rowHeight); int y = _y + 2 + (row * _rowHeight);
int pos = row*_cols + col; int pos = row*_cols + col;
uInt32 textColor = onTop ? kTextColor : kColor; ColorId textColor = onTop ? kTextColor : kColor;
// Draw the selected item inverted, on a highlighted background. // Draw the selected item inverted, on a highlighted background.
if (_currentRow == row && _currentCol == col && if (_currentRow == row && _currentCol == col &&
@ -636,12 +636,12 @@ void DataGridWidget::drawWidget(bool hilite)
if(_changedList[pos]) if(_changedList[pos])
{ {
s.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1, s.fillRect(x - 3, y - 1, _colWidth-1, _rowHeight-1,
onTop ? uInt32(kDbgChangedColor) : _bgcolorlo); onTop ? kDbgChangedColor : _bgcolorlo);
if(_hiliteList[pos]) if(_hiliteList[pos])
textColor = kDbgColorHi; textColor = kDbgColorHi;
else else
textColor = onTop ? uInt32(kDbgChangedTextColor) : textColor; textColor = onTop ? kDbgChangedTextColor : textColor;
} }
else if(_hiliteList[pos]) else if(_hiliteList[pos])
textColor = kDbgColorHi; textColor = kDbgColorHi;

View File

@ -72,7 +72,7 @@ PromptWidget::PromptWidget(GuiObject* boss, const GUI::Font& font,
void PromptWidget::drawWidget(bool hilite) void PromptWidget::drawWidget(bool hilite)
{ {
//cerr << "PromptWidget::drawWidget\n"; //cerr << "PromptWidget::drawWidget\n";
uInt32 fgcolor, bgcolor; ColorId fgcolor, bgcolor;
FBSurface& s = _boss->dialog().surface(); FBSurface& s = _boss->dialog().surface();
bool onTop = _boss->dialog().isOnTop(); bool onTop = _boss->dialog().isOnTop();
@ -90,13 +90,13 @@ void PromptWidget::drawWidget(bool hilite)
if(c & (1 << 17)) // inverse video flag if(c & (1 << 17)) // inverse video flag
{ {
fgcolor = _bgcolor; fgcolor = _bgcolor;
bgcolor = (c & 0x1ffff) >> 8; bgcolor = ColorId((c & 0x1ffff) >> 8);
s.fillRect(x, y, _kConsoleCharWidth, _kConsoleCharHeight, bgcolor); s.fillRect(x, y, _kConsoleCharWidth, _kConsoleCharHeight, bgcolor);
} }
else else
fgcolor = c >> 8; fgcolor = ColorId(c >> 8);
s.drawChar(_font, c & 0x7f, x, y, onTop ? fgcolor : uInt32(kColor)); s.drawChar(_font, c & 0x7f, x, y, onTop ? fgcolor : kColor);
x += _kConsoleCharWidth; x += _kConsoleCharWidth;
} }
y += _kConsoleLineHeight; y += _kConsoleLineHeight;
@ -833,13 +833,11 @@ void PromptWidget::putcharIntern(int c)
nextLine(); nextLine();
else if(c & 0x80) { // set foreground color to TIA color else if(c & 0x80) { // set foreground color to TIA color
// don't print or advance cursor // don't print or advance cursor
// there are only 128 TIA colors, but _textcolor = ColorId((c & 0x7f) << 1);
// OverlayColor contains 256 of them
_textcolor = (c & 0x7f) << 1;
} }
else if(c && c < 0x1e) { // first actual character is large dash else if(c && c < 0x1e) { // first actual character is large dash
// More colors (the regular GUI ones) // More colors (the regular GUI ones)
_textcolor = c + 0x100; _textcolor = ColorId(c + 0x100);
} }
else if(c == 0x7f) { // toggle inverse video (DEL char) else if(c == 0x7f) { // toggle inverse video (DEL char)
_inverse = !_inverse; _inverse = !_inverse;

View File

@ -468,7 +468,7 @@ void RomListWidget::drawWidget(bool hilite)
bool onTop = _boss->dialog().isOnTop(); bool onTop = _boss->dialog().isOnTop();
const CartDebug::DisassemblyList& dlist = myDisasm->list; const CartDebug::DisassemblyList& dlist = myDisasm->list;
int i, pos, xpos, ypos, len = int(dlist.size()); int i, pos, xpos, ypos, len = int(dlist.size());
uInt32 textColor = onTop ? kTextColor : kColor; ColorId textColor = onTop ? kTextColor : kColor;
const GUI::Rect& r = getEditRect(); const GUI::Rect& r = getEditRect();
const GUI::Rect& l = getLineRect(); const GUI::Rect& l = getLineRect();
@ -489,7 +489,7 @@ void RomListWidget::drawWidget(bool hilite)
xpos = _x + CheckboxWidget::boxSize() + 10; ypos = _y + 2; xpos = _x + CheckboxWidget::boxSize() + 10; ypos = _y + 2;
for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++, ypos += _fontHeight) for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++, ypos += _fontHeight)
{ {
uInt32 bytesColor = textColor; ColorId bytesColor = textColor;
// Draw checkboxes for correct lines (takes scrolling into account) // Draw checkboxes for correct lines (takes scrolling into account)
myCheckList[i]->setState(myBPState->isSet(dlist[pos].address)); myCheckList[i]->setState(myBPState->isSet(dlist[pos].address));
@ -514,7 +514,7 @@ void RomListWidget::drawWidget(bool hilite)
// Draw labels // Draw labels
s.drawString(_font, dlist[pos].label, xpos, ypos, _labelWidth, s.drawString(_font, dlist[pos].label, xpos, ypos, _labelWidth,
dlist[pos].hllabel ? textColor : uInt32(kColor)); dlist[pos].hllabel ? textColor : kColor);
// Bytes are only editable if they represent code, graphics, or accessible data // Bytes are only editable if they represent code, graphics, or accessible data
// Otherwise, the disassembly should get all remaining space // Otherwise, the disassembly should get all remaining space

View File

@ -273,7 +273,7 @@ void TiaZoomWidget::drawWidget(bool hilite)
for(x = myXOff, col = 0; x < myNumCols+myXOff; ++x, col += wzoom) for(x = myXOff, col = 0; x < myNumCols+myXOff; ++x, col += wzoom)
{ {
uInt32 idx = y*width + x; uInt32 idx = y*width + x;
uInt32 color = currentFrame[idx] | (idx > scanoffset ? 1 : 0); ColorId color = ColorId(currentFrame[idx] | (idx > scanoffset ? 1 : 0));
s.fillRect(_x + col + 1, _y + row + 1, wzoom, hzoom, color); s.fillRect(_x + col + 1, _y + row + 1, wzoom, hzoom, color);
} }
} }

View File

@ -94,7 +94,7 @@ void ToggleBitWidget::drawWidget(bool hilite)
{ {
for (col = 0; col < _cols; col++) for (col = 0; col < _cols; col++)
{ {
uInt32 textColor = kTextColor; ColorId textColor = kTextColor;
int x = _x + 4 + (col * _colWidth); int x = _x + 4 + (col * _colWidth);
int y = _y + 2 + (row * _rowHeight); int y = _y + 2 + (row * _rowHeight);
int pos = row*_cols + col; int pos = row*_cols + col;

View File

@ -28,11 +28,11 @@ class TogglePixelWidget : public ToggleWidget
int x, int y, int cols, int rows); int x, int y, int cols, int rows);
virtual ~TogglePixelWidget() = default; virtual ~TogglePixelWidget() = default;
void setColor(int color) { void setColor(ColorId color) {
_pixelColor = (color >= 0 && color <= kNumColors) ? color : kDlgColor; _pixelColor = color <= kNumColors ? color : kDlgColor;
} }
void setBackgroundColor(int color) { void setBackgroundColor(ColorId color) {
_backgroundColor = (color >= 0 && color <= kNumColors) ? color : kDlgColor; _backgroundColor = color <= kNumColors ? color : kDlgColor;
} }
void setState(const BoolArray& state); void setState(const BoolArray& state);
@ -42,7 +42,7 @@ class TogglePixelWidget : public ToggleWidget
void setCrossed(bool enable) { _crossBits = enable; } void setCrossed(bool enable) { _crossBits = enable; }
private: private:
int _pixelColor, _backgroundColor; ColorId _pixelColor, _backgroundColor;
bool _swapBits; bool _swapBits;
bool _crossBits; bool _crossBits;

View File

@ -60,7 +60,7 @@ void FBSurface::readPixels(uInt8* buffer, uInt32 pitch, const GUI::Rect& rect) c
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::pixel(uInt32 x, uInt32 y, uInt32 color) void FBSurface::pixel(uInt32 x, uInt32 y, ColorId color)
{ {
uInt32* buffer = myPixels + y * myPitch + x; uInt32* buffer = myPixels + y * myPitch + x;
@ -68,7 +68,7 @@ void FBSurface::pixel(uInt32 x, uInt32 y, uInt32 color)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, uInt32 color) void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, ColorId color)
{ {
// draw line using Bresenham algorithm // draw line using Bresenham algorithm
Int32 dx = (x2 - x); Int32 dx = (x2 - x);
@ -127,7 +127,7 @@ void FBSurface::line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, uInt32 color)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color) void FBSurface::hLine(uInt32 x, uInt32 y, uInt32 x2, ColorId color)
{ {
uInt32* buffer = myPixels + y * myPitch + x; uInt32* buffer = myPixels + y * myPitch + x;
while(x++ <= x2) while(x++ <= x2)
@ -135,7 +135,7 @@ void FBSurface::hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::vLine(uInt32 x, uInt32 y, uInt32 y2, uInt32 color) void FBSurface::vLine(uInt32 x, uInt32 y, uInt32 y2, ColorId color)
{ {
uInt32* buffer = static_cast<uInt32*>(myPixels + y * myPitch + x); uInt32* buffer = static_cast<uInt32*>(myPixels + y * myPitch + x);
while(y++ <= y2) while(y++ <= y2)
@ -146,7 +146,7 @@ void FBSurface::vLine(uInt32 x, uInt32 y, uInt32 y2, uInt32 color)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color) void FBSurface::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, ColorId color)
{ {
while(h--) while(h--)
hLine(x, y+h, x+w-1, color); hLine(x, y+h, x+w-1, color);
@ -154,9 +154,9 @@ void FBSurface::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawChar(const GUI::Font& font, uInt8 chr, void FBSurface::drawChar(const GUI::Font& font, uInt8 chr,
uInt32 tx, uInt32 ty, uInt32 color, uInt32 shadowColor) uInt32 tx, uInt32 ty, ColorId color, ColorId shadowColor)
{ {
if(shadowColor != 0) if(shadowColor != kNone)
{ {
drawChar(font, chr, tx + 1, ty + 0, shadowColor); drawChar(font, chr, tx + 1, ty + 0, shadowColor);
drawChar(font, chr, tx + 0, ty + 1, shadowColor); drawChar(font, chr, tx + 0, ty + 1, shadowColor);
@ -208,14 +208,14 @@ void FBSurface::drawChar(const GUI::Font& font, uInt8 chr,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawBitmap(uInt32* bitmap, uInt32 tx, uInt32 ty, void FBSurface::drawBitmap(uInt32* bitmap, uInt32 tx, uInt32 ty,
uInt32 color, uInt32 h) ColorId color, uInt32 h)
{ {
drawBitmap(bitmap, tx, ty, color, h, h); drawBitmap(bitmap, tx, ty, color, h, h);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawBitmap(uInt32* bitmap, uInt32 tx, uInt32 ty, void FBSurface::drawBitmap(uInt32* bitmap, uInt32 tx, uInt32 ty,
uInt32 color, uInt32 w, uInt32 h) ColorId color, uInt32 w, uInt32 h)
{ {
uInt32* buffer = myPixels + ty * myPitch + tx; uInt32* buffer = myPixels + ty * myPitch + tx;
@ -241,7 +241,7 @@ void FBSurface::drawPixels(uInt32* data, uInt32 tx, uInt32 ty, uInt32 numpixels)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::box(uInt32 x, uInt32 y, uInt32 w, uInt32 h, void FBSurface::box(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
uInt32 colorA, uInt32 colorB) ColorId colorA, ColorId colorB)
{ {
hLine(x + 1, y, x + w - 2, colorA); hLine(x + 1, y, x + w - 2, colorA);
hLine(x, y + 1, x + w - 1, colorA); hLine(x, y + 1, x + w - 1, colorA);
@ -256,7 +256,7 @@ void FBSurface::box(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
uInt32 color, FrameStyle style) ColorId color, FrameStyle style)
{ {
switch(style) switch(style)
{ {
@ -285,8 +285,8 @@ void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawString(const GUI::Font& font, const string& s, void FBSurface::drawString(const GUI::Font& font, const string& s,
int x, int y, int w, int x, int y, int w,
uInt32 color, TextAlign align, ColorId color, TextAlign align,
int deltax, bool useEllipsis, uInt32 shadowColor) int deltax, bool useEllipsis, ColorId shadowColor)
{ {
const string ELLIPSIS = "\x1d"; // "..." const string ELLIPSIS = "\x1d"; // "..."
const int leftX = x, rightX = x + w; const int leftX = x, rightX = x + w;

View File

@ -79,7 +79,7 @@ class FBSurface
@param y The y coordinate @param y The y coordinate
@param color The color of the line @param color The color of the line
*/ */
virtual void pixel(uInt32 x, uInt32 y, uInt32 color); virtual void pixel(uInt32 x, uInt32 y, ColorId color);
/** /**
This method should be called to draw a line. This method should be called to draw a line.
@ -90,7 +90,7 @@ class FBSurface
@param y2 The second y coordinate @param y2 The second y coordinate
@param color The color of the line @param color The color of the line
*/ */
virtual void line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, uInt32 color); virtual void line(uInt32 x, uInt32 y, uInt32 x2, uInt32 y2, ColorId color);
/** /**
This method should be called to draw a horizontal line. This method should be called to draw a horizontal line.
@ -100,7 +100,7 @@ class FBSurface
@param x2 The second x coordinate @param x2 The second x coordinate
@param color The color of the line @param color The color of the line
*/ */
virtual void hLine(uInt32 x, uInt32 y, uInt32 x2, uInt32 color); virtual void hLine(uInt32 x, uInt32 y, uInt32 x2, ColorId color);
/** /**
This method should be called to draw a vertical line. This method should be called to draw a vertical line.
@ -110,7 +110,7 @@ class FBSurface
@param y2 The second y coordinate @param y2 The second y coordinate
@param color The color of the line @param color The color of the line
*/ */
virtual void vLine(uInt32 x, uInt32 y, uInt32 y2, uInt32 color); virtual void vLine(uInt32 x, uInt32 y, uInt32 y2, ColorId color);
/** /**
This method should be called to draw a filled rectangle. This method should be called to draw a filled rectangle.
@ -122,7 +122,7 @@ class FBSurface
@param color The fill color of the rectangle @param color The fill color of the rectangle
*/ */
virtual void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, virtual void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
uInt32 color); ColorId color);
/** /**
This method should be called to draw the specified character. This method should be called to draw the specified character.
@ -134,7 +134,7 @@ class FBSurface
@param color The color of the character @param color The color of the character
*/ */
virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y, virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
uInt32 color, uInt32 shadowColor = 0); ColorId color, ColorId shadowColor = kNone);
/** /**
This method should be called to draw the bitmap image. This method should be called to draw the bitmap image.
@ -145,7 +145,7 @@ class FBSurface
@param color The color of the bitmap @param color The color of the bitmap
@param h The height of the data image @param h The height of the data image
*/ */
virtual void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, uInt32 color, virtual void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, ColorId color,
uInt32 h = 8); uInt32 h = 8);
/** /**
@ -158,7 +158,7 @@ class FBSurface
@param w The width of the data image @param w The width of the data image
@param h The height of the data image @param h The height of the data image
*/ */
virtual void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, uInt32 color, virtual void drawBitmap(uInt32* bitmap, uInt32 x, uInt32 y, ColorId color,
uInt32 w, uInt32 h); uInt32 w, uInt32 h);
/** /**
@ -185,7 +185,7 @@ class FBSurface
@param colorB Darker color for inside line. @param colorB Darker color for inside line.
*/ */
virtual void box(uInt32 x, uInt32 y, uInt32 w, uInt32 h, virtual void box(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
uInt32 colorA, uInt32 colorB); ColorId colorA, ColorId colorB);
/** /**
This method should be called to draw a framed rectangle with This method should be called to draw a framed rectangle with
@ -199,7 +199,7 @@ class FBSurface
@param style The 'FrameStyle' to use for the surrounding frame @param style The 'FrameStyle' to use for the surrounding frame
*/ */
virtual void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, virtual void frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
uInt32 color, FrameStyle style = FrameStyle::Solid); ColorId color, FrameStyle style = FrameStyle::Solid);
/** /**
This method should be called to draw the specified string. This method should be called to draw the specified string.
@ -216,8 +216,8 @@ class FBSurface
*/ */
virtual void drawString( virtual void drawString(
const GUI::Font& font, const string& s, int x, int y, int w, const GUI::Font& font, const string& s, int x, int y, int w,
uInt32 color, TextAlign align = TextAlign::Left, ColorId color, TextAlign align = TextAlign::Left,
int deltax = 0, bool useEllipsis = true, uInt32 shadowColor = 0); int deltax = 0, bool useEllipsis = true, ColorId shadowColor = kNone);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Note: The following methods are FBSurface-specific, and must be // Note: The following methods are FBSurface-specific, and must be

View File

@ -138,7 +138,7 @@ bool FrameBuffer::initialize()
else if(myOSystem.settings().getString("uipalette") == "light") else if(myOSystem.settings().getString("uipalette") == "light")
palID = 2; palID = 2;
for(int i = 0, j = 256; i < kNumColors-256; ++i, ++j) for(uInt32 i = 0, j = 256; i < kNumColors-256; ++i, ++j)
{ {
uInt8 r = (ourGUIColors[palID][i] >> 16) & 0xff; uInt8 r = (ourGUIColors[palID][i] >> 16) & 0xff;
uInt8 g = (ourGUIColors[palID][i] >> 8) & 0xff; uInt8 g = (ourGUIColors[palID][i] >> 8) & 0xff;
@ -413,7 +413,6 @@ void FrameBuffer::showMessage(const string& message, MessagePosition position,
void FrameBuffer::drawFrameStats(float framesPerSecond) void FrameBuffer::drawFrameStats(float framesPerSecond)
{ {
const ConsoleInfo& info = myOSystem.console().about(); const ConsoleInfo& info = myOSystem.console().about();
uInt32 color;
int xPos = 2, yPos = 0; int xPos = 2, yPos = 0;
const int dy = font().getFontHeight() + 2; const int dy = font().getFontHeight() + 2;
@ -422,8 +421,8 @@ void FrameBuffer::drawFrameStats(float framesPerSecond)
myStatsMsg.surface->invalidate(); myStatsMsg.surface->invalidate();
// draw scanlines // draw scanlines
color = myOSystem.console().tia().frameBufferScanlinesLastFrame() != myLastScanlines ? ColorId color = myOSystem.console().tia().frameBufferScanlinesLastFrame() != myLastScanlines ?
uInt32(kDbgColorRed) : myStatsMsg.color; kDbgColorRed : myStatsMsg.color;
ss ss
<< myOSystem.console().tia().frameBufferScanlinesLastFrame() << myOSystem.console().tia().frameBufferScanlinesLastFrame()

View File

@ -518,13 +518,13 @@ class FrameBuffer
int counter; int counter;
int x, y, w, h; int x, y, w, h;
MessagePosition position; MessagePosition position;
uInt32 color; ColorId color;
shared_ptr<FBSurface> surface; shared_ptr<FBSurface> surface;
bool enabled; bool enabled;
Message() Message()
: counter(-1), x(0), y(0), w(0), h(0), position(MessagePosition::BottomCenter), : counter(-1), x(0), y(0), w(0), h(0), position(MessagePosition::BottomCenter),
color(0), enabled(false) { } color(kNone), enabled(false) { }
}; };
Message myMsg; Message myMsg;
Message myStatsMsg; Message myStatsMsg;

View File

@ -18,6 +18,8 @@
#ifndef FRAMEBUFFER_CONSTANTS_HXX #ifndef FRAMEBUFFER_CONSTANTS_HXX
#define FRAMEBUFFER_CONSTANTS_HXX #define FRAMEBUFFER_CONSTANTS_HXX
#include "bspf.hxx"
// Return values for initialization of framebuffer window // Return values for initialization of framebuffer window
enum class FBInitStatus { enum class FBInitStatus {
Success, Success,
@ -39,47 +41,50 @@ enum class MessagePosition {
BottomRight BottomRight
}; };
// TODO - make this 'enum class'
// Colors indices to use for the various GUI elements // Colors indices to use for the various GUI elements
enum { // Abstract away what a color actually is, so we can easily change it in
// the future, if necessary
using ColorId = uInt32;
static constexpr ColorId
kColor = 256, kColor = 256,
kBGColor, kBGColor = 257,
kBGColorLo, kBGColorLo = 258,
kBGColorHi, kBGColorHi = 259,
kShadowColor, kShadowColor = 260,
kTextColor, kTextColor = 261,
kTextColorHi, kTextColorHi = 262,
kTextColorEm, kTextColorEm = 263,
kTextColorInv, kTextColorInv = 264,
kDlgColor, kDlgColor = 265,
kWidColor, kWidColor = 266,
kWidColorHi, kWidColorHi = 267,
kWidFrameColor, kWidFrameColor = 268,
kBtnColor, kBtnColor = 269,
kBtnColorHi, kBtnColorHi = 270,
kBtnBorderColor, kBtnBorderColor = 271,
kBtnBorderColorHi, kBtnBorderColorHi = 272,
kBtnTextColor, kBtnTextColor = 273,
kBtnTextColorHi, kBtnTextColorHi = 274,
kCheckColor, kCheckColor = 275,
kScrollColor, kScrollColor = 276,
kScrollColorHi, kScrollColorHi = 277,
kSliderColor, kSliderColor = 278,
kSliderColorHi, kSliderColorHi = 279,
kSliderBGColor, kSliderBGColor = 280,
kSliderBGColorHi, kSliderBGColorHi = 281,
kSliderBGColorLo, kSliderBGColorLo = 282,
kDbgChangedColor, kDbgChangedColor = 283,
kDbgChangedTextColor, kDbgChangedTextColor = 284,
kDbgColorHi, kDbgColorHi = 285,
kDbgColorRed, kDbgColorRed = 286,
kColorInfo, kColorInfo = 287,
kColorTitleBar, kColorTitleBar = 288,
kColorTitleText, kColorTitleText = 289,
kColorTitleBarLo, kColorTitleBarLo = 290,
kColorTitleTextLo, kColorTitleTextLo = 291,
kNumColors kNumColors = 292,
}; kNone = 0 // placeholder to represent default/no color
;
// Text alignment modes for drawString() // Text alignment modes for drawString()
enum class TextAlign { enum class TextAlign {

View File

@ -169,7 +169,7 @@ void AboutDialog::displayInfo()
{ {
const char* str = myDescStr[i].c_str(); const char* str = myDescStr[i].c_str();
TextAlign align = TextAlign::Center; TextAlign align = TextAlign::Center;
uInt32 color = kTextColor; ColorId color = kTextColor;
while (str[0] == '\\') while (str[0] == '\\')
{ {

View File

@ -112,7 +112,7 @@ void CheckListWidget::drawWidget(bool hilite)
_checkList[i]->draw(); _checkList[i]->draw();
const int y = _y + 2 + _fontHeight * i + 2; const int y = _y + 2 + _fontHeight * i + 2;
uInt32 textColor = kTextColor; ColorId textColor = kTextColor;
GUI::Rect r(getEditRect()); GUI::Rect r(getEditRect());
@ -138,7 +138,7 @@ void CheckListWidget::drawWidget(bool hilite)
} }
else else
s.drawString(_font, _list[pos], _x + r.left, y, r.width(), s.drawString(_font, _list[pos], _x + r.left, y, r.width(),
onTop ? textColor : uInt32(kColor)); onTop ? textColor : kColor);
} }
// Only draw the caret while editing, and if it's in the current viewport // Only draw the caret while editing, and if it's in the current viewport

View File

@ -28,7 +28,7 @@ ColorWidget::ColorWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h, int cmd) int x, int y, int w, int h, int cmd)
: Widget(boss, font, x, y, w, h), : Widget(boss, font, x, y, w, h),
CommandSender(boss), CommandSender(boss),
_color(0), _color(kNone),
_cmd(cmd), _cmd(cmd),
_crossGrid(false) _crossGrid(false)
{ {
@ -36,7 +36,7 @@ ColorWidget::ColorWidget(GuiObject* boss, const GUI::Font& font,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ColorWidget::setColor(int color) void ColorWidget::setColor(ColorId color)
{ {
_color = color; _color = color;
setDirty(); setDirty();

View File

@ -39,8 +39,8 @@ class ColorWidget : public Widget, public CommandSender
int x, int y, int w, int h, int cmd = 0); int x, int y, int w, int h, int cmd = 0);
virtual ~ColorWidget() = default; virtual ~ColorWidget() = default;
void setColor(int color); void setColor(ColorId color);
int getColor() const { return _color; } ColorId getColor() const { return _color; }
void setCrossed(bool enable) { _crossGrid = enable; } void setCrossed(bool enable) { _crossGrid = enable; }
@ -48,7 +48,7 @@ class ColorWidget : public Widget, public CommandSender
void drawWidget(bool hilite) override; void drawWidget(bool hilite) override;
protected: protected:
int _color; ColorId _color;
int _cmd; int _cmd;
bool _crossGrid; bool _crossGrid;

View File

@ -118,7 +118,7 @@ class ContextMenu : public Dialog, public CommandSender
int _selectedOffset, _selectedItem; int _selectedOffset, _selectedItem;
bool _showScroll; bool _showScroll;
bool _isScrolling; bool _isScrolling;
uInt32 _scrollUpColor, _scrollDnColor; ColorId _scrollUpColor, _scrollDnColor;
int _cmd; int _cmd;

View File

@ -1090,7 +1090,7 @@ void DeveloperDialog::handleDebugColours(int idx, int color)
return; return;
} }
static constexpr int dbg_color[2][DEBUG_COLORS] = { static constexpr ColorId dbg_color[2][DEBUG_COLORS] = {
{ {
TIA::FixedColor::NTSC_RED, TIA::FixedColor::NTSC_RED,
TIA::FixedColor::NTSC_ORANGE, TIA::FixedColor::NTSC_ORANGE,

View File

@ -55,7 +55,7 @@ class Dialog : public GuiObject
void close(); void close();
bool isVisible() const override { return _visible; } bool isVisible() const override { return _visible; }
bool isOnTop() { return _onTop; } bool isOnTop() const { return _onTop; }
virtual void center(); virtual void center();
virtual void drawDialog(); virtual void drawDialog();

View File

@ -95,8 +95,8 @@ void EditTextWidget::drawWidget(bool hilite)
adjustOffset(); adjustOffset();
s.drawString(_font, editString(), _x + 2, _y + 2, getEditRect().width(), s.drawString(_font, editString(), _x + 2, _y + 2, getEditRect().width(),
_changed && onTop _changed && onTop
? uInt32(kDbgChangedTextColor) ? kDbgChangedTextColor
: onTop ? _textcolor : uInt32(kColor), : onTop ? _textcolor : kColor,
TextAlign::Left, -_editScrollOffset, false); TextAlign::Left, -_editScrollOffset, false);
// Draw the caret // Draw the caret

View File

@ -206,7 +206,7 @@ void PopUpWidget::drawWidget(bool hilite)
// Draw the label, if any // Draw the label, if any
if(_labelWidth > 0) if(_labelWidth > 0)
s.drawString(_font, _label, _x, _y + myTextY, _labelWidth, s.drawString(_font, _label, _x, _y + myTextY, _labelWidth,
isEnabled() && onTop ? _textcolor : uInt32(kColor), TextAlign::Left); isEnabled() && onTop ? _textcolor : kColor, TextAlign::Left);
// Draw a thin frame around us. // Draw a thin frame around us.
s.frameRect(x, _y, w, _h, isEnabled() && hilite ? kWidColorHi : kColor); s.frameRect(x, _y, w, _h, isEnabled() && hilite ? kWidColorHi : kColor);

View File

@ -164,7 +164,7 @@ void RadioButtonWidget::drawWidget(bool hilite)
// Draw the inner bounding circle with enabled color // Draw the inner bounding circle with enabled color
s.drawBitmap(radio_img_innercircle, _x + 1, _y + _boxY + 1, isEnabled() s.drawBitmap(radio_img_innercircle, _x + 1, _y + _boxY + 1, isEnabled()
? _bgcolor : uInt32(kColor), 12, 12); ? _bgcolor : kColor, 12, 12);
// draw state // draw state
if(_state) if(_state)

View File

@ -68,7 +68,7 @@ void StringListWidget::drawWidget(bool hilite)
for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++) for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++)
{ {
const int y = _y + 2 + _fontHeight * i; const int y = _y + 2 + _fontHeight * i;
uInt32 textColor = onTop ? kTextColor : kShadowColor; ColorId textColor = onTop ? kTextColor : kShadowColor;
// Draw the selected item inverted, on a highlighted background. // Draw the selected item inverted, on a highlighted background.
if (onTop && _selectedItem == pos && _hilite) if (onTop && _selectedItem == pos && _hilite)

View File

@ -268,7 +268,7 @@ void TabWidget::drawWidget(bool hilite)
int i, x = _x + kTabLeftOffset; int i, x = _x + kTabLeftOffset;
for (i = 0; i < int(_tabs.size()); ++i) for (i = 0; i < int(_tabs.size()); ++i)
{ {
uInt32 fontcolor = _tabs[i].enabled && onTop? kTextColor : kColor; ColorId fontcolor = _tabs[i].enabled && onTop? kTextColor : kColor;
int yOffset = (i == _activeTab) ? 0 : 1; int yOffset = (i == _activeTab) ? 0 : 1;
s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1, s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1,
(i == _activeTab) (i == _activeTab)

View File

@ -181,7 +181,7 @@ void TimeLineWidget::drawWidget(bool hilite)
if(idx > 1) if(idx > 1)
{ {
int xt = x + valueToPos(idx - 1); int xt = x + valueToPos(idx - 1);
uInt32 color; ColorId color = kNone;
if(isEnabled()) if(isEnabled())
{ {

View File

@ -307,7 +307,7 @@ void Widget::setDirtyInChain(Widget* start)
StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h, int x, int y, int w, int h,
const string& text, TextAlign align, const string& text, TextAlign align,
uInt32 shadowColor) ColorId shadowColor)
: Widget(boss, font, x, y, w, h), : Widget(boss, font, x, y, w, h),
_align(align) _align(align)
{ {
@ -326,7 +326,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int x, int y,
const string& text, TextAlign align, const string& text, TextAlign align,
uInt32 shadowColor) ColorId shadowColor)
: StaticTextWidget(boss, font, x, y, font.getStringWidth(text), font.getLineHeight(), : StaticTextWidget(boss, font, x, y, font.getStringWidth(text), font.getLineHeight(),
text, align, shadowColor) text, align, shadowColor)
{ {
@ -356,7 +356,7 @@ void StaticTextWidget::drawWidget(bool hilite)
FBSurface& s = _boss->dialog().surface(); FBSurface& s = _boss->dialog().surface();
bool onTop = _boss->dialog().isOnTop(); bool onTop = _boss->dialog().isOnTop();
s.drawString(_font, _label, _x, _y, _w, s.drawString(_font, _label, _x, _y, _w,
isEnabled() && onTop ? _textcolor : uInt32(kColor), _align, 0, true, _shadowcolor); isEnabled() && onTop ? _textcolor : kColor, _align, 0, true, _shadowcolor);
setDirty(); setDirty();
} }
@ -646,8 +646,8 @@ void CheckboxWidget::drawWidget(bool hilite)
s.frameRect(_x, _y + _boxY, 14, 14, onTop && hilite && isEnabled() && isEditable() ? kWidColorHi : kColor); s.frameRect(_x, _y + _boxY, 14, 14, onTop && hilite && isEnabled() && isEditable() ? kWidColorHi : kColor);
// Do we draw a square or cross? // Do we draw a square or cross?
s.fillRect(_x + 1, _y + _boxY + 1, 12, 12, s.fillRect(_x + 1, _y + _boxY + 1, 12, 12,
_changed ? onTop ? uInt32(kDbgChangedColor) : uInt32(kDlgColor) : _changed ? onTop ? kDbgChangedColor : kDlgColor :
isEnabled() ? onTop ? _bgcolor : uInt32(kDlgColor) : uInt32(kColor)); isEnabled() ? onTop ? _bgcolor : kDlgColor : kColor);
if(_state) if(_state)
s.drawBitmap(_img, _x + 2, _y + _boxY + 2, onTop && isEnabled() ? hilite && isEditable() ? kWidColorHi : kCheckColor s.drawBitmap(_img, _x + 2, _y + _boxY + 2, onTop && isEnabled() ? hilite && isEditable() ? kWidColorHi : kCheckColor
: kColor, 10); : kColor, 10);
@ -868,7 +868,7 @@ void SliderWidget::drawWidget(bool hilite)
for(int i = 1; i < _numIntervals; ++i) for(int i = 1; i < _numIntervals; ++i)
{ {
int xt = x + (_w - _labelWidth - _valueLabelGap - _valueLabelWidth) * i / _numIntervals - 1; int xt = x + (_w - _labelWidth - _valueLabelGap - _valueLabelWidth) * i / _numIntervals - 1;
uInt32 color; ColorId color = kNone;
if(isEnabled()) if(isEnabled())
{ {

View File

@ -109,11 +109,11 @@ class Widget : public GuiObject
virtual const GUI::Font& font() const { return _font; } virtual const GUI::Font& font() const { return _font; }
void setTextColor(uInt32 color) { _textcolor = color; setDirty(); } void setTextColor(ColorId color) { _textcolor = color; setDirty(); }
void setTextColorHi(uInt32 color) { _textcolorhi = color; setDirty(); } void setTextColorHi(ColorId color) { _textcolorhi = color; setDirty(); }
void setBGColor(uInt32 color) { _bgcolor = color; setDirty(); } void setBGColor(ColorId color) { _bgcolor = color; setDirty(); }
void setBGColorHi(uInt32 color) { _bgcolorhi = color; setDirty(); } void setBGColorHi(ColorId color) { _bgcolorhi = color; setDirty(); }
void setShadowColor(uInt32 color) { _shadowcolor = color; setDirty(); } void setShadowColor(ColorId color) { _shadowcolor = color; setDirty(); }
virtual void loadConfig() { } virtual void loadConfig() { }
@ -140,13 +140,13 @@ class Widget : public GuiObject
bool _hasFocus; bool _hasFocus;
int _fontWidth; int _fontWidth;
int _fontHeight; int _fontHeight;
uInt32 _bgcolor; ColorId _bgcolor;
uInt32 _bgcolorhi; ColorId _bgcolorhi;
uInt32 _bgcolorlo; ColorId _bgcolorlo;
uInt32 _textcolor; ColorId _textcolor;
uInt32 _textcolorhi; ColorId _textcolorhi;
uInt32 _textcolorlo; ColorId _textcolorlo;
uInt32 _shadowcolor; ColorId _shadowcolor;
public: public:
static Widget* findWidgetInChain(Widget* start, int x, int y); static Widget* findWidgetInChain(Widget* start, int x, int y);
@ -183,11 +183,11 @@ class StaticTextWidget : public Widget
StaticTextWidget(GuiObject* boss, const GUI::Font& font, StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h, int x, int y, int w, int h,
const string& text = "", TextAlign align = TextAlign::Left, const string& text = "", TextAlign align = TextAlign::Left,
uInt32 shadowColor = 0); ColorId shadowColor = kNone);
StaticTextWidget(GuiObject* boss, const GUI::Font& font, StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int x, int y,
const string& text = "", TextAlign align = TextAlign::Left, const string& text = "", TextAlign align = TextAlign::Left,
uInt32 shadowColor = 0); ColorId shadowColor = kNone);
void setValue(int value); void setValue(int value);
void setLabel(const string& label); void setLabel(const string& label);
void setAlign(TextAlign align) { _align = align; setDirty(); } void setAlign(TextAlign align) { _align = align; setDirty(); }
@ -293,7 +293,7 @@ class CheckboxWidget : public ButtonWidget
bool _changed; bool _changed;
uInt32* _img; uInt32* _img;
uInt32 _fillColor; ColorId _fillColor;
int _boxY; int _boxY;
int _textY; int _textY;