protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) { tbCompleted.Text = string.Format("{0}", e.FinalVelocities.LinearVelocity); tbCompleted.Text += string.Format("\r\n{0}", e.TotalManipulation.Translation); UIElement el = e.Source as UIElement; el.Effect = new BlurEffect() { Radius = 10.0 }; MatrixTransform xform = el.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; Matrix from = matrix; Matrix to = matrix; to.Translate(e.TotalManipulation.Translation.X * Math.Abs(e.FinalVelocities.LinearVelocity.X), e.TotalManipulation.Translation.Y * Math.Abs(e.FinalVelocities.LinearVelocity.Y)); if (Math.Abs(e.FinalVelocities.LinearVelocity.X) > 0.5 || Math.Abs(e.FinalVelocities.LinearVelocity.Y) > 0.5) { MatrixAnimation b = new MatrixAnimation() { From = from, To = to, Duration = TimeSpan.FromMilliseconds(500), FillBehavior = FillBehavior.HoldEnd }; (el.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); } base.OnManipulationCompleted(e); }
protected override void OnManipulationDelta(ManipulationDeltaEventArgs args) { UIElement element = args.Source as UIElement; MatrixTransform xform = element.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; ManipulationDelta delta = args.DeltaManipulation; Point center = args.ManipulationOrigin; /* * matrix.Translate(-center.X, -center.Y); * matrix.Scale(delta.Scale.X, delta.Scale.Y); * matrix.Rotate(delta.Rotation); * matrix.Translate(center.X, center.Y); * matrix.Translate(delta.Translation.X, delta.Translation.Y); * xform.Matrix = matrix; */ Matrix to = matrix; to.Translate(-center.X, -center.Y); to.Scale(delta.Scale.X, delta.Scale.Y); to.Rotate(delta.Rotation); to.Translate(center.X, center.Y); to.Translate(delta.Translation.X, delta.Translation.Y); MatrixAnimation b = new MatrixAnimation() { From = matrix, To = to, Duration = TimeSpan.FromMilliseconds(0), FillBehavior = FillBehavior.HoldEnd }; (element.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); tbTranslate.Text = string.Format("Translation: {0}, {1}", delta.Translation.X, delta.Translation.Y); tbTranslate.Text += string.Format("\r\nTotal Translation: {0}, {1}", args.CumulativeManipulation.Translation.X, args.CumulativeManipulation.Translation.Y); args.Handled = true; base.OnManipulationDelta(args); }
protected override void OnManipulationDelta(ManipulationDeltaEventArgs args) { if (rct_fadeout.Visibility == Visibility.Visible) { return; } UIElement element = args.Source as UIElement; MatrixTransform xform = element.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; ManipulationDelta delta = args.DeltaManipulation; Point center_precalc = args.ManipulationOrigin; Point center = new Point(); center.X = center_precalc.X + 50; center.Y = center_precalc.Y + 1650; // offset 추가 (moveinit 애니메이션 때문에) /* * matrix.Translate(-center.X, -center.Y); * matrix.Scale(delta.Scale.X, delta.Scale.Y); * matrix.Rotate(delta.Rotation); * matrix.Translate(center.X, center.Y); * matrix.Translate(delta.Translation.X, delta.Translation.Y); * xform.Matrix = matrix; */ //Debug.WriteLine("Manipulation Scale.X : " + delta.Scale.X); Debug.WriteLine("M11: " + matrix.M11.ToString() + "/ M12: " + matrix.M12.ToString() + "/ M21: " + matrix.M21.ToString() + "/ M22: " + matrix.M22.ToString()); int nScaleStat = 0; if (delta.Scale.X == 1) // deltaX가 0이면 크기 아무 변화없음 { nScaleStat = 0; } else if (delta.Scale.X > 1) // deltaX가 1보다 크면.. { nScaleStat = 1; } else if (delta.Scale.X < 1) { nScaleStat = -1; } Matrix to = matrix; to.Translate(-center.X, -center.Y); if ((nScaleStat == 1) && (matrix.M11 > 1.2)) { } else if ((nScaleStat == -1) && (matrix.M11 < 0.5)) { //nScaleStat = 0; } else { to.Scale(delta.Scale.X, delta.Scale.Y); } //tbTranslate.Text = string.Format("Translation: {0}, {1}", delta.Translation.X, delta.Translation.Y); //tbTranslate.Text += string.Format("\r\nTotal Translation: {0}, {1}", args.CumulativeManipulation.Translation.X, args.CumulativeManipulation.Translation.Y); //double currTransX= m_ptTranslate.X + args.CumulativeManipulation.Translation.X; //if (currTransX > 1000) //{ // return; //} to.Rotate(delta.Rotation); to.Translate(center.X, center.Y); to.Translate(delta.Translation.X, delta.Translation.Y); MatrixAnimation b = new MatrixAnimation() { From = matrix, To = to, Duration = TimeSpan.FromMilliseconds(0), FillBehavior = FillBehavior.HoldEnd }; (element.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); args.Handled = true; base.OnManipulationDelta(args); }
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) { UIElement el = e.Source as UIElement; MatrixTransform xform = el.RenderTransform as MatrixTransform; Matrix matrix = xform.Matrix; //m_ptTranslate += e.TotalManipulation.Translation; //tbCompleted.Text = string.Format("{0}", e.TotalManipulation.Translation); //tbCompleted.Text += string.Format("\r\nX: {0}, Y: {1}", matrix.OffsetX, matrix.OffsetY); bool bOutBound = false; double nOutBoundX = 0.0f; double nOutBoundY = 0.0f; double nDownBound = 2700.0f - (matrix.M11 * 2500); double nUpperBound = 1600.0f; double nRightBound = 850 - (matrix.M11 * 2000); double nLeftBound = 50.0f; // *matrix.M11; if (matrix.OffsetY < nDownBound) // 최종 목적지 : 위 { double nOutBound = matrix.OffsetY - nDownBound; //MessageBox.Show("bound::down!", nOutBound.ToString()); nOutBoundY = nOutBound; bOutBound = true; } if (matrix.OffsetY > nUpperBound) // 최종 목적지 : 아래 { double nOutBound = matrix.OffsetY - nUpperBound; //MessageBox.Show("bound::up!", nOutBound.ToString()); nOutBoundY = nOutBound; bOutBound = true; } if (matrix.OffsetX < nRightBound) // 최종 목적지 : 왼쪽 { double nOutBound = matrix.OffsetX - nRightBound; //MessageBox.Show("bound::right!", nOutBound.ToString()); nOutBoundX = nOutBound; bOutBound = true; } if (matrix.OffsetX > nLeftBound) // 최종 목적지 : 오른쪽 { double nOutBound = matrix.OffsetX - nLeftBound; //MessageBox.Show("bound::left!", nOutBound.ToString()); nOutBoundX = nOutBound; bOutBound = true; } //bOutBound= false; if (bOutBound) { Matrix to = matrix; to.Translate(-nOutBoundX, -nOutBoundY); MatrixAnimation b = new MatrixAnimation() { From = matrix, To = to, Duration = TimeSpan.FromMilliseconds(350), FillBehavior = FillBehavior.HoldEnd }; (el.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); } //m_ptTranslate.X += e.TotalManipulation.Translation.X; //m_ptTranslate.Y += e.TotalManipulation.Translation.Y; //UIElement el = e.Source as UIElement; //el.Effect = new BlurEffect() { Radius= 10.0}; //MatrixTransform xform = el.RenderTransform as MatrixTransform; //Matrix matrix = xform.Matrix; //Matrix from = matrix; //Matrix to = matrix; //to.Translate(e.TotalManipulation.Translation.X * Math.Abs(e.FinalVelocities.LinearVelocity.X), e.TotalManipulation.Translation.Y * Math.Abs(e.FinalVelocities.LinearVelocity.Y)); //if (Math.Abs(e.FinalVelocities.LinearVelocity.X) > 0.5 || Math.Abs(e.FinalVelocities.LinearVelocity.Y) > 0.5) //{ // MatrixAnimation b = new MatrixAnimation() // { // From = from, // To = to, // Duration = TimeSpan.FromMilliseconds(500), // FillBehavior = FillBehavior.HoldEnd // }; // (el.RenderTransform as MatrixTransform).BeginAnimation(MatrixTransform.MatrixProperty, b); //} base.OnManipulationCompleted(e); }