generic shadowed char/string drawing added

TimeMachineDialog fully transparent now (experimental)
info stats indicates scanline/frame rate changes in red
This commit is contained in:
thrust26 2018-01-16 11:14:26 +01:00 committed by Stephen Anthony
parent 72ff2a40fa
commit 6f7ff023a6
8 changed files with 60 additions and 37 deletions

View File

@ -154,8 +154,15 @@ void FBSurface::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawChar(const GUI::Font& font, uInt8 chr,
uInt32 tx, uInt32 ty, uInt32 color)
uInt32 tx, uInt32 ty, uInt32 color, uInt32 shadowColor)
{
if(shadowColor != 0)
{
drawChar(font, chr, tx + 1, ty + 0, shadowColor);
drawChar(font, chr, tx + 0, ty + 1, shadowColor);
drawChar(font, chr, tx + 1, ty + 1, shadowColor);
}
const FontDesc& desc = font.desc();
// If this character is not included in the font, use the default char.
@ -300,7 +307,7 @@ void FBSurface::frameRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
void FBSurface::drawString(const GUI::Font& font, const string& s,
int x, int y, int w,
uInt32 color, TextAlign align,
int deltax, bool useEllipsis)
int deltax, bool useEllipsis, uInt32 shadowColor)
{
const string ELLIPSIS = "\x1d"; // "..."
const int leftX = x, rightX = x + w;
@ -367,7 +374,7 @@ void FBSurface::drawString(const GUI::Font& font, const string& s,
if(x+w > rightX)
break;
if(x >= leftX)
drawChar(font, str[i], x, y, color);
drawChar(font, str[i], x, y, color, shadowColor);
x += w;
}

View File

@ -134,7 +134,7 @@ class FBSurface
@param color The color of the character
*/
virtual void drawChar(const GUI::Font& font, uInt8 c, uInt32 x, uInt32 y,
uInt32 color);
uInt32 color, uInt32 shadowColor = 0);
/**
This method should be called to draw the bitmap image.
@ -217,7 +217,7 @@ class FBSurface
virtual void drawString(
const GUI::Font& font, const string& s, int x, int y, int w,
uInt32 color, TextAlign align = TextAlign::Left,
int deltax = 0, bool useEllipsis = true);
int deltax = 0, bool useEllipsis = true, uInt32 shadowColor = 0);
/**
This method should be called to indicate that the surface has been

View File

@ -229,7 +229,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title,
// Create surfaces for TIA statistics and general messages
myStatsMsg.color = kColorInfo;
myStatsMsg.w = infoFont().getMaxCharWidth() * 24 + 2;
myStatsMsg.w = infoFont().getMaxCharWidth() * 30 + 2;
myStatsMsg.h = (infoFont().getFontHeight() + 2) * 2;
if(!myStatsMsg.surface)
@ -288,33 +288,32 @@ void FrameBuffer::update()
{
const ConsoleInfo& info = myOSystem.console().about();
char msg[30];
std::snprintf(msg, 30, "%3u @ %3.2ffps => %s",
myOSystem.console().tia().scanlinesLastFrame(),
myOSystem.console().getFramerate(), info.DisplayFormat.c_str());
uInt32 color;
myStatsMsg.surface->invalidate();
string bsinfo = info.BankSwitch +
(myOSystem.settings().getBool("dev.settings") ? "| Developer" : "| Player");
// draw shadowed text
myStatsMsg.surface->drawString(infoFont(), msg, 1 + 1, 1 + 0,
myStatsMsg.w, kBGColor);
myStatsMsg.surface->drawString(infoFont(), msg, 1 + 0, 1 + 1,
myStatsMsg.w, kBGColor);
myStatsMsg.surface->drawString(infoFont(), msg, 1 + 1, 1 + 1,
myStatsMsg.w, kBGColor);
color = myOSystem.console().tia().scanlinesLastFrame() != myLastScanlines ? kDbgColorRed : myStatsMsg.color;
std::snprintf(msg, 30, "%3u", myOSystem.console().tia().scanlinesLastFrame());
myStatsMsg.surface->drawString(infoFont(), msg, 1, 1,
myStatsMsg.w, myStatsMsg.color);
myStatsMsg.surface->drawString(infoFont(), bsinfo, 1 + 1, 15 + 0,
myStatsMsg.w, kBGColor);
myStatsMsg.surface->drawString(infoFont(), bsinfo, 1 + 0, 15 + 1,
myStatsMsg.w, kBGColor);
myStatsMsg.surface->drawString(infoFont(), bsinfo, 1 + 1, 15 + 1,
myStatsMsg.w, kBGColor);
myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor);
color = myOSystem.console().getFramerate() != myLastFrameRate ? kDbgColorRed : myStatsMsg.color;
std::snprintf(msg, 30, "@ %3.2ffps", myOSystem.console().getFramerate());
myStatsMsg.surface->drawString(infoFont(), msg, 1 + infoFont().getStringWidth("262 "), 1,
myStatsMsg.w, color, TextAlign::Left, 0, true, kBGColor);
std::snprintf(msg, 30, "=> %s", info.DisplayFormat.c_str());
myStatsMsg.surface->drawString(infoFont(), msg, 1+ infoFont().getStringWidth("262 @ 60.00fps "), 1,
myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor);
myStatsMsg.surface->drawString(infoFont(), bsinfo, 1, 15,
myStatsMsg.w, myStatsMsg.color);
myStatsMsg.w, myStatsMsg.color, TextAlign::Left, 0, true, kBGColor);
myStatsMsg.surface->setDirty();
myStatsMsg.surface->setDstPos(myImageRect.x() + 1, myImageRect.y() + 1);
myStatsMsg.surface->render();
}
myLastScanlines = myOSystem.console().tia().scanlinesLastFrame();
myLastFrameRate = myOSystem.console().getFramerate();
myPausedCount = 0;
break; // EventHandlerState::EMULATION
}

View File

@ -510,6 +510,9 @@ class FrameBuffer
Message myMsg;
Message myStatsMsg;
bool myStatsEnabled;
uInt32 myLastScanlines;
float myLastFrameRate;
bool myGrabMouse;

View File

@ -273,6 +273,8 @@ void Dialog::drawDialog()
if(_flags & WIDGET_CLEARBG)
// cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl;
s.fillRect(_x, _y, _w, _h, kDlgColor);
else
s.invalidate();
if(_flags & WIDGET_BORDER)
#ifndef FLAT_UI
s.box(_x, _y, _w, _h, kColor, kShadowColor);

View File

@ -193,23 +193,26 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
_w = 20 * (buttonWidth + BUTTON_GAP) + 20;
_h = V_BORDER * 2 + rowHeight + buttonHeight + 2;
//this->clearFlags(WIDGET_CLEARBG); // does only work combined with blending!
//this->clearFlags(WIDGET_BORDER);
this->clearFlags(WIDGET_CLEARBG); // does only work combined with blending (0..100)!
this->clearFlags(WIDGET_BORDER);
xpos = H_BORDER;
ypos = V_BORDER;
// Add index info
myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, " ");
myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, " ", TextAlign::Left, kBGColor);
myCurrentIdxWidget->setTextColor(kWidColor);
myLastIdxWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("8888"), ypos,
" ", TextAlign::Right);
" ", TextAlign::Right, kBGColor);
myLastIdxWidget->setTextColor(kWidColor);
ypos += rowHeight;
// Add time info
myCurrentTimeWidget = new StaticTextWidget(this, font, xpos, ypos + 3, "04:32 59");
//myCurrentTimeWidget->setFlags(WIDGET_CLEARBG);
myCurrentTimeWidget = new StaticTextWidget(this, font, xpos, ypos + 3, "04:32 59", TextAlign::Left, kBGColor);
myCurrentTimeWidget->setTextColor(kWidColor);
myLastTimeWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("XX:XX XX"), ypos + 3,
"12:25 59");
"12:25 59", TextAlign::Right, kBGColor);
myLastTimeWidget->setTextColor(kWidColor);
xpos = myCurrentTimeWidget->getRight() + BUTTON_GAP * 4;
// Add buttons
@ -253,7 +256,9 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
xpos = myUnwindAllWidget->getRight() + BUTTON_GAP * 3;
// Add message
myMessageWidget = new StaticTextWidget(this, font, xpos, ypos + 3, " ");
myMessageWidget = new StaticTextWidget(this, font, xpos, ypos + 3, " ",
TextAlign::Left, kBGColor);
myMessageWidget->setTextColor(kWidColor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -304,7 +304,8 @@ void Widget::setDirtyInChain(Widget* start)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const string& text, TextAlign align)
const string& text, TextAlign align,
uInt32 shadowColor)
: Widget(boss, font, x, y, w, h),
_align(align)
{
@ -313,6 +314,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
_bgcolorhi = kDlgColor;
_textcolor = kTextColor;
_textcolorhi = kTextColor;
_shadowcolor = shadowColor;
_label = text;
_editable = false;
@ -321,8 +323,9 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y,
const string& text, TextAlign align)
: StaticTextWidget(boss, font, x, y, font.getStringWidth(text), font.getLineHeight(), text, align)
const string& text, TextAlign align,
uInt32 shadowColor)
: StaticTextWidget(boss, font, x, y, font.getStringWidth(text), font.getLineHeight(), text, align, shadowColor)
{
}
@ -349,7 +352,7 @@ void StaticTextWidget::drawWidget(bool hilite)
{
FBSurface& s = _boss->dialog().surface();
s.drawString(_font, _label, _x, _y, _w,
isEnabled() ? _textcolor : uInt32(kColor), _align);
isEnabled() ? _textcolor : uInt32(kColor), _align, 0, true, _shadowcolor);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -111,6 +111,7 @@ class Widget : public GuiObject
void setTextColorHi(uInt32 color) { _textcolorhi = color; }
void setBGColor(uInt32 color) { _bgcolor = color; }
void setBGColorHi(uInt32 color) { _bgcolorhi = color; }
void setShadowColor(uInt32 color) { _shadowcolor = color; }
virtual void loadConfig() { }
@ -141,6 +142,7 @@ class Widget : public GuiObject
uInt32 _bgcolorhi;
uInt32 _textcolor;
uInt32 _textcolorhi;
uInt32 _shadowcolor;
public:
static Widget* findWidgetInChain(Widget* start, int x, int y);
@ -176,10 +178,12 @@ class StaticTextWidget : public Widget
public:
StaticTextWidget(GuiObject* boss, const GUI::Font& font,
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);
StaticTextWidget(GuiObject* boss, const GUI::Font& font,
int x, int y,
const string& text, TextAlign align = TextAlign::Left);
const string& text, TextAlign align = TextAlign::Left,
uInt32 shadowColor = 0);
void setValue(int value);
void setLabel(const string& label);
void setAlign(TextAlign align) { _align = align; }