diff options
author | Eugene Sandulenko | 2014-05-03 02:50:47 +0300 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | f0c52096f3e9215cb584b3862f2cd4b9632761d5 (patch) | |
tree | dd16034089864033d71055e97f107f3c664250e7 | |
parent | 53a42ececfff48b93cef414bc2762806786da8d5 (diff) | |
download | scummvm-rg350-f0c52096f3e9215cb584b3862f2cd4b9632761d5.tar.gz scummvm-rg350-f0c52096f3e9215cb584b3862f2cd4b9632761d5.tar.bz2 scummvm-rg350-f0c52096f3e9215cb584b3862f2cd4b9632761d5.zip |
GUI: Implemented possibility to use alphabitmaps in GraphicsWidget
-rw-r--r-- | graphics/VectorRendererSpec.cpp | 2 | ||||
-rw-r--r-- | gui/ThemeEngine.cpp | 47 | ||||
-rw-r--r-- | gui/ThemeEngine.h | 8 | ||||
-rw-r--r-- | gui/widget.cpp | 31 | ||||
-rw-r--r-- | gui/widget.h | 2 |
5 files changed, 87 insertions, 3 deletions
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp index a50bb27c1a..e87397b349 100644 --- a/graphics/VectorRendererSpec.cpp +++ b/graphics/VectorRendererSpec.cpp @@ -888,7 +888,7 @@ template<typename PixelType> void VectorRendererSpec<PixelType>:: blitKeyBitmapClip(const Graphics::Surface *source, const Common::Rect &r, const Common::Rect &clipping) { if (clipping.isEmpty() || clipping.contains(r)) { - blitAlphaBitmap(source, r); + blitKeyBitmap(source, r); return; } diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 1a648b44a0..26729b916f 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -170,11 +170,22 @@ protected: bool _alpha; }; +class ThemeItemABitmap : public ThemeItem { +public: + ThemeItemABitmap(ThemeEngine *engine, const Common::Rect &area, Graphics::TransparentSurface *bitmap, bool alpha) : + ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha) {} + + void drawSelf(bool draw, bool restore); + +protected: + Graphics::TransparentSurface *_bitmap; + bool _alpha; +}; + class ThemeItemBitmapClip : public ThemeItem { public: ThemeItemBitmapClip(ThemeEngine *engine, const Common::Rect &area, const Common::Rect &clip, const Graphics::Surface *bitmap, bool alpha) : ThemeItem(engine, area), _bitmap(bitmap), _alpha(alpha), _clip(clip) {} - void drawSelf(bool draw, bool restore); protected: @@ -318,10 +329,20 @@ void ThemeItemBitmap::drawSelf(bool draw, bool restore) { _engine->addDirtyRect(_area); } -void ThemeItemBitmapClip::drawSelf(bool draw, bool restore) { +void ThemeItemABitmap::drawSelf(bool draw, bool restore) { if (restore) _engine->restoreBackground(_area); + if (draw) + _engine->renderer()->blitAlphaBitmap(_bitmap, _area); + + _engine->addDirtyRect(_area); +} + +void ThemeItemBitmapClip::drawSelf(bool draw, bool restore) { + if (restore) + _engine->restoreBackground(_area); + if (draw) { if (_alpha) _engine->renderer()->blitKeyBitmapClip(_bitmap, _area, _clip); @@ -1093,6 +1114,21 @@ void ThemeEngine::queueBitmap(const Graphics::Surface *bitmap, const Common::Rec } } +void ThemeEngine::queueABitmap(Graphics::TransparentSurface *bitmap, const Common::Rect &r, bool alpha) { + + Common::Rect area = r; + area.clip(_screen.w, _screen.h); + + ThemeItemABitmap *q = new ThemeItemABitmap(this, area, bitmap, alpha); + + if (_buffering) { + _screenQueue.push_back(q); + } else { + q->drawSelf(true, false); + delete q; + } +} + void ThemeEngine::queueBitmapClip(const Graphics::Surface *bitmap, const Common::Rect &r, const Common::Rect &clip, bool alpha) { Common::Rect area = r; @@ -1481,6 +1517,13 @@ 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) { + if (!ready()) + return; + + queueABitmap(&surface, r, themeTrans); +} + void ThemeEngine::drawSurfaceClip(const Common::Rect &r, const Common::Rect &clip, const Graphics::Surface &surface, WidgetStateInfo state, int alpha, bool themeTrans) { if (!ready()) return; diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index 92aafc8975..ccc5e03f92 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -355,6 +355,9 @@ 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 drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled); void drawSliderClip(const Common::Rect &r, const Common::Rect &clippingRect, int width, @@ -544,6 +547,10 @@ public: return _bitmaps.contains(name) ? _bitmaps[name] : 0; } + const Graphics::TransparentSurface *getAImageSurface(const Common::String &name) const { + return _abitmaps.contains(name) ? _abitmaps[name] : 0; + } + /** * Interface for the Theme Parser: Creates a new cursor by loading the given * bitmap and sets it as the active cursor. @@ -630,6 +637,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); /** * DEBUG: Draws a white square and writes some text next to it. diff --git a/gui/widget.cpp b/gui/widget.cpp index dfc0a5b50c..62a69d9540 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -702,6 +702,25 @@ void GraphicsWidget::setGfx(const Graphics::Surface *gfx) { _gfx.copyFrom(*gfx); } +void GraphicsWidget::setAGfx(const Graphics::TransparentSurface *gfx) { + _agfx.free(); + + if (!gfx || !gfx->getPixels()) + return; + + if (gfx->format.bytesPerPixel == 1) { + warning("GraphicsWidget::setGfx got paletted surface passed"); + return; + } + + if (gfx->w > _w || gfx->h > _h) { + 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); +} + void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) { if (w == -1) w = _w; @@ -728,6 +747,18 @@ void GraphicsWidget::drawWidget() { const int y = _y + (_h - _gfx.h) / 2; g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + _gfx.w, y + _gfx.h), getBossClipRect(), _gfx, _state, _alpha, _transparency); + } else if (_agfx.getPixels()) { + // Check whether the set up surface needs to be converted to the GUI + // color format. + const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat(); + if (_agfx.format != requiredFormat) { + _agfx.convertToInPlace(requiredFormat); + } + + 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); } } diff --git a/gui/widget.h b/gui/widget.h index d7b4c7b6f2..5e3eea73a0 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -362,6 +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 useAlpha(int alpha) { _alpha = alpha; } void useThemeTransparency(bool enable) { _transparency = enable; } @@ -370,6 +371,7 @@ protected: void drawWidget(); Graphics::Surface _gfx; + Graphics::TransparentSurface _agfx; int _alpha; bool _transparency; }; |