mirror of https://github.com/stella-emu/stella.git
move Widget flags into GuiObject
This commit is contained in:
parent
76b6855284
commit
8e118b055d
|
@ -323,7 +323,7 @@ class FBSurface
|
||||||
This method should be called to reset the surface to empty
|
This method should be called to reset the surface to empty
|
||||||
pixels / colour black.
|
pixels / colour black.
|
||||||
*/
|
*/
|
||||||
virtual void invalidate() = 0;
|
virtual void invalidate() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This method should be called to reset a surface area to empty
|
This method should be called to reset a surface area to empty
|
||||||
|
|
|
@ -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)
|
const string& title, int x, int y, int w, int h)
|
||||||
: GuiObject(instance, parent, *this, x, y, w, h),
|
: GuiObject(instance, parent, *this, x, y, w, h),
|
||||||
_font(font),
|
_font(font),
|
||||||
_title(title),
|
_title(title)
|
||||||
_flags(Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG)
|
|
||||||
{
|
{
|
||||||
|
_flags = Widget::FLAG_ENABLED | Widget::FLAG_BORDER | Widget::FLAG_CLEARBG;
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,14 +411,14 @@ void Dialog::drawDialog()
|
||||||
|| (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::FLAG_CLEARBG)
|
if(clearsBackground())
|
||||||
{
|
{
|
||||||
// cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl;
|
// cerr << "Dialog::drawDialog(): w = " << _w << ", h = " << _h << " @ " << &s << endl << endl;
|
||||||
|
|
||||||
if(_flags & Widget::FLAG_TRANSPARENT)
|
if(hasBackground())
|
||||||
s.invalidateRect(_x, _y + _th, _w, _h - _th);
|
|
||||||
else
|
|
||||||
s.fillRect(_x, _y + _th, _w, _h - _th, _onTop ? kDlgColor : kBGColorLo);
|
s.fillRect(_x, _y + _th, _w, _h - _th, _onTop ? kDlgColor : kBGColorLo);
|
||||||
|
else
|
||||||
|
s.invalidateRect(_x, _y + _th, _w, _h - _th);
|
||||||
if(_th)
|
if(_th)
|
||||||
{
|
{
|
||||||
s.fillRect(_x, _y, _w, _th, _onTop ? kColorTitleBar : kColorTitleBarLo);
|
s.fillRect(_x, _y, _w, _th, _onTop ? kColorTitleBar : kColorTitleBarLo);
|
||||||
|
@ -431,7 +431,7 @@ void Dialog::drawDialog()
|
||||||
s.invalidate();
|
s.invalidate();
|
||||||
cerr << "invalidate " << typeid(*this).name() << endl;
|
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);
|
s.frameRect(_x, _y, _w, _h, _onTop ? kColor : kShadowColor);
|
||||||
|
|
||||||
// Make all child widgets dirty
|
// Make all child widgets dirty
|
||||||
|
|
|
@ -90,10 +90,6 @@ class Dialog : public GuiObject
|
||||||
*/
|
*/
|
||||||
void addSurface(const shared_ptr<FBSurface>& surface);
|
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);
|
void setTitle(const string& title);
|
||||||
bool hasTitle() { return !_title.empty(); }
|
bool hasTitle() { return !_title.empty(); }
|
||||||
|
|
||||||
|
@ -235,8 +231,6 @@ class Dialog : public GuiObject
|
||||||
shared_ptr<FBSurface> _surface;
|
shared_ptr<FBSurface> _surface;
|
||||||
|
|
||||||
int _tabID{0};
|
int _tabID{0};
|
||||||
int _flags{0};
|
|
||||||
//bool _dirty{false};
|
|
||||||
uInt32 _max_w{0}; // maximum wanted width
|
uInt32 _max_w{0}; // maximum wanted width
|
||||||
uInt32 _max_h{0}; // maximum wanted height
|
uInt32 _max_h{0}; // maximum wanted height
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,20 @@ class GuiObject : public CommandReceiver
|
||||||
friend class Widget;
|
friend class Widget;
|
||||||
friend class DialogContainer;
|
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:
|
public:
|
||||||
// The commands generated by various widgets
|
// The commands generated by various widgets
|
||||||
enum {
|
enum {
|
||||||
|
@ -83,6 +97,14 @@ class GuiObject : public CommandReceiver
|
||||||
virtual bool isChainDirty() const = 0;
|
virtual bool isChainDirty() const = 0;
|
||||||
virtual bool needsRedraw() const { return isDirty() || isChainDirty(); };
|
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 */
|
/** Add given widget(s) to the focus list */
|
||||||
virtual void addFocusWidget(Widget* w) = 0;
|
virtual void addFocusWidget(Widget* w) = 0;
|
||||||
virtual void addToFocusList(WidgetArray& list) = 0;
|
virtual void addToFocusList(WidgetArray& list) = 0;
|
||||||
|
@ -109,6 +131,7 @@ class GuiObject : public CommandReceiver
|
||||||
protected:
|
protected:
|
||||||
int _x{0}, _y{0}, _w{0}, _h{0};
|
int _x{0}, _y{0}, _w{0}, _h{0};
|
||||||
bool _dirty{false};
|
bool _dirty{false};
|
||||||
|
uInt32 _flags{0};
|
||||||
|
|
||||||
Widget* _firstWidget{nullptr};
|
Widget* _firstWidget{nullptr};
|
||||||
WidgetArray _focusList;
|
WidgetArray _focusList;
|
||||||
|
|
|
@ -36,10 +36,9 @@ TimeLineWidget::TimeLineWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
_labelWidth(labelWidth)
|
_labelWidth(labelWidth)
|
||||||
{
|
{
|
||||||
_flags = Widget::FLAG_ENABLED | Widget::FLAG_TRACK_MOUSE
|
_flags = Widget::FLAG_ENABLED | Widget::FLAG_TRACK_MOUSE
|
||||||
| Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT;
|
| Widget::FLAG_CLEARBG | Widget::FLAG_NOBG;
|
||||||
|
|
||||||
_bgcolor = kDlgColor;
|
_bgcolor = kDlgColor;
|
||||||
//_bgcolor = kBGColor;
|
|
||||||
_bgcolorhi = kDlgColor;
|
_bgcolorhi = kDlgColor;
|
||||||
|
|
||||||
if(!_label.empty() && _labelWidth == 0)
|
if(!_label.empty() && _labelWidth == 0)
|
||||||
|
|
|
@ -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_CLEARBG); // does only work combined with blending (0..100)!
|
||||||
this->clearFlags(Widget::FLAG_BORDER);
|
this->clearFlags(Widget::FLAG_BORDER);
|
||||||
|
this->setFlags(Widget::FLAG_NOBG);
|
||||||
|
|
||||||
xpos = H_BORDER;
|
xpos = H_BORDER;
|
||||||
ypos = V_BORDER;
|
ypos = V_BORDER;
|
||||||
|
@ -225,9 +226,10 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
// Add index info
|
// Add index info
|
||||||
myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, "1000", TextAlign::Left, kBGColor);
|
myCurrentIdxWidget = new StaticTextWidget(this, font, xpos, ypos, "1000", TextAlign::Left, kBGColor);
|
||||||
myCurrentIdxWidget->setTextColor(kColorInfo);
|
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,
|
myLastIdxWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("1000"), ypos,
|
||||||
"1000", TextAlign::Right, kBGColor);
|
"1000", TextAlign::Right, kBGColor);
|
||||||
|
myLastIdxWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
|
||||||
myLastIdxWidget->setTextColor(kColorInfo);
|
myLastIdxWidget->setTextColor(kColorInfo);
|
||||||
|
|
||||||
// Add timeline
|
// Add timeline
|
||||||
|
@ -242,10 +244,11 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
// Add time info
|
// Add time info
|
||||||
int ypos_s = ypos + (buttonHeight - font.getFontHeight() + 1) / 2; // align to button vertical center
|
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 = 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);
|
myCurrentTimeWidget->setTextColor(kColorInfo);
|
||||||
myLastTimeWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("00:00.00"), ypos_s,
|
myLastTimeWidget = new StaticTextWidget(this, font, _w - H_BORDER - font.getStringWidth("00:00.00"), ypos_s,
|
||||||
"00:00.00", TextAlign::Right, kBGColor);
|
"00:00.00", TextAlign::Right, kBGColor);
|
||||||
|
myLastTimeWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
|
||||||
myLastTimeWidget->setTextColor(kColorInfo);
|
myLastTimeWidget->setTextColor(kColorInfo);
|
||||||
xpos = myCurrentTimeWidget->getRight() + BUTTON_GAP * 4;
|
xpos = myCurrentTimeWidget->getRight() + BUTTON_GAP * 4;
|
||||||
|
|
||||||
|
@ -289,7 +292,7 @@ TimeMachineDialog::TimeMachineDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
// Add message
|
// Add message
|
||||||
myMessageWidget = new StaticTextWidget(this, font, xpos, ypos_s,
|
myMessageWidget = new StaticTextWidget(this, font, xpos, ypos_s,
|
||||||
" ", TextAlign::Left, kBGColor);
|
" ", TextAlign::Left, kBGColor);
|
||||||
myMessageWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_TRANSPARENT);
|
myMessageWidget->setFlags(Widget::FLAG_CLEARBG | Widget::FLAG_NOBG);
|
||||||
myMessageWidget->setTextColor(kColorInfo);
|
myMessageWidget->setTextColor(kColorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,6 @@ void Widget::draw()
|
||||||
FBSurface& s = _boss->dialog().surface();
|
FBSurface& s = _boss->dialog().surface();
|
||||||
|
|
||||||
bool onTop = _boss->dialog().isOnTop();
|
bool onTop = _boss->dialog().isOnTop();
|
||||||
|
|
||||||
bool hasBorder = _flags & Widget::FLAG_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
|
||||||
|
@ -115,23 +113,29 @@ void Widget::draw()
|
||||||
_y = getAbsY();
|
_y = getAbsY();
|
||||||
|
|
||||||
// Clear background (unless alpha blending is enabled)
|
// Clear background (unless alpha blending is enabled)
|
||||||
if(_flags & Widget::FLAG_CLEARBG)
|
if(clearsBackground())
|
||||||
{
|
{
|
||||||
int x = _x, y = _y, w = _w, h = _h;
|
int x = _x, y = _y, w = _w, h = _h;
|
||||||
if(hasBorder)
|
if(hasBorder())
|
||||||
{
|
{
|
||||||
x++; y++; w -= 2; h -= 2;
|
x++; y++; w -= 2; h -= 2;
|
||||||
}
|
}
|
||||||
if(isTransparent())
|
if(hasBackground())
|
||||||
s.invalidateRect(x, y, w, h);
|
s.fillRect(x, y, w, h, !onTop
|
||||||
|
? _bgcolorlo
|
||||||
|
: (_flags & Widget::FLAG_HILITED) && isEnabled()
|
||||||
|
? _bgcolorhi : _bgcolor);
|
||||||
else
|
else
|
||||||
s.fillRect(x, y, w, h, !onTop ? _bgcolorlo : (_flags & Widget::FLAG_HILITED) && isEnabled() ? _bgcolorhi : _bgcolor);
|
s.invalidateRect(x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw border
|
// 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;
|
_x += 4;
|
||||||
_y += 4;
|
_y += 4;
|
||||||
_w -= 8;
|
_w -= 8;
|
||||||
|
@ -142,7 +146,7 @@ void Widget::draw()
|
||||||
drawWidget((_flags & Widget::FLAG_HILITED) ? true : false);
|
drawWidget((_flags & Widget::FLAG_HILITED) ? true : false);
|
||||||
|
|
||||||
// Restore x/y
|
// Restore x/y
|
||||||
if(hasBorder)
|
if(hasBorder())
|
||||||
{
|
{
|
||||||
_x -= 4;
|
_x -= 4;
|
||||||
_y -= 4;
|
_y -= 4;
|
||||||
|
@ -350,6 +354,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
_align(align)
|
_align(align)
|
||||||
{
|
{
|
||||||
_flags = Widget::FLAG_ENABLED;
|
_flags = Widget::FLAG_ENABLED;
|
||||||
|
|
||||||
_bgcolor = kDlgColor;
|
_bgcolor = kDlgColor;
|
||||||
_bgcolorhi = kDlgColor;
|
_bgcolorhi = kDlgColor;
|
||||||
_textcolor = kTextColor;
|
_textcolor = kTextColor;
|
||||||
|
@ -692,7 +697,7 @@ SliderWidget::SliderWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
_valueLabelWidth(valueLabelWidth),
|
_valueLabelWidth(valueLabelWidth),
|
||||||
_forceLabelSign(forceLabelSign)
|
_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;
|
_bgcolor = kDlgColor;
|
||||||
_bgcolorhi = kDlgColor;
|
_bgcolorhi = kDlgColor;
|
||||||
|
|
||||||
|
|
|
@ -42,20 +42,6 @@ class Widget : public GuiObject
|
||||||
{
|
{
|
||||||
friend class Dialog;
|
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:
|
public:
|
||||||
Widget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h);
|
Widget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h);
|
||||||
~Widget() override;
|
~Widget() override;
|
||||||
|
@ -97,16 +83,11 @@ class Widget : public GuiObject
|
||||||
/** Set/clear FLAG_ENABLED */
|
/** Set/clear FLAG_ENABLED */
|
||||||
void setEnabled(bool e);
|
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 isEnabled() const { return _flags & FLAG_ENABLED; }
|
||||||
bool isVisible() const override { return !(_flags & FLAG_INVISIBLE); }
|
bool isVisible() const override { return !(_flags & FLAG_INVISIBLE); }
|
||||||
virtual bool wantsFocus() const { return _flags & FLAG_RETAIN_FOCUS; }
|
virtual bool wantsFocus() const { return _flags & FLAG_RETAIN_FOCUS; }
|
||||||
bool wantsTab() const { return _flags & FLAG_WANTS_TAB; }
|
bool wantsTab() const { return _flags & FLAG_WANTS_TAB; }
|
||||||
bool wantsRaw() const { return _flags & FLAG_WANTS_RAWDATA; }
|
bool wantsRaw() const { return _flags & FLAG_WANTS_RAWDATA; }
|
||||||
bool isTransparent() const { return _flags & FLAG_TRANSPARENT; }
|
|
||||||
|
|
||||||
void setID(uInt32 id) { _id = id; }
|
void setID(uInt32 id) { _id = id; }
|
||||||
uInt32 getID() const { return _id; }
|
uInt32 getID() const { return _id; }
|
||||||
|
@ -140,7 +121,6 @@ class Widget : public GuiObject
|
||||||
const GUI::Font& _font;
|
const GUI::Font& _font;
|
||||||
Widget* _next{nullptr};
|
Widget* _next{nullptr};
|
||||||
uInt32 _id{0};
|
uInt32 _id{0};
|
||||||
uInt32 _flags{0};
|
|
||||||
bool _hasFocus{false};
|
bool _hasFocus{false};
|
||||||
int _fontWidth{0};
|
int _fontWidth{0};
|
||||||
int _lineHeight{0};
|
int _lineHeight{0};
|
||||||
|
|
|
@ -51,6 +51,7 @@ class FBSurfaceLIBRETRO : public FBSurface
|
||||||
void translateCoords(Int32& x, Int32& y) const override { }
|
void translateCoords(Int32& x, Int32& y) const override { }
|
||||||
bool render() override { return true; }
|
bool render() override { return true; }
|
||||||
void invalidate() override { }
|
void invalidate() override { }
|
||||||
|
void invalidateRect(uInt32, uInt32, uInt32, uInt32) override { }
|
||||||
void free() override { }
|
void free() override { }
|
||||||
void reload() override { }
|
void reload() override { }
|
||||||
void resize(uInt32 width, uInt32 height) override { }
|
void resize(uInt32 width, uInt32 height) override { }
|
||||||
|
|
Loading…
Reference in New Issue