add 'change-on-release' trackbar property & fix mouseRelease event timing
This commit is contained in:
parent
3fee1072b7
commit
8ca12127db
@ -131,7 +131,7 @@ void GUI::actMouse(float delta) {
|
||||
focus->defocus();
|
||||
focus = nullptr;
|
||||
}
|
||||
} else if (pressed) {
|
||||
} else if (!Events::clicked(mousecode::BUTTON_1) && pressed) {
|
||||
pressed->mouseRelease(this, Events::cursor.x, Events::cursor.y);
|
||||
pressed = nullptr;
|
||||
}
|
||||
|
||||
@ -60,11 +60,16 @@ void TrackBar::mouseMove(GUI*, int x, int) {
|
||||
value = (value < min) ? min : value;
|
||||
value = (int64_t)round(value / step) * step;
|
||||
|
||||
if (consumer) {
|
||||
if (consumer && !changeOnRelease) {
|
||||
consumer(value);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackBar::mouseRelease(GUI*, int, int) {
|
||||
if (consumer && changeOnRelease) {
|
||||
consumer(value);
|
||||
}
|
||||
}
|
||||
|
||||
double TrackBar::getValue() const {
|
||||
return value;
|
||||
@ -90,6 +95,10 @@ glm::vec4 TrackBar::getTrackColor() const {
|
||||
return trackColor;
|
||||
}
|
||||
|
||||
bool TrackBar::isChangeOnRelease() const {
|
||||
return changeOnRelease;
|
||||
}
|
||||
|
||||
void TrackBar::setValue(double x) {
|
||||
value = x;
|
||||
}
|
||||
@ -113,3 +122,7 @@ void TrackBar::setTrackWidth(int width) {
|
||||
void TrackBar::setTrackColor(glm::vec4 color) {
|
||||
trackColor = color;
|
||||
}
|
||||
|
||||
void TrackBar::setChangeOnRelease(bool flag) {
|
||||
changeOnRelease = flag;
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ namespace gui {
|
||||
double value;
|
||||
double step;
|
||||
int trackWidth;
|
||||
bool changeOnRelease = false;
|
||||
public:
|
||||
TrackBar(double min,
|
||||
double max,
|
||||
@ -26,6 +27,7 @@ namespace gui {
|
||||
virtual void setConsumer(doubleconsumer consumer);
|
||||
|
||||
virtual void mouseMove(GUI*, int x, int y) override;
|
||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||
|
||||
virtual double getValue() const;
|
||||
virtual double getMin() const;
|
||||
@ -33,6 +35,7 @@ namespace gui {
|
||||
virtual double getStep() const;
|
||||
virtual int getTrackWidth() const;
|
||||
virtual glm::vec4 getTrackColor() const;
|
||||
virtual bool isChangeOnRelease() const;
|
||||
|
||||
virtual void setValue(double);
|
||||
virtual void setMin(double);
|
||||
@ -40,6 +43,7 @@ namespace gui {
|
||||
virtual void setStep(double);
|
||||
virtual void setTrackWidth(int);
|
||||
virtual void setTrackColor(glm::vec4);
|
||||
virtual void setChangeOnRelease(bool);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -416,6 +416,9 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, const xml::xmle
|
||||
if (element->has("track-color")) {
|
||||
bar->setTrackColor(element->attr("track-color").asColor());
|
||||
}
|
||||
if (element->has("change-on-release")) {
|
||||
bar->setChangeOnRelease(element->attr("change-on-release").asBool());
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user