diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/options.cpp | 9 | ||||
-rw-r--r-- | gui/widget.cpp | 27 | ||||
-rw-r--r-- | gui/widget.h | 3 |
3 files changed, 21 insertions, 18 deletions
diff --git a/gui/options.cpp b/gui/options.cpp index 61c45c18f4..d2f282a087 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -125,22 +125,19 @@ GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector) // 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); diff --git a/gui/widget.cpp b/gui/widget.cpp index 2e7a502b08..451f74af5d 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -190,19 +190,20 @@ void CheckboxWidget::drawWidget(bool hilite) { // 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 @@ SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 c 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::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(_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; } diff --git a/gui/widget.h b/gui/widget.h index 8c8db73608..ae9e07d63e 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -190,8 +190,9 @@ protected: 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; } |