[Scummvm-cvs-logs] scummvm master -> cebbc11dac77d30fac3be4cc0ebdc6bc059636ef

lordhoto lordhoto at gmail.com
Wed Jun 13 04:50:54 CEST 2012


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d5eb3e3c06 GUI: Allow querying of the pixel format used by ThemeEngine.
cebbc11dac GUI: Allow Surfaces with abitrary RGB pixel formats to be used in PicButtonWidget and GraphicsWidget.


Commit: d5eb3e3c06a1f396f578b21c4a3aaff3519513a5
    https://github.com/scummvm/scummvm/commit/d5eb3e3c06a1f396f578b21c4a3aaff3519513a5
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-06-12T19:32:11-07:00

Commit Message:
GUI: Allow querying of the pixel format used by ThemeEngine.

Changed paths:
    gui/ThemeEngine.h



diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h
index 67221d9..21711e2 100644
--- a/gui/ThemeEngine.h
+++ b/gui/ThemeEngine.h
@@ -276,6 +276,11 @@ public:
 	void disable();
 
 	/**
+	 * Query the set up pixel format.
+	 */
+	const Graphics::PixelFormat getPixelFormat() const { return _overlayFormat; }
+
+	/**
 	 * Implementation of the GUI::Theme API. Called when a
 	 * new dialog is opened. Note that the boolean parameter
 	 * meaning has been changed.


Commit: cebbc11dac77d30fac3be4cc0ebdc6bc059636ef
    https://github.com/scummvm/scummvm/commit/cebbc11dac77d30fac3be4cc0ebdc6bc059636ef
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-06-12T19:48:34-07:00

Commit Message:
GUI: Allow Surfaces with abitrary RGB pixel formats to be used in PicButtonWidget and GraphicsWidget.

Only 1Bpp aka paletted surfaces are not supported.

Changed paths:
    gui/widget.cpp
    gui/widget.h



diff --git a/gui/widget.cpp b/gui/widget.cpp
index 657245c..1b68e36 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -376,7 +376,7 @@ void ButtonWidget::wantTickle(bool tickled) {
 
 PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey)
 	: ButtonWidget(boss, x, y, w, h, "", tooltip, cmd, hotkey),
-	  _gfx(), _alpha(256), _transparency(false) {
+	  _gfx(new Graphics::Surface()), _alpha(256), _transparency(false) {
 
 	setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
 	_type = kButtonWidget;
@@ -384,38 +384,54 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co
 
 PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
 	: ButtonWidget(boss, name, "", tooltip, cmd, hotkey),
-	  _alpha(256), _transparency(false) {
+	  _gfx(new Graphics::Surface()), _alpha(256), _transparency(false) {
 	setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
 	_type = kButtonWidget;
 }
 
 PicButtonWidget::~PicButtonWidget() {
-	_gfx.free();
+	_gfx->free();
+	delete _gfx;
 }
 
 void PicButtonWidget::setGfx(const Graphics::Surface *gfx) {
-	_gfx.free();
+	_gfx->free();
 
 	if (!gfx || !gfx->pixels)
 		return;
 
+	if (gfx->format.bytesPerPixel == 1) {
+		warning("PicButtonWidget::setGfx got paletted surface passed");
+		return;
+	}
+
+
 	if (gfx->w > _w || gfx->h > _h) {
 		warning("PicButtonWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
 		return;
 	}
 
-	// TODO: add conversion to OverlayColor
-	_gfx.copyFrom(*gfx);
+	_gfx->copyFrom(*gfx);
 }
 
 void PicButtonWidget::drawWidget() {
 	g_gui.theme()->drawButton(Common::Rect(_x, _y, _x+_w, _y+_h), "", _state, getFlags());
 
-	if (sizeof(OverlayColor) == _gfx.format.bytesPerPixel && _gfx.pixels) {
-		const int x = _x + (_w - _gfx.w) / 2;
-		const int y = _y + (_h - _gfx.h) / 2;
+	if (_gfx->pixels) {
+		// Check whether the set up surface needs to be converted to the GUI
+		// color format.
+		const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
+		if (_gfx->format != requiredFormat) {
+			Graphics::Surface *converted = _gfx->convertTo(requiredFormat);
+			_gfx->free();
+			delete _gfx;
+			_gfx = converted;
+		}
+
+		const int x = _x + (_w - _gfx->w) / 2;
+		const int y = _y + (_h - _gfx->h) / 2;
 
-		g_gui.theme()->drawSurface(Common::Rect(x, y, x + _gfx.w,  y + _gfx.h), _gfx, _state, _alpha, _transparency);
+		g_gui.theme()->drawSurface(Common::Rect(x, y, x + _gfx->w,  y + _gfx->h), *_gfx, _state, _alpha, _transparency);
 	}
 }
 
@@ -603,34 +619,39 @@ int SliderWidget::posToValue(int pos) {
 #pragma mark -
 
 GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip)
-	: Widget(boss, x, y, w, h, tooltip), _gfx(), _alpha(256), _transparency(false) {
+	: Widget(boss, x, y, w, h, tooltip), _gfx(new Graphics::Surface()), _alpha(256), _transparency(false) {
 	setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
 	_type = kGraphicsWidget;
 }
 
 GraphicsWidget::GraphicsWidget(GuiObject *boss, const Common::String &name, const char *tooltip)
-	: Widget(boss, name, tooltip), _gfx(), _alpha(256), _transparency(false) {
+	: Widget(boss, name, tooltip), _gfx(new Graphics::Surface()), _alpha(256), _transparency(false) {
 	setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
 	_type = kGraphicsWidget;
 }
 
 GraphicsWidget::~GraphicsWidget() {
-	_gfx.free();
+	_gfx->free();
+	delete _gfx;
 }
 
 void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
-	_gfx.free();
+	_gfx->free();
 
 	if (!gfx || !gfx->pixels)
 		return;
 
+	if (gfx->format.bytesPerPixel == 1) {
+		warning("GraphicsWidget::setGfx got paletted surface passed");
+		return;
+	}
+
 	if (gfx->w > _w || gfx->h > _h) {
 		warning("GraphicsWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
 		return;
 	}
 
-	// TODO: add conversion to OverlayColor
-	_gfx.copyFrom(*gfx);
+	_gfx->copyFrom(*gfx);
 }
 
 void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
@@ -639,19 +660,29 @@ void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
 	if (h == -1)
 		h = _h;
 
-	Graphics::PixelFormat overlayFormat = g_system->getOverlayFormat();
+	const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
 
-	_gfx.free();
-	_gfx.create(w, h, overlayFormat);
-	_gfx.fillRect(Common::Rect(0, 0, w, h), _gfx.format.RGBToColor(r, g, b));
+	_gfx->free();
+	_gfx->create(w, h, requiredFormat);
+	_gfx->fillRect(Common::Rect(0, 0, w, h), _gfx->format.RGBToColor(r, g, b));
 }
 
 void GraphicsWidget::drawWidget() {
-	if (sizeof(OverlayColor) == _gfx.format.bytesPerPixel && _gfx.pixels) {
-		const int x = _x + (_w - _gfx.w) / 2;
-		const int y = _y + (_h - _gfx.h) / 2;
+	if (_gfx->pixels) {
+		// Check whether the set up surface needs to be converted to the GUI
+		// color format.
+		const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
+		if (_gfx->format != requiredFormat) {
+			Graphics::Surface *converted = _gfx->convertTo(requiredFormat);
+			_gfx->free();
+			delete _gfx;
+			_gfx = converted;
+		}
+
+		const int x = _x + (_w - _gfx->w) / 2;
+		const int y = _y + (_h - _gfx->h) / 2;
 
-		g_gui.theme()->drawSurface(Common::Rect(x, y, x + _gfx.w,  y + _gfx.h), _gfx, _state, _alpha, _transparency);
+		g_gui.theme()->drawSurface(Common::Rect(x, y, x + _gfx->w,  y + _gfx->h), *_gfx, _state, _alpha, _transparency);
 	}
 }
 
diff --git a/gui/widget.h b/gui/widget.h
index 6a6c67c..6de5686 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -227,7 +227,7 @@ public:
 protected:
 	void drawWidget();
 
-	Graphics::Surface _gfx;
+	Graphics::Surface *_gfx;
 	int _alpha;
 	bool _transparency;
 };
@@ -355,7 +355,7 @@ public:
 protected:
 	void drawWidget();
 
-	Graphics::Surface _gfx;
+	Graphics::Surface *_gfx;
 	int _alpha;
 	bool _transparency;
 };






More information about the Scummvm-git-logs mailing list