diff options
-rw-r--r-- | gui/widget.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp index b3c4aa4a58..9afb874524 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -202,16 +202,17 @@ void CheckboxWidget::drawWidget(bool hilite) SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey) : ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), - _value(0), _oldValue(1), _valueMin(0), _valueMax(100) + _value(0), _valueMin(0), _valueMax(100) { _flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG; _type = kSliderWidget; } -void SliderWidget::handleMouseMoved(int x, int y, int button) { +void SliderWidget::handleMouseMoved(int x, int y, int button) { + // TODO: when the mouse is dragged outside the widget, the slider should + // snap back to the old value. if (isEnabled() && _isDragging) { int newValue = posToValue(x); - if (newValue < _valueMin) newValue = _valueMin; else if (newValue > _valueMax) @@ -228,13 +229,8 @@ void SliderWidget::handleMouseMoved(int x, int y, int button) { void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) { if (isEnabled()) { - int barx; - - barx = valueToPos(_value); - - // only start dragging if mouse is over bar - if (x > (barx - 3) && x < (barx + 3)) - _isDragging = true; + _isDragging = true; + handleMouseMoved(x, y, button); } } @@ -254,22 +250,16 @@ void SliderWidget::drawWidget(bool hilite) // Draw the box gui->box(_x, _y, _w, _h); - // Remove old 'bar' if necessary - if (_value != _oldValue) { - gui->fillRect(_x + valueToPos(_oldValue), _y + 2, 2, _h - 4, gui->_bgcolor); - _oldValue = _value; - } - // Draw the 'bar' - gui->fillRect(_x + valueToPos(_value), _y + 2, 2, _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor); + gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor); } int SliderWidget::valueToPos(int value) { - return 2 + ((_w - 6) * (value - _valueMin) / (_valueMax - _valueMin)); + return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin)); } int SliderWidget::posToValue(int pos) { - return (pos - 2) * (_valueMax - _valueMin) / (_w - 6) + _valueMin; + return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin; } |