From 2a9cf65eeb305525c55c4d157ef8b1a104b8f7d7 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 28 Apr 2014 01:05:04 +0300 Subject: GUI: Add mode to skip drawing of button for PicButton --- gui/widget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index f2a29c3100..1d0247883c 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -398,7 +398,7 @@ void ButtonWidget::setUnpressedState() { PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, "", tooltip, cmd, hotkey), - _gfx(), _alpha(256), _transparency(false) { + _gfx(), _alpha(256), _transparency(false), _showButton(true) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; @@ -406,7 +406,7 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, name, "", tooltip, cmd, hotkey), - _gfx(), _alpha(256), _transparency(false) { + _gfx(), _alpha(256), _transparency(false), _showButton(true) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; } @@ -449,7 +449,8 @@ void PicButtonWidget::setGfx(int w, int h, int r, int g, int b) { } void PicButtonWidget::drawWidget() { - g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags()); + if (_showButton) + g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags()); if (_gfx.getPixels()) { // Check whether the set up surface needs to be converted to the GUI -- cgit v1.2.3 From 762671ccd841c5f54e4cf241a5372c26210b5865 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 2 May 2014 18:09:30 +0300 Subject: GUI: Added possibility to specify several state images for PicButtonWidget --- gui/widget.cpp | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index 1d0247883c..dfc0a5b50c 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -398,7 +398,7 @@ void ButtonWidget::setUnpressedState() { PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, "", tooltip, cmd, hotkey), - _gfx(), _alpha(256), _transparency(false), _showButton(true) { + _alpha(256), _transparency(false), _showButton(true) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; @@ -406,17 +406,18 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, name, "", tooltip, cmd, hotkey), - _gfx(), _alpha(256), _transparency(false), _showButton(true) { + _alpha(256), _transparency(false), _showButton(true) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; } PicButtonWidget::~PicButtonWidget() { - _gfx.free(); + for (int i = 0; i < kPicButtonStateMax + 1; i++) + _gfx[i].free(); } -void PicButtonWidget::setGfx(const Graphics::Surface *gfx) { - _gfx.free(); +void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum) { + _gfx[statenum].free(); if (!gfx || !gfx->getPixels()) return; @@ -432,10 +433,10 @@ void PicButtonWidget::setGfx(const Graphics::Surface *gfx) { return; } - _gfx.copyFrom(*gfx); + _gfx[statenum].copyFrom(*gfx); } -void PicButtonWidget::setGfx(int w, int h, int r, int g, int b) { +void PicButtonWidget::setGfx(int w, int h, int r, int g, int b, int statenum) { if (w == -1) w = _w; if (h == -1) @@ -443,27 +444,41 @@ void PicButtonWidget::setGfx(int w, int h, int r, int g, int b) { const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat(); - _gfx.free(); - _gfx.create(w, h, requiredFormat); - _gfx.fillRect(Common::Rect(0, 0, w, h), _gfx.format.RGBToColor(r, g, b)); + _gfx[statenum].free(); + _gfx[statenum].create(w, h, requiredFormat); + _gfx[statenum].fillRect(Common::Rect(0, 0, w, h), _gfx[statenum].format.RGBToColor(r, g, b)); } void PicButtonWidget::drawWidget() { if (_showButton) g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags()); - if (_gfx.getPixels()) { + Graphics::Surface *gfx; + + if (_state == ThemeEngine::kStateHighlight) + gfx = &_gfx[kPicButtonHighlight]; + else if (_state == ThemeEngine::kStateDisabled) + gfx = &_gfx[kPicButtonStateDisabled]; + else if (_state == ThemeEngine::kStatePressed) + gfx = &_gfx[kPicButtonStatePressed]; + else + gfx = &_gfx[kPicButtonStateEnabled]; + + if (!gfx) + gfx = &_gfx[kPicButtonStateEnabled]; + + if (gfx->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 (_gfx.format != requiredFormat) { - _gfx.convertToInPlace(requiredFormat); + if (gfx->format != requiredFormat) { + gfx->convertToInPlace(requiredFormat); } - const int x = _x + (_w - _gfx.w) / 2; - const int y = _y + (_h - _gfx.h) / 2; + const int x = _x + (_w - gfx->w) / 2; + 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); + g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + gfx->w, y + gfx->h), getBossClipRect(), *gfx, _state, _alpha, _transparency); } } -- cgit v1.2.3 From f0c52096f3e9215cb584b3862f2cd4b9632761d5 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 3 May 2014 02:50:47 +0300 Subject: GUI: Implemented possibility to use alphabitmaps in GraphicsWidget --- gui/widget.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gui/widget.cpp') 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); } } -- cgit v1.2.3 From 75f9b099dc3e198c7a1750a6e26ac4945719492f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 9 May 2014 19:00:49 +0300 Subject: GUI: Added possibility to specify scale mode for AlphaBitmaps --- gui/widget.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'gui/widget.cpp') 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); + } } } -- cgit v1.2.3 From 30f7556beed2de07caa338650a89f18b0b71cae5 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 May 2014 17:49:34 +0300 Subject: GUI: Added support for alphabitmaps in picbuttons --- gui/widget.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 19 deletions(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index d3de824fc5..ffdca7337b 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -402,13 +402,15 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; + _mode = ThemeEngine::kAutoScaleNone; } PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, name, "", tooltip, cmd, hotkey), - _alpha(256), _transparency(false), _showButton(true) { + _alpha(256), _transparency(false), _showButton(true), _isAlpha(false) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; + _mode = ThemeEngine::kAutoScaleNone; } PicButtonWidget::~PicButtonWidget() { @@ -436,6 +438,23 @@ void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum) { _gfx[statenum].copyFrom(*gfx); } +void PicButtonWidget::setAGfx(const Graphics::TransparentSurface *gfx, int statenum, ThemeEngine::AutoScaleMode mode) { + _agfx[statenum].free(); + + if (!gfx || !gfx->getPixels()) + return; + + if (gfx->format.bytesPerPixel == 1) { + warning("PicButtonWidget::setGfx got paletted surface passed"); + return; + } + + _agfx[statenum].copyFrom(*gfx); + + _isAlpha = true; + _mode = mode; +} + void PicButtonWidget::setGfx(int w, int h, int r, int g, int b, int statenum) { if (w == -1) w = _w; @@ -453,32 +472,60 @@ void PicButtonWidget::drawWidget() { if (_showButton) g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags()); - Graphics::Surface *gfx; + if (!_isAlpha) { + Graphics::Surface *gfx; - if (_state == ThemeEngine::kStateHighlight) - gfx = &_gfx[kPicButtonHighlight]; - else if (_state == ThemeEngine::kStateDisabled) - gfx = &_gfx[kPicButtonStateDisabled]; - else if (_state == ThemeEngine::kStatePressed) - gfx = &_gfx[kPicButtonStatePressed]; - else - gfx = &_gfx[kPicButtonStateEnabled]; + if (_state == ThemeEngine::kStateHighlight) + gfx = &_gfx[kPicButtonHighlight]; + else if (_state == ThemeEngine::kStateDisabled) + gfx = &_gfx[kPicButtonStateDisabled]; + else if (_state == ThemeEngine::kStatePressed) + gfx = &_gfx[kPicButtonStatePressed]; + else + gfx = &_gfx[kPicButtonStateEnabled]; - if (!gfx) - gfx = &_gfx[kPicButtonStateEnabled]; + if (!gfx->getPixels()) + gfx = &_gfx[kPicButtonStateEnabled]; - if (gfx->getPixels()) { + if (gfx->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 (gfx->format != requiredFormat) { - gfx->convertToInPlace(requiredFormat); + const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat(); + if (gfx->format != requiredFormat) { + gfx->convertToInPlace(requiredFormat); + } + + const int x = _x + (_w - gfx->w) / 2; + const int y = _y + (_h - gfx->h) / 2; + + g_gui.theme()->drawSurface(Common::Rect(x, y, x + gfx->w, y + gfx->h), *gfx, _state, _alpha, _transparency); } + } else { + Graphics::TransparentSurface *gfx; + + if (_state == ThemeEngine::kStateHighlight) + gfx = &_agfx[kPicButtonHighlight]; + else if (_state == ThemeEngine::kStateDisabled) + gfx = &_agfx[kPicButtonStateDisabled]; + else if (_state == ThemeEngine::kStatePressed) + gfx = &_agfx[kPicButtonStatePressed]; + else + gfx = &_agfx[kPicButtonStateEnabled]; - const int x = _x + (_w - gfx->w) / 2; - const int y = _y + (_h - gfx->h) / 2; + if (!gfx->getPixels()) + gfx = &_agfx[kPicButtonStateEnabled]; - g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + gfx->w, y + gfx->h), getBossClipRect(), *gfx, _state, _alpha, _transparency); + if (gfx->getPixels()) { + if (_mode == GUI::ThemeEngine::kAutoScaleNone) { + const int x = _x + (_w - gfx->w) / 2; + const int y = _y + (_h - gfx->h) / 2; + + g_gui.theme()->drawASurface(Common::Rect(x, y, x + gfx->w, y + gfx->h), *gfx, _mode); + + } else { + g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), *gfx, _mode); + } + } } } -- cgit v1.2.3 From 6524a8d103c87def348b9560418850cb48d24ce4 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 4 Aug 2014 01:12:49 +0200 Subject: GUI: Added transparency to PicWidgets --- gui/widget.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index ffdca7337b..fcfd0f8986 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -398,7 +398,7 @@ void ButtonWidget::setUnpressedState() { PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, "", tooltip, cmd, hotkey), - _alpha(256), _transparency(false), _showButton(true) { + _alpha(255), _transparency(false), _showButton(true) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; @@ -407,7 +407,7 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, name, "", tooltip, cmd, hotkey), - _alpha(256), _transparency(false), _showButton(true), _isAlpha(false) { + _alpha(255), _transparency(false), _showButton(true), _isAlpha(false) { setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); _type = kButtonWidget; _mode = ThemeEngine::kAutoScaleNone; @@ -520,10 +520,10 @@ void PicButtonWidget::drawWidget() { const int x = _x + (_w - gfx->w) / 2; const int y = _y + (_h - gfx->h) / 2; - g_gui.theme()->drawASurface(Common::Rect(x, y, x + gfx->w, y + gfx->h), *gfx, _mode); + g_gui.theme()->drawASurface(Common::Rect(x, y, x + gfx->w, y + gfx->h), *gfx, _mode, _alpha); } else { - g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), *gfx, _mode); + g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), *gfx, _mode, _alpha); } } } @@ -715,13 +715,13 @@ int SliderWidget::posToValue(int pos) { #pragma mark - GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip) - : Widget(boss, x, y, w, h, tooltip), _gfx(), _alpha(256), _transparency(false) { + : Widget(boss, x, y, w, h, tooltip), _gfx(), _alpha(255), _transparency(false) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG); _type = kGraphicsWidget; } GraphicsWidget::GraphicsWidget(GuiObject *boss, const Common::String &name, const char *tooltip) - : Widget(boss, name, tooltip), _gfx(), _alpha(256), _transparency(false) { + : Widget(boss, name, tooltip), _gfx(), _alpha(255), _transparency(false) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG); _type = kGraphicsWidget; } @@ -807,10 +807,10 @@ void GraphicsWidget::drawWidget() { 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, _mode, _alpha); } else { - g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), _agfx, _mode); + g_gui.theme()->drawASurface(Common::Rect(_x, _y, _x + _w, _y + _h), _agfx, _mode, _alpha); } } } -- cgit v1.2.3 From a686049c46387be53010357050bd252845a48d48 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 22 Jul 2016 11:15:58 +0300 Subject: GUI: Fix widget clipping --- gui/widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/widget.cpp') diff --git a/gui/widget.cpp b/gui/widget.cpp index fcfd0f8986..f6e6d09a8a 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -498,7 +498,7 @@ void PicButtonWidget::drawWidget() { const int x = _x + (_w - gfx->w) / 2; const int y = _y + (_h - gfx->h) / 2; - g_gui.theme()->drawSurface(Common::Rect(x, y, x + gfx->w, y + gfx->h), *gfx, _state, _alpha, _transparency); + g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + gfx->w, y + gfx->h), getBossClipRect(), *gfx, _state, _alpha, _transparency); } } else { Graphics::TransparentSurface *gfx; -- cgit v1.2.3