move Widget flags into GuiObject

This commit is contained in:
thrust26 2020-11-11 08:56:11 +01:00
parent 76b6855284
commit 8e118b055d
9 changed files with 58 additions and 53 deletions

View File

@ -323,7 +323,7 @@ class FBSurface
This method should be called to reset the surface to empty
pixels / colour black.
*/
virtual void invalidate() = 0;
virtual void invalidate() {};
/**
This method should be called to reset a surface area to empty

View File

@ -49,9 +49,9 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font
const string& title, int x, int y, int w, int h)
: GuiObject(instance, parent, *this, x, y, w, h),
_font(font),
_title(title),
_flags(Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG)
_title(title)
{
_flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG;
setTitle(title);
}
@ -411,14 +411,14 @@ void Dialog::drawDialog()
|| (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this
&& !parent().myDialogStack.top()->hasTitle());
if(_flags & Widget::FLAG_CLEARBG)
if(clearsBackground())
{
// cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl;
if(_flags & Widget::FLAG_TRANSPARENT)
s.invalidateRect(_x, _y + _th, _w, _h - _th);
else
if(hasBackground())
s.fillRect(_x, _y + _th, _w, _h - _th, _onTop ? kDlgColor : kBGColorLo);
else
s.invalidateRect(_x, _y + _th, _w, _h - _th);
if(_th)
{
s.fillRect(_x, _y, _w, _th, _onTop ? kColorTitleBar : kColorTitleBarLo);
@ -431,7 +431,7 @@ void Dialog::drawDialog()
s.invalidate();
cerr << "invalidate " << typeid(*this).name() << endl;
}
if(_flags & Widget::FLAG_BORDER) // currently only used by Dialog itself
if(hasBorder()) // currently only used by Dialog itself
s.frameRect(_x, _y, _w, _h, _onTop ? kColor : kShadowColor);
// Make all child widgets dirty

View File

@ -90,10 +90,6 @@ class Dialog : public GuiObject
*/
void addSurface(const shared_ptr<FBSurface>& surface);
void setFlags(int flags) { _flags |= flags; setDirty(); }
void clearFlags(int flags) { _flags &= ~flags; setDirty(); }
int getFlags() const { return _flags; }
void setTitle(const string& title);
bool hasTitle() { return !_title.empty(); }
@ -235,8 +231,6 @@ class Dialog : public GuiObject
shared_ptr<FBSurface> _surface;
int _tabID{0};
int _flags{0};
//bool _dirty{false};
uInt32 _max_w{0}; // maximum wanted width
uInt32 _max_h{0}; // maximum wanted height

View File

@ -41,6 +41,20 @@ class GuiObject : public CommandReceiver
friend class Widget;
friend class DialogContainer;
public:
enum : uInt32 {
FLAG_ENABLED = 1 << 0,
FLAG_INVISIBLE = 1 << 1,
FLAG_HILITED = 1 << 2,
FLAG_BORDER = 1 << 3,
FLAG_CLEARBG = 1 << 4,
FLAG_TRACK_MOUSE = 1 << 5,
FLAG_RETAIN_FOCUS = 1 << 6,
FLAG_WANTS_TAB = 1 << 7,
FLAG_WANTS_RAWDATA = 1 << 8,
FLAG_NOBG = 1 << 9
};
public:
// The commands generated by various widgets
enum {
@ -83,6 +97,14 @@ class GuiObject : public CommandReceiver
virtual bool isChainDirty() const = 0;
virtual bool needsRedraw() const { return isDirty() || isChainDirty(); };
void setFlags(uInt32 flags) { _flags |= flags; setDirty(); }
void clearFlags(uInt32 flags) { _flags &= ~flags; setDirty(); }
uInt32 getFlags() const { return _flags; }
bool hasBorder() const { return _flags & FLAG_BORDER; }
bool clearsBackground() const { return _flags & FLAG_CLEARBG; }
bool hasBackground() const { return !(_flags & FLAG_NOBG); }
/** Add given widget(s) to the focus list */
virtual void addFocusWidget(Widget* w) = 0;
virtual void addToFocusList(WidgetArray& list) = 0;
@ -107,10 +129,11 @@ class GuiObject : public CommandReceiver
Dialog& myDialog;
protected:
int _x{0}, _y{0}, _w{0}, _h{0};
bool _dirty{false};
int _x{0}, _y{0}, _w{0}, _h{0};
bool _dirty{false};
uInt32 _flags{0};
Widget* _firstWidget{nullptr};
Widget* _firstWidget{nullptr};
WidgetArray _focusList;
private:

View File

@ -36,10 +36,9 @@ TimeLineWidget::TimeLineWidget(GuiObject* boss, const GUI::Font& font,
_labelWidth(labelWidth)
{
_flags = Widget::FLAG_ENABLED | Widget::FLAG_TRACK_MOUSE
| Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT;
| Widget::FLAG_CLEARBG | Widget::FLAG_NOBG;
_bgcolor = kDlgColor;
//_bgcolor = kBGColor;
_bgcolorhi = kDlgColor;
if(!_label.empty() && _labelWidth == 0)

View File

@ -218,6 +218,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
this->clearFlags(Widget::FLAG_CLEARBG); // does only work combined with blending (0..100)!
this->clearFlags(Widget::FLAG_BORDER);
this->setFlags(Widget::FLAG_NOBG);
xpos = H_BORDER;
ypos = V_BORDER;
@ -225,9 +226,10 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
// Add index info
myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, "1000", TextAlign::Left, kBGColor);
myCurrentIdxWidget->setTextColor(kColorInfo);
myCurrentIdxWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT);
myCurrentIdxWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
myLastIdxWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("1000"), ypos,
"1000", TextAlign::Right, kBGColor);
myLastIdxWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
myLastIdxWidget->setTextColor(kColorInfo);
// Add timeline
@ -242,10 +244,11 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
// Add time info
int ypos_s = ypos + (buttonHeight - font.getFontHeight() + 1) / 2; // align to button vertical center
myCurrentTimeWidget = new StaticTextWidget(this, font, xpos, ypos_s, "00:00.00", TextAlign::Left, kBGColor);
myCurrentTimeWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT);
myCurrentTimeWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
myCurrentTimeWidget->setTextColor(kColorInfo);
myLastTimeWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("00:00.00"), ypos_s,
"00:00.00", TextAlign::Right, kBGColor);
myLastTimeWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
myLastTimeWidget->setTextColor(kColorInfo);
xpos = myCurrentTimeWidget->getRight() + BUTTON_GAP * 4;
@ -289,7 +292,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
// Add message
myMessageWidget = new StaticTextWidget(this, font, xpos, ypos_s,
" ", TextAlign::Left, kBGColor);
myMessageWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT);
myMessageWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
myMessageWidget->setTextColor(kColorInfo);
}

View File

@ -106,8 +106,6 @@ void Widget::draw()
FBSurface& s = _boss->dialog().surface();
bool onTop = _boss->dialog().isOnTop();
bool hasBorder = _flags & Widget::FLAG_BORDER; // currently only used by Dialog widget
int oldX = _x, oldY = _y;
// Account for our relative position in the dialog
@ -115,23 +113,29 @@ void Widget::draw()
_y = getAbsY();
// Clear background (unless alpha blending is enabled)
if(_flags & Widget::FLAG_CLEARBG)
if(clearsBackground())
{
int x = _x, y = _y, w = _w, h = _h;
if(hasBorder)
if(hasBorder())
{
x++; y++; w -= 2; h -= 2;
}
if(isTransparent())
s.invalidateRect(x, y, w, h);
if(hasBackground())
s.fillRect(x, y, w, h, !onTop
? _bgcolorlo
: (_flags & Widget::FLAG_HILITED) && isEnabled()
? _bgcolorhi : _bgcolor);
else
s.fillRect(x, y, w, h, !onTop ? _bgcolorlo : (_flags & Widget::FLAG_HILITED) && isEnabled() ? _bgcolorhi : _bgcolor);
s.invalidateRect(x, y, w, h);
}
// Draw border
if(hasBorder)
if(hasBorder())
{
s.frameRect(_x, _y, _w, _h, !onTop ? kColor : (_flags & Widget::FLAG_HILITED) && isEnabled() ? kWidColorHi : kColor);
s.frameRect(_x, _y, _w, _h, !onTop
? kColor
: (_flags & Widget::FLAG_HILITED) && isEnabled()
? kWidColorHi : kColor);
_x += 4;
_y += 4;
_w -= 8;
@ -142,7 +146,7 @@ void Widget::draw()
drawWidget((_flags & Widget::FLAG_HILITED) ? true : false);
// Restore x/y
if(hasBorder)
if(hasBorder())
{
_x -= 4;
_y -= 4;
@ -350,6 +354,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
_align(align)
{
_flags = Widget::FLAG_ENABLED;
_bgcolor = kDlgColor;
_bgcolorhi = kDlgColor;
_textcolor = kTextColor;
@ -692,7 +697,7 @@ SliderWidget::SliderWidget(GuiObject* boss, const GUI::Font& font,
_valueLabelWidth(valueLabelWidth),
_forceLabelSign(forceLabelSign)
{
_flags = Widget::FLAG_ENABLED | Widget::FLAG_TRACK_MOUSE | Widget::FLAG_CLEARBG;;
_flags = Widget::FLAG_ENABLED | Widget::FLAG_TRACK_MOUSE | Widget::FLAG_CLEARBG;
_bgcolor = kDlgColor;
_bgcolorhi = kDlgColor;

View File

@ -42,20 +42,6 @@ class Widget : public GuiObject
{
friend class Dialog;
public:
enum : uInt32 {
FLAG_ENABLED = 1 << 0,
FLAG_INVISIBLE = 1 << 1,
FLAG_HILITED = 1 << 2,
FLAG_BORDER = 1 << 3,
FLAG_CLEARBG = 1 << 4,
FLAG_TRACK_MOUSE = 1 << 5,
FLAG_RETAIN_FOCUS = 1 << 6,
FLAG_WANTS_TAB = 1 << 7,
FLAG_WANTS_RAWDATA = 1 << 8,
FLAG_TRANSPARENT = 1 << 9
};
public:
Widget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h);
~Widget() override;
@ -97,16 +83,11 @@ class Widget : public GuiObject
/** Set/clear FLAG_ENABLED */
void setEnabled(bool e);
void setFlags(uInt32 flags) { _flags |= flags; setDirty(); }
void clearFlags(uInt32 flags) { _flags &= ~flags; setDirty(); }
uInt32 getFlags() const { return _flags; }
bool isEnabled() const { return _flags & FLAG_ENABLED; }
bool isVisible() const override { return !(_flags & FLAG_INVISIBLE); }
virtual bool wantsFocus() const { return _flags & FLAG_RETAIN_FOCUS; }
bool wantsTab() const { return _flags & FLAG_WANTS_TAB; }
bool wantsRaw() const { return _flags & FLAG_WANTS_RAWDATA; }
bool isTransparent() const { return _flags & FLAG_TRANSPARENT; }
void setID(uInt32 id) { _id = id; }
uInt32 getID() const { return _id; }
@ -140,7 +121,6 @@ class Widget : public GuiObject
const GUI::Font& _font;
Widget* _next{nullptr};
uInt32 _id{0};
uInt32 _flags{0};
bool _hasFocus{false};
int _fontWidth{0};
int _lineHeight{0};

View File

@ -51,6 +51,7 @@ class FBSurfaceLIBRETRO : public FBSurface
void translateCoords(Int32& x, Int32& y) const override { }
bool render() override { return true; }
void invalidate() override { }
void invalidateRect(uInt32, uInt32, uInt32, uInt32) override { }
void free() override { }
void reload() override { }
void resize(uInt32 width, uInt32 height) override { }