/// <summary> /// Implementation of <see cref="FilterManipulation"/> that forces the center of mass of the /// manipulation target to remain inside its container. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public static void ClampCenterOfMass(object sender, FilterManipulationEventArgs args) { var inputProcessor = sender as InputProcessor; var target = inputProcessor.Target; var container = inputProcessor.Reference; // Get the bounding box and the center of mass of the manipulation target, // expressed in the coordinate system of its container var rect = target.RenderTransform.TransformBounds( new Windows.Foundation.Rect(0, 0, target.ActualWidth, target.ActualHeight)); var centerOfMass = new Windows.Foundation.Point { X = rect.Left + (rect.Width / 2), Y = rect.Top + (rect.Height / 2) }; // Apply delta transform to the center of mass var transform = new Windows.UI.Xaml.Media.CompositeTransform { CenterX = args.Pivot.X, CenterY = args.Pivot.Y, Rotation = args.Delta.Rotation, ScaleX = args.Delta.Scale, ScaleY = args.Delta.Scale, TranslateX = args.Delta.Translation.X, TranslateY = args.Delta.Translation.Y }; var transformedCenterOfMass = transform.TransformPoint(centerOfMass); // Reset the transformation if the transformed center of mass falls outside the container if (transformedCenterOfMass.X < 0 || transformedCenterOfMass.X > container.ActualWidth || transformedCenterOfMass.Y < 0 || transformedCenterOfMass.Y > container.ActualHeight) { args.Delta = new Windows.UI.Input.ManipulationDelta { Rotation = 0F, Scale = 1F, Translation = new Windows.Foundation.Point(0, 0) }; } }
public void ResetManipulation() { // Reset previous transform to the initial transform of the element this._previousTransform = new Windows.UI.Xaml.Media.MatrixTransform() { Matrix = this._initialTransform.Matrix }; // Recreate delta transfrom. This way it is initalized to the identity transform. this._deltaTransform = new Windows.UI.Xaml.Media.CompositeTransform(); // The actual transform is obtained as the composition of the delta transform // with the previous transform this._transform = new Windows.UI.Xaml.Media.TransformGroup() { Children = { this._previousTransform, this._deltaTransform } }; // Set the element's transform this._target.RenderTransform = this._transform; }
/// <summary> /// Implementation of <see cref="FilterManipulation"/> that forces the center of mass of the /// manipulation target to remain inside its container. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public static void ClampCenterOfMass(object sender, Manipulations.FilterManipulationEventArgs args) { var inputProcessor = sender as Manipulations.InputProcessor; var target = inputProcessor.Target; var container = inputProcessor.Reference; // Get the bounding box and the center of mass of the manipulation target, // expressed in the coordinate system of its container var rect = target.RenderTransform.TransformBounds( new Windows.Foundation.Rect(0, 0, target.ActualWidth, target.ActualHeight)); var centerOfMass = new Windows.Foundation.Point { X = rect.Left + (rect.Width / 2), Y = rect.Top + (rect.Height / 2) }; // Apply delta transform to the center of mass var transform = new Windows.UI.Xaml.Media.CompositeTransform { CenterX = args.Pivot.X, CenterY = args.Pivot.Y, Rotation = args.Delta.Rotation, ScaleX = args.Delta.Scale, ScaleY = args.Delta.Scale, TranslateX = args.Delta.Translation.X, TranslateY = args.Delta.Translation.Y }; var transformedCenterOfMass = transform.TransformPoint(centerOfMass); // Reset the transformation if the transformed center of mass falls outside the container if (transformedCenterOfMass.X < 0 || transformedCenterOfMass.X > container.ActualWidth || transformedCenterOfMass.Y < 0 || transformedCenterOfMass.Y > container.ActualHeight) { args.Delta = new Windows.UI.Input.ManipulationDelta { Rotation = 0F, Scale = 1F, Translation = new Windows.Foundation.Point(0, 0) }; } }
public void ResetManipulation() { // Reset previous transform to the initial transform of the element this._previousTransform = new Windows.UI.Xaml.Media.MatrixTransform() { Matrix = this._initialTransform.Matrix }; this._deltaTransform = new Windows.UI.Xaml.Media.CompositeTransform(); this._transform = new Windows.UI.Xaml.Media.TransformGroup() { Children = { this._previousTransform, this._deltaTransform } }; // Set the element's transform this._target.RenderTransform = this._transform; }
public static void ClampCenterOfMass(object sender, FilterManipulationEventArgs args) { var inputProcessor = sender as InputProcessor; var target = inputProcessor.Target; var container = inputProcessor.Reference; var rect = target.RenderTransform.TransformBounds( new Windows.Foundation.Rect(0, 0, target.ActualWidth, target.ActualHeight)); var centerOfMass = new Windows.Foundation.Point { X = rect.Left + (rect.Width / 2), Y = rect.Top + (rect.Height / 2) }; var transform = new Windows.UI.Xaml.Media.CompositeTransform { CenterX = args.Pivot.X, CenterY = args.Pivot.Y, Rotation = args.Delta.Rotation, ScaleX = args.Delta.Scale, ScaleY = args.Delta.Scale, TranslateX = args.Delta.Translation.X, TranslateY = args.Delta.Translation.Y }; var transformedCenterOfMass = transform.TransformPoint(centerOfMass); if (transformedCenterOfMass.X < 0 || transformedCenterOfMass.X > container.ActualWidth || transformedCenterOfMass.Y < 0 || transformedCenterOfMass.Y > container.ActualHeight) { args.Delta = new Windows.UI.Input.ManipulationDelta { Rotation = 0F, Scale = 1F, Translation = new Windows.Foundation.Point(0, 0) }; } }