public void ScaleAtBottom(double deltaInPixel) { var position = Mouse.GetPosition(CurveEditor); var bottomV = CurveEditor.yToV(position.Y); CurveEditor.DisableRebuildOnCurveChangeEvents(); if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) { var snapBottomValue = CurveEditor._ValueSnapHandler.CheckForSnapping(bottomV); if (!Double.IsNaN(snapBottomValue)) { bottomV = snapBottomValue; } } var scale = (bottomV - MinV) / (MaxV - MinV); if (!Double.IsNaN(scale) && Math.Abs(scale) < 10000) { var idx = 0; foreach (var ep in CurvePointsControls) { ep.ManipulateV(MinV + (ep.V - MinV) * scale); _addOrUpdateKeyframeCommands[idx].KeyframeValue = ep.m_vdef; ++idx; } _moveKeyframesCommand.Do(); } CurveEditor.EnableRebuildOnCurveChangeEvents(); UpdateShapeAndLines(); }
private void OnDragRightTangentDelta(object sender, DragDeltaEventArgs e) { CurveEditor.DisableRebuildOnCurveChangeEvents(); RightTangentPosition += new Vector(e.HorizontalChange, e.VerticalChange); var v = LimitWeightTanget(new Vector(Math.Max(RightTangentPosition.X, 0), RightTangentPosition.Y)); RightTangentPosition = new Point(v.X, v.Y); m_vdef.OutType = VDefinition.Interpolation.Spline; m_vdef.OutEditMode = VDefinition.EditMode.Tangent; double angleOut = Math.PI / 2 - Math.Atan2(CurveEditor.xToU(0.0) - CurveEditor.xToU(v.X), CurveEditor.yToV(0.0) - CurveEditor.yToV(v.Y)); m_vdef.OutTangentAngle = angleOut; if (Keyboard.Modifiers == ModifierKeys.Control) { m_vdef.BrokenTangents = true; } if (!m_vdef.BrokenTangents) { m_vdef.InType = VDefinition.Interpolation.Spline; m_vdef.InEditMode = VDefinition.EditMode.Tangent; LeftTangentPosition = new Point(-v.X, -v.Y); m_vdef.InTangentAngle = angleOut - Math.PI; } _addOrUpdateKeyframeCommand.KeyframeValue = m_vdef; _addOrUpdateKeyframeCommand.Do(); if (TV != null) { TV.TriggerRepaint(); } CurveEditor.EnableRebuildOnCurveChangeEvents(); CurveEditor.UpdateLine(Curve); }
private void OnDragDelta(object sender, DragDeltaEventArgs e) { var delta = new Vector(e.HorizontalChange, e.VerticalChange); double deltaU = CurveEditor.xToU(delta.X) - CurveEditor.xToU(0); double deltaV = CurveEditor.yToV(delta.Y) - CurveEditor.yToV(0); if (m_MoveDirection == MoveDirection.Undecided) { if (Math.Abs(delta.X) + Math.Abs(delta.Y) > DRAG_THRESHOLD) { if (Math.Abs(delta.X) > Math.Abs(delta.Y)) { m_MoveDirection = MoveDirection.Horizontal; XCenterThumb.Cursor = Cursors.ScrollWE; } else { m_MoveDirection = MoveDirection.Vertical; XCenterThumb.Cursor = Cursors.ScrollNS; } } } else { CurveEditor.DisableRebuildOnCurveChangeEvents(); if (m_MoveDirection == MoveDirection.Vertical) { V += deltaV; } if (m_MoveDirection == MoveDirection.Horizontal) { // Snap when pressing Shift if (TV != null && TV.TimeSnapHandler != null && Keyboard.Modifiers == ModifierKeys.Shift) { var snapU = TV.TimeSnapHandler.CheckForSnapping(U + deltaU); if (!Double.IsNaN(snapU)) { deltaU = snapU - U; } } // Prevent overwriting existing keys ManipulateU(U + deltaU); } switch (m_MoveDirection) { case MoveDirection.Vertical: _addOrUpdateKeyframeCommand.KeyframeValue = m_vdef; _addOrUpdateKeyframeCommand.Do(); break; case MoveDirection.Horizontal: _moveKeyframeCommand.NewTime = U; //_moveKeyframeCommand.Do(); break; } m_vdef = Curve.GetV(U); // since SetOrUpdateV clones vdef, we have to get a new value if (TV != null) { TV.TriggerRepaint(); } UpdateControlTangents(); CurveEditor.EnableRebuildOnCurveChangeEvents(); App.Current.UpdateRequiredAfterUserInteraction = true; CurveEditor.UpdateLine(Curve); //CurveEditor.UpdateEditBox(); } }