private static void RescaleWidgets(bool hullInFirstWidgetSpace, Vector2?pivotPoint, List <Widget> widgets, int controlPointIndex, Vector2 curMousePos, Vector2 prevMousePos, bool proportional, bool convertScaleToSize) { WidgetTransformsHelper.ApplyTransformationToWidgetsGroupObb( SceneView.Scene, widgets, pivotPoint, hullInFirstWidgetSpace, curMousePos, prevMousePos, convertScaleToSize, (originalVectorInObbSpace, deformedVectorInObbSpace) => { var deformationScaleInObbSpace = new Vector2d( Math.Abs(originalVectorInObbSpace.X) < Mathf.ZeroTolerance ? 1 : deformedVectorInObbSpace.X / originalVectorInObbSpace.X, Math.Abs(originalVectorInObbSpace.Y) < Mathf.ZeroTolerance ? 1 : deformedVectorInObbSpace.Y / originalVectorInObbSpace.Y ); if (!lookupInvolvedAxes[controlPointIndex][0]) { deformationScaleInObbSpace.X = proportional ? deformationScaleInObbSpace.Y : 1; } else if (!lookupInvolvedAxes[controlPointIndex][1]) { deformationScaleInObbSpace.Y = proportional ? deformationScaleInObbSpace.X : 1; } else if (proportional) { deformationScaleInObbSpace.X = (deformationScaleInObbSpace.X + deformationScaleInObbSpace.Y) / 2; deformationScaleInObbSpace.Y = deformationScaleInObbSpace.X; } return(new Transform2d(Vector2d.Zero, deformationScaleInObbSpace, 0)); } ); }
private void RotateWidgets(Vector2 pivotPoint, List<Widget> widgets, Vector2 curMousePos, Vector2 prevMousePos, bool snapped, List<Tuple<Widget, AccumulativeRotationHelper>> accumulativeRotationHelpers) { WidgetTransformsHelper.ApplyTransformationToWidgetsGroupObb( sv.Scene, widgets, widgets.Count <= 1 ? (Vector2?) null : pivotPoint, widgets.Count <= 1, curMousePos, prevMousePos, false, (originalVectorInObbSpace, deformedVectorInObbSpace) => { double rotation = 0; if (originalVectorInObbSpace.Length > Mathf.ZeroTolerance && deformedVectorInObbSpace.Length > Mathf.ZeroTolerance) { rotation = Mathd.Wrap180(deformedVectorInObbSpace.Atan2Deg - originalVectorInObbSpace.Atan2Deg); } if (snapped) { rotation = WidgetTransformsHelper.RoundTo(rotation, 15); } foreach (Tuple<Widget, AccumulativeRotationHelper> tuple in accumulativeRotationHelpers) { tuple.Item2.Rotate((float) rotation); } return new Transform2d(Vector2d.Zero, Vector2d.One, rotation); } ); foreach (Tuple<Widget, AccumulativeRotationHelper> tuple in accumulativeRotationHelpers) { SetAnimableProperty.Perform(tuple.Item1, nameof(Widget.Rotation), tuple.Item2.Rotation, CoreUserPreferences.Instance.AutoKeyframes); } }
private static IEnumerator <object> Drag() { var initialMousePos = SceneView.MousePosition; while ((SceneView.MousePosition - initialMousePos).Length <= Threshold && SceneView.Input.IsMousePressed()) { Utils.ChangeCursorIfDefault(MouseCursor.Hand); yield return(null); } if (!SceneView.Input.IsMousePressed()) { yield break; } if (SceneView.Input.IsKeyPressed(Key.Alt)) { Document.Current.History.DoTransaction(SceneView.DuplicateSelectedNodes); } using (Document.Current.History.BeginTransaction()) { var widgets = Document.Current.SelectedNodes().Editable().OfType <Widget>().ToList(); var dragDirection = DragDirection.Any; Utils.CalcHullAndPivot(widgets, Document.Current.Container.AsWidget, out _, out var pivot); while (SceneView.Input.IsMousePressed()) { Document.Current.History.RollbackTransaction(); Utils.ChangeCursorIfDefault(MouseCursor.Hand); var curMousePos = SceneView.MousePosition; var shiftPressed = SceneView.Input.IsKeyPressed(Key.Shift); if (shiftPressed) { switch (dragDirection) { case DragDirection.Horizontal: curMousePos.Y = initialMousePos.Y; break; case DragDirection.Vertical: curMousePos.X = initialMousePos.X; break; default: if ((curMousePos - initialMousePos).Length > 5 / SceneView.Scene.Scale.X) { var d = curMousePos - initialMousePos; dragDirection = d.X.Abs() > d.Y.Abs() ? DragDirection.Horizontal : DragDirection.Vertical; } break; } } else { dragDirection = DragDirection.Any; } var mouseDelta = curMousePos - initialMousePos; mouseDelta = mouseDelta.Snap(Vector2.Zero); var requiredSnap = SceneViewCommands.SnapWidgetPivotToRuler.Checked || SceneViewCommands.SnapWidgetBorderToRuler.Checked; if (mouseDelta != Vector2.Zero && requiredSnap) { var rulers = GetRulers(); foreach (var widget in widgets) { var points = new List <Vector2>(); if (SceneViewCommands.SnapWidgetPivotToRuler.Checked) { points.Add(widget.CalcPositionInSpaceOf(SceneView.Scene)); } if (SceneViewCommands.SnapWidgetBorderToRuler.Checked) { points.AddRange(widget.CalcHullInSpaceOf(SceneView.Scene)); } foreach (var point in points) { var pointMoved = point + mouseDelta; var pointSnapped = SnapPointToRulers(pointMoved, rulers); mouseDelta += pointSnapped - pointMoved; } } } Transform2d OnCalculateTransformation(Vector2d originalVectorInObbSpace, Vector2d deformedVectorInObbSpace) => new Transform2d((deformedVectorInObbSpace - originalVectorInObbSpace).Snap(Vector2d.Zero), Vector2d.One, 0); WidgetTransformsHelper.ApplyTransformationToWidgetsGroupObb( SceneView.Scene, widgets, widgets.Count <= 1 ? (Vector2?)null : pivot, widgets.Count <= 1, initialMousePos + mouseDelta, initialMousePos, false, OnCalculateTransformation ); yield return(null); } Document.Current.History.CommitTransaction(); SceneView.Input.ConsumeKey(Key.Mouse0); } }