[Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.22,1.23 widget.h,1.20,1.21

Max Horn fingolfin at users.sourceforge.net
Fri Jul 26 16:30:03 CEST 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv26101

Modified Files:
	widget.cpp widget.h 
Log Message:
fixed slider

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- widget.cpp	26 Jul 2002 15:34:04 -0000	1.22
+++ widget.cpp	26 Jul 2002 23:29:43 -0000	1.23
@@ -190,7 +190,7 @@
 
 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 @@
 
 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::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))
@@ -246,4 +230,31 @@
 	}
 
 	_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;
 }

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- widget.h	26 Jul 2002 15:34:04 -0000	1.20
+++ widget.h	26 Jul 2002 23:29:43 -0000	1.21
@@ -170,7 +170,7 @@
 /* SliderWidget */
 class SliderWidget : public ButtonWidget {
 protected:
-	int		_value, _old_value;
+	int		_value, _oldValue;
 	int		_valueMin, _valueMax;
 	bool	_isDragging;
 public:
@@ -189,6 +189,9 @@
 
 protected:
 	void drawWidget(bool hilite);
+	
+	int valueToPos(int value);
+	int posToValue(int pos);
 };
 
 





More information about the Scummvm-git-logs mailing list