diff options
author | Max Horn | 2005-05-08 22:38:29 +0000 |
---|---|---|
committer | Max Horn | 2005-05-08 22:38:29 +0000 |
commit | 3279513b6490226d39b1f2eee03ddf7b48c4f5be (patch) | |
tree | d21b57a969e75209eca71f69e904f95cccda4215 | |
parent | 1cddaa828cebeb9aa474505eff7a69403818a1c0 (diff) | |
download | scummvm-rg350-3279513b6490226d39b1f2eee03ddf7b48c4f5be.tar.gz scummvm-rg350-3279513b6490226d39b1f2eee03ddf7b48c4f5be.tar.bz2 scummvm-rg350-3279513b6490226d39b1f2eee03ddf7b48c4f5be.zip |
A simple widget which renders any 16 bit graphics surface given to it (part of patch #1163026)
svn-id: r17977
-rw-r--r-- | gui/widget.cpp | 45 | ||||
-rw-r--r-- | gui/widget.h | 17 |
2 files changed, 60 insertions, 2 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp index e8a7d80183..6bc483e63d 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -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 @@ int SliderWidget::posToValue(int pos) { 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 diff --git a/gui/widget.h b/gui/widget.h index 3a97cab747..1b6623d620 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -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 @@ enum { kListWidget = 'LIST', kScrollBarWidget = 'SCRB', kPopUpWidget = 'POPU', - kTabWidget = 'TABW' + kTabWidget = 'TABW', + kGraphicsWidget = 'GFXW' }; enum { @@ -210,6 +212,19 @@ protected: 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 |