[Scummvm-cvs-logs] CVS: scummvm/gui options.cpp,1.82,1.83 widget.cpp,1.48,1.49 widget.h,1.42,1.43

Max Horn fingolfin at users.sourceforge.net
Wed May 18 03:26:55 CEST 2005


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13717

Modified Files:
	options.cpp widget.cpp widget.h 
Log Message:
Remove the label code from SliderWidget (simplifies it a lot); instead use a StaticTextWidget for the label

Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- options.cpp	18 May 2005 10:12:20 -0000	1.82
+++ options.cpp	18 May 2005 10:24:02 -0000	1.83
@@ -407,19 +407,22 @@
 
 int OptionsDialog::addVolumeControls(GuiObject *boss, int yoffset) {
 	// Volume controllers
-	_musicVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "Music volume: ", 100, kMusicVolumeChanged);
+	new StaticTextWidget(boss, 5, yoffset + 2, 100, kLineHeight, "Music volume: ", kTextAlignRight);
+	_musicVolumeSlider = new SliderWidget(boss, 105, yoffset, 85, 12, kMusicVolumeChanged);
 	_musicVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
 	_musicVolumeSlider->setMinValue(0); _musicVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
 	_musicVolumeLabel->setFlags(WIDGET_CLEARBG);
 	yoffset += 16;
 
-	_sfxVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "SFX volume: ", 100, kSfxVolumeChanged);
+	new StaticTextWidget(boss, 5, yoffset + 2, 100, kLineHeight, "SFX volume: ", kTextAlignRight);
+	_sfxVolumeSlider = new SliderWidget(boss, 105, yoffset, 85, 12, kSfxVolumeChanged);
 	_sfxVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
 	_sfxVolumeSlider->setMinValue(0); _sfxVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
 	_sfxVolumeLabel->setFlags(WIDGET_CLEARBG);
 	yoffset += 16;
 
-	_speechVolumeSlider = new SliderWidget(boss, 5, yoffset, 185, 12, "Speech volume: ", 100, kSpeechVolumeChanged);
+	new StaticTextWidget(boss, 5, yoffset + 2, 100, kLineHeight, "Speech volume: ", kTextAlignRight);
+	_speechVolumeSlider = new SliderWidget(boss, 105, yoffset, 85, 12, kSpeechVolumeChanged);
 	_speechVolumeLabel = new StaticTextWidget(boss, 200, yoffset + 2, 24, kLineHeight, "100%", kTextAlignLeft);
 	_speechVolumeSlider->setMinValue(0); _speechVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
 	_speechVolumeLabel->setFlags(WIDGET_CLEARBG);

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- widget.cpp	18 May 2005 07:23:21 -0000	1.48
+++ widget.cpp	18 May 2005 10:24:02 -0000	1.49
@@ -236,17 +236,17 @@
 
 #pragma mark -
 
-SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, uint32 cmd, uint8 hotkey, WidgetSize ws)
-	: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey, ws),
-	  _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false),
-	  _labelWidth(labelWidth) {
+SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd)
+	: Widget(boss, x, y, w, h), CommandSender(boss),
+	  _cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false)
+	  {
 	_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
 	_type = kSliderWidget;
 }
 
 void SliderWidget::handleMouseMoved(int x, int y, int button) {
-	if (isEnabled() && _isDragging && x >= (int)_labelWidth) {
-		int newValue = posToValue(x - _labelWidth);
+	if (isEnabled() && _isDragging && x >= 0) {
+		int newValue = posToValue(x);
 		if (newValue < _valueMin)
 			newValue = _valueMin;
 		else if (newValue > _valueMax)
@@ -277,25 +277,21 @@
 void SliderWidget::drawWidget(bool hilite) {
 	NewGui *gui = &g_gui;
 
-	// Draw the label, if any
-	if (_labelWidth > 0)
-		gui->drawString(_font, _label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
-
 	// Draw the box
-	gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
+	gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
 
 	// Draw the 'bar'
-	gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4,
+	gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4,
 				!isEnabled() ? gui->_color :
 				hilite ? gui->_textcolorhi : gui->_textcolor);
 }
 
 int SliderWidget::valueToPos(int value) {
-	return ((_w - _labelWidth - 4) * (value - _valueMin) / (_valueMax - _valueMin));
+	return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin));
 }
 
 int SliderWidget::posToValue(int pos) {
-	return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
+	return (pos) * (_valueMax - _valueMin) / (_w - 4) + _valueMin;
 }
 
 #pragma mark -

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- widget.h	18 May 2005 07:23:21 -0000	1.42
+++ widget.h	18 May 2005 10:24:02 -0000	1.43
@@ -204,14 +204,19 @@
 };
 
 /* SliderWidget */
-class SliderWidget : public ButtonWidget {
+class SliderWidget : public Widget, public CommandSender {
 protected:
+	uint32	_cmd;
 	int		_value, _oldValue;
 	int		_valueMin, _valueMax;
 	bool	_isDragging;
 	uint	_labelWidth;
 public:
-	SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label = String::emptyString, uint labelWidth = 0, uint32 cmd = 0, uint8 hotkey = 0, WidgetSize ws = kDefaultWidgetSize);
+	SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd = 0);
+
+	void setCmd(uint32 cmd)		{ _cmd = cmd; }
+	uint32 getCmd() const		{ return _cmd; }
+
 	void setValue(int value)	{ _value = value; }
 	int getValue() const		{ return _value; }
 
@@ -223,6 +228,8 @@
 	void handleMouseMoved(int x, int y, int button);
 	void handleMouseDown(int x, int y, int button, int clickCount);
 	void handleMouseUp(int x, int y, int button, int clickCount);
+	void handleMouseEntered(int button)	{ setFlags(WIDGET_HILITED); draw(); }
+	void handleMouseLeft(int button)	{ clearFlags(WIDGET_HILITED); draw(); }
 
 protected:
 	void drawWidget(bool hilite);





More information about the Scummvm-git-logs mailing list