aboutsummaryrefslogtreecommitdiff
path: root/gui/widget.cpp
diff options
context:
space:
mode:
authorMax Horn2002-12-12 23:21:29 +0000
committerMax Horn2002-12-12 23:21:29 +0000
commitf6de146c5ed9bd61956f343e1e68b15f9519c048 (patch)
treee9a8be52afe5e4d93eefbe55c68aa5258b5742d5 /gui/widget.cpp
parent307bb1048e5f33bb4c6862882adea3564cec5e4c (diff)
downloadscummvm-rg350-f6de146c5ed9bd61956f343e1e68b15f9519c048.tar.gz
scummvm-rg350-f6de146c5ed9bd61956f343e1e68b15f9519c048.tar.bz2
scummvm-rg350-f6de146c5ed9bd61956f343e1e68b15f9519c048.zip
changed the slider widget, better suited to represent volume settings this way (IMO)
svn-id: r5918
Diffstat (limited to 'gui/widget.cpp')
-rw-r--r--gui/widget.cpp28
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;
}