improved dialog darkening when not on top

This commit is contained in:
thrust26 2018-08-06 08:10:01 +02:00
parent f2f952f09b
commit 7336e27111
9 changed files with 54 additions and 26 deletions

View File

@ -56,6 +56,7 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font
_okWidget(nullptr), _okWidget(nullptr),
_cancelWidget(nullptr), _cancelWidget(nullptr),
_visible(false), _visible(false),
_onTop(true),
_processCancel(false), _processCancel(false),
_title(title), _title(title),
_th(0), _th(0),
@ -331,25 +332,25 @@ void Dialog::drawDialog()
cerr << COUNT++ << " Dialog::drawDialog()\n"; cerr << COUNT++ << " Dialog::drawDialog()\n";
// Dialog is still on top if e.g a ContextMenu is opened // Dialog is still on top if e.g a ContextMenu is opened
bool onTop = parent().myDialogStack.top() == this _onTop = parent().myDialogStack.top() == this
|| (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this || (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this
&& !parent().myDialogStack.top()->hasTitle()); && !parent().myDialogStack.top()->hasTitle());
if(_flags & WIDGET_CLEARBG) if(_flags & WIDGET_CLEARBG)
{ {
// cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl; // cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl;
s.fillRect(_x, _y + _th, _w, _h - _th, onTop ? kDlgColor : kBGColorLo); s.fillRect(_x, _y + _th, _w, _h - _th, _onTop ? kDlgColor : kBGColorLo);
if(_th) if(_th)
{ {
s.fillRect(_x, _y, _w, _th, onTop ? kColorTitleBar : kColorTitleBarLo); s.fillRect(_x, _y, _w, _th, _onTop ? kColorTitleBar : kColorTitleBarLo);
s.drawString(_font, _title, _x + 10, _y + 2 + 1, _font.getStringWidth(_title), s.drawString(_font, _title, _x + 10, _y + 2 + 1, _font.getStringWidth(_title),
onTop ? kColorTitleText : kColorTitleTextLo); _onTop ? kColorTitleText : kColorTitleTextLo);
} }
} }
else else
s.invalidate(); s.invalidate();
if(_flags & WIDGET_BORDER) if(_flags & WIDGET_BORDER) // currently only used by Dialog itself
s.frameRect(_x, _y, _w, _h, onTop ? kColor : kShadowColor); s.frameRect(_x, _y, _w, _h, _onTop ? kColor : kShadowColor);
// Make all child widget dirty // Make all child widget dirty
Widget* w = _firstWidget; Widget* w = _firstWidget;

View File

@ -55,6 +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; }
virtual void center(); virtual void center();
virtual void drawDialog(); virtual void drawDialog();
@ -152,6 +153,7 @@ class Dialog : public GuiObject
Widget* _cancelWidget; Widget* _cancelWidget;
bool _visible; bool _visible;
bool _onTop;
bool _processCancel; bool _processCancel;
string _title; string _title;
int _th; int _th;

View File

@ -28,7 +28,7 @@ EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
_changed(false) _changed(false)
{ {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
startEditMode(); // We're always in edit mode startEditMode(); // We're always in edit mode
} }
@ -85,7 +85,10 @@ void EditTextWidget::drawWidget(bool hilite)
if(_changed) if(_changed)
s.fillRect(_x, _y, _w, _h, kDbgChangedColor); s.fillRect(_x, _y, _w, _h, kDbgChangedColor);
else if(!isEditable()) else if(!isEditable())
s.fillRect(_x, _y, _w, _h, kDlgColor); {
bool onTop = _boss->dialog().isOnTop();
s.fillRect(_x, _y, _w, _h, onTop ? kDlgColor : kBGColorLo);
}
// Draw a thin frame around us. // Draw a thin frame around us.
s.frameRect(_x, _y, _w, _h, hilite && isEditable() && isEnabled() ? kWidColorHi : kColor); s.frameRect(_x, _y, _w, _h, hilite && isEditable() && isEnabled() ? kWidColorHi : kColor);

View File

@ -39,6 +39,7 @@ EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
_bgcolor = kWidColor; _bgcolor = kWidColor;
_bgcolorhi = kWidColor; _bgcolorhi = kWidColor;
_bgcolorlo = kDlgColor;
_textcolor = kTextColor; _textcolor = kTextColor;
_textcolorhi = kTextColor; _textcolorhi = kTextColor;

View File

@ -39,7 +39,8 @@ RomInfoWidget::RomInfoWidget(GuiObject* boss, const GUI::Font& font,
GUI::Size(320, TIAConstants::maxViewableHeight)) GUI::Size(320, TIAConstants::maxViewableHeight))
{ {
_flags = WIDGET_ENABLED; _flags = WIDGET_ENABLED;
_bgcolor = _bgcolorhi = kWidColor; _bgcolor = kDlgColor;
_bgcolorlo = kBGColorLo;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -139,10 +140,11 @@ void RomInfoWidget::parseProperties()
void RomInfoWidget::drawWidget(bool hilite) void RomInfoWidget::drawWidget(bool hilite)
{ {
FBSurface& s = dialog().surface(); FBSurface& s = dialog().surface();
bool onTop = _boss->dialog().isOnTop();
const int yoff = myAvail.h + 10; const int yoff = myAvail.h + 10;
s.fillRect(_x+2, _y+2, _w-4, _h-4, kDlgColor); s.fillRect(_x+2, _y+2, _w-4, _h-4, onTop ? _bgcolor : _bgcolorlo);
s.frameRect(_x, _y, _w, _h, kColor); s.frameRect(_x, _y, _w, _h, kColor);
s.frameRect(_x, _y+yoff, _w, _h-yoff, kColor); s.frameRect(_x, _y+yoff, _w, _h-yoff, kColor);

View File

@ -29,6 +29,7 @@ StringListWidget::StringListWidget(GuiObject* boss, const GUI::Font& font,
boss->instance().settings().getInt("listdelay") >= 300), boss->instance().settings().getInt("listdelay") >= 300),
_hilite(hilite) _hilite(hilite)
{ {
_bgcolorlo = kDlgColor;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -77,7 +78,10 @@ void StringListWidget::drawWidget(bool hilite)
textColor = kTextColorInv; textColor = kTextColorInv;
} }
else else
s.frameRect(_x + 1, _y + 1 + _fontHeight * i, _w - 1, _fontHeight, kWidColorHi); {
bool onTop = _boss->dialog().isOnTop();
s.frameRect(_x + 1, _y + 1 + _fontHeight * i, _w - 1, _fontHeight, onTop ? kWidColorHi : kBGColorLo);
}
} }
GUI::Rect r(getEditRect()); GUI::Rect r(getEditRect());

View File

@ -262,6 +262,7 @@ void TabWidget::drawWidget(bool hilite)
Widget::setDirtyInChain(_tabs[_activeTab].firstWidget); Widget::setDirtyInChain(_tabs[_activeTab].firstWidget);
FBSurface& s = dialog().surface(); FBSurface& s = dialog().surface();
bool onTop = _boss->dialog().isOnTop();
// Iterate over all tabs and draw them // Iterate over all tabs and draw them
int i, x = _x + kTabLeftOffset; int i, x = _x + kTabLeftOffset;
@ -269,25 +270,27 @@ void TabWidget::drawWidget(bool hilite)
{ {
uInt32 fontcolor = _tabs[i].enabled ? kTextColor : kColor; uInt32 fontcolor = _tabs[i].enabled ? kTextColor : kColor;
int yOffset = (i == _activeTab) ? 0 : 1; int yOffset = (i == _activeTab) ? 0 : 1;
s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1, (i == _activeTab) s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1,
? kDlgColor : kBGColorHi); // ? kWidColor : kDlgColor (i == _activeTab)
? onTop ? kDlgColor : kBGColorLo
: onTop ? kBGColorHi : kDlgColor); // ? kWidColor : kDlgColor
s.drawString(_font, _tabs[i].title, x + kTabPadding + yOffset, s.drawString(_font, _tabs[i].title, x + kTabPadding + yOffset,
_y + yOffset + (_tabHeight - _fontHeight - 1), _y + yOffset + (_tabHeight - _fontHeight - 1),
_tabWidth - 2 * kTabPadding, fontcolor, TextAlign::Center); _tabWidth - 2 * kTabPadding, fontcolor, TextAlign::Center);
if(i == _activeTab) if(i == _activeTab)
{ {
s.hLine(x, _y, x + _tabWidth - 1, kWidColor); s.hLine(x, _y, x + _tabWidth - 1, onTop ? kWidColor : kDlgColor);
s.vLine(x + _tabWidth, _y + 1, _y + _tabHeight - 1, kBGColorLo); s.vLine(x + _tabWidth, _y + 1, _y + _tabHeight - 1, onTop ? kBGColorLo : kColor);
} }
else else
s.hLine(x, _y + _tabHeight, x + _tabWidth, kWidColor); s.hLine(x, _y + _tabHeight, x + _tabWidth, onTop ? kWidColor : kDlgColor);
x += _tabWidth + kTabSpacing; x += _tabWidth + kTabSpacing;
} }
// fill empty right space // fill empty right space
s.hLine(x - kTabSpacing + 1, _y + _tabHeight, _x + _w - 1, kWidColor); s.hLine(x - kTabSpacing + 1, _y + _tabHeight, _x + _w - 1, onTop ? kWidColor : kDlgColor);
s.hLine(_x, _y + _h - 1, _x + _w - 1, kBGColorLo); s.hLine(_x, _y + _h - 1, _x + _w - 1, onTop ? kBGColorLo : kColor);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -38,8 +38,10 @@ Widget::Widget(GuiObject* boss, const GUI::Font& font,
_hasFocus(false), _hasFocus(false),
_bgcolor(kWidColor), _bgcolor(kWidColor),
_bgcolorhi(kWidColor), _bgcolorhi(kWidColor),
_bgcolorlo(kBGColorLo),
_textcolor(kTextColor), _textcolor(kTextColor),
_textcolorhi(kTextColorHi), _textcolorhi(kTextColorHi),
_textcolorlo(kBGColorLo),
_shadowcolor(kShadowColor) _shadowcolor(kShadowColor)
{ {
// Insert into the widget list of the boss // Insert into the widget list of the boss
@ -77,7 +79,9 @@ void Widget::draw()
FBSurface& s = _boss->dialog().surface(); FBSurface& s = _boss->dialog().surface();
bool hasBorder = _flags & WIDGET_BORDER; bool onTop = _boss->dialog().isOnTop();
bool hasBorder = _flags & WIDGET_BORDER; // currently only used by Dialog widget
int oldX = _x, oldY = _y; int oldX = _x, oldY = _y;
// Account for our relative position in the dialog // Account for our relative position in the dialog
@ -92,13 +96,13 @@ void Widget::draw()
{ {
x++; y++; w-=2; h-=2; x++; y++; w-=2; h-=2;
} }
s.fillRect(x, y, w, h, (_flags & WIDGET_HILITED) && isEnabled() ? _bgcolorhi : _bgcolor); s.fillRect(x, y, w, h, !onTop ? _bgcolorlo : (_flags & WIDGET_HILITED) && isEnabled() ? _bgcolorhi : _bgcolor);
} }
// Draw border // Draw border
if(hasBorder) if(hasBorder)
{ {
s.frameRect(_x, _y, _w, _h, (_flags & WIDGET_HILITED) && isEnabled() ? kWidColorHi : kColor); s.frameRect(_x, _y, _w, _h, !onTop ? kColor : (_flags & WIDGET_HILITED) && isEnabled() ? kWidColorHi : kColor);
_x += 4; _x += 4;
_y += 4; _y += 4;
_w -= 8; _w -= 8;
@ -203,6 +207,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
FBSurface& s = boss->dialog().surface(); FBSurface& s = boss->dialog().surface();
int size = int(arr.size()), pos = -1; int size = int(arr.size()), pos = -1;
Widget* tmp; Widget* tmp;
bool onTop = boss->dialog().isOnTop();
for(int i = 0; i < size; ++i) for(int i = 0; i < size; ++i)
{ {
tmp = arr[i]; tmp = arr[i];
@ -226,7 +232,7 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
else else
tmp->_hasFocus = false; tmp->_hasFocus = false;
s.frameRect(x, y, w, h, kDlgColor); s.frameRect(x, y, w, h, onTop ? kDlgColor : kBGColorLo);
tmp->setDirty(); tmp->setDirty();
} }
@ -279,7 +285,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
else else
tmp->_hasFocus = true; tmp->_hasFocus = true;
s.frameRect(x, y, w, h, kWidFrameColor, FrameStyle::Dashed); if (onTop)
s.frameRect(x, y, w, h, kWidFrameColor, FrameStyle::Dashed);
tmp->setDirty(); tmp->setDirty();
@ -368,8 +375,10 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
_flags = WIDGET_ENABLED | WIDGET_CLEARBG; _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
_bgcolor = kBtnColor; _bgcolor = kBtnColor;
_bgcolorhi = kBtnColorHi; _bgcolorhi = kBtnColorHi;
_bgcolorlo = kColor;
_textcolor = kBtnTextColor; _textcolor = kBtnTextColor;
_textcolorhi = kBtnTextColorHi; _textcolorhi = kBtnTextColorHi;
_textcolorlo = kBGColorLo;
_editable = false; _editable = false;
} }
@ -457,16 +466,17 @@ void ButtonWidget::setBitmap(uInt32* bitmap, int bmw, int bmh)
void ButtonWidget::drawWidget(bool hilite) void ButtonWidget::drawWidget(bool hilite)
{ {
FBSurface& s = _boss->dialog().surface(); FBSurface& s = _boss->dialog().surface();
bool onTop = _boss->dialog().isOnTop();
s.frameRect(_x, _y, _w, _h, hilite && isEnabled() ? kBtnBorderColorHi : kBtnBorderColor); s.frameRect(_x, _y, _w, _h, !onTop ? kShadowColor : hilite && isEnabled() ? kBtnBorderColorHi : kBtnBorderColor);
if (!_useBitmap) if (!_useBitmap)
s.drawString(_font, _label, _x, _y + (_h - _fontHeight)/2 + 1, _w, s.drawString(_font, _label, _x, _y + (_h - _fontHeight)/2 + 1, _w,
!isEnabled() ? /*hilite ? uInt32(kColor) :*/ uInt32(kBGColorLo) : !(isEnabled() && onTop) ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, _align); hilite ? _textcolorhi : _textcolor, _align);
else else
s.drawBitmap(_bitmap, _x + (_w - _bmw) / 2, _y + (_h - _bmh) / 2, s.drawBitmap(_bitmap, _x + (_w - _bmw) / 2, _y + (_h - _bmh) / 2,
!isEnabled() ? /*hilite ? uInt32(kColor) :*/ uInt32(kBGColorLo) : !(isEnabled() && onTop) ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, hilite ? _textcolorhi : _textcolor,
_bmw, _bmh); _bmw, _bmh);

View File

@ -142,8 +142,10 @@ class Widget : public GuiObject
int _fontHeight; int _fontHeight;
uInt32 _bgcolor; uInt32 _bgcolor;
uInt32 _bgcolorhi; uInt32 _bgcolorhi;
uInt32 _bgcolorlo;
uInt32 _textcolor; uInt32 _textcolor;
uInt32 _textcolorhi; uInt32 _textcolorhi;
uInt32 _textcolorlo;
uInt32 _shadowcolor; uInt32 _shadowcolor;
public: public: