[Scummvm-cvs-logs] SF.net SVN: scummvm: [20669] scummvm/trunk/gui

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Mon Feb 13 10:01:08 CET 2006


Revision: 20669
Author:   lordhoto
Date:     2006-02-13 10:00:04 -0800 (Mon, 13 Feb 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm?rev=20669&view=rev

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

Modified Paths:
--------------
    scummvm/trunk/gui/TabWidget.cpp
    scummvm/trunk/gui/ThemeNew.cpp
    scummvm/trunk/gui/theme.cpp
    scummvm/trunk/gui/theme.h
Modified: scummvm/trunk/gui/TabWidget.cpp
===================================================================
--- scummvm/trunk/gui/TabWidget.cpp	2006-02-13 13:46:38 UTC (rev 20668)
+++ scummvm/trunk/gui/TabWidget.cpp	2006-02-13 18:00:04 UTC (rev 20669)
@@ -128,32 +128,12 @@
 	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) {

Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp	2006-02-13 13:46:38 UTC (rev 20668)
+++ scummvm/trunk/gui/ThemeNew.cpp	2006-02-13 18:00:04 UTC (rev 20669)
@@ -597,17 +597,40 @@
 	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 @@
 				} 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);

Modified: scummvm/trunk/gui/theme.cpp
===================================================================
--- scummvm/trunk/gui/theme.cpp	2006-02-13 13:46:38 UTC (rev 20668)
+++ scummvm/trunk/gui/theme.cpp	2006-02-13 18:00:04 UTC (rev 20669)
@@ -172,26 +172,31 @@
 	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 @@
 	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 @@
 	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 @@
 	}
 	_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);
 	}
 }
 

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2006-02-13 13:46:38 UTC (rev 20668)
+++ scummvm/trunk/gui/theme.h	2006-02-13 18:00:04 UTC (rev 20669)
@@ -121,7 +121,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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);







More information about the Scummvm-git-logs mailing list