diff options
author | Jordi Vilalta Prat | 2008-12-23 23:36:38 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2008-12-23 23:36:38 +0000 |
commit | f75893a2940901493b7901bda15b796aeab3fd74 (patch) | |
tree | ae89248ecd096d2ab8e137413cf5f591aa037632 /gui | |
parent | 51c22d99050196c0ba528204e9db3609ae3e27ae (diff) | |
download | scummvm-rg350-f75893a2940901493b7901bda15b796aeab3fd74.tar.gz scummvm-rg350-f75893a2940901493b7901bda15b796aeab3fd74.tar.bz2 scummvm-rg350-f75893a2940901493b7901bda15b796aeab3fd74.zip |
Modify the SliderWidget value by using the mouse wheel
svn-id: r35513
Diffstat (limited to 'gui')
-rw-r--r-- | gui/widget.cpp | 24 | ||||
-rw-r--r-- | gui/widget.h | 1 |
2 files changed, 22 insertions, 3 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp index f8af13ccbc..ade68fd46d 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -309,16 +309,34 @@ void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) { _isDragging = false; } +void SliderWidget::handleMouseWheel(int x, int y, int direction) { + if (isEnabled() && !_isDragging) { + // Increment or decrement one position + int newValue = posToValue(valueToPos(_value) - 1 * direction); + + if (newValue < _valueMin) + newValue = _valueMin; + else if (newValue > _valueMax) + newValue = _valueMax; + + if (newValue != _value) { + _value = newValue; + draw(); + sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog + } + } +} + void SliderWidget::drawWidget() { - g_gui.theme()->drawSlider(Common::Rect(_x, _y, _x+_w, _y+_h), valueToPos(_value), _state); + g_gui.theme()->drawSlider(Common::Rect(_x, _y, _x + _w, _y + _h), valueToPos(_value) + 1, _state); } int SliderWidget::valueToPos(int value) { - return (_w * (value - _valueMin) / (_valueMax - _valueMin)); + return ((_w - 1) * (value - _valueMin + 1) / (_valueMax - _valueMin)); } int SliderWidget::posToValue(int pos) { - return (pos) * (_valueMax - _valueMin) / _w + _valueMin; + return (pos) * (_valueMax - _valueMin) / (_w - 1) + _valueMin; } #pragma mark - diff --git a/gui/widget.h b/gui/widget.h index a37ef5c7f4..39bf81b352 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -229,6 +229,7 @@ public: 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(); } + void handleMouseWheel(int x, int y, int direction); protected: void drawWidget(); |