[Scummvm-cvs-logs] CVS: scummvm/gui widget.cpp,1.22,1.23 widget.h,1.27,1.28 options.cpp,1.30,1.31

Max Horn fingolfin at users.sourceforge.net
Sun Nov 2 16:44:07 CET 2003


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv7809/gui

Modified Files:
	widget.cpp widget.h options.cpp 
Log Message:
added built-in label for SliderWidget

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	2 Nov 2003 22:31:20 -0000	1.22
+++ widget.cpp	3 Nov 2003 00:43:29 -0000	1.23
@@ -190,19 +190,20 @@
 
 	// If checked, draw cross inside the box
 	if (_state)
-		gui->drawBitmap(checked_img, _x + 3, _y + 3, !isEnabled() ? gui->_color : gui->_textcolor);
+		gui->drawBitmap(checked_img, _x + 3, _y + 3, isEnabled() ? gui->_textcolor : gui->_color);
 	else
 		gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
 
 	// Finally draw the label
-	gui->drawString(_label, _x + 20, _y + 3, _w, !isEnabled() ? gui->_color : gui->_textcolor);
+	gui->drawString(_label, _x + 20, _y + 3, _w, isEnabled() ? gui->_textcolor : gui->_color);
 }
 
 #pragma mark -
 
-SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd, uint8 hotkey)
-	: ButtonWidget(boss, x, y, w, h, "", cmd, hotkey),
-	  _value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false) {
+SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, int labelWidth, uint32 cmd, uint8 hotkey)
+	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
+	  _value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false),
+	  _labelWidth(labelWidth) {
 	_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
 	_type = kSliderWidget;
 }
@@ -210,8 +211,8 @@
 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 (isEnabled() && _isDragging && x >= _labelWidth) {
+		int newValue = posToValue(x - _labelWidth);
 		if (newValue < _valueMin)
 			newValue = _valueMin;
 		else if (newValue > _valueMax)
@@ -242,17 +243,21 @@
 void SliderWidget::drawWidget(bool hilite) {
 	NewGui *gui = &g_gui;
 
+	// Draw the label, if any
+	if (_labelWidth > 0)
+		gui->drawString(_label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
+
 	// Draw the box
-	gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
+	gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
 
 	// Draw the 'bar'
-	gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
+	gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4, hilite ? gui->_textcolorhi : gui->_textcolor);
 }
 
 int SliderWidget::valueToPos(int value) {
-	return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin));
+	return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
 }
 
 int SliderWidget::posToValue(int pos) {
-	return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin;
+	return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
 }

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- widget.h	3 Nov 2003 00:17:12 -0000	1.27
+++ widget.h	3 Nov 2003 00:43:29 -0000	1.28
@@ -190,8 +190,9 @@
 	int		_value, _oldValue;
 	int		_valueMin, _valueMax;
 	bool	_isDragging;
+	int		_labelWidth;
 public:
-	SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd = 0, uint8 hotkey = 0);
+	SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label = String::emptyString, int labelWidth = 0, uint32 cmd = 0, uint8 hotkey = 0);
 	void setValue(int value)	{ _value = value; }
 	int getValue() const		{ return _value; }
 

Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- options.cpp	3 Nov 2003 00:27:18 -0000	1.30
+++ options.cpp	3 Nov 2003 00:43:29 -0000	1.31
@@ -125,22 +125,19 @@
 	// Volume controllers
 	int yoffset = vBorder + 16;
 
-	new StaticTextWidget(tab, 5, yoffset+2, 100, 16, "Master volume: ", kTextAlignRight);
-	_masterVolumeSlider = new SliderWidget(tab, 105, yoffset, 85, 12, kMasterVolumeChanged);
+	_masterVolumeSlider = new SliderWidget(tab, 5, yoffset, 185, 12,  "Master volume: ", 100, kMasterVolumeChanged);
 	_masterVolumeLabel = new StaticTextWidget(tab, 200, yoffset+2, 24, 16, "100%", kTextAlignLeft);
 	_masterVolumeSlider->setMinValue(0); _masterVolumeSlider->setMaxValue(255);
 	_masterVolumeLabel->setFlags(WIDGET_CLEARBG);
 	yoffset += 16;
 
-	new StaticTextWidget(tab, 5, yoffset+2, 100, 16, "Music volume: ", kTextAlignRight);
-	_musicVolumeSlider = new SliderWidget(tab, 105, yoffset, 85, 12, kMusicVolumeChanged);
+	_musicVolumeSlider = new SliderWidget(tab, 5, yoffset, 185, 12, "Music volume: ", 100, kMusicVolumeChanged);
 	_musicVolumeLabel = new StaticTextWidget(tab, 200, yoffset+2, 24, 16, "100%", kTextAlignLeft);
 	_musicVolumeSlider->setMinValue(0); _musicVolumeSlider->setMaxValue(255);
 	_musicVolumeLabel->setFlags(WIDGET_CLEARBG);
 	yoffset += 16;
 
-	new StaticTextWidget(tab, 5, yoffset+2, 100, 16, "SFX volume: ", kTextAlignRight);
-	_sfxVolumeSlider = new SliderWidget(tab, 105, yoffset, 85, 12, kSfxVolumeChanged);
+	_sfxVolumeSlider = new SliderWidget(tab, 5, yoffset, 185, 12, "SFX volume: ", 100, kSfxVolumeChanged);
 	_sfxVolumeLabel = new StaticTextWidget(tab, 200, yoffset+2, 24, 16, "100%", kTextAlignLeft);
 	_sfxVolumeSlider->setMinValue(0); _sfxVolumeSlider->setMaxValue(255);
 	_sfxVolumeLabel->setFlags(WIDGET_CLEARBG);





More information about the Scummvm-git-logs mailing list