From 4c9761592a1b5a2958d778b3a5327ba2309f6bfb Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 18 May 2005 10:24:02 +0000 Subject: Remove the label code from SliderWidget (simplifies it a lot); instead use a StaticTextWidget for the label svn-id: r18163 --- gui/options.cpp | 9 ++++++--- gui/widget.cpp | 24 ++++++++++-------------- gui/widget.h | 11 +++++++++-- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/gui/options.cpp b/gui/options.cpp index 1b0a69185e..ca6ea27af8 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -407,19 +407,22 @@ int OptionsDialog::addMIDIControls(GuiObject *boss, int yoffset) { 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); diff --git a/gui/widget.cpp b/gui/widget.cpp index 53e8c48df6..08e485e596 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -236,17 +236,17 @@ void CheckboxWidget::drawWidget(bool hilite) { #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::handleMouseUp(int x, int y, int button, int clickCount) { 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 - diff --git a/gui/widget.h b/gui/widget.h index 58c16a7d14..430b53457d 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -204,14 +204,19 @@ protected: }; /* 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 @@ public: 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); -- cgit v1.2.3