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),
_cancelWidget(nullptr),
_visible(false),
_onTop(true),
_processCancel(false),
_title(title),
_th(0),
@ -331,25 +332,25 @@ void Dialog::drawDialog()
cerr << COUNT++ << " Dialog::drawDialog()\n";
// 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.top()->hasTitle());
if(_flags & WIDGET_CLEARBG)
{
// 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)
{
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),
onTop ? kColorTitleText : kColorTitleTextLo);
_onTop ? kColorTitleText : kColorTitleTextLo);
}
}
else
s.invalidate();
if(_flags & WIDGET_BORDER)
s.frameRect(_x, _y, _w, _h, onTop ? kColor : kShadowColor);
if(_flags & WIDGET_BORDER) // currently only used by Dialog itself
s.frameRect(_x, _y, _w, _h, _onTop ? kColor : kShadowColor);
// Make all child widget dirty
Widget* w = _firstWidget;

View File

@ -55,6 +55,7 @@ class Dialog : public GuiObject
void close();
bool isVisible() const override { return _visible; }
bool isOnTop() { return _onTop; }
virtual void center();
virtual void drawDialog();
@ -152,6 +153,7 @@ class Dialog : public GuiObject
Widget* _cancelWidget;
bool _visible;
bool _onTop;
bool _processCancel;
string _title;
int _th;

View File

@ -28,7 +28,7 @@ EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
_changed(false)
{
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
startEditMode(); // We're always in edit mode
}
@ -85,7 +85,10 @@ void EditTextWidget::drawWidget(bool hilite)
if(_changed)
s.fillRect(_x, _y, _w, _h, kDbgChangedColor);
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.
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;
_bgcolorhi = kWidColor;
_bgcolorlo = kDlgColor;
_textcolor = kTextColor;
_textcolorhi = kTextColor;

View File

@ -39,7 +39,8 @@ RomInfoWidget::RomInfoWidget(GuiObject* boss, const GUI::Font& font,
GUI::Size(320, TIAConstants::maxViewableHeight))
{
_flags = WIDGET_ENABLED;
_bgcolor = _bgcolorhi = kWidColor;
_bgcolor = kDlgColor;
_bgcolorlo = kBGColorLo;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -139,10 +140,11 @@ void RomInfoWidget::parseProperties()
void RomInfoWidget::drawWidget(bool hilite)
{
FBSurface& s = dialog().surface();
bool onTop = _boss->dialog().isOnTop();
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+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),
_hilite(hilite)
{
_bgcolorlo = kDlgColor;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -77,7 +78,10 @@ void StringListWidget::drawWidget(bool hilite)
textColor = kTextColorInv;
}
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());

View File

@ -262,6 +262,7 @@ void TabWidget::drawWidget(bool hilite)
Widget::setDirtyInChain(_tabs[_activeTab].firstWidget);
FBSurface& s = dialog().surface();
bool onTop = _boss->dialog().isOnTop();
// Iterate over all tabs and draw them
int i, x = _x + kTabLeftOffset;
@ -269,25 +270,27 @@ void TabWidget::drawWidget(bool hilite)
{
uInt32 fontcolor = _tabs[i].enabled ? kTextColor : kColor;
int yOffset = (i == _activeTab) ? 0 : 1;
s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1, (i == _activeTab)
? kDlgColor : kBGColorHi); // ? kWidColor : kDlgColor
s.fillRect(x, _y + 1, _tabWidth, _tabHeight - 1,
(i == _activeTab)
? onTop ? kDlgColor : kBGColorLo
: onTop ? kBGColorHi : kDlgColor); // ? kWidColor : kDlgColor
s.drawString(_font, _tabs[i].title, x + kTabPadding + yOffset,
_y + yOffset + (_tabHeight - _fontHeight - 1),
_tabWidth - 2 * kTabPadding, fontcolor, TextAlign::Center);
if(i == _activeTab)
{
s.hLine(x, _y, x + _tabWidth - 1, kWidColor);
s.vLine(x + _tabWidth, _y + 1, _y + _tabHeight - 1, kBGColorLo);
s.hLine(x, _y, x + _tabWidth - 1, onTop ? kWidColor : kDlgColor);
s.vLine(x + _tabWidth, _y + 1, _y + _tabHeight - 1, onTop ? kBGColorLo : kColor);
}
else
s.hLine(x, _y + _tabHeight, x + _tabWidth, kWidColor);
s.hLine(x, _y + _tabHeight, x + _tabWidth, onTop ? kWidColor : kDlgColor);
x += _tabWidth + kTabSpacing;
}
// fill empty right space
s.hLine(x - kTabSpacing + 1, _y + _tabHeight, _x + _w - 1, kWidColor);
s.hLine(_x, _y + _h - 1, _x + _w - 1, kBGColorLo);
s.hLine(x - kTabSpacing + 1, _y + _tabHeight, _x + _w - 1, onTop ? kWidColor : kDlgColor);
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),
_bgcolor(kWidColor),
_bgcolorhi(kWidColor),
_bgcolorlo(kBGColorLo),
_textcolor(kTextColor),
_textcolorhi(kTextColorHi),
_textcolorlo(kBGColorLo),
_shadowcolor(kShadowColor)
{
// Insert into the widget list of the boss
@ -77,7 +79,9 @@ void Widget::draw()
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;
// Account for our relative position in the dialog
@ -92,13 +96,13 @@ void Widget::draw()
{
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
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;
_y += 4;
_w -= 8;
@ -203,6 +207,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
FBSurface& s = boss->dialog().surface();
int size = int(arr.size()), pos = -1;
Widget* tmp;
bool onTop = boss->dialog().isOnTop();
for(int i = 0; i < size; ++i)
{
tmp = arr[i];
@ -226,7 +232,7 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
else
tmp->_hasFocus = false;
s.frameRect(x, y, w, h, kDlgColor);
s.frameRect(x, y, w, h, onTop ? kDlgColor : kBGColorLo);
tmp->setDirty();
}
@ -279,7 +285,8 @@ Widget* Widget::setFocusForChain(GuiObject* boss, WidgetArray& arr,
else
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();
@ -368,8 +375,10 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
_flags = WIDGET_ENABLED | WIDGET_CLEARBG;
_bgcolor = kBtnColor;
_bgcolorhi = kBtnColorHi;
_bgcolorlo = kColor;
_textcolor = kBtnTextColor;
_textcolorhi = kBtnTextColorHi;
_textcolorlo = kBGColorLo;
_editable = false;
}
@ -457,16 +466,17 @@ void ButtonWidget::setBitmap(uInt32* bitmap, int bmw, int bmh)
void ButtonWidget::drawWidget(bool hilite)
{
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)
s.drawString(_font, _label, _x, _y + (_h - _fontHeight)/2 + 1, _w,
!isEnabled() ? /*hilite ? uInt32(kColor) :*/ uInt32(kBGColorLo) :
!(isEnabled() && onTop) ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, _align);
else
s.drawBitmap(_bitmap, _x + (_w - _bmw) / 2, _y + (_h - _bmh) / 2,
!isEnabled() ? /*hilite ? uInt32(kColor) :*/ uInt32(kBGColorLo) :
!(isEnabled() && onTop) ? _textcolorlo :
hilite ? _textcolorhi : _textcolor,
_bmw, _bmh);

View File

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