ShiroSmith 4 سال پیش
والد
کامیت
e573b7c4b1
2فایلهای تغییر یافته به همراه20 افزوده شده و 12 حذف شده
  1. 6 6
      hide/comp/CurveEditor.hx
  2. 14 6
      hrt/prefab/Curve.hx

+ 6 - 6
hide/comp/CurveEditor.hx

@@ -286,14 +286,14 @@ class CurveEditor extends Component {
 	}
 
 	public function setYZoom(yMin: Float, yMax: Float) {
-		var margin = 20;
-		yScale = (height - margin*2) / (yMax - yMin);
-		yOffset = (yMax + yMin) / 2.0;
+		var margin = 20.0;
+		yScale = (height - margin * 2.0) / (yMax - yMin);
+		yOffset = (yMax + yMin) * 0.5;
 	}
 
 	public function setXZoom(xMin: Float, xMax: Float) {
-		var margin = 20;
-		xScale = (width - margin*2) / (xMax - xMin);
+		var margin = 10.0;
+		xScale = (width - margin * 2.0) / (xMax - xMin);
 		xOffset = xMin;
 	}
 
@@ -317,7 +317,7 @@ class CurveEditor extends Component {
 			setYZoom(bounds.yMin, bounds.yMax);
 		}
 		if(!lockViewX) {
-			setYZoom(bounds.xMax, bounds.xMax);
+			setXZoom(bounds.xMin, bounds.xMax);
 		}
 		saveView();
 	}

+ 14 - 6
hrt/prefab/Curve.hx

@@ -1,4 +1,5 @@
 package hrt.prefab;
+import hide.comp.CurveEditor;
 using Lambda;
 
 class CurveHandle {
@@ -69,6 +70,11 @@ class Curve extends Prefab {
 			loop = o.loop;
 		if(o.keyMode != null)
 			keyMode = o.keyMode;
+
+		if( keys.length == 0 ) {
+			addKey(0.0, 0.0);
+			addKey(1.0, 1.0);
+		}
 	}
 
 	public override function save() {
@@ -256,15 +262,17 @@ class Curve extends Prefab {
 	#if editor
 	override function edit( ctx : EditContext ) {
 		super.edit(ctx);
-
 		ctx.properties.add(new hide.Element('
-			<div class="group" name="Parameters">
-				<dl>
-					<dt>Loop curve</dt><dd><input type="checkbox" field="loop"/></dd>
-				</dl>
-			</div>'), this, function(pname) {
+		<div class="group" name="Parameters">
+			<dl>
+				<dt>Loop curve</dt><dd><input type="checkbox" field="loop"/></dd>
+			</dl>
+		</div>'), this, function(pname) {
 			ctx.onChange(this, pname);
 		});
+
+		var ce = new CurveEditor(ctx.properties.undo, ctx.properties.element);
+		ce.curve = this;
 	}
 
 	override function getHideProps() : HideProps {