mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-03 01:15:58 +00:00
GUI: Switch GUI to ManagedSurface
This commit is contained in:
parent
6217cf8a37
commit
bd083c7fa7
@ -27,7 +27,7 @@
|
||||
#include "common/scummsys.h"
|
||||
#include "common/str.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
#include "graphics/transparent_surface.h"
|
||||
|
||||
#include "gui/ThemeEngine.h"
|
||||
@ -52,8 +52,8 @@ typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, co
|
||||
|
||||
struct DrawStep {
|
||||
DrawingFunctionCallback drawingCall; /**< Pointer to drawing function */
|
||||
Graphics::Surface* blitSrc;
|
||||
Graphics::TransparentSurface* blitAlphaSrc;
|
||||
Graphics::ManagedSurface *blitSrc;
|
||||
Graphics::TransparentSurface *blitAlphaSrc;
|
||||
|
||||
struct Color {
|
||||
uint8 r, g, b;
|
||||
@ -300,14 +300,14 @@ public:
|
||||
*
|
||||
* @param surface Pointer to a Surface object.
|
||||
*/
|
||||
virtual void setSurface(TransparentSurface *surface) {
|
||||
virtual void setSurface(ManagedSurface *surface) {
|
||||
_activeSurface = surface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently active drawing surface
|
||||
*/
|
||||
virtual TransparentSurface *getActiveSurface() {
|
||||
virtual ManagedSurface *getActiveSurface() {
|
||||
return _activeSurface;
|
||||
}
|
||||
|
||||
@ -515,14 +515,14 @@ public:
|
||||
* @param source Surface to blit into the drawing surface.
|
||||
* @param r Position in the active drawing surface to do the blitting.
|
||||
*/
|
||||
virtual void blitSurface(const Graphics::Surface *source, const Common::Rect &r) = 0;
|
||||
virtual void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) = 0;
|
||||
|
||||
/**
|
||||
* Blits a given graphics surface at the specified position of the current drawing surface.
|
||||
*/
|
||||
virtual void blitSubSurface(const Graphics::Surface *source, const Common::Point &p) = 0;
|
||||
virtual void blitSubSurface(const Graphics::ManagedSurface *source, const Common::Point &p) = 0;
|
||||
|
||||
virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) = 0;
|
||||
virtual void blitKeyBitmap(const Graphics::ManagedSurface *source, const Common::Point &p) = 0;
|
||||
|
||||
virtual void blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &p, bool themeTrans) = 0;
|
||||
|
||||
@ -554,7 +554,7 @@ public:
|
||||
virtual void applyScreenShading(GUI::ThemeEngine::ShadingStyle) = 0;
|
||||
|
||||
protected:
|
||||
TransparentSurface *_activeSurface; /**< Pointer to the surface currently being drawn */
|
||||
ManagedSurface *_activeSurface; /**< Pointer to the surface currently being drawn */
|
||||
|
||||
FillMode _fillMode; /**< Defines in which way (if any) are filled the drawn shapes */
|
||||
ShadowFillMode _shadowFillMode;
|
||||
|
@ -739,7 +739,7 @@ copyFrame(OSystem *sys, const Common::Rect &r) {
|
||||
|
||||
template<typename PixelType>
|
||||
void VectorRendererSpec<PixelType>::
|
||||
blitSurface(const Graphics::Surface *source, const Common::Rect &r) {
|
||||
blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) {
|
||||
assert(source->w == _activeSurface->w && source->h == _activeSurface->h);
|
||||
|
||||
byte *dst_ptr = (byte *)_activeSurface->getBasePtr(r.left, r.top);
|
||||
@ -760,7 +760,7 @@ blitSurface(const Graphics::Surface *source, const Common::Rect &r) {
|
||||
|
||||
template<typename PixelType>
|
||||
void VectorRendererSpec<PixelType>::
|
||||
blitSubSurface(const Graphics::Surface *source, const Common::Point &p) {
|
||||
blitSubSurface(const Graphics::ManagedSurface *source, const Common::Point &p) {
|
||||
Common::Rect drawRect(p.x, p.y, p.x + source->w, p.y + source->h);
|
||||
drawRect.clip(_clippingArea);
|
||||
|
||||
@ -851,7 +851,7 @@ blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &
|
||||
|
||||
template<typename PixelType>
|
||||
void VectorRendererSpec<PixelType>::
|
||||
blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) {
|
||||
blitKeyBitmap(const Graphics::ManagedSurface *source, const Common::Point &p) {
|
||||
Common::Rect drawRect(p.x, p.y, p.x + source->w, p.y + source->h);
|
||||
drawRect.clip(_clippingArea);
|
||||
|
||||
@ -891,7 +891,7 @@ void VectorRendererSpec<PixelType>::
|
||||
blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, GUI::ThemeEngine::AutoScaleMode autoscale,
|
||||
Graphics::DrawStep::VectorAlignment xAlign, Graphics::DrawStep::VectorAlignment yAlign, int alpha) {
|
||||
if (autoscale == GUI::ThemeEngine::kAutoScaleStretch) {
|
||||
source->blit(*_activeSurface, r.left, r.top, Graphics::FLIP_NONE,
|
||||
source->blit(*_activeSurface->surfacePtr(), r.left, r.top, Graphics::FLIP_NONE,
|
||||
nullptr, TS_ARGB(alpha, 255, 255, 255),
|
||||
r.width(), r.height());
|
||||
} else if (autoscale == GUI::ThemeEngine::kAutoScaleFit) {
|
||||
@ -908,15 +908,15 @@ blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, GUI
|
||||
if (yAlign == Graphics::DrawStep::kVectorAlignCenter)
|
||||
offy = (r.height() - (int)(source->h * ratio)) >> 1;
|
||||
|
||||
source->blit(*_activeSurface, r.left + offx, r.top + offy, Graphics::FLIP_NONE,
|
||||
source->blit(*_activeSurface->surfacePtr(), r.left + offx, r.top + offy, Graphics::FLIP_NONE,
|
||||
nullptr, TS_ARGB(alpha, 255, 255, 255),
|
||||
(int)(source->w * ratio), (int)(source->h * ratio));
|
||||
|
||||
} else if (autoscale == GUI::ThemeEngine::kAutoScaleNinePatch) {
|
||||
Graphics::NinePatchBitmap nine(source, false);
|
||||
nine.blit(*_activeSurface, r.left, r.top, r.width(), r.height());
|
||||
nine.blit(*_activeSurface->surfacePtr(), r.left, r.top, r.width(), r.height());
|
||||
} else {
|
||||
source->blit(*_activeSurface, r.left, r.top);
|
||||
source->blit(*_activeSurface->surfacePtr(), r.left, r.top);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,10 +88,10 @@ public:
|
||||
void copyWholeFrame(OSystem *sys) override { copyFrame(sys, Common::Rect(0, 0, _activeSurface->w, _activeSurface->h)); }
|
||||
|
||||
void fillSurface() override;
|
||||
void blitSurface(const Graphics::Surface *source, const Common::Rect &r) override;
|
||||
void blitSubSurface(const Graphics::Surface *source, const Common::Point &p) override;
|
||||
void blitSurface(const Graphics::ManagedSurface *source, const Common::Rect &r) override;
|
||||
void blitSubSurface(const Graphics::ManagedSurface *source, const Common::Point &p) override;
|
||||
void blitManagedSurface(const Graphics::ManagedSurface *source, const Common::Point &p, bool themeTrans) override;
|
||||
void blitKeyBitmap(const Graphics::Surface *source, const Common::Point &p) override;
|
||||
void blitKeyBitmap(const Graphics::ManagedSurface *source, const Common::Point &p) override;
|
||||
void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r,
|
||||
GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone,
|
||||
Graphics::DrawStep::VectorAlignment xAlign = Graphics::DrawStep::kVectorAlignManual,
|
||||
|
@ -249,7 +249,7 @@ ThemeEngine::~ThemeEngine() {
|
||||
|
||||
// Release all graphics surfaces
|
||||
for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) {
|
||||
Graphics::Surface *surf = i->_value;
|
||||
Graphics::ManagedSurface *surf = i->_value;
|
||||
if (surf) {
|
||||
surf->free();
|
||||
delete surf;
|
||||
@ -405,7 +405,7 @@ void ThemeEngine::refresh() {
|
||||
// Flush all bitmaps if the overlay pixel format changed.
|
||||
if (_overlayFormat != _system->getOverlayFormat()) {
|
||||
for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) {
|
||||
Graphics::Surface *surf = i->_value;
|
||||
Graphics::ManagedSurface *surf = i->_value;
|
||||
if (surf) {
|
||||
surf->free();
|
||||
delete surf;
|
||||
@ -708,7 +708,7 @@ bool ThemeEngine::addTextColor(TextColor colorId, int r, int g, int b) {
|
||||
|
||||
bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String &scalablefile, int width, int height) {
|
||||
// Nothing has to be done if the bitmap already has been loaded.
|
||||
Graphics::Surface *surf = _bitmaps[filename];
|
||||
Graphics::ManagedSurface *surf = _bitmaps[filename];
|
||||
if (surf) {
|
||||
surf->free();
|
||||
delete surf;
|
||||
@ -738,7 +738,7 @@ bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String
|
||||
}
|
||||
|
||||
if (srcSurface && srcSurface->format.bytesPerPixel != 1)
|
||||
surf = srcSurface->convertTo(_overlayFormat);
|
||||
surf = new Graphics::ManagedSurface(srcSurface->convertTo(_overlayFormat));
|
||||
#else
|
||||
error("No PNG support compiled in");
|
||||
#endif
|
||||
@ -759,7 +759,7 @@ bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String
|
||||
}
|
||||
|
||||
if (srcSurface && srcSurface->format.bytesPerPixel != 1)
|
||||
surf = srcSurface->convertTo(_overlayFormat);
|
||||
surf = new Graphics::ManagedSurface(srcSurface->convertTo(_overlayFormat));
|
||||
}
|
||||
|
||||
if (!scalablefile.empty()) {
|
||||
@ -780,12 +780,12 @@ bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String
|
||||
_bitmapDims[filename] = new Common::Point(width * _scaleFactor, height * _scaleFactor);
|
||||
|
||||
if (_scaleFactor != 1.0) {
|
||||
Graphics::Surface *tmp2 = surf->scale(surf->w * _scaleFactor, surf->h * _scaleFactor, false);
|
||||
Graphics::Surface *tmp2 = surf->rawSurface().scale(surf->w * _scaleFactor, surf->h * _scaleFactor, false);
|
||||
|
||||
surf->free();
|
||||
delete surf;
|
||||
|
||||
surf = tmp2;
|
||||
surf = new Graphics::ManagedSurface(tmp2);
|
||||
}
|
||||
// Store the surface into our hashmap (attention, may store NULL entries!)
|
||||
_bitmaps[filename] = surf;
|
||||
@ -1332,24 +1332,6 @@ void ThemeEngine::drawPopUpWidget(const Common::Rect &r, const Common::U32String
|
||||
}
|
||||
}
|
||||
|
||||
void ThemeEngine::drawSurface(const Common::Point &p, const Graphics::Surface &surface, bool themeTrans) {
|
||||
if (!ready())
|
||||
return;
|
||||
|
||||
if (_layerToDraw == kDrawLayerBackground)
|
||||
return;
|
||||
|
||||
_vectorRenderer->setClippingRect(_clip);
|
||||
if (themeTrans)
|
||||
_vectorRenderer->blitKeyBitmap(&surface, p);
|
||||
else
|
||||
_vectorRenderer->blitSubSurface(&surface, p);
|
||||
|
||||
Common::Rect dirtyRect = Common::Rect(p.x, p.y, p.x + surface.w, p.y + surface.h);
|
||||
dirtyRect.clip(_clip);
|
||||
addDirtyRect(dirtyRect);
|
||||
}
|
||||
|
||||
void ThemeEngine::drawSurface(const Common::Point &p, const Graphics::ManagedSurface &surface, bool themeTrans) {
|
||||
if (!ready())
|
||||
return;
|
||||
@ -1612,7 +1594,7 @@ void ThemeEngine::applyScreenShading(ShadingStyle style) {
|
||||
|
||||
bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int hotspotY) {
|
||||
// Try to locate the specified file among all loaded bitmaps
|
||||
const Graphics::Surface *cursor = _bitmaps[filename];
|
||||
const Graphics::ManagedSurface *cursor = _bitmaps[filename];
|
||||
if (!cursor)
|
||||
return false;
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "common/str.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/surface.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
#include "graphics/transparent_surface.h"
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
@ -202,7 +202,7 @@ private:
|
||||
|
||||
class ThemeEngine {
|
||||
protected:
|
||||
typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
|
||||
typedef Common::HashMap<Common::String, Graphics::ManagedSurface *> ImagesMap;
|
||||
typedef Common::HashMap<Common::String, Graphics::SVGBitmap *> SVGMap;
|
||||
typedef Common::HashMap<Common::String, Common::Point *> PointMap;
|
||||
typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
|
||||
@ -459,7 +459,6 @@ public:
|
||||
void drawDropDownButton(const Common::Rect &r, uint32 dropdownWidth, const Common::U32String &str,
|
||||
WidgetStateInfo buttonState, bool inButton, bool inDropdown, bool rtl = false);
|
||||
|
||||
void drawSurface(const Common::Point &p, const Graphics::Surface &surface, bool themeTrans = false);
|
||||
void drawSurface(const Common::Point &p, const Graphics::ManagedSurface &surface, bool themeTrans = false);
|
||||
|
||||
void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled, bool rtl = false);
|
||||
@ -640,7 +639,7 @@ public:
|
||||
return _bitmapDims.contains(name) ? _bitmapDims[name] : 0;
|
||||
}
|
||||
|
||||
Graphics::Surface *getImageSurface(const Common::String &name) const {
|
||||
Graphics::ManagedSurface *getImageSurface(const Common::String &name) const {
|
||||
return _bitmaps.contains(name) ? _bitmaps[name] : 0;
|
||||
}
|
||||
|
||||
@ -762,10 +761,10 @@ protected:
|
||||
GUI::ThemeEval *_themeEval;
|
||||
|
||||
/** Main screen surface. This is blitted straight into the overlay. */
|
||||
Graphics::TransparentSurface _screen;
|
||||
Graphics::ManagedSurface _screen;
|
||||
|
||||
/** Backbuffer surface. Stores previous states of the screen to blit back */
|
||||
Graphics::TransparentSurface _backBuffer;
|
||||
Graphics::ManagedSurface _backBuffer;
|
||||
|
||||
/**
|
||||
* Filter the submitted DrawData descriptors according to their layer attribute
|
||||
|
@ -85,7 +85,7 @@ RecorderDialog::RecorderDialog() : Dialog("RecorderDialog"), _list(nullptr), _cu
|
||||
_notesText = new StaticTextWidget(this, "RecorderDialog.Notes", _("Notes: "));
|
||||
}
|
||||
if (_gfxWidget)
|
||||
_gfxWidget->setGfx(nullptr);
|
||||
_gfxWidget->setGfx((Graphics::Surface *)nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -417,7 +417,7 @@ void SaveLoadChooserSimple::addThumbnailContainer() {
|
||||
|
||||
int SaveLoadChooserSimple::runIntern() {
|
||||
if (_gfxWidget)
|
||||
_gfxWidget->setGfx(nullptr);
|
||||
_gfxWidget->setGfx((Graphics::ManagedSurface *)nullptr);
|
||||
|
||||
_resultString.clear();
|
||||
reflowLayout();
|
||||
@ -1086,7 +1086,7 @@ void SaveLoadChooserGrid::destroyButtons() {
|
||||
|
||||
void SaveLoadChooserGrid::hideButtons() {
|
||||
for (ButtonArray::iterator i = _buttons.begin(), end = _buttons.end(); i != end; ++i) {
|
||||
i->button->setGfx(nullptr);
|
||||
i->button->setGfx((Graphics::ManagedSurface *)nullptr);
|
||||
i->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
@ -543,7 +543,7 @@ void DropdownButtonWidget::drawWidget() {
|
||||
|
||||
#pragma mark -
|
||||
|
||||
Graphics::Surface *scaleGfx(const Graphics::Surface *gfx, int w, int h) {
|
||||
Graphics::Surface *scaleGfx(const Graphics::ManagedSurface *gfx, int w, int h) {
|
||||
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
||||
Graphics::Surface tmp;
|
||||
|
||||
@ -586,7 +586,7 @@ PicButtonWidget::~PicButtonWidget() {
|
||||
_gfx[i].free();
|
||||
}
|
||||
|
||||
void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool scale) {
|
||||
void PicButtonWidget::setGfx(const Graphics::ManagedSurface *gfx, int statenum, bool scale) {
|
||||
_gfx[statenum].free();
|
||||
|
||||
if (!gfx || !gfx->getPixels())
|
||||
@ -599,7 +599,7 @@ void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool sc
|
||||
|
||||
float sf = g_gui.getScaleFactor();
|
||||
if (scale && sf != 1.0) {
|
||||
Graphics::Surface *tmp2 = gfx->scale(gfx->w * sf, gfx->h * sf, false);
|
||||
Graphics::Surface *tmp2 = gfx->rawSurface().scale(gfx->w * sf, gfx->h * sf, false);
|
||||
_gfx[statenum].copyFrom(*tmp2);
|
||||
tmp2->free();
|
||||
delete tmp2;
|
||||
@ -608,11 +608,15 @@ void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool sc
|
||||
}
|
||||
}
|
||||
|
||||
void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool scale) {
|
||||
setGfx(new Graphics::ManagedSurface(gfx), statenum, scale);
|
||||
}
|
||||
|
||||
void PicButtonWidget::setGfxFromTheme(const char *name, int statenum, bool scale) {
|
||||
Graphics::SVGBitmap *svg = g_gui.theme()->getSVG(name);
|
||||
|
||||
if (!svg) {
|
||||
const Graphics::Surface *gfx = g_gui.theme()->getImageSurface(name);
|
||||
const Graphics::ManagedSurface *gfx = g_gui.theme()->getImageSurface(name);
|
||||
|
||||
setGfx(gfx, statenum, scale);
|
||||
|
||||
@ -885,7 +889,7 @@ GraphicsWidget::~GraphicsWidget() {
|
||||
_gfx.free();
|
||||
}
|
||||
|
||||
void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
|
||||
void GraphicsWidget::setGfx(const Graphics::ManagedSurface *gfx) {
|
||||
_gfx.free();
|
||||
|
||||
if (!gfx || !gfx->getPixels())
|
||||
@ -906,6 +910,10 @@ void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
|
||||
setGfx(new Graphics::ManagedSurface(gfx));
|
||||
}
|
||||
|
||||
void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
|
||||
if (w == -1)
|
||||
w = _w;
|
||||
@ -923,7 +931,7 @@ void GraphicsWidget::setGfxFromTheme(const char *name) {
|
||||
Graphics::SVGBitmap *svg = g_gui.theme()->getSVG(name);
|
||||
|
||||
if (!svg) {
|
||||
const Graphics::Surface *gfx = g_gui.theme()->getImageSurface(name);
|
||||
const Graphics::ManagedSurface *gfx = g_gui.theme()->getImageSurface(name);
|
||||
|
||||
setGfx(gfx);
|
||||
|
||||
|
@ -289,6 +289,7 @@ public:
|
||||
PicButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0);
|
||||
~PicButtonWidget() override;
|
||||
|
||||
void setGfx(const Graphics::ManagedSurface *gfx, int statenum = kPicButtonStateEnabled, bool scale = true);
|
||||
void setGfx(const Graphics::Surface *gfx, int statenum = kPicButtonStateEnabled, bool scale = true);
|
||||
void setGfxFromTheme(const char *name, int statenum = kPicButtonStateEnabled, bool scale = true);
|
||||
void setGfx(int w, int h, int r, int g, int b, int statenum = kPicButtonStateEnabled);
|
||||
@ -420,6 +421,7 @@ public:
|
||||
GraphicsWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String());
|
||||
~GraphicsWidget() override;
|
||||
|
||||
void setGfx(const Graphics::ManagedSurface *gfx);
|
||||
void setGfx(const Graphics::Surface *gfx);
|
||||
void setGfx(int w, int h, int r, int g, int b);
|
||||
void setGfxFromTheme(const char *name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user