aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/EditTextWidget.cpp8
-rw-r--r--gui/EditTextWidget.h2
-rw-r--r--gui/ListWidget.cpp10
-rw-r--r--gui/ListWidget.h2
-rw-r--r--gui/PopUpWidget.cpp10
-rw-r--r--gui/PopUpWidget.h2
-rw-r--r--gui/ScrollBarWidget.cpp7
-rw-r--r--gui/ScrollBarWidget.h2
-rw-r--r--gui/TabWidget.cpp4
-rw-r--r--gui/TabWidget.h2
-rw-r--r--gui/ThemeClassic.cpp26
-rw-r--r--gui/ThemeClassic.h28
-rw-r--r--gui/ThemeModern.cpp117
-rw-r--r--gui/ThemeModern.h28
-rw-r--r--gui/about.cpp2
-rw-r--r--gui/dialog.cpp3
-rw-r--r--gui/theme.cpp1
-rw-r--r--gui/theme.h36
-rw-r--r--gui/widget.cpp95
-rw-r--r--gui/widget.h28
20 files changed, 220 insertions, 193 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index 806b2a5a16..3b5afab669 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -31,7 +31,7 @@ namespace GUI {
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text)
: EditableWidget(boss, x, y - 1, w, h + 2) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
_type = kEditTextWidget;
setEditString(text);
@@ -39,7 +39,7 @@ EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, cons
EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String &text)
: EditableWidget(boss, name) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
_type = kEditTextWidget;
_hints |= THEME_HINT_USE_SHADOW;
@@ -81,12 +81,12 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
}
-void EditTextWidget::drawWidget(bool hilite) {
+void EditTextWidget::drawWidget() {
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), _hints, Theme::kWidgetBackgroundEditText);
// Draw the text
adjustOffset();
- g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, Theme::kStateEnabled, Theme::kTextAlignLeft, false, -_editScrollOffset, false, _font);
+ g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, _state, Theme::kTextAlignLeft, false, -_editScrollOffset, false, _font);
}
Common::Rect EditTextWidget::getEditRect() const {
diff --git a/gui/EditTextWidget.h b/gui/EditTextWidget.h
index 7fabb52d8d..661ba28e1b 100644
--- a/gui/EditTextWidget.h
+++ b/gui/EditTextWidget.h
@@ -53,7 +53,7 @@ public:
virtual void reflowLayout();
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
void receivedFocusWidget();
void lostFocusWidget();
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 52d90fd6b2..539a2efa78 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -44,7 +44,7 @@ ListWidget::ListWidget(GuiObject *boss, const String &name)
_scrollBar = new ScrollBarWidget(this, _w - _scrollBarWidth, 0, _scrollBarWidth, _h);
_scrollBar->setTarget(this);
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
setHints(THEME_HINT_SAVE_BACKGROUND | THEME_HINT_USE_SHADOW);
_type = kListWidget;
_editMode = false;
@@ -326,7 +326,7 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
}
}
-void ListWidget::drawWidget(bool hilite) {
+void ListWidget::drawWidget() {
int i, pos, len = _list.size();
Common::String buffer;
@@ -355,7 +355,7 @@ void ListWidget::drawWidget(bool hilite) {
char temp[10];
sprintf(temp, "%2d. ", (pos + _numberingMode));
buffer = temp;
- g_gui.theme()->drawText(Common::Rect(_x, y, _x + r.left + _leftPadding, y + fontHeight - 2), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, _leftPadding);
+ g_gui.theme()->drawText(Common::Rect(_x, y, _x + r.left + _leftPadding, y + fontHeight - 2), buffer, _state, Theme::kTextAlignLeft, inverted, _leftPadding);
pad = 0;
}
@@ -365,7 +365,7 @@ void ListWidget::drawWidget(bool hilite) {
buffer = _editString;
adjustOffset();
width = _w - r.left - _hlRightPadding - _leftPadding;
- g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight-2), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, pad);
+ g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight-2), buffer, _state, Theme::kTextAlignLeft, inverted, pad);
} else {
int maxWidth = _textWidth[i];
buffer = _list[pos];
@@ -377,7 +377,7 @@ void ListWidget::drawWidget(bool hilite) {
width = _w - r.left - _hlRightPadding;
if (width > maxWidth)
maxWidth = width;
- g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + maxWidth, y + fontHeight-2), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, pad);
+ g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + maxWidth, y + fontHeight-2), buffer, _state, Theme::kTextAlignLeft, inverted, pad);
}
_textWidth[i] = width;
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index 50d16f494f..7c35d9b9fe 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -106,7 +106,7 @@ public:
void endEditMode();
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
//! Finds the item at position (x,y). Returns -1 if there is no item there.
int findItem(int x, int y) const;
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index 6df54343b6..91b7c40687 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -357,7 +357,7 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const String &label, uint labelWidth)
: Widget(boss, name), CommandSender(boss), _label(label), _labelWidth(labelWidth) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS);
setHints(THEME_HINT_SAVE_BACKGROUND);
_type = kPopUpWidget;
@@ -368,7 +368,6 @@ PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const String &labe
}
void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {
-
if (isEnabled()) {
PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY());
int newSel = popupDialog.runModal();
@@ -420,19 +419,18 @@ void PopUpWidget::setSelectedTag(uint32 tag) {
}
}
-void PopUpWidget::drawWidget(bool hilite) {
+void PopUpWidget::drawWidget() {
int x = _x + _labelWidth + _labelSpacing;
int w = _w - _labelWidth - _labelSpacing;
// Draw the label, if any
if (_labelWidth > 0)
- g_gui.theme()->drawText(Common::Rect(_x+2,_y+3,_x+2+_labelWidth, _y+3+g_gui.theme()->getFontHeight()), _label,
- isEnabled() ? Theme::kStateEnabled : Theme::kStateDisabled, Theme::kTextAlignRight);
+ g_gui.theme()->drawText(Common::Rect(_x+2,_y+3,_x+2+_labelWidth, _y+3+g_gui.theme()->getFontHeight()), _label, _state, Theme::kTextAlignRight);
Common::String sel;
if (_selectedItem >= 0)
sel = _entries[_selectedItem].name;
- g_gui.theme()->drawPopUpWidget(Common::Rect(x, _y, x+w, _y+_h), sel, _leftPadding, isEnabled() ? (hilite ? Theme::kStateHighlight : Theme::kStateEnabled) : Theme::kStateDisabled, g_gui.theme()->convertAligment(kTextAlignLeft));
+ g_gui.theme()->drawPopUpWidget(Common::Rect(x, _y, x+w, _y+_h), sel, _leftPadding, _state, g_gui.theme()->convertAligment(kTextAlignLeft));
}
} // End of namespace GUI
diff --git a/gui/PopUpWidget.h b/gui/PopUpWidget.h
index 89801fc8d3..8a7a8e867d 100644
--- a/gui/PopUpWidget.h
+++ b/gui/PopUpWidget.h
@@ -87,7 +87,7 @@ public:
virtual void reflowLayout();
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
};
} // End of namespace GUI
diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp
index 42e031e515..52af9c97b5 100644
--- a/gui/ScrollBarWidget.cpp
+++ b/gui/ScrollBarWidget.cpp
@@ -32,7 +32,7 @@ namespace GUI {
ScrollBarWidget::ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h)
: Widget (boss, x, y, w, h), CommandSender(boss) {
- _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG | WIDGET_WANT_TICKLE;
+ setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG | WIDGET_WANT_TICKLE);
_type = kScrollBarWidget;
_part = kNoPart;
@@ -183,7 +183,7 @@ void ScrollBarWidget::recalc() {
}
}
-void ScrollBarWidget::drawWidget(bool hilite) {
+void ScrollBarWidget::drawWidget() {
if (_draggingPart != kNoPart)
_part = _draggingPart;
@@ -198,8 +198,7 @@ void ScrollBarWidget::drawWidget(bool hilite) {
state = Theme::kScrollbarStateSlider;
}
- g_gui.theme()->drawScrollbar(Common::Rect(_x, _y, _x+_w, _y+_h), _sliderPos, _sliderHeight, state,
- isEnabled() ? (hilite ? Theme::kStateHighlight : Theme::kStateEnabled) : Theme::kStateDisabled);
+ g_gui.theme()->drawScrollbar(Common::Rect(_x, _y, _x+_w, _y+_h), _sliderPos, _sliderHeight, state, _state);
}
} // End of namespace GUI
diff --git a/gui/ScrollBarWidget.h b/gui/ScrollBarWidget.h
index e926f1d424..5352bdcf73 100644
--- a/gui/ScrollBarWidget.h
+++ b/gui/ScrollBarWidget.h
@@ -80,7 +80,7 @@ public:
void recalc();
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
void checkBounds(int old_pos);
};
diff --git a/gui/TabWidget.cpp b/gui/TabWidget.cpp
index d539dc3805..7b4547a446 100644
--- a/gui/TabWidget.cpp
+++ b/gui/TabWidget.cpp
@@ -50,7 +50,7 @@ void TabWidget::init() {
_tabSpacing = g_gui.theme()->getTabSpacing();
_tabPadding = g_gui.theme()->getTabPadding();
- _flags = WIDGET_ENABLED;
+ setFlags(WIDGET_ENABLED);
_type = kTabWidget;
_activeTab = -1;
_firstVisibleTab = 0;
@@ -248,7 +248,7 @@ void TabWidget::reflowLayout() {
_tabPadding = g_gui.theme()->getTabPadding();
}
-void TabWidget::drawWidget(bool hilite) {
+void TabWidget::drawWidget() {
Common::Array<Common::String> tabs;
for (int i = _firstVisibleTab; i < (int)_tabs.size(); ++i) {
tabs.push_back(_tabs[i].title);
diff --git a/gui/TabWidget.h b/gui/TabWidget.h
index a8c5e07525..bf316a7ac3 100644
--- a/gui/TabWidget.h
+++ b/gui/TabWidget.h
@@ -99,7 +99,7 @@ protected:
// Essentially this compensates for the space taken up by the tab title header.
virtual int16 getChildY() const;
- virtual void drawWidget(bool hilite);
+ virtual void drawWidget();
virtual Widget *findWidget(int x, int y);
};
diff --git a/gui/ThemeClassic.cpp b/gui/ThemeClassic.cpp
index 812b8de408..b178b4b8df 100644
--- a/gui/ThemeClassic.cpp
+++ b/gui/ThemeClassic.cpp
@@ -170,7 +170,7 @@ int ThemeClassic::getTabPadding() const {
return 3;
}
-void ThemeClassic::drawDialogBackground(const Common::Rect &r, uint16 hints, State state) {
+void ThemeClassic::drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -187,7 +187,7 @@ void ThemeClassic::drawDialogBackground(const Common::Rect &r, uint16 hints, Sta
addDirtyRect(r, (hints & THEME_HINT_SAVE_BACKGROUND) != 0);
}
-void ThemeClassic::drawText(const Common::Rect &r, const Common::String &str, State state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
+void ThemeClassic::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
if (!_initOk)
return;
@@ -202,7 +202,7 @@ void ThemeClassic::drawText(const Common::Rect &r, const Common::String &str, St
addDirtyRect(r);
}
-void ThemeClassic::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, State state) {
+void ThemeClassic::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state) {
if (!_initOk)
return;
restoreBackground(r);
@@ -210,7 +210,7 @@ void ThemeClassic::drawChar(const Common::Rect &r, byte ch, const Graphics::Font
addDirtyRect(r);
}
-void ThemeClassic::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, State state) {
+void ThemeClassic::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state) {
if (!_initOk || background == kWidgetBackgroundNo)
return;
@@ -238,7 +238,7 @@ void ThemeClassic::drawWidgetBackground(const Common::Rect &r, uint16 hints, Wid
addDirtyRect(r, (hints & THEME_HINT_SAVE_BACKGROUND) != 0);
}
-void ThemeClassic::drawButton(const Common::Rect &r, const Common::String &str, State state, uint16 hints) {
+void ThemeClassic::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
if (!_initOk)
return;
restoreBackground(r);
@@ -251,7 +251,7 @@ void ThemeClassic::drawButton(const Common::Rect &r, const Common::String &str,
addDirtyRect(r);
}
-void ThemeClassic::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, State state, int alpha, bool themeTrans) {
+void ThemeClassic::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
if (!_initOk)
return;
@@ -278,7 +278,7 @@ void ThemeClassic::drawSurface(const Common::Rect &r, const Graphics::Surface &s
addDirtyRect(r);
}
-void ThemeClassic::drawSlider(const Common::Rect &r, int width, State state) {
+void ThemeClassic::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
if (!_initOk)
return;
Common::Rect r2 = r;
@@ -299,7 +299,7 @@ void ThemeClassic::drawSlider(const Common::Rect &r, int width, State state) {
addDirtyRect(r);
}
-void ThemeClassic::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, State state, TextAlign align) {
+void ThemeClassic::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align) {
if (!_initOk)
return;
@@ -329,7 +329,7 @@ void ThemeClassic::drawPopUpWidget(const Common::Rect &r, const Common::String &
addDirtyRect(r);
}
-void ThemeClassic::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, State state) {
+void ThemeClassic::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -373,7 +373,7 @@ void ThemeClassic::drawCheckbox(const Common::Rect &r, const Common::String &str
addDirtyRect(r);
}
-void ThemeClassic::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, State state) {
+void ThemeClassic::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) {
if (!_initOk)
return;
restoreBackground(r);
@@ -399,7 +399,7 @@ void ThemeClassic::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, c
addDirtyRect(r);
}
-void ThemeClassic::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scroll, State state) {
+void ThemeClassic::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scroll, WidgetStateInfo state) {
if (!_initOk)
return;
restoreBackground(r);
@@ -462,7 +462,7 @@ void ThemeClassic::drawScrollbar(const Common::Rect &r, int sliderY, int sliderH
addDirtyRect(r);
}
-void ThemeClassic::drawCaret(const Common::Rect &r, bool erase, State state) {
+void ThemeClassic::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -477,7 +477,7 @@ void ThemeClassic::drawCaret(const Common::Rect &r, bool erase, State state) {
addDirtyRect(r);
}
-void ThemeClassic::drawLineSeparator(const Common::Rect &r, State state) {
+void ThemeClassic::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
if (!_initOk)
return;
_screen.hLine(r.left - 1, r.top + r.height() / 2, r.right, _shadowcolor);
diff --git a/gui/ThemeClassic.h b/gui/ThemeClassic.h
index 966f45ba8a..0450da5aee 100644
--- a/gui/ThemeClassic.h
+++ b/gui/ThemeClassic.h
@@ -58,20 +58,20 @@ public:
int getStringWidth(const Common::String &str, FontStyle font) const { if (_initOk) return _font->getStringWidth(str); return 0; }
int getCharWidth(byte c, FontStyle font) const { if (_initOk) return _font->getCharWidth(c); return 0; }
- void drawDialogBackground(const Common::Rect &r, uint16 hints, State state);
- void drawText(const Common::Rect &r, const Common::String &str, State state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font);
- void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, State state);
-
- void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, State state);
- void drawButton(const Common::Rect &r, const Common::String &str, State state, uint16 hints);
- void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, State state, int alpha, bool themeTrans);
- void drawSlider(const Common::Rect &r, int width, State state);
- void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, State state);
- void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, State state);
- void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, State state);
- void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, State state, TextAlign align);
- void drawCaret(const Common::Rect &r, bool erase, State state);
- void drawLineSeparator(const Common::Rect &r, State state);
+ void drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state);
+ void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font);
+ void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state);
+
+ void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state);
+ void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints);
+ void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans);
+ void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state);
+ void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state);
+ void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state);
+ void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state);
+ void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align);
+ void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state);
+ void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state);
void restoreBackground(Common::Rect r, bool special = false);
bool addDirtyRect(Common::Rect r, bool save = false, bool special = false);
diff --git a/gui/ThemeModern.cpp b/gui/ThemeModern.cpp
index 38db2ede4a..99244b85f5 100644
--- a/gui/ThemeModern.cpp
+++ b/gui/ThemeModern.cpp
@@ -50,8 +50,10 @@ extern int gBitFormat;
namespace GUI {
+// TODO: This should be moved to ThemeModern
OverlayColor getColorAlpha(OverlayColor col1, OverlayColor col2, int alpha);
OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max, uint factor);
+void getStateColor(OverlayColor &s, OverlayColor &e, OverlayColor enabledS, OverlayColor enabledE, OverlayColor highlightS, OverlayColor highlightE, Theme::WidgetStateInfo state);
#pragma mark -
@@ -251,7 +253,7 @@ void ThemeModern::resetDrawArea() {
#define surface(x) (_images[x])
-void ThemeModern::drawDialogBackground(const Common::Rect &r, uint16 hints, State state) {
+void ThemeModern::drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -285,7 +287,7 @@ void ThemeModern::drawDialogBackground(const Common::Rect &r, uint16 hints, Stat
addDirtyRect(r2, (hints & THEME_HINT_SAVE_BACKGROUND) != 0, true);
}
-void ThemeModern::drawText(const Common::Rect &r, const Common::String &str, State state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
+void ThemeModern::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
if (!_initOk)
return;
@@ -304,7 +306,7 @@ void ThemeModern::drawText(const Common::Rect &r, const Common::String &str, Sta
addDirtyRect(r);
}
-void ThemeModern::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, State state) {
+void ThemeModern::drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state) {
if (!_initOk)
return;
restoreBackground(r);
@@ -312,7 +314,7 @@ void ThemeModern::drawChar(const Common::Rect &r, byte ch, const Graphics::Font
addDirtyRect(r);
}
-void ThemeModern::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, State state) {
+void ThemeModern::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -389,7 +391,7 @@ void ThemeModern::drawWidgetBackground(const Common::Rect &r, uint16 hints, Widg
addDirtyRect((hints & THEME_HINT_USE_SHADOW) ? r2 : r, (hints & THEME_HINT_SAVE_BACKGROUND) != 0);
}
-void ThemeModern::drawButton(const Common::Rect &r, const Common::String &str, State state, uint16 hints) {
+void ThemeModern::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
if (!_initOk)
return;
@@ -401,15 +403,17 @@ void ThemeModern::drawButton(const Common::Rect &r, const Common::String &str, S
// shadow
drawShadow(r, surface(kButtonBkgdCorner), surface(kButtonBkgdTop), surface(kButtonBkgdLeft), surface(kButtonBkgd), kShadowButton);
- if (state == kStateHighlight) {
- drawRectMasked(r, surface(kButtonBkgdCorner), surface(kButtonBkgdTop), surface(kButtonBkgdLeft), surface(kButtonBkgd),
- 256, _colors[kButtonBackgroundHighlightStart], _colors[kButtonBackgroundHighlightEnd],
- _gradientFactors[kButtonFactor]);
- } else {
- drawRectMasked(r, surface(kButtonBkgdCorner), surface(kButtonBkgdTop), surface(kButtonBkgdLeft), surface(kButtonBkgd),
- (state == kStateDisabled) ? -30 : 256, _colors[kButtonBackgroundStart], _colors[kButtonBackgroundEnd],
- _gradientFactors[kButtonFactor]);
- }
+ OverlayColor start, end;
+ int alpha = 256;
+
+ getStateColor(start, end, _colors[kButtonBackgroundStart], _colors[kButtonBackgroundEnd],
+ _colors[kButtonBackgroundHighlightStart], _colors[kButtonBackgroundHighlightEnd], state);
+
+ if (state != kStateHighlight)
+ alpha = (state == kStateDisabled) ? -30 : 256;
+
+ drawRectMasked(r, surface(kButtonBkgdCorner), surface(kButtonBkgdTop), surface(kButtonBkgdLeft), surface(kButtonBkgd),
+ alpha, start, end, _gradientFactors[kButtonFactor]);
const int off = (r.height() - getFontHeight()) / 2;
@@ -433,7 +437,7 @@ void ThemeModern::drawButton(const Common::Rect &r, const Common::String &str, S
addDirtyRect(r2);
}
-void ThemeModern::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, State state, int alpha, bool themeTrans) {
+void ThemeModern::drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
if (!_initOk)
return;
@@ -476,7 +480,7 @@ void ThemeModern::drawSurface(const Common::Rect &r, const Graphics::Surface &su
addDirtyRect(rect);
}
-void ThemeModern::drawSlider(const Common::Rect &rr, int width, State state) {
+void ThemeModern::drawSlider(const Common::Rect &rr, int width, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -497,18 +501,22 @@ void ThemeModern::drawSlider(const Common::Rect &rr, int width, State state) {
}
drawShadow(r2, surface(kButtonBkgdCorner), surface(kButtonBkgdTop), surface(kButtonBkgdLeft), surface(kButtonBkgd), kShadowButton);
- if (state == kStateHighlight) {
- drawRectMasked(r2, surface(kSliderCorner), surface(kSliderTop), surface(kSliderLeft), surface(kSliderBkgd),
- 256, _colors[kSliderHighStart], _colors[kSliderHighEnd], _gradientFactors[kSliderFactor]);
- } else {
- drawRectMasked(r2, surface(kSliderCorner), surface(kSliderTop), surface(kSliderLeft), surface(kSliderBkgd),
- (state == kStateDisabled) ? -30 : 256, _colors[kSliderStart], _colors[kSliderEnd], _gradientFactors[kSliderFactor]);
- }
+
+ OverlayColor start, end;
+ int alpha = 256;
+
+ getStateColor(start, end, _colors[kSliderStart], _colors[kSliderEnd], _colors[kSliderHighStart], _colors[kSliderHighEnd], state);
+
+ if (state != kStateHighlight)
+ alpha = (state == kStateDisabled) ? -30 : 256;
+
+ drawRectMasked(r2, surface(kSliderCorner), surface(kSliderTop), surface(kSliderLeft), surface(kSliderBkgd),
+ alpha, start, end, _gradientFactors[kSliderFactor]);
addDirtyRect(r);
}
-void ThemeModern::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, State state, TextAlign align) {
+void ThemeModern::drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align) {
if (!_initOk)
return;
@@ -550,7 +558,7 @@ void ThemeModern::drawPopUpWidget(const Common::Rect &r, const Common::String &s
addDirtyRect(r2);
}
-void ThemeModern::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, State state) {
+void ThemeModern::drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state) {
if (!_initOk)
return;
Common::Rect r2 = r;
@@ -568,7 +576,7 @@ void ThemeModern::drawCheckbox(const Common::Rect &r, const Common::String &str,
addDirtyRect(r);
}
-void ThemeModern::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, State state) {
+void ThemeModern::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -632,7 +640,7 @@ void ThemeModern::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, co
addDirtyRect(Common::Rect(r.left, r.top-2, r.right, r.bottom));
}
-void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState, State state) {
+void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState, WidgetStateInfo state) {
if (!_initOk)
return;
const int UP_DOWN_BOX_HEIGHT = r.width() + 1;
@@ -643,16 +651,11 @@ void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHe
_colors[kScrollbarBackgroundStart], _colors[kScrollbarBackgroundEnd], _gradientFactors[kScrollbarBkgdFactor]);
// draws the 'up' button
- OverlayColor buttonStart = 0;
- OverlayColor buttonEnd = 0;
+ OverlayColor buttonStart = _colors[kScrollbarButtonStart];
+ OverlayColor buttonEnd = _colors[kScrollbarButtonEnd];
- if (scrollState == kScrollbarStateUp) {
- buttonStart = _colors[kScrollbarButtonHighlightStart];
- buttonEnd = _colors[kScrollbarButtonHighlightEnd];
- } else {
- buttonStart = _colors[kScrollbarButtonStart];
- buttonEnd = _colors[kScrollbarButtonEnd];
- }
+ if (scrollState == kScrollbarStateUp)
+ getStateColor(buttonStart, buttonEnd, buttonStart, buttonEnd, _colors[kScrollbarButtonHighlightStart], _colors[kScrollbarButtonHighlightEnd], state);
r2.bottom = r2.top + UP_DOWN_BOX_HEIGHT;
drawRectMasked(r2, surface(kScrollbarBkgdCorner), surface(kScrollbarBkgdTop), surface(kScrollbarBkgdLeft), surface(kScrollbarBkgd), 256,
@@ -666,16 +669,11 @@ void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHe
drawSurface(r2, arrow, false, false, 256);
// draws the slider
- OverlayColor sliderStart = 0;
- OverlayColor sliderEnd = 0;
+ OverlayColor sliderStart = _colors[kScrollbarSliderStart];
+ OverlayColor sliderEnd = _colors[kScrollbarSliderEnd];
- if (scrollState == kScrollbarStateSlider) {
- sliderStart = _colors[kScrollbarSliderHighlightStart];
- sliderEnd = _colors[kScrollbarSliderHighlightEnd];
- } else {
- sliderStart = _colors[kScrollbarSliderStart];
- sliderEnd = _colors[kScrollbarSliderEnd];
- }
+ if (scrollState == kScrollbarStateSlider)
+ getStateColor(sliderStart, sliderEnd, sliderStart, sliderEnd, _colors[kScrollbarSliderHighlightStart], _colors[kScrollbarSliderHighlightEnd], state);
r2 = r;
r2.left += 1;
@@ -697,14 +695,11 @@ void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHe
sliderEnd, sliderStart, _gradientFactors[kScrollbarFactor]);
// draws the 'down' button
+ buttonStart = _colors[kScrollbarButtonStart];
+ buttonEnd = _colors[kScrollbarButtonEnd];
- if (scrollState == kScrollbarStateDown) {
- buttonStart = _colors[kScrollbarButtonHighlightStart];
- buttonEnd = _colors[kScrollbarButtonHighlightEnd];
- } else {
- buttonStart = _colors[kScrollbarButtonStart];
- buttonEnd = _colors[kScrollbarButtonEnd];
- }
+ if (scrollState == kScrollbarStateDown)
+ getStateColor(buttonStart, buttonEnd, buttonStart, buttonEnd, _colors[kScrollbarButtonHighlightStart], _colors[kScrollbarButtonHighlightEnd], state);
r2 = r;
r2.top = r2.bottom - UP_DOWN_BOX_HEIGHT;
@@ -720,7 +715,7 @@ void ThemeModern::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHe
addDirtyRect(r);
}
-void ThemeModern::drawCaret(const Common::Rect &r, bool erase, State state) {
+void ThemeModern::drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state) {
if (!_initOk)
return;
@@ -749,7 +744,7 @@ void ThemeModern::drawCaret(const Common::Rect &r, bool erase, State state) {
addDirtyRect(r);
}
-void ThemeModern::drawLineSeparator(const Common::Rect &r, State state) {
+void ThemeModern::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
if (!_initOk)
return;
_screen.hLine(r.left - 1, r.top + r.height() / 2, r.right, _system->RGBToColor(0, 0, 0));
@@ -1572,6 +1567,20 @@ OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max
return calcGradient<ColorMasks<555> >(start, end, pos);
}
}
+
+void getStateColor(OverlayColor &s, OverlayColor &e,
+ OverlayColor enabledS, OverlayColor enabledE,
+ OverlayColor highlightS, OverlayColor highlightE,
+ Theme::WidgetStateInfo state) {
+ if (state == Theme::kStateHighlight) {
+ s = highlightS;
+ e = highlightE;
+ } else {
+ s = enabledS;
+ e = enabledE;
+ }
+}
+
} // end of namespace GUI
#endif
diff --git a/gui/ThemeModern.h b/gui/ThemeModern.h
index 584fae25ef..ab1b5a7835 100644
--- a/gui/ThemeModern.h
+++ b/gui/ThemeModern.h
@@ -60,20 +60,20 @@ public:
int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const { if (_fonts[font]) return _fonts[font]->getStringWidth(str); return 0; }
int getCharWidth(byte c, FontStyle font = kFontStyleBold) const { if (_fonts[font]) return _fonts[font]->getCharWidth(c); return 0; }
- void drawDialogBackground(const Common::Rect &r, uint16 hints, State state);
- void drawText(const Common::Rect &r, const Common::String &str, State state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font);
- void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, State state);
-
- void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, State state);
- void drawButton(const Common::Rect &r, const Common::String &str, State state, uint16 hints);
- void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, State state, int alpha, bool themeTrans);
- void drawSlider(const Common::Rect &r, int width, State state);
- void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, State state);
- void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, State state);
- void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, State state);
- void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, State state, TextAlign align);
- void drawCaret(const Common::Rect &r, bool erase, State state);
- void drawLineSeparator(const Common::Rect &r, State state);
+ void drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state);
+ void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font);
+ void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state);
+
+ void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background, WidgetStateInfo state);
+ void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints);
+ void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans);
+ void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state);
+ void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state);
+ void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state);
+ void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state);
+ void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state, TextAlign align);
+ void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state);
+ void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state);
void restoreBackground(Common::Rect r, bool special = false);
bool addDirtyRect(Common::Rect r, bool backup = false, bool special = false);
diff --git a/gui/about.cpp b/gui/about.cpp
index a6f76d7c02..c346d5ad87 100644
--- a/gui/about.cpp
+++ b/gui/about.cpp
@@ -218,7 +218,7 @@ void AboutDialog::drawDialog() {
for (int line = firstLine; line < lastLine; line++) {
const char *str = _lines[line].c_str();
Theme::TextAlign align = Theme::kTextAlignCenter;
- Theme::State state = Theme::kStateEnabled;
+ Theme::WidgetStateInfo state = Theme::kStateEnabled;
while (str[0] == '\\') {
switch (str[1]) {
case 'C':
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index f6854e2b62..ef396301be 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -296,9 +296,8 @@ void Dialog::handleMouseMoved(int x, int y, int button) {
void Dialog::handleTickle() {
// Focused widget receives tickle notifications
- if (_focusedWidget && _focusedWidget->getFlags() & WIDGET_WANT_TICKLE) {
+ if (_focusedWidget && _focusedWidget->getFlags() & WIDGET_WANT_TICKLE)
_focusedWidget->handleTickle();
- }
}
void Dialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
diff --git a/gui/theme.cpp b/gui/theme.cpp
index 6aef7d1e37..1765c3d5f5 100644
--- a/gui/theme.cpp
+++ b/gui/theme.cpp
@@ -258,3 +258,4 @@ bool Theme::themeConfigUseable(const Common::String &stylefile, const Common::St
}
} // End of namespace GUI
+
diff --git a/gui/theme.h b/gui/theme.h
index 248c1fb068..69ea122535 100644
--- a/gui/theme.h
+++ b/gui/theme.h
@@ -105,11 +105,13 @@ public:
//! State of the widget to be drawn
enum State {
- kStateDisabled, //! Indicates that the widget is disabled, that does NOT include that it is invisible
- kStateEnabled, //! Indicates that the widget is enabled
- kStateHighlight //! Indicates that the widget is highlighted by the user
+ kStateDisabled, //! Indicates that the widget is disabled, that does NOT include that it is invisible
+ kStateEnabled, //! Indicates that the widget is enabled
+ kStateHighlight //! Indicates that the widget is highlighted by the user
};
+ typedef State WidgetStateInfo;
+
enum ScrollbarState {
kScrollbarStateNo,
kScrollbarStateUp,
@@ -277,21 +279,21 @@ public:
virtual int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const = 0;
virtual int getCharWidth(byte c, FontStyle font = kFontStyleBold) const = 0;
- virtual void drawDialogBackground(const Common::Rect &r, uint16 hints, State state = kStateEnabled) = 0;
- virtual void drawText(const Common::Rect &r, const Common::String &str, State state = kStateEnabled, TextAlign align = kTextAlignCenter, bool inverted = false, int deltax = 0, bool useEllipsis = true, FontStyle font = kFontStyleBold) = 0;
+ virtual void drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignCenter, bool inverted = false, int deltax = 0, bool useEllipsis = true, FontStyle font = kFontStyleBold) = 0;
// this should ONLY be used by the debugger until we get a nicer solution
- virtual void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, State state = kStateEnabled) = 0;
-
- virtual void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain, State state = kStateEnabled) = 0;
- virtual void drawButton(const Common::Rect &r, const Common::String &str, State state = kStateEnabled, uint16 hints = 0) = 0;
- virtual void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, State state = kStateEnabled, int alpha = 256, bool themeTrans = false) = 0;
- virtual void drawSlider(const Common::Rect &r, int width, State state = kStateEnabled) = 0;
- virtual void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, State state = kStateEnabled) = 0;
- virtual void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, State state = kStateEnabled) = 0;
- virtual void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, State state = kStateEnabled) = 0;
- virtual void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, State state = kStateEnabled, TextAlign align = kTextAlignLeft) = 0;
- virtual void drawCaret(const Common::Rect &r, bool erase, State state = kStateEnabled) = 0;
- virtual void drawLineSeparator(const Common::Rect &r, State state = kStateEnabled) = 0;
+ virtual void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state = kStateEnabled) = 0;
+
+ virtual void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0) = 0;
+ virtual void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, WidgetStateInfo state = kStateEnabled, int alpha = 256, bool themeTrans = false) = 0;
+ virtual void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax, WidgetStateInfo state = kStateEnabled, TextAlign align = kTextAlignLeft) = 0;
+ virtual void drawCaret(const Common::Rect &r, bool erase, WidgetStateInfo state = kStateEnabled) = 0;
+ virtual void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled) = 0;
virtual void restoreBackground(Common::Rect r, bool special = false) = 0;
virtual bool addDirtyRect(Common::Rect r, bool save = false, bool special = false) = 0;
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 893128ce1e..e9afc30301 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -33,13 +33,15 @@ namespace GUI {
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
: GuiObject(x, y, w, h), _type(0), _boss(boss),
- _id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW), _hasFocus(false) {
+ _id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW),
+ _hasFocus(false), _state(Theme::kStateEnabled) {
init();
}
Widget::Widget(GuiObject *boss, const Common::String &name)
: GuiObject(name), _type(0), _boss(boss),
- _id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW), _hasFocus(false) {
+ _id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW),
+ _hasFocus(false), _state(Theme::kStateDisabled) {
init();
}
@@ -51,6 +53,11 @@ void Widget::init() {
_hints = THEME_HINT_FIRST_DRAW | THEME_HINT_SAVE_BACKGROUND;
}
+Widget::~Widget() {
+ delete _next;
+ _next = 0;
+}
+
void Widget::resize(int x, int y, int w, int h) {
_x = x;
_y = y;
@@ -58,9 +65,24 @@ void Widget::resize(int x, int y, int w, int h) {
_h = h;
}
-Widget::~Widget() {
- delete _next;
- _next = 0;
+void Widget::setFlags(int flags) {
+ updateState(_flags, _flags | flags);
+ _flags |= flags;
+}
+
+void Widget::clearFlags(int flags) {
+ updateState(_flags, _flags & ~flags);
+ _flags &= ~flags;
+}
+
+void Widget::updateState(int oldFlags, int newFlags) {
+ if (newFlags & WIDGET_ENABLED) {
+ _state = Theme::kStateEnabled;
+ if (newFlags & WIDGET_HILITED)
+ _state = Theme::kStateHighlight;
+ } else {
+ _state = Theme::kStateDisabled;
+ }
}
void Widget::draw() {
@@ -75,10 +97,6 @@ void Widget::draw() {
_x = getAbsX();
_y = getAbsY();
- // Clear background (unless alpha blending is enabled)
- //if (_flags & WIDGET_CLEARBG)
- // gui->fillRect(_x, _y, _w, _h, gui->_bgcolor);
-
// Draw border
if (_flags & WIDGET_BORDER) {
gui->theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), _hints, Theme::kWidgetBackgroundBorder);
@@ -89,7 +107,7 @@ void Widget::draw() {
}
// Now perform the actual widget draw
- drawWidget((_flags & WIDGET_HILITED) ? true : false);
+ drawWidget();
// Restore x/y
if (_flags & WIDGET_BORDER) {
@@ -133,6 +151,7 @@ Widget *Widget::findWidgetInChain(Widget *w, const char *name) {
}
return 0;
}
+
bool Widget::isEnabled() const {
if (g_gui.evaluator()->getVar(_name + ".enabled") == 0) {
return false;
@@ -147,19 +166,18 @@ bool Widget::isVisible() const {
return !(_flags & WIDGET_INVISIBLE);
}
-
#pragma mark -
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &text, TextAlignment align)
: Widget(boss, x, y, w, h), _align(align) {
- _flags = WIDGET_ENABLED;
+ setFlags(WIDGET_ENABLED);
_type = kStaticTextWidget;
_label = text;
}
StaticTextWidget::StaticTextWidget(GuiObject *boss, const Common::String &name, const Common::String &text)
: Widget(boss, name) {
- _flags = WIDGET_ENABLED;
+ setFlags(WIDGET_ENABLED);
_type = kStaticTextWidget;
_label = text;
@@ -191,10 +209,8 @@ void StaticTextWidget::setAlign(TextAlignment align) {
}
-void StaticTextWidget::drawWidget(bool hilite) {
- g_gui.theme()->drawText(Common::Rect(_x, _y, _x+_w, _y+_h), _label,
- isEnabled() ? Theme::kStateEnabled : Theme::kStateDisabled,
- g_gui.theme()->convertAligment(_align));
+void StaticTextWidget::drawWidget() {
+ g_gui.theme()->drawText(Common::Rect(_x, _y, _x+_w, _y+_h), _label, _state, g_gui.theme()->convertAligment(_align));
}
#pragma mark -
@@ -202,14 +218,14 @@ void StaticTextWidget::drawWidget(bool hilite) {
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey) {
- _flags = WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
_type = kButtonWidget;
}
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::String &label, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, name, label), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey) {
- _flags = WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
_hints = THEME_HINT_USE_SHADOW;
_type = kButtonWidget;
}
@@ -219,21 +235,21 @@ void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
sendCommand(_cmd, 0);
}
-void ButtonWidget::drawWidget(bool hilite) {
- g_gui.theme()->drawButton(Common::Rect(_x, _y, _x+_w, _y+_h), _label, isEnabled() ? (hilite ? Theme::kStateHighlight : Theme::kStateEnabled) : Theme::kStateDisabled, _hints);
+void ButtonWidget::drawWidget() {
+ g_gui.theme()->drawButton(Common::Rect(_x, _y, _x+_w, _y+_h), _label, _state, _hints);
}
#pragma mark -
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) {
- _flags = WIDGET_ENABLED;
+ setFlags(WIDGET_ENABLED);
_type = kCheckboxWidget;
}
CheckboxWidget::CheckboxWidget(GuiObject *boss, const Common::String &name, const Common::String &label, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, name, label, cmd, hotkey), _state(false) {
- _flags = WIDGET_ENABLED;
+ setFlags(WIDGET_ENABLED);
_type = kCheckboxWidget;
}
@@ -246,15 +262,14 @@ void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
void CheckboxWidget::setState(bool state) {
if (_state != state) {
_state = state;
- _flags ^= WIDGET_INV_BORDER;
+ //_flags ^= WIDGET_INV_BORDER;
draw();
}
sendCommand(_cmd, _state);
}
-void CheckboxWidget::drawWidget(bool hilite) {
- g_gui.theme()->drawCheckbox(Common::Rect(_x, _y, _x+_w, _y+_h), _label, _state,
- isEnabled() ? (hilite ? Theme::kStateHighlight : Theme::kStateEnabled) : Theme::kStateDisabled);
+void CheckboxWidget::drawWidget() {
+ g_gui.theme()->drawCheckbox(Common::Rect(_x, _y, _x+_w, _y+_h), _label, _state, Widget::_state);
}
#pragma mark -
@@ -262,14 +277,14 @@ void CheckboxWidget::drawWidget(bool hilite) {
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd)
: Widget(boss, x, y, w, h), CommandSender(boss),
_cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false) {
- _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG);
_type = kSliderWidget;
}
SliderWidget::SliderWidget(GuiObject *boss, const Common::String &name, uint32 cmd)
: Widget(boss, name), CommandSender(boss),
_cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false) {
- _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG);
_type = kSliderWidget;
}
@@ -303,9 +318,8 @@ void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
_isDragging = false;
}
-void SliderWidget::drawWidget(bool hilite) {
- g_gui.theme()->drawSlider(Common::Rect(_x, _y, _x+_w, _y+_h), valueToPos(_value),
- isEnabled() ? (hilite ? Theme::kStateHighlight : Theme::kStateEnabled) : Theme::kStateDisabled);
+void SliderWidget::drawWidget() {
+ g_gui.theme()->drawSlider(Common::Rect(_x, _y, _x+_w, _y+_h), valueToPos(_value), _state);
}
int SliderWidget::valueToPos(int value) {
@@ -320,7 +334,7 @@ int SliderWidget::posToValue(int pos) {
GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h)
: Widget(boss, x, y, w, h), _gfx(), _alpha(256), _transparency(false) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
_type = kGraphicsWidget;
// HACK: Don't save the background. We want to be sure that redrawing
// the widget updates the screen, even when there isn't any image
@@ -330,7 +344,7 @@ GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h)
GraphicsWidget::GraphicsWidget(GuiObject *boss, const Common::String &name)
: Widget(boss, name), _gfx(), _alpha(256), _transparency(false) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
_type = kGraphicsWidget;
// HACK: Don't save the background. We want to be sure that redrawing
// the widget updates the screen, even when there isn't any image
@@ -372,25 +386,24 @@ void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
}
}
-void GraphicsWidget::drawWidget(bool hilite) {
- if (sizeof(OverlayColor) == _gfx.bytesPerPixel && _gfx.pixels) {
- g_gui.theme()->drawSurface(Common::Rect(_x, _y, _x+_w, _y+_h), _gfx, Theme::kStateEnabled, _alpha, _transparency);
- }
+void GraphicsWidget::drawWidget() {
+ if (sizeof(OverlayColor) == _gfx.bytesPerPixel && _gfx.pixels)
+ g_gui.theme()->drawSurface(Common::Rect(_x, _y, _x+_w, _y+_h), _gfx, _state, _alpha, _transparency);
}
#pragma mark -
ContainerWidget::ContainerWidget(GuiObject *boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
_type = kContainerWidget;
}
ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) : Widget(boss, name) {
- _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
+ setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
_type = kContainerWidget;
}
-void ContainerWidget::drawWidget(bool hilite) {
+void ContainerWidget::drawWidget() {
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), _hints, Theme::kWidgetBackgroundBorder);
}
diff --git a/gui/widget.h b/gui/widget.h
index 1381bbfb4b..a91204c679 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -31,6 +31,7 @@
#include "graphics/font.h"
#include "graphics/surface.h"
#include "gui/object.h"
+#include "gui/theme.h"
namespace Graphics {
class Font;
@@ -45,7 +46,7 @@ enum {
WIDGET_INVISIBLE = 1 << 1,
WIDGET_HILITED = 1 << 2,
WIDGET_BORDER = 1 << 3,
- WIDGET_INV_BORDER = 1 << 4,
+ //WIDGET_INV_BORDER = 1 << 4,
WIDGET_CLEARBG = 1 << 5,
WIDGET_WANT_TICKLE = 1 << 7,
WIDGET_TRACK_MOUSE = 1 << 8,
@@ -97,9 +98,12 @@ protected:
GuiObject *_boss;
Widget *_next;
uint16 _id;
- uint16 _flags;
uint16 _hints;
bool _hasFocus;
+ Theme::WidgetStateInfo _state;
+
+private:
+ uint16 _flags;
public:
static Widget *findWidgetInChain(Widget *start, int x, int y);
@@ -139,8 +143,8 @@ public:
void lostFocus() { _hasFocus = false; lostFocusWidget(); }
virtual bool wantsFocus() { return false; }
- void setFlags(int flags) { _flags |= flags; }
- void clearFlags(int flags) { _flags &= ~flags; }
+ void setFlags(int flags);
+ void clearFlags(int flags);
int getFlags() const { return _flags; }
void setHints(int hints) { _hints |= hints; }
@@ -152,7 +156,9 @@ public:
bool isVisible() const;
protected:
- virtual void drawWidget(bool hilite) {}
+ void updateState(int oldFlags, int newFlags);
+
+ virtual void drawWidget() = 0;
virtual void receivedFocusWidget() {}
virtual void lostFocusWidget() {}
@@ -182,7 +188,7 @@ public:
TextAlignment getAlign() const { return _align; }
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
};
/* ButtonWidget */
@@ -203,7 +209,7 @@ public:
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
};
/* CheckboxWidget */
@@ -223,7 +229,7 @@ public:
bool getState() const { return _state; }
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
};
/* SliderWidget */
@@ -256,7 +262,7 @@ public:
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
int valueToPos(int value);
int posToValue(int pos);
@@ -276,7 +282,7 @@ public:
void useThemeTransparency(bool enable) { _transparency = enable; }
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
Graphics::Surface _gfx;
int _alpha;
@@ -290,7 +296,7 @@ public:
ContainerWidget(GuiObject *boss, const Common::String &name);
protected:
- void drawWidget(bool hilite);
+ void drawWidget();
};
} // End of namespace GUI