Browse Source

[curve] Better handling of curves with maxTime

Clément Espeute 7 months ago
parent
commit
52bd8913aa
1 changed files with 23 additions and 3 deletions
  1. 23 3
      hide/comp/CurveEditor.hx

+ 23 - 3
hide/comp/CurveEditor.hx

@@ -774,8 +774,9 @@ class CurveEditor extends hide.comp.Component {
 			if (c.selected || curves.length == 1) {
 			if (c.selected || curves.length == 1) {
 				if(c.minValue < c.maxValue)
 				if(c.minValue < c.maxValue)
 					val = hxd.Math.clamp(val, 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();
 		afterChange();
@@ -1211,7 +1212,26 @@ class CurveEditor extends hide.comp.Component {
 			this.duration = duration;
 			this.duration = duration;
 
 
 		var minX = xt(0) - 1;
 		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, 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, 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' });
 		svg.line(overlayGroup, maxX, svg.element.height(), maxX, 0, { stroke:'#000000', 'stroke-width':'1px' });