aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2002-07-26 23:29:43 +0000
committerMax Horn2002-07-26 23:29:43 +0000
commitf831a948ded1886cdfce9b12b9e53a58ee5e01c1 (patch)
treec730c799284f66eb13cd335b417c468167ca4cf7 /gui
parente0f1d6c5aa5523d2f1035330c484b96b718da4c8 (diff)
downloadscummvm-rg350-f831a948ded1886cdfce9b12b9e53a58ee5e01c1.tar.gz
scummvm-rg350-f831a948ded1886cdfce9b12b9e53a58ee5e01c1.tar.bz2
scummvm-rg350-f831a948ded1886cdfce9b12b9e53a58ee5e01c1.zip
fixed slider
svn-id: r4646
Diffstat (limited to 'gui')
-rw-r--r--gui/widget.cpp61
-rw-r--r--gui/widget.h5
2 files changed, 40 insertions, 26 deletions
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 0989b86ec6..bb0e419d71 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -190,7 +190,7 @@ void CheckboxWidget::drawWidget(bool hilite)
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),
- _value(0), _old_value(1), _valueMin(0), _valueMax(100)
+ _value(0), _oldValue(1), _valueMin(0), _valueMax(100)
{
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
_type = kSliderWidget;
@@ -198,11 +198,12 @@ SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, const char
void SliderWidget::handleMouseMoved(int x, int y, int button) {
if (_isDragging) {
- int newValue = x * 100 / _w;
- if (newValue < 0)
- newValue = 0;
- else if (newValue > 100)
- newValue = 100;
+ int newValue = posToValue(x);
+
+ if (newValue < _valueMin)
+ newValue = _valueMin;
+ else if (newValue > _valueMax)
+ newValue = _valueMax;
if (newValue != _value) {
_value = newValue;
@@ -211,27 +212,10 @@ void SliderWidget::handleMouseMoved(int x, int y, int button) {
}
}
-void SliderWidget::drawWidget(bool hilite)
-{
- NewGui *gui = _boss->getGui();
-
- // Draw the box
- gui->box(_x, _y, _w, _h);
-
- // Remove old 'bar' if necessary
- if (_value != _old_value) {
- gui->fillRect(_x + 2 + ((_w - 5) * (_old_value - _valueMin) / (_valueMax - _valueMin)), _y + 2, 2, _h - 4, gui->_bgcolor);
- _old_value = _value;
- }
-
- // Draw the 'bar'
- gui->fillRect(_x + 2 + ((_w - 5) * (_value - _valueMin) / (_valueMax - _valueMin)), _y + 2, 2, _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
-}
-
void SliderWidget::handleMouseDown(int x, int y, int button) {
int barx;
-
- barx = 2 + ((_w - 5) * (_value - _valueMin) / (_valueMax - _valueMin));
+
+ barx = valueToPos(_value);
// only start dragging if mouse is over bar
if (x > (barx - 3) && x < (barx + 3))
@@ -247,3 +231,30 @@ void SliderWidget::handleMouseUp(int x, int y, int button) {
_isDragging = false;
}
+
+void SliderWidget::drawWidget(bool hilite)
+{
+ NewGui *gui = _boss->getGui();
+
+ // 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);
+}
+
+int SliderWidget::valueToPos(int value)
+{
+ return 2 + ((_w - 6) * (value - _valueMin) / (_valueMax - _valueMin));
+}
+
+int SliderWidget::posToValue(int pos)
+{
+ return (pos - 2) * (_valueMax - _valueMin) / (_w - 6) + _valueMin;
+}
diff --git a/gui/widget.h b/gui/widget.h
index af3a0dd854..380e00a23a 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -170,7 +170,7 @@ protected:
/* SliderWidget */
class SliderWidget : public ButtonWidget {
protected:
- int _value, _old_value;
+ int _value, _oldValue;
int _valueMin, _valueMax;
bool _isDragging;
public:
@@ -189,6 +189,9 @@ public:
protected:
void drawWidget(bool hilite);
+
+ int valueToPos(int value);
+ int posToValue(int pos);
};