diff options
author | James Brown | 2002-07-08 13:52:50 +0000 |
---|---|---|
committer | James Brown | 2002-07-08 13:52:50 +0000 |
commit | 7be66a5f0531a6bf183ee53a6d5b575d3815261e (patch) | |
tree | cd9685d9514ca567b9d0d8db0e8b4d01feddebbe /gui | |
parent | 0ea6fac17425829dedb940597d0d461407dbb6ad (diff) | |
download | scummvm-rg350-7be66a5f0531a6bf183ee53a6d5b575d3815261e.tar.gz scummvm-rg350-7be66a5f0531a6bf183ee53a6d5b575d3815261e.tar.bz2 scummvm-rg350-7be66a5f0531a6bf183ee53a6d5b575d3815261e.zip |
Add slider widget
svn-id: r4496
Diffstat (limited to 'gui')
-rw-r--r-- | gui/dialog.cpp | 8 | ||||
-rw-r--r-- | gui/widget.cpp | 30 | ||||
-rw-r--r-- | gui/widget.h | 16 |
3 files changed, 54 insertions, 0 deletions
diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 682a36fb2c..7bfd85c2e6 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -67,12 +67,17 @@ void Dialog::handleKey(char key, int modifiers) void Dialog::handleMouseMoved(int x, int y, int button) { Widget *w = findWidget(x - _x, y - _y); + if (!w) + return; + if (_mouseWidget != w) { if (_mouseWidget) _mouseWidget->handleMouseLeft(button); if (w) w->handleMouseEntered(button); _mouseWidget = w; + } else if (w->getFlags() & WIDGET_TRACK_MOUSE) { + w->handleMouseMoved(x - _x - w->_x, y - _y - w->_y, button); } } @@ -147,6 +152,9 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui) // FIXME - test new CheckboxWidget(this, 50, 20, 100, 16, "Toggle me", 0); + + // FIXME - test + new SliderWidget(this, 50, 50, 100, 16, "Volume", 0); } void SaveLoadDialog::handleCommand(uint32 cmd) diff --git a/gui/widget.cpp b/gui/widget.cpp index cb3fce0ed5..dc65a1422a 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -153,3 +153,33 @@ void CheckboxWidget::drawWidget(bool hilite) // Finally draw the label gui->drawString(_text, _x + 20, _y + 3, _w, gui->_textcolor); } + +#pragma mark - +SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd, uint8 hotkey) + : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey) +{ + _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE; + _type = kSliderWidget; +} + +void SliderWidget::drawWidget(bool hilite) +{ + NewGui *gui = _boss->getGui(); + + // Draw the box + gui->box(_x, _y, _w, _h); + + // Draw the 'bar' + gui->line(_x + 2 + ((_w - 5)* _value / 100), _y + 2, _x + 2 + ((_w - 5)* _value / 100), _y + _h - 3, hilite ? gui->_textcolorhi : gui->_textcolor); +} + +void SliderWidget::handleMouseMoved(int x, int y, int state) { + if (state == 1) { + int newvalue = x * 100 / _w; + + if (newvalue != _value) { + _value = newvalue; + setFlags(WIDGET_CLEARBG); draw(); clearFlags(WIDGET_CLEARBG); + } + } +}
\ No newline at end of file diff --git a/gui/widget.h b/gui/widget.h index 0e8e15cce7..afcf19011f 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -33,12 +33,14 @@ enum { WIDGET_BORDER = 1 << 3, WIDGET_CLEARBG = 1 << 4, WIDGET_WANT_TICKLE = 1 << 5, + WIDGET_TRACK_MOUSE = 1 << 6 }; enum { kStaticTextWidget = 'TEXT', kButtonWidget = 'BTTN', kCheckboxWidget = 'CHKB', + kSliderWidget = 'SLDE' }; /* Widget */ @@ -58,6 +60,7 @@ public: virtual void handleClick(int button) {} virtual void handleMouseEntered(int button) {} virtual void handleMouseLeft(int button) {} + virtual void handleMouseMoved(int x, int y, int button) {} void draw(); void setFlags(int flags) { _flags |= flags; } @@ -116,5 +119,18 @@ protected: void drawWidget(bool hilite); }; +/* SliderWidget */ +class SliderWidget : public ButtonWidget { +protected: + int _value; +public: + SliderWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd = 0, uint8 hotkey = 0); + void handleMouseMoved(int x, int y, int button); + +protected: + void drawWidget(bool hilite); +}; + + #endif |