mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-31 22:05:10 +02:00
Allow defining active areas for sliders. Fixes settings window.
This commit is contained in:
parent
34abc9f82d
commit
507d8bf7fd
@ -372,7 +372,15 @@ std::shared_ptr<CSlider> InterfaceObjectConfigurable::buildSlider(const JsonNode
|
|||||||
auto itemsTotal = config["itemsTotal"].Integer();
|
auto itemsTotal = config["itemsTotal"].Integer();
|
||||||
auto value = config["selected"].Integer();
|
auto value = config["selected"].Integer();
|
||||||
bool horizontal = config["orientation"].String() == "horizontal";
|
bool horizontal = config["orientation"].String() == "horizontal";
|
||||||
return std::make_shared<CSlider>(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal, style);
|
auto const & result = std::make_shared<CSlider>(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<CAnimImage> InterfaceObjectConfigurable::buildImage(const JsonNode & config) const
|
std::shared_ptr<CAnimImage> InterfaceObjectConfigurable::buildImage(const JsonNode & config) const
|
||||||
|
@ -575,7 +575,7 @@ void CSlider::mouseMoved (const Point & cursorPosition)
|
|||||||
v += 0.5;
|
v += 0.5;
|
||||||
if(v!=value)
|
if(v!=value)
|
||||||
{
|
{
|
||||||
moveTo((int)v);
|
moveTo(static_cast<int>(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,6 +584,16 @@ void CSlider::setScrollStep(int to)
|
|||||||
scrollStep = to;
|
scrollStep = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSlider::setScrollBounds(const Rect & bounds )
|
||||||
|
{
|
||||||
|
scrollBounds = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSlider::clearScrollBounds()
|
||||||
|
{
|
||||||
|
scrollBounds = boost::none;
|
||||||
|
}
|
||||||
|
|
||||||
int CSlider::getAmount() const
|
int CSlider::getAmount() const
|
||||||
{
|
{
|
||||||
return amount;
|
return amount;
|
||||||
@ -775,7 +785,19 @@ void CSlider::showAll(SDL_Surface * to)
|
|||||||
|
|
||||||
void CSlider::wheelScrolled(bool down, bool in)
|
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)
|
void CSlider::keyPressed(const SDL_Keycode & key)
|
||||||
|
@ -229,6 +229,8 @@ class CSlider : public CIntObject
|
|||||||
std::shared_ptr<CButton> right;
|
std::shared_ptr<CButton> right;
|
||||||
std::shared_ptr<CButton> slider;
|
std::shared_ptr<CButton> slider;
|
||||||
|
|
||||||
|
boost::optional<Rect> scrollBounds;
|
||||||
|
|
||||||
int capacity;//how many elements can be active at same time (e.g. hero list = 5)
|
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)
|
int positions; //number of highest position (0 if there is only one)
|
||||||
bool horizontal;
|
bool horizontal;
|
||||||
@ -252,6 +254,10 @@ public:
|
|||||||
/// Controls how many items wil be scrolled via one click
|
/// Controls how many items wil be scrolled via one click
|
||||||
void setScrollStep(int to);
|
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
|
/// Value modifiers
|
||||||
void moveLeft();
|
void moveLeft();
|
||||||
void moveRight();
|
void moveRight();
|
||||||
|
@ -147,7 +147,7 @@ GeneralOptionsTab::GeneralOptionsTab()
|
|||||||
musicVolumeLabel->setText(std::to_string(CCS->musich->getVolume()) + "%");
|
musicVolumeLabel->setText(std::to_string(CCS->musich->getVolume()) + "%");
|
||||||
|
|
||||||
std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
|
std::shared_ptr<CLabel> soundVolumeLabel = widget<CLabel>("soundValueLabel");
|
||||||
musicVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
|
soundVolumeLabel->setText(std::to_string(CCS->soundh->getVolume()) + "%");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +138,7 @@
|
|||||||
"name": "musicSlider",
|
"name": "musicSlider",
|
||||||
"type": "slider",
|
"type": "slider",
|
||||||
"position": {"x": 385, "y": 115},
|
"position": {"x": 385, "y": 115},
|
||||||
|
"scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 },
|
||||||
"size": 200,
|
"size": 200,
|
||||||
"style": "brown",
|
"style": "brown",
|
||||||
"orientation": "horizontal",
|
"orientation": "horizontal",
|
||||||
@ -165,6 +166,7 @@
|
|||||||
"name": "soundVolumeSlider",
|
"name": "soundVolumeSlider",
|
||||||
"type": "slider",
|
"type": "slider",
|
||||||
"position": {"x": 385, "y": 175},
|
"position": {"x": 385, "y": 175},
|
||||||
|
"scrollBounds" : { "x" : -4, "y" : -34, "w" : 208, "h" : 52 },
|
||||||
"size": 200,
|
"size": 200,
|
||||||
"style": "brown",
|
"style": "brown",
|
||||||
"orientation": "horizontal",
|
"orientation": "horizontal",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user