aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorEugene Sandulenko2011-01-03 12:23:50 +0000
committerEugene Sandulenko2011-01-03 12:23:50 +0000
commit04a9082d0256597e61724e2418f388b61b4ba792 (patch)
treea76c7f5d3db82d37fcffdd4bd144cb419c99bc19 /gui
parente00c17712c142763d5fca42f5ebb69062f8648a3 (diff)
downloadscummvm-rg350-04a9082d0256597e61724e2418f388b61b4ba792.tar.gz
scummvm-rg350-04a9082d0256597e61724e2418f388b61b4ba792.tar.bz2
scummvm-rg350-04a9082d0256597e61724e2418f388b61b4ba792.zip
GUI: Implement PicButtonWidget
It is a button with picture intead of text. To be used by Hugo engine svn-id: r55099
Diffstat (limited to 'gui')
-rw-r--r--gui/widget.cpp48
-rw-r--r--gui/widget.h30
2 files changed, 78 insertions, 0 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp
index fc95526251..3f75c973d4 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -303,6 +303,54 @@ void ButtonWidget::drawWidget() {
#pragma mark -
+PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey)
+ : Widget(boss, x, y, w, h, tooltip), CommandSender(boss),
+ _cmd(cmd), _hotkey(hotkey), _gfx(), _alpha(256), _transparency(false) {
+
+ setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
+ _type = kButtonWidget;
+}
+
+PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
+ : Widget(boss, name, tooltip), CommandSender(boss),
+ _cmd(cmd), _gfx(), _alpha(256), _transparency(false) {
+ setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
+ _type = kButtonWidget;
+}
+
+void PicButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
+ if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
+ sendCommand(_cmd, 0);
+}
+
+void PicButtonWidget::setGfx(const Graphics::Surface *gfx) {
+ _gfx.free();
+
+ if (!gfx || !gfx->pixels)
+ return;
+
+ if (gfx->w > _w || gfx->h > _h) {
+ warning("PicButtonWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
+ return;
+ }
+
+ // TODO: add conversion to OverlayColor
+ _gfx.copyFrom(*gfx);
+}
+
+void PicButtonWidget::drawWidget() {
+ g_gui.theme()->drawButton(Common::Rect(_x, _y, _x+_w, _y+_h), "", _state, getFlags());
+
+ if (sizeof(OverlayColor) == _gfx.bytesPerPixel && _gfx.pixels) {
+ 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);
+ }
+}
+
+#pragma mark -
+
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey), _state(false) {
setFlags(WIDGET_ENABLED);
diff --git a/gui/widget.h b/gui/widget.h
index 92bfbf8256..544b9c7601 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -198,6 +198,36 @@ protected:
void drawWidget();
};
+/* PicButtonWidget */
+class PicButtonWidget : public Widget, public CommandSender {
+ friend class Dialog; // Needed for the hotkey handling
+protected:
+ uint32 _cmd;
+ uint8 _hotkey;
+public:
+ PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip = 0, uint32 cmd = 0, uint8 hotkey = 0);
+ PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip = 0, uint32 cmd = 0, uint8 hotkey = 0);
+
+ void setCmd(uint32 cmd) { _cmd = cmd; }
+ uint32 getCmd() const { return _cmd; }
+
+ void setGfx(const Graphics::Surface *gfx);
+
+ void useAlpha(int alpha) { _alpha = alpha; }
+ void useThemeTransparency(bool enable) { _transparency = enable; }
+
+ void handleMouseUp(int x, int y, int button, int clickCount);
+ void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
+ void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
+
+protected:
+ void drawWidget();
+
+ Graphics::Surface _gfx;
+ int _alpha;
+ bool _transparency;
+};
+
/* CheckboxWidget */
class CheckboxWidget : public ButtonWidget {
protected: