diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index 5cc58e86b..79b7de24c 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -372,7 +372,15 @@ std::shared_ptr InterfaceObjectConfigurable::buildSlider(const JsonNode auto itemsTotal = config["itemsTotal"].Integer(); auto value = config["selected"].Integer(); bool horizontal = config["orientation"].String() == "horizontal"; - return std::make_shared(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal, style); + auto const & result = std::make_shared(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal, style); + + if (!config["scrollBounds"].isNull()) + { + Rect bounds = readRect(config["scrollBounds"]); + result->setScrollBounds(bounds); + } + + return result; } std::shared_ptr InterfaceObjectConfigurable::buildImage(const JsonNode & config) const diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index a8c6eea15..c9d39c1e0 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -575,7 +575,7 @@ void CSlider::mouseMoved (const Point & cursorPosition) v += 0.5; if(v!=value) { - moveTo((int)v); + moveTo(static_cast(v)); } } @@ -584,6 +584,16 @@ void CSlider::setScrollStep(int to) scrollStep = to; } +void CSlider::setScrollBounds(const Rect & bounds ) +{ + scrollBounds = bounds; +} + +void CSlider::clearScrollBounds() +{ + scrollBounds = boost::none; +} + int CSlider::getAmount() const { return amount; @@ -775,7 +785,19 @@ void CSlider::showAll(SDL_Surface * to) void CSlider::wheelScrolled(bool down, bool in) { - moveTo(value + 3 * (down ? +scrollStep : -scrollStep)); + if (scrollBounds) + { + Rect testTarget = *scrollBounds + pos.topLeft(); + + if (!testTarget.isInside(GH.getCursorPosition())) + return; + } + + // vertical slider -> scrolling up move slider upwards + // horizontal slider -> scrolling up moves slider towards right + bool positive = (down != horizontal); + + moveTo(value + 3 * (positive ? +scrollStep : -scrollStep)); } void CSlider::keyPressed(const SDL_Keycode & key) diff --git a/client/widgets/Buttons.h b/client/widgets/Buttons.h index d698260be..da5677cef 100644 --- a/client/widgets/Buttons.h +++ b/client/widgets/Buttons.h @@ -229,6 +229,8 @@ class CSlider : public CIntObject std::shared_ptr right; std::shared_ptr slider; + boost::optional scrollBounds; + int capacity;//how many elements can be active at same time (e.g. hero list = 5) int positions; //number of highest position (0 if there is only one) bool horizontal; @@ -252,6 +254,10 @@ public: /// Controls how many items wil be scrolled via one click void setScrollStep(int to); + /// If set, mouse scroll will only scroll slider when inside of this area + void setScrollBounds(const Rect & bounds ); + void clearScrollBounds(); + /// Value modifiers void moveLeft(); void moveRight(); diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index da5886e1f..6430e73d0 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -147,7 +147,7 @@ GeneralOptionsTab::GeneralOptionsTab() musicVolumeLabel->setText(std::to_string(CCS->musich->getVolume()) + "%"); std::shared_ptr soundVolumeLabel = widget("soundValueLabel"); - musicVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%"); + soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%"); } diff --git a/config/widgets/settings/generalOptionsTab.json b/config/widgets/settings/generalOptionsTab.json index 15518c2d9..61ef7b146 100644 --- a/config/widgets/settings/generalOptionsTab.json +++ b/config/widgets/settings/generalOptionsTab.json @@ -138,6 +138,7 @@ "name": "musicSlider", "type": "slider", "position": {"x": 385, "y": 115}, + "scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 }, "size": 200, "style": "brown", "orientation": "horizontal", @@ -165,6 +166,7 @@ "name": "soundVolumeSlider", "type": "slider", "position": {"x": 385, "y": 175}, + "scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 }, "size": 200, "style": "brown", "orientation": "horizontal",