Skip to content

Commit

Permalink
[curve] Better handling of curves with maxTime
Browse files Browse the repository at this point in the history
  • Loading branch information
EspeuteClement committed Jan 24, 2025
1 parent af51fc4 commit 52bd891
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions hide/comp/CurveEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,9 @@ class CurveEditor extends hide.comp.Component {
if (c.selected || curves.length == 1) {
if(c.minValue < c.maxValue)
val = hxd.Math.clamp(val, c.minValue, c.maxValue);

c.addKey(time, val, c.keyMode);
c.selected = true;
var key = c.addKey(time, val, c.keyMode);
fixKey(key);
}

afterChange();
Expand Down Expand Up @@ -1211,7 +1212,26 @@ class CurveEditor extends hide.comp.Component {
this.duration = duration;

var minX = xt(0) - 1;
var maxX = xt(this.duration == 0 ? 5000 : this.duration);

var maxTime = this.duration == 0 ? 5000 : this.duration;
var curvesMaxTime = 0.0;

// Restrict the "time" to the max of the curves if all curves have a max time
// (usefull when editting Per instance values)
for (curve in curves) {
if (curve.maxTime > 0) {
curvesMaxTime = hxd.Math.max(curvesMaxTime, curve.maxTime);
} else {
curvesMaxTime = 0.0;
break;
}
}

if (curvesMaxTime > 0) {
maxTime = curvesMaxTime;
}

var maxX = xt(maxTime);
svg.line(overlayGroup, xt(1), svg.element.height(), xt(1), 0, { stroke:'#000000', 'stroke-width':'1px', 'stroke-dasharray':'10, 5' });
svg.line(overlayGroup, minX, svg.element.height(), minX, 0, { stroke:'#000000', 'stroke-width':'1px' });
svg.line(overlayGroup, maxX, svg.element.height(), maxX, 0, { stroke:'#000000', 'stroke-width':'1px' });
Expand Down

0 comments on commit 52bd891

Please sign in to comment.