GUI: Added possibility to specify scale mode for AlphaBitmaps
This commit is contained in:
parent
38114eb760
commit
75f9b099dc
8 changed files with 45 additions and 37 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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, _state, _alpha, _transparency);
|
||||
g_gui.theme()->drawASurface(Common::Rect(x, y, x + _agfx.w, y + _agfx.h), _agfx, _mode);
|
||||
|
||||
} else {
|
||||
g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), _agfx, _mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue