Implemented new tab drawing, should look nicer now. (The border under the active tab isn't drawn anymore)

svn-id: r20669
This commit is contained in:
Johannes Schickel 2006-02-13 18:00:04 +00:00
parent 1b459ee959
commit e067a7f288
4 changed files with 71 additions and 48 deletions

View File

@ -128,32 +128,12 @@ bool TabWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
return Widget::handleKeyDown(ascii, keycode, modifiers);
}
/*static void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB, bool omitBottom) {
NewGui &gui = g_gui;
gui.hLine(x + 1, y, x + width - 2, colorA);
gui.hLine(x, y + 1, x + width - 1, colorA);
gui.vLine(x, y + 1, y + height - (omitBottom ? 1 : 2), colorA);
gui.vLine(x + 1, y, y + height - (omitBottom ? 2 : 1), colorA);
if (!omitBottom) {
gui.hLine(x + 1, y + height - 2, x + width - 1, colorB);
gui.hLine(x + 1, y + height - 1, x + width - 2, colorB);
}
gui.vLine(x + width - 1, y + 1, y + height - (omitBottom ? 1 : 2), colorB);
gui.vLine(x + width - 2, y + 1, y + height - (omitBottom ? 2 : 1), colorB);
}*/
void TabWidget::drawWidget(bool hilite) {
// Iterate over all tabs and draw them
int i, x = _x + kTabLeftOffset;
for (i = 0; i < (int)_tabs.size(); ++i) {
int yOffset = (i == _activeTab) ? 0 : 2;
g_gui.theme()->drawTab(Common::Rect(x, _y+yOffset, x+_tabWidth, _y+_tabHeight), _tabs[i].title, (i == _activeTab));
x += _tabWidth + kTabSpacing;
Common::Array<Common::String> tabs;
for (int i = 0; i < (int)_tabs.size(); ++i) {
tabs.push_back(_tabs[i].title);
}
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y+_tabHeight-2, _x+_w, _y+_h), _hints, Theme::kWidgetBackgroundBorderSmall);
g_gui.theme()->drawTab(Common::Rect(_x, _y, _x+_w, _y+_h), _tabHeight, _tabWidth, tabs, _activeTab, _hints);
}
Widget *TabWidget::findWidget(int x, int y) {

View File

@ -597,17 +597,40 @@ void ThemeNew::drawCheckbox(const Common::Rect &r, const Common::String &str, bo
addDirtyRect(r);
}
void ThemeNew::drawTab(const Common::Rect &r, const Common::String &str, bool active, kState state) {
OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max, uint factor);
void ThemeNew::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, kState state) {
if (!_initOk)
return;
drawRectMasked(r, surface(kTabBkgdCorner), surface(kTabBkgdTop), surface(kTabBkgdLeft), surface(kTabBkgd),
(state == kStateDisabled) ? 128 : 256, _colors[kTabBackgroundStart], _colors[kTabBackgroundEnd],
_gradientFactors[kTabFactor], true);
if (active) {
_font->drawString(&_screen, str, r.left, r.top+2, r.width(), getColor(kStateHighlight), Graphics::kTextAlignCenter, 0, true);
} else {
_font->drawString(&_screen, str, r.left, r.top+2, r.width(), getColor(state), Graphics::kTextAlignCenter, 0, true);
restoreBackground(r);
int tabXOffset = surface(kWidgetSmallBkgdCorner)->w;
OverlayColor tabEnd = calcGradient(_colors[kTabBackgroundStart], _colors[kTabBackgroundEnd], tabHeight, r.height(), _gradientFactors[kTabFactor]);
for (int i = 0; i < (int)tabs.size(); ++i) {
if (i == active)
continue;
Common::Rect tabRect(r.left + tabXOffset + i * tabWidth, r.top, r.left + tabXOffset + i * tabWidth + tabWidth, r.top + tabHeight);
drawRectMasked(tabRect, surface(kTabBkgdCorner), surface(kTabBkgdTop), surface(kTabBkgdLeft), surface(kTabBkgd),
128, _colors[kTabBackgroundStart], tabEnd, _gradientFactors[kTabFactor], true);
_font->drawString(&_screen, tabs[i], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateEnabled), Graphics::kTextAlignCenter, 0, true);
}
Common::Rect widgetBackground = Common::Rect(r.left, r.top + tabHeight, r.right, r.bottom);
drawRectMasked(widgetBackground, surface(kWidgetSmallBkgdCorner), surface(kWidgetSmallBkgdTop), surface(kWidgetSmallBkgdLeft), surface(kWidgetSmallBkgd),
(state == kStateDisabled) ? 128 : 256, tabEnd, _colors[kTabBackgroundEnd],
_gradientFactors[kTabFactor]);
addDirtyRect(widgetBackground, true);
Common::Rect tabRect(r.left + tabXOffset + active * tabWidth, r.top, r.left + tabXOffset + active * tabWidth + tabWidth, r.top + tabHeight + 1);
drawRectMasked(tabRect, surface(kTabBkgdCorner), surface(kTabBkgdTop), surface(kTabBkgdLeft), surface(kTabBkgd),
256, _colors[kTabBackgroundStart], tabEnd, _gradientFactors[kTabFactor], true);
_font->drawString(&_screen, tabs[active], tabRect.left, tabRect.top+2, tabRect.width(), getColor(kStateHighlight), Graphics::kTextAlignCenter, 0, true);
addDirtyRect(r);
}
@ -914,7 +937,7 @@ void ThemeNew::drawRectMasked(const Common::Rect &r, const Graphics::Surface *co
} else {
drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, true, alpha, startCol, endCol);
}
} else if (!y || y == partsH - 1) {
} else if (!y || (y == partsH - 1 && !skipLastRow)) {
drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), top, upDown, false, alpha, startCol, endCol);
} else {
drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), fill, upDown, false, alpha, startCol, endCol);

View File

@ -172,26 +172,31 @@ void ThemeClassic::drawWidgetBackground(const Common::Rect &r, uint16 hints, kWi
if (!_initOk || background == kWidgetBackgroundNo)
return;
restoreBackground(r);
if ((hints & THEME_HINT_SAVE_BACKGROUND) && !(hints & THEME_HINT_FIRST_DRAW)) {
addDirtyRect(r);
return;
}
switch (background) {
case kWidgetBackgroundBorder:
restoreBackground(r);
box(r.left, r.top, r.width(), r.height(), _color, _shadowcolor);
break;
case kWidgetBackgroundBorderSmall:
restoreBackground(r);
box(r.left, r.top, r.width(), r.height());
break;
case kWidgetBackgroundPlain:
restoreBackground(r);
// nothing to do here
break;
default:
break;
};
addDirtyRect(r);
addDirtyRect(r, (hints & THEME_HINT_SAVE_BACKGROUND) != 0);
}
void ThemeClassic::drawButton(const Common::Rect &r, const Common::String &str, kState state) {
@ -299,12 +304,27 @@ void ThemeClassic::drawCheckbox(const Common::Rect &r, const Common::String &str
addDirtyRect(r);
}
void ThemeClassic::drawTab(const Common::Rect &r, const Common::String &str, bool active, kState state) {
void ThemeClassic::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, kState state) {
if (!_initOk)
return;
restoreBackground(r);
box(r.left, r.top, r.width(), r.height(), _color, _shadowcolor);
_font->drawString(&_screen, str, r.left, r.top+2, r.width(), getColor(state), Graphics::kTextAlignCenter, 0, true);
for (int i = 0; i < (int)tabs.size(); ++i) {
if (i == active)
continue;
box(r.left + i * tabWidth, r.top+2, tabWidth, tabHeight-2, _color, _shadowcolor);
_font->drawString(&_screen, tabs[i], r.left + i * tabWidth, r.top+4, tabWidth, getColor(state), Graphics::kTextAlignCenter, 0, true);
}
box(r.left + active * tabWidth, r.top, tabWidth, tabHeight, _color, _shadowcolor, true);
_font->drawString(&_screen, tabs[active], r.left + active * tabWidth, r.top+2, tabWidth, getColor(kStateHighlight), Graphics::kTextAlignCenter, 0, true);
_screen.hLine(r.left, r.top + tabHeight, r.left + active * tabWidth + 1, _color);
_screen.hLine(r.left + active * tabWidth + tabWidth - 2, r.top + tabHeight, r.right, _color);
_screen.hLine(r.left, r.bottom - 1, r.right - 1, _shadowcolor);
_screen.vLine(r.left, r.top + tabHeight, r.bottom - 1, _color);
_screen.vLine(r.right - 1, r.top + tabHeight, r.bottom - 1, _shadowcolor);
addDirtyRect(r);
}
@ -444,7 +464,7 @@ bool ThemeClassic::addDirtyRect(Common::Rect r, bool save) {
return true;
}
void ThemeClassic::box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB) {
void ThemeClassic::box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB, bool skipLastRow) {
if (y >= 0) {
_screen.hLine(x + 1, y, x + width - 2, colorA);
_screen.hLine(x, y + 1, x + width - 1, colorA);
@ -456,12 +476,12 @@ void ThemeClassic::box(int x, int y, int width, int height, OverlayColor colorA,
}
_screen.vLine(x, drawY + 1, drawY + height - 2, colorA);
_screen.vLine(x + 1, drawY, drawY + height - 1, colorA);
_screen.vLine(x + width - 1, drawY + 1, drawY + height - 2, colorB);
_screen.vLine(x + width - 2, drawY + 1, drawY + height - 1, colorB);
if (y + height >= 0) {
if (y + height >= 0 && !skipLastRow) {
_screen.hLine(x + 1, drawY + height - 2, x + width - 1, colorB);
_screen.hLine(x + 1, drawY + height - 1, x + width - 2, colorB);
_screen.vLine(x + width - 1, drawY + 1, drawY + height - 2, colorB);
_screen.vLine(x + width - 2, drawY + 1, drawY + height - 1, colorB);
}
}

View File

@ -121,7 +121,7 @@ public:
virtual void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, kState state = kStateEnabled) = 0;
virtual void drawSlider(const Common::Rect &r, int width, kState state = kStateEnabled) = 0;
virtual void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, kState state = kStateEnabled) = 0;
virtual void drawTab(const Common::Rect &r, const Common::String &str, bool active, kState state = kStateEnabled) = 0;
virtual void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, kState state = kStateEnabled) = 0;
virtual void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, kScrollbarState, kState state = kStateEnabled) = 0;
virtual void drawCaret(const Common::Rect &r, bool erase, kState state = kStateEnabled) = 0;
virtual void drawLineSeparator(const Common::Rect &r, kState state = kStateEnabled) = 0;
@ -200,7 +200,7 @@ public:
void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, kState state);
void drawSlider(const Common::Rect &r, int width, kState state);
void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, kState state);
void drawTab(const Common::Rect &r, const Common::String &str, bool active, kState state);
void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, kState state);
void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, kScrollbarState, kState state);
void drawCaret(const Common::Rect &r, bool erase, kState state);
void drawLineSeparator(const Common::Rect &r, kState state);
@ -208,7 +208,7 @@ private:
void restoreBackground(Common::Rect r);
bool addDirtyRect(Common::Rect r, bool save = false);
void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB);
void box(int x, int y, int width, int height, OverlayColor colorA, OverlayColor colorB, bool skipLastRow = false);
void box(int x, int y, int width, int height);
OverlayColor getColor(kState state);
@ -269,7 +269,7 @@ public:
void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, kState state);
void drawSlider(const Common::Rect &r, int width, kState state);
void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked, kState state);
void drawTab(const Common::Rect &r, const Common::String &str, bool active, kState state);
void drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, kState state);
void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, kScrollbarState, kState state);
void drawCaret(const Common::Rect &r, bool erase, kState state);
void drawLineSeparator(const Common::Rect &r, kState state);