1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

fix stuck (press) slider w. clicking on empty area

This commit is contained in:
Laserlicht 2025-02-23 20:11:56 +01:00
parent bf77dd8a7f
commit eeef7efac5
4 changed files with 56 additions and 27 deletions

View File

@ -206,6 +206,11 @@ bool CButton::isHighlighted()
return getState() == EButtonState::HIGHLIGHTED; return getState() == EButtonState::HIGHLIGHTED;
} }
bool CButton::isPressed()
{
return getState() == EButtonState::PRESSED;
}
void CButton::setHoverable(bool on) void CButton::setHoverable(bool on)
{ {
hoverable = on; hoverable = on;

View File

@ -105,6 +105,7 @@ public:
/// State modifiers /// State modifiers
bool isBlocked(); bool isBlocked();
bool isHighlighted(); bool isHighlighted();
bool isPressed();
/// Constructor /// Constructor
CButton(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help, CButton(Point position, const AnimationPath & defName, const std::pair<std::string, std::string> & help,

View File

@ -21,6 +21,13 @@
void CSlider::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) void CSlider::mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance)
{ {
bool onControl = pos.isInside(cursorPosition) && !left->pos.isInside(cursorPosition) && !right->pos.isInside(cursorPosition);
if(!onControl && !slider->isPressed())
return;
if(onControl && !slider->isPressed())
slider->clickPressed(cursorPosition);
double newPosition = 0; double newPosition = 0;
if(getOrientation() == Orientation::HORIZONTAL) if(getOrientation() == Orientation::HORIZONTAL)
{ {
@ -129,10 +136,8 @@ void CSlider::scrollTo(int to, bool callCallbacks)
moved(getValue()); moved(getValue());
} }
void CSlider::clickPressed(const Point & cursorPosition) double CSlider::getClickPos(const Point & cursorPosition)
{ {
if(!slider->isBlocked())
{
double pw = 0; double pw = 0;
double rw = 0; double rw = 0;
if(getOrientation() == Orientation::HORIZONTAL) if(getOrientation() == Orientation::HORIZONTAL)
@ -146,27 +151,42 @@ void CSlider::clickPressed(const Point & cursorPosition)
rw = pw / (pos.h-48); rw = pw / (pos.h-48);
} }
return rw;
}
void CSlider::clickPressed(const Point & cursorPosition)
{
bool onControl = pos.isInside(cursorPosition) && !left->pos.isInside(cursorPosition) && !right->pos.isInside(cursorPosition);
if(!onControl)
return;
if(slider->isBlocked())
return;
// click on area covered by buttons -> ignore, will be handled by left/right buttons // click on area covered by buttons -> ignore, will be handled by left/right buttons
auto rw = getClickPos(cursorPosition);
if (!vstd::iswithin(rw, 0, 1)) if (!vstd::iswithin(rw, 0, 1))
return; return;
slider->clickPressed(cursorPosition); slider->clickPressed(cursorPosition);
scrollTo((int)(rw * positions + 0.5)); scrollTo((int)(rw * positions + 0.5));
}
void CSlider::clickReleased(const Point & cursorPosition)
{
if(slider->isBlocked())
return; return;
}
slider->clickReleased(cursorPosition);
} }
bool CSlider::receiveEvent(const Point &position, int eventType) const bool CSlider::receiveEvent(const Point &position, int eventType) const
{ {
if (eventType == LCLICK) if (eventType == LCLICK)
{ return true; //capture "clickReleased" also outside of control
return pos.isInside(position) && !left->pos.isInside(position) && !right->pos.isInside(position);
}
if(eventType != WHEEL && eventType != GESTURE) if(eventType != WHEEL && eventType != GESTURE)
{
return CIntObject::receiveEvent(position, eventType); return CIntObject::receiveEvent(position, eventType);
}
if (!scrollBounds) if (!scrollBounds)
return true; return true;

View File

@ -38,6 +38,8 @@ class CSlider : public Scrollable
void updateSliderPos(); void updateSliderPos();
double getClickPos(const Point & cursorPosition);
public: public:
enum EStyle enum EStyle
{ {
@ -71,6 +73,7 @@ public:
bool receiveEvent(const Point & position, int eventType) const override; bool receiveEvent(const Point & position, int eventType) const override;
void keyPressed(EShortcut key) override; void keyPressed(EShortcut key) override;
void clickPressed(const Point & cursorPosition) override; void clickPressed(const Point & cursorPosition) override;
void clickReleased(const Point & cursorPosition) override;
void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override; void mouseDragged(const Point & cursorPosition, const Point & lastUpdateDistance) override;
void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override; void gesturePanning(const Point & initialPosition, const Point & currentPosition, const Point & lastUpdateDistance) override;
void showAll(Canvas & to) override; void showAll(Canvas & to) override;