[Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.42,1.43 widget.h,1.39,1.40
Max Horn
fingolfin at users.sourceforge.net
Sun May 8 15:40:10 CEST 2005
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6537
Modified Files:
widget.cpp widget.h
Log Message:
A simple widget which renders any 16 bit graphics surface given to it (part of patch #1163026)
Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- widget.cpp 16 Apr 2005 17:53:18 -0000 1.42
+++ widget.cpp 8 May 2005 22:38:29 -0000 1.43
@@ -24,7 +24,6 @@
#include "gui/dialog.h"
#include "gui/newgui.h"
-
namespace GUI {
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
@@ -276,4 +275,48 @@
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
}
+#pragma mark -
+
+GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h)
+ : Widget(boss, x, y, w, h), _gfx() {
+ _flags = WIDGET_ENABLED | WIDGET_CLEARBG;
+ _type = kGraphicsWidget;
+}
+
+GraphicsWidget::~GraphicsWidget() {
+ _gfx.free();
+}
+
+void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
+ _gfx.free();
+
+ if (!gfx)
+ return;
+ if (!gfx->pixels)
+ return;
+
+ // TODO: add conversion to OverlayColor
+ _gfx.create(gfx->w, gfx->h, gfx->bytesPerPixel);
+ memcpy(_gfx.pixels, gfx->pixels, gfx->h * gfx->pitch);
+}
+
+void GraphicsWidget::drawWidget(bool hilite) {
+ if (sizeof(OverlayColor) != _gfx.bytesPerPixel || !_gfx.pixels) {
+ // FIXME: It doesn't really make sense to render this text here, since
+ // this widget might be used for other things than rendering savegame
+ // graphics/previews...
+ g_gui.drawString("No preview", _x, _y + _h / 2 - g_gui.getFontHeight() / 2, _w, g_gui._textcolor, Graphics::kTextAlignCenter);
+ return;
+ }
+
+ uint drawWidth = _gfx.w, drawHeight = _gfx.h;
+
+ if (_w < _gfx.w)
+ drawWidth = _w;
+ if (_h < _gfx.h)
+ drawHeight = _h;
+
+ g_gui.drawSurface(_gfx, _x, _y);
+}
+
} // End of namespace GUI
Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- widget.h 16 Apr 2005 17:53:18 -0000 1.39
+++ widget.h 8 May 2005 22:38:29 -0000 1.40
@@ -24,6 +24,7 @@
#include "common/scummsys.h"
#include "common/str.h"
#include "graphics/font.h"
+#include "graphics/surface.h"
#include "gui/object.h"
namespace GUI {
@@ -52,7 +53,8 @@
kListWidget = 'LIST',
kScrollBarWidget = 'SCRB',
kPopUpWidget = 'POPU',
- kTabWidget = 'TABW'
+ kTabWidget = 'TABW',
+ kGraphicsWidget = 'GFXW'
};
enum {
@@ -210,6 +212,19 @@
int posToValue(int pos);
};
+/* GraphicsWidget */
+class GraphicsWidget : public Widget {
+public:
+ GraphicsWidget(GuiObject *boss, int x, int y, int w, int h);
+ ~GraphicsWidget();
+
+ void setGfx(const Graphics::Surface *gfx);
+protected:
+ void drawWidget(bool hilite);
+
+ Graphics::Surface _gfx;
+};
+
} // End of namespace GUI
#endif
More information about the Scummvm-git-logs
mailing list