Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curve: Prevent forcing 1.0 min value to 0.99 #29959

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions scene/resources/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Curve::Curve() {
_baked_cache_dirty = false;
_min_value = 0;
_max_value = 1;
_minmax_set_once = 0b00;
}

int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, TangentMode left_mode, TangentMode right_mode) {
Expand Down Expand Up @@ -282,20 +283,24 @@ void Curve::update_auto_tangents(int i) {
#define MIN_Y_RANGE 0.01

void Curve::set_min_value(float p_min) {
if (p_min > _max_value - MIN_Y_RANGE)
if (_minmax_set_once & 0b11 && p_min > _max_value - MIN_Y_RANGE) {
_min_value = _max_value - MIN_Y_RANGE;
else
} else {
_minmax_set_once |= 0b10; // first bit is "min set"
_min_value = p_min;
}
// Note: min and max are indicative values,
// it's still possible that existing points are out of range at this point.
emit_signal(SIGNAL_RANGE_CHANGED);
}

void Curve::set_max_value(float p_max) {
if (p_max < _min_value + MIN_Y_RANGE)
if (_minmax_set_once & 0b11 && p_max < _min_value + MIN_Y_RANGE) {
_max_value = _min_value + MIN_Y_RANGE;
else
} else {
_minmax_set_once |= 0b01; // second bit is "max set"
_max_value = p_max;
}
emit_signal(SIGNAL_RANGE_CHANGED);
}

Expand Down
1 change: 1 addition & 0 deletions scene/resources/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Curve : public Resource {
int _bake_resolution;
float _min_value;
float _max_value;
int _minmax_set_once; // Encodes whether min and max have been set a first time, first bit for min and second for max.
};

VARIANT_ENUM_CAST(Curve::TangentMode)
Expand Down