/// <summary> /// This is the method to use when removing a key in the editor. It will remove /// the corresponding KeyWrapper from the control. /// </summary> /// <param name="key"></param> public void RemoveKey(long id) { KeyWrapper wrapper = Control.Keys[id]; Control.Keys.Remove(wrapper); Curve.Keys.Remove(wrapper.Key); ComputeTangents(); }
public override void Undo() { KeyWrapper key = Control.Keys[affectedKey]; key.SetInTangent(prevTangentInValue); key.SetOutTangent(prevTangentOutValue); key.TangentInMode = prevTangentInMode; key.TangentOutMode = prevTangentOutMode; }
/// <summary> /// Performs the actual movement of the keys. /// </summary> private void ScaleKeys(Point newMin, Point newMax) { for (int i = 0; i < affectedKeys.Length; i++) { // Remap to the new box; Point newPosition = new Point((newMax.X - newMin.X) * normalizedPos[i].X + newMin.X, (newMax.Y - newMin.Y) * normalizedPos[i].Y + newMin.Y); KeyWrapper k = Control.Keys[affectedKeys[i]]; k.MoveKey((float)(newPosition.X - k.Key.Position), (float)(newPosition.Y - k.Key.Value)); } }
/// <summary> /// This is the method to use when adding a key in the editor. It will create /// the corresponding KeyWrapper and add it to the control. /// </summary> public KeyWrapper AddKey(CurveKey key, long id = -1) { Curve.Keys.Add(key); KeyWrapper newKey = new KeyWrapper(key, this, KeyTangentMode.Smooth, id); Control.Keys.Add(newKey); ComputeTangents(); return(newKey); }
/// <summary> /// Computes the tangents of all automatic keys. /// </summary> public void ComputeTangents() { for (int i = 0; i < Curve.Keys.Count; i++) { KeyWrapper wrapper = Control.GetWrapper(Curve.Keys[i]); if (wrapper != null) { wrapper.ComputeTangentIfAuto(); } } }
/// <summary> /// Performs the actual movement of the keys. /// </summary> private void ChangeTangent(float tangent) { KeyWrapper key = Control.Keys[affectedKey]; if (selectedTangent == TangentSelectionMode.In) { key.SetInTangent(tangent); } else { key.SetOutTangent(tangent); } }
/// <summary> /// Creates a new command to select the given keys. You can pass null to deselect all. /// </summary> public ChangeTangentCommand(CurveEditorControl2 control, long keyId, TangentSelectionMode selectedTangent) : base(control) { // Store the parameters. this.selectedTangent = selectedTangent; this.affectedKey = keyId; KeyWrapper key = control.Keys[keyId]; prevTangentInValue = key.Key.TangentIn; prevTangentOutValue = key.Key.TangentOut; prevTangentInMode = key.TangentInMode; prevTangentOutMode = key.TangentOutMode; }
/// <summary> /// Performs the actual movement of the keys. /// </summary> private void MoveKeys(float positionOffset, float valueOffset) { List <CurveWrapper> affectedCurves = new List <CurveWrapper>(); for (int i = 0; i < affectedKeys.Length; i++) { KeyWrapper key = Control.Keys[affectedKeys[i]]; key.MoveKey(positionOffset, valueOffset); // Create the set of curve affected by this move so we can recalculate // the auto tangents. if (!affectedCurves.Contains(key.Curve)) { affectedCurves.Add(key.Curve); } } // Compute all auto tangents. foreach (CurveWrapper curve in affectedCurves) { curve.ComputeTangents(); } }
/// <summary> /// This method is only to be used when undoing a RemoveKeys command. /// </summary> internal void RestoreKey(KeyWrapper key) { Curve.Keys.Add(key.Key); Control.Keys.Add(key); ComputeTangents(); }
/// <summary> /// This is the method to use when adding a key in the editor. It will create /// the corresponding KeyWrapper and add it to the control. /// </summary> public KeyWrapper AddKey(CurveKey key, long id = -1) { Curve.Keys.Add(key); var newKey = new KeyWrapper(key, this, KeyTangentMode.Smooth, id); Control.Keys.Add(newKey); ComputeTangents(); return newKey; }