mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-18 16:03:05 +00:00
A simple widget which renders any 16 bit graphics surface given to it (part of patch #1163026)
svn-id: r17977
This commit is contained in:
parent
1cddaa828c
commit
3279513b64
@ -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
|
||||
|
17
gui/widget.h
17
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user