GUI: Implemented more modes to autoscale

This commit is contained in:
Eugene Sandulenko 2014-05-05 21:36:16 +03:00 committed by Alexander Tkachev
parent 4474ccf814
commit ec7312ac13
5 changed files with 32 additions and 11 deletions

View File

@ -68,6 +68,12 @@ struct DrawStep {
kVectorAlignCenter
};
enum AutoScaleMode {
kAutoScaleNone = 0,
kAutoScaleStretch = 1,
kAutoScaleFit = 2
};
VectorAlignment xAlign;
VectorAlignment yAlign;
@ -80,7 +86,7 @@ struct DrawStep {
uint32 scale; /**< scale of all the coordinates in FIXED POINT with 16 bits mantissa */
bool autoscale; /**< scale alphaimage if present */
Graphics::DrawStep::AutoScaleMode autoscale; /**< scale alphaimage if present */
DrawingFunctionCallback drawingCall; /**< Pointer to drawing function */
Graphics::Surface *blitSrc;
@ -495,7 +501,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, bool autoscale) = 0;
virtual void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale = Graphics::DrawStep::kAutoScaleNone) = 0;
/**
* Draws a string into the screen. Wrapper for the Graphics::Font string drawing

View File

@ -886,13 +886,25 @@ blitKeyBitmap(const Graphics::Surface *source, const Common::Rect &r) {
template<typename PixelType>
void VectorRendererSpec<PixelType>::
blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, bool autoscale) {
if (autoscale)
blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale) {
if (autoscale == Graphics::DrawStep::kAutoScaleStretch) {
source->blit(*_activeSurface, r.left, r.top, Graphics::FLIP_NONE,
nullptr, TS_ARGB(255, 255, 255, 255),
r.width(), r.height());
else
} else if (autoscale == Graphics::DrawStep::kAutoScaleFit) {
double ratio = (double)r.width() / source->w;
double ratio2 = (double)r.height() / source->h;
if (ratio2 < ratio)
ratio = ratio2;
source->blit(*_activeSurface, r.left, r.top, Graphics::FLIP_NONE,
nullptr, TS_ARGB(255, 255, 255, 255),
(int)(source->w * ratio), (int)(source->h * ratio));
} else {
source->blit(*_activeSurface, r.left, r.top);
}
}
template<typename PixelType>

View File

@ -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, bool autoscale);
void blitAlphaBitmap(Graphics::TransparentSurface *source, const Common::Rect &r, Graphics::DrawStep::AutoScaleMode autoscale = Graphics::DrawStep::kAutoScaleNone);
void applyScreenShading(GUI::ThemeEngine::ShadingStyle shadingStyle);

View File

@ -334,7 +334,7 @@ void ThemeItemABitmap::drawSelf(bool draw, bool restore) {
_engine->restoreBackground(_area);
if (draw)
_engine->renderer()->blitAlphaBitmap(_bitmap, _area, false);
_engine->renderer()->blitAlphaBitmap(_bitmap, _area);
_engine->addDirtyRect(_area);
}

View File

@ -468,10 +468,13 @@ bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawst
drawstep->blitAlphaSrc = _theme->getAlphaBitmap(stepNode->values["file"]);
if (stepNode->values.contains("autoscale") && stepNode->values["autoscale"] == "true")
drawstep->autoscale = true;
else
drawstep->autoscale = false;
if (stepNode->values.contains("autoscale"))
if (stepNode->values["autoscale"] == "true" || stepNode->values["autoscale"] == "stretch")
drawstep->autoscale = Graphics::DrawStep::kAutoScaleStretch;
else if (stepNode->values["autoscale"] == "fit")
drawstep->autoscale = Graphics::DrawStep::kAutoScaleFit;
else
drawstep->autoscale = Graphics::DrawStep::kAutoScaleNone;
if (!drawstep->blitAlphaSrc)
return parserError("The given filename hasn't been loaded into the GUI.");