aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graphics/VectorRenderer.h11
-rw-r--r--graphics/VectorRendererSpec.cpp10
-rw-r--r--graphics/VectorRendererSpec.h2
-rw-r--r--gui/ThemeEngine.cpp16
-rw-r--r--gui/ThemeEngine.h13
-rw-r--r--gui/ThemeParser.cpp11
-rw-r--r--gui/widget.cpp16
-rw-r--r--gui/widget.h3
8 files changed, 45 insertions, 37 deletions
diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h
index 0a83dc5d49..b79172931d 100644
--- a/graphics/VectorRenderer.h
+++ b/graphics/VectorRenderer.h
@@ -68,13 +68,6 @@ struct DrawStep {
kVectorAlignCenter
};
- enum AutoScaleMode {
- kAutoScaleNone = 0,
- kAutoScaleStretch = 1,
- kAutoScaleFit = 2,
- kAutoScaleNinePatch = 3
- };
-
VectorAlignment xAlign;
VectorAlignment yAlign;
@@ -87,7 +80,7 @@ struct DrawStep {
uint32 scale; /**< scale of all the coordinates in FIXED POINT with 16 bits mantissa */
- Graphics::DrawStep::AutoScaleMode autoscale; /**< scale alphaimage if present */
+ GUI::ThemeEngine::AutoScaleMode autoscale; /**< scale alphaimage if present */
DrawingFunctionCallback drawingCall; /**< Pointer to drawing function */
Graphics::Surface *blitSrc;
@@ -502,7 +495,7 @@ public:
virtual void blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r) = 0;
virtual void blitKeyBitmapClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) = 0;
- virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale = Graphics::DrawStep::kAutoScaleNone) = 0;
+ virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone) = 0;
/**
* Draws a string into the screen. Wrapper for the Graphics::Font string drawing
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp
index f3e496af70..0b947e4a0f 100644
--- a/graphics/VectorRendererSpec.cpp
+++ b/graphics/VectorRendererSpec.cpp
@@ -887,12 +887,12 @@ blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r) {
template<typename PixelType>
void VectorRendererSpec<PixelType>::
-blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale) {
- if (autoscale == Graphics::DrawStep::kAutoScaleStretch) {
+blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, GUI::ThemeEngine::AutoScaleMode autoscale) {
+ if (autoscale == GUI::ThemeEngine::kAutoScaleStretch) {
source->blit(*_activeSurface, r.left, r.top, Graphics::FLIP_NONE,
nullptr, TS_ARGB(255, 255, 255, 255),
- r.width(), r.height());
- } else if (autoscale == Graphics::DrawStep::kAutoScaleFit) {
+ r.width(), r.height());
+ } else if (autoscale == GUI::ThemeEngine::kAutoScaleFit) {
double ratio = (double)r.width() / source->w;
double ratio2 = (double)r.height() / source->h;
@@ -903,7 +903,7 @@ blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Gra
nullptr, TS_ARGB(255, 255, 255, 255),
(int)(source->w * ratio), (int)(source->h * ratio));
- } else if (autoscale == Graphics::DrawStep::kAutoScaleNinePatch) {
+ } else if (autoscale == GUI::ThemeEngine::kAutoScaleNinePatch) {
Graphics::NinePatchBitmap nine(source, false);
nine.blit(*_activeSurface, r.left, r.top, r.width(), r.height());
} else {
diff --git a/graphics/VectorRendererSpec.h b/graphics/VectorRendererSpec.h
index 50ee268d4d..f8c1e73c6c 100644
--- a/graphics/VectorRendererSpec.h
+++ b/graphics/VectorRendererSpec.h
@@ -95,7 +95,7 @@ public:
void blitSubSurfaceClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping);
void blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r);
void blitKeyBitmapClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping);
- void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale = Graphics::DrawStep::kAutoScaleNone);
+ void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, GUI::ThemeEngine::AutoScaleMode autoscale = GUI::ThemeEngine::kAutoScaleNone);
void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle);
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 26729b916f..57c2e5d870 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -172,14 +172,14 @@ protected:
class ThemeItemABitmap : public ThemeItem {
public:
- ThemeItemABitmap(ThemeEngine *engine, const Common::Rect &area, Graphics::TransparentSurface *bitmap, bool alpha) :
- ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha) {}
+ ThemeItemABitmap(ThemeEngine *engine, const Common::Rect &area, Graphics::TransparentSurface *bitmap, ThemeEngine::AutoScaleMode autoscale) :
+ ThemeItem(engine, area), _bitmap(bitmap), _autoscale(autoscale) {}
void drawSelf(bool draw, bool restore);
protected:
Graphics::TransparentSurface *_bitmap;
- bool _alpha;
+ ThemeEngine::AutoScaleMode _autoscale;
};
class ThemeItemBitmapClip : public ThemeItem {
@@ -334,7 +334,7 @@ void ThemeItemABitmap::drawSelf(bool draw, bool restore) {
_engine->restoreBackground(_area);
if (draw)
- _engine->renderer()->blitAlphaBitmap(_bitmap, _area);
+ _engine->renderer()->blitAlphaBitmap(_bitmap, _area, _autoscale);
_engine->addDirtyRect(_area);
}
@@ -1114,12 +1114,12 @@ void ThemeEngine::queueBitmap(const Graphics::Surface *bitmap, const Common::Rec
}
}
-void ThemeEngine::queueABitmap(Graphics::TransparentSurface *bitmap, const Common::Rect &r, bool alpha) {
+void ThemeEngine::queueABitmap(Graphics::TransparentSurface *bitmap, const Common::Rect &r, AutoScaleMode autoscale) {
Common::Rect area = r;
area.clip(_screen.w, _screen.h);
- ThemeItemABitmap *q = new ThemeItemABitmap(this, area, bitmap, alpha);
+ ThemeItemABitmap *q = new ThemeItemABitmap(this, area, bitmap, autoscale);
if (_buffering) {
_screenQueue.push_back(q);
@@ -1517,11 +1517,11 @@ void ThemeEngine::drawSurface(const Common::Rect &r, const Graphics::Surface &su
queueBitmap(&surface, r, themeTrans);
}
-void ThemeEngine::drawASurface(const Common::Rect &r, Graphics::TransparentSurface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
+void ThemeEngine::drawASurface(const Common::Rect &r, Graphics::TransparentSurface &surface, AutoScaleMode autoscale) {
if (!ready())
return;
- queueABitmap(&surface, r, themeTrans);
+ queueABitmap(&surface, r, autoscale);
}
void ThemeEngine::drawSurfaceClip(const Common::Rect &r, const Common::Rect &clip, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) {
diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h
index ccc5e03f92..625bab7a1b 100644
--- a/gui/ThemeEngine.h
+++ b/gui/ThemeEngine.h
@@ -225,6 +225,14 @@ public:
kShadingLuminance ///< Converting colors to luminance for unused areas
};
+ /// AlphaBitmap scale mode selector
+ enum AutoScaleMode {
+ kAutoScaleNone = 0, ///< Use image dimensions
+ kAutoScaleStretch = 1, ///< Stretch image to full widget size
+ kAutoScaleFit = 2, ///< Scale image to widget size but keep aspect ratio
+ kAutoScaleNinePatch = 3 ///< 9-patch image
+ };
+
// Special image ids for images used in the GUI
static const char *const kImageLogo; ///< ScummVM logo used in the launcher
static const char *const kImageLogoSmall; ///< ScummVM logo used in the GMM
@@ -355,8 +363,7 @@ public:
void drawSurfaceClip(const Common::Rect &r, const Common::Rect &clippingRect, const Graphics::Surface &surface,
WidgetStateInfo state = kStateEnabled, int alpha = 255, bool themeTrans = false);
- void drawASurface(const Common::Rect &r, Graphics::TransparentSurface &surface,
- WidgetStateInfo state = kStateEnabled, int alpha = 256, bool themeTrans = false);
+ void drawASurface(const Common::Rect &r, Graphics::TransparentSurface &surface, AutoScaleMode autoscale);
void drawSlider(const Common::Rect &r, int width,
WidgetStateInfo state = kStateEnabled);
@@ -637,7 +644,7 @@ protected:
bool elipsis, Graphics::TextAlign alignH = Graphics::kTextAlignLeft, TextAlignVertical alignV = kTextAlignVTop, int deltax = 0, const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
void queueBitmap(const Graphics::Surface *bitmap, const Common::Rect &r, bool alpha);
void queueBitmapClip(const Graphics::Surface *bitmap, const Common::Rect &clippingRect, const Common::Rect &r, bool alpha);
- void queueABitmap(Graphics::TransparentSurface *bitmap, const Common::Rect &r, bool alpha);
+ void queueABitmap(Graphics::TransparentSurface *bitmap, const Common::Rect &r, AutoScaleMode autoscale);
/**
* DEBUG: Draws a white square and writes some text next to it.
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index d4701c49f6..72a4d77560 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -468,16 +468,17 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst
drawstep->blitAlphaSrc = _theme->getAlphaBitmap(stepNode->values["file"]);
- if (stepNode->values.contains("autoscale"))
+ if (stepNode->values.contains("autoscale")) {
if (stepNode->values["autoscale"] == "true" || stepNode->values["autoscale"] == "stretch") {
- drawstep->autoscale = Graphics::DrawStep::kAutoScaleStretch;
+ drawstep->autoscale = ThemeEngine::kAutoScaleStretch;
} else if (stepNode->values["autoscale"] == "fit") {
- drawstep->autoscale = Graphics::DrawStep::kAutoScaleFit;
+ drawstep->autoscale = ThemeEngine::kAutoScaleFit;
} else if (stepNode->values["autoscale"] == "9patch") {
- drawstep->autoscale = Graphics::DrawStep::kAutoScaleNinePatch;
+ drawstep->autoscale = ThemeEngine::kAutoScaleNinePatch;
} else {
- drawstep->autoscale = Graphics::DrawStep::kAutoScaleNone;
+ drawstep->autoscale = ThemeEngine::kAutoScaleNone;
}
+ }
if (!drawstep->blitAlphaSrc)
return parserError("The given filename hasn't been loaded into the GUI.");
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 62a69d9540..d3de824fc5 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -702,7 +702,7 @@ void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
_gfx.copyFrom(*gfx);
}
-void GraphicsWidget::setAGfx(const Graphics::TransparentSurface *gfx) {
+void GraphicsWidget::setAGfx(const Graphics::TransparentSurface *gfx, ThemeEngine::AutoScaleMode mode) {
_agfx.free();
if (!gfx || !gfx->getPixels())
@@ -713,12 +713,13 @@ void GraphicsWidget::setAGfx(const Graphics::TransparentSurface *gfx) {
return;
}
- if (gfx->w > _w || gfx->h > _h) {
+ if ((gfx->w > _w || gfx->h > _h) && mode == ThemeEngine::kAutoScaleNone) {
warning("GraphicsWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
return;
}
_agfx.copyFrom(*gfx);
+ _mode = mode;
}
void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
@@ -755,10 +756,15 @@ void GraphicsWidget::drawWidget() {
_agfx.convertToInPlace(requiredFormat);
}
- const int x = _x + (_w - _agfx.w) / 2;
- const int y = _y + (_h - _agfx.h) / 2;
+ if (_mode == GUI::ThemeEngine::kAutoScaleNone) {
+ const int x = _x + (_w - _agfx.w) / 2;
+ const int y = _y + (_h - _agfx.h) / 2;
+
+ g_gui.theme()->drawASurface(Common::Rect(x, y, x + _agfx.w, y + _agfx.h), _agfx, _mode);
- g_gui.theme()->drawASurface(Common::Rect(x, y, x + _agfx.w, y + _agfx.h), _agfx, _state, _alpha, _transparency);
+ } else {
+ g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), _agfx, _mode);
+ }
}
}
diff --git a/gui/widget.h b/gui/widget.h
index 5e3eea73a0..e2e8bffa7e 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -362,7 +362,7 @@ public:
void setGfx(const Graphics::Surface *gfx);
void setGfx(int w, int h, int r, int g, int b);
- void setAGfx(const Graphics::TransparentSurface *gfx);
+ void setAGfx(const Graphics::TransparentSurface *gfx, ThemeEngine::AutoScaleMode mode = ThemeEngine::kAutoScaleNone);
void useAlpha(int alpha) { _alpha = alpha; }
void useThemeTransparency(bool enable) { _transparency = enable; }
@@ -374,6 +374,7 @@ protected:
Graphics::TransparentSurface _agfx;
int _alpha;
bool _transparency;
+ ThemeEngine::AutoScaleMode _mode;
};
/* ContainerWidget */