GUI: Added support for alphabitmaps in picbuttons
This commit is contained in:
parent
c6e04845cc
commit
30f7556bee
2 changed files with 70 additions and 19 deletions
|
@ -402,13 +402,15 @@ PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, co
|
||||||
|
|
||||||
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
||||||
_type = kButtonWidget;
|
_type = kButtonWidget;
|
||||||
|
_mode = ThemeEngine::kAutoScaleNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
|
PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
|
||||||
: ButtonWidget(boss, name, "", tooltip, cmd, 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);
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
||||||
_type = kButtonWidget;
|
_type = kButtonWidget;
|
||||||
|
_mode = ThemeEngine::kAutoScaleNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
PicButtonWidget::~PicButtonWidget() {
|
PicButtonWidget::~PicButtonWidget() {
|
||||||
|
@ -436,6 +438,23 @@ void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum) {
|
||||||
_gfx[statenum].copyFrom(*gfx);
|
_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) {
|
void PicButtonWidget::setGfx(int w, int h, int r, int g, int b, int statenum) {
|
||||||
if (w == -1)
|
if (w == -1)
|
||||||
w = _w;
|
w = _w;
|
||||||
|
@ -453,32 +472,60 @@ void PicButtonWidget::drawWidget() {
|
||||||
if (_showButton)
|
if (_showButton)
|
||||||
g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags());
|
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)
|
if (_state == ThemeEngine::kStateHighlight)
|
||||||
gfx = &_gfx[kPicButtonHighlight];
|
gfx = &_gfx[kPicButtonHighlight];
|
||||||
else if (_state == ThemeEngine::kStateDisabled)
|
else if (_state == ThemeEngine::kStateDisabled)
|
||||||
gfx = &_gfx[kPicButtonStateDisabled];
|
gfx = &_gfx[kPicButtonStateDisabled];
|
||||||
else if (_state == ThemeEngine::kStatePressed)
|
else if (_state == ThemeEngine::kStatePressed)
|
||||||
gfx = &_gfx[kPicButtonStatePressed];
|
gfx = &_gfx[kPicButtonStatePressed];
|
||||||
else
|
else
|
||||||
gfx = &_gfx[kPicButtonStateEnabled];
|
gfx = &_gfx[kPicButtonStateEnabled];
|
||||||
|
|
||||||
if (!gfx)
|
if (!gfx->getPixels())
|
||||||
gfx = &_gfx[kPicButtonStateEnabled];
|
gfx = &_gfx[kPicButtonStateEnabled];
|
||||||
|
|
||||||
if (gfx->getPixels()) {
|
if (gfx->getPixels()) {
|
||||||
// Check whether the set up surface needs to be converted to the GUI
|
// Check whether the set up surface needs to be converted to the GUI
|
||||||
// color format.
|
// color format.
|
||||||
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
||||||
if (gfx->format != requiredFormat) {
|
if (gfx->format != requiredFormat) {
|
||||||
gfx->convertToInPlace(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;
|
||||||
|
|
||||||
const int x = _x + (_w - gfx->w) / 2;
|
if (_state == ThemeEngine::kStateHighlight)
|
||||||
const int y = _y + (_h - gfx->h) / 2;
|
gfx = &_agfx[kPicButtonHighlight];
|
||||||
|
else if (_state == ThemeEngine::kStateDisabled)
|
||||||
|
gfx = &_agfx[kPicButtonStateDisabled];
|
||||||
|
else if (_state == ThemeEngine::kStatePressed)
|
||||||
|
gfx = &_agfx[kPicButtonStatePressed];
|
||||||
|
else
|
||||||
|
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())
|
||||||
|
gfx = &_agfx[kPicButtonStateEnabled];
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,7 @@ public:
|
||||||
~PicButtonWidget();
|
~PicButtonWidget();
|
||||||
|
|
||||||
void setGfx(const Graphics::Surface *gfx, int statenum = kPicButtonStateEnabled);
|
void setGfx(const Graphics::Surface *gfx, int statenum = kPicButtonStateEnabled);
|
||||||
|
void setAGfx(const Graphics::TransparentSurface *gfx, int statenum = kPicButtonStateEnabled, ThemeEngine::AutoScaleMode mode = ThemeEngine::kAutoScaleNone);
|
||||||
void setGfx(int w, int h, int r, int g, int b, int statenum = kPicButtonStateEnabled);
|
void setGfx(int w, int h, int r, int g, int b, int statenum = kPicButtonStateEnabled);
|
||||||
|
|
||||||
void useAlpha(int alpha) { _alpha = alpha; }
|
void useAlpha(int alpha) { _alpha = alpha; }
|
||||||
|
@ -241,9 +242,12 @@ protected:
|
||||||
void drawWidget();
|
void drawWidget();
|
||||||
|
|
||||||
Graphics::Surface _gfx[kPicButtonStateMax + 1];
|
Graphics::Surface _gfx[kPicButtonStateMax + 1];
|
||||||
|
Graphics::TransparentSurface _agfx[kPicButtonStateMax + 1];
|
||||||
int _alpha;
|
int _alpha;
|
||||||
bool _transparency;
|
bool _transparency;
|
||||||
bool _showButton;
|
bool _showButton;
|
||||||
|
bool _isAlpha;
|
||||||
|
ThemeEngine::AutoScaleMode _mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CheckboxWidget */
|
/* CheckboxWidget */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue