internal void ShowTwist(TwistDirection twistDirection) { Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.RotationProperty); Double totalTwistTime = 1.0; ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).To = (twistDirection == TwistDirection.Clockwise) ? currentAngle + 90 : currentAngle - 90; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime)); QuadrantRotation.BeginTime = TimeSpan.FromSeconds(1); SineEase f = new SineEase(); f.EasingMode = EasingMode.EaseOut; ((DoubleAnimation)QuadrantTranslation.Children[0]).From = 0; Double to = 0; switch (this.Name.ToLower()) { case "upperleft": case "lowerleft": to = -1 * MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0; break; case "upperright": case "lowerright": to = MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0; break; } ((DoubleAnimation)QuadrantTranslation.Children[0]).To = to; ((DoubleAnimation)QuadrantTranslation.Children[0]).EasingFunction = f; ((DoubleAnimation)QuadrantTranslation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime / 2.0)); ((DoubleAnimation)QuadrantTranslation.Children[1]).From = 0; switch (this.Name.ToLower()) { case "upperleft": case "upperright": to = -1 * MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0; break; case "lowerleft": case "lowerright": to = MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0; break; } ((DoubleAnimation)QuadrantTranslation.Children[1]).To = to; ((DoubleAnimation)QuadrantTranslation.Children[1]).EasingFunction = f; ((DoubleAnimation)QuadrantTranslation.Children[1]).Duration = new Duration(TimeSpan.FromSeconds(totalTwistTime / 2.0)); QuadrantTranslation.AutoReverse = true; QuadrantTranslation.BeginTime = TimeSpan.FromSeconds(1); QuadrantRotation.Begin(); QuadrantTranslation.Begin(); }
internal void ShowTwist(TwistDirection twistDirection) { Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(RotateTransform.AngleProperty); ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).To = (twistDirection == TwistDirection.Clockwise) ? currentAngle + 90 : currentAngle - 90; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(1)); QuadrantRotation.BeginTime = TimeSpan.FromSeconds(1); QuadrantRotation.Begin(); }
void PentagoQuadrant_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (mouseDrag) { mouseDrag = false; Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(RotateTransform.AngleProperty); Duration dur = new Duration(TimeSpan.FromSeconds(0.1)); Double to = currentAngle; if ((currentAngle % 90) != 0) { Double mod360 = currentAngle % 360; Double mod45 = currentAngle % 45; if (mod360 < 0) { mod360 += 360; } if (mod45 < 0) { mod45 += 45; } to = currentAngle - mod45; if ((mod360 <= 90 && mod360 > 45) || (mod360 <= 360 && mod360 > 315) || (mod360 <= 270 && mod360 > 225) || (mod360 <= 180 && mod360 > 135)) { to += 45; } } ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).To = to; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = dur; QuadrantRotation.ClearValue(Storyboard.BeginTimeProperty); TwistDirection direction = GetTwistDirectionFromAngles(origAngle, to); if (direction != TwistDirection.None) { sendTwistNotification = true; latestTwistDirection = direction; } this.ReleaseMouseCapture(); QuadrantRotation.Begin(); this.ClearValue(Canvas.ZIndexProperty); } }
void PentagoQuadrant_MouseMove(object sender, MouseEventArgs e) { if (mouseDrag) { Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(RotateTransform.AngleProperty); Point pos = e.GetPosition(MasterCanvas); Point center = new Point(MasterCanvas.ActualWidth / 2, MasterCanvas.ActualHeight / 2); Double newAngle = Math.Atan2( (center.Y - pos.Y), (pos.X - center.X) ); newAngle *= (360 / (2 * Math.PI)); Double delta = newAngle - refAngle; if (Math.Abs(delta) >= 90 && Math.Abs(delta) <= 270) { if (dragBlockOn) { return; } if (Math.Abs(delta) <= 180) { delta = (delta > 0) ? 90 : -90; } else { delta = (delta > 0) ? 270 : -270; } dragBlockOn = true; } else { dragBlockOn = false; } Double newToAngle = origAngle - (delta); Duration dur = new Duration(TimeSpan.FromSeconds(0.01)); ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).To = newToAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = dur; QuadrantRotation.ClearValue(Storyboard.BeginTimeProperty); QuadrantRotation.Begin(); } }
public void Reset() { ((DoubleAnimation)QuadrantRotation.Children[0]).From = 0; ((DoubleAnimation)QuadrantRotation.Children[0]).To = 0; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = new Duration(TimeSpan.FromSeconds(0.1)); QuadrantRotation.ClearValue(Storyboard.BeginTimeProperty); QuadrantRotation.Begin(); NWDot.Reset(); NDot.Reset(); NEDot.Reset(); WDot.Reset(); CenterDot.Reset(); EDot.Reset(); SWDot.Reset(); SDot.Reset(); SEDot.Reset(); }
void PentagoQuadrant_MouseMove(object sender, MouseEventArgs e) { if (mouseDrag) { Double currentAngle = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.RotationProperty); Double currentX = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.TranslateXProperty); Double currentY = (double)MasterGrid.RenderTransform.GetValue(CompositeTransform.TranslateYProperty); Point pos = e.GetPosition(RefGrid); Point center = new Point(RefGrid.ActualWidth / 2, RefGrid.ActualHeight / 2); Double newAngle = Math.Atan2( (center.Y - pos.Y), (pos.X - center.X) ); newAngle *= (360 / (2 * Math.PI)); Double delta = newAngle - refAngle; if (Math.Abs(delta) >= 90 && Math.Abs(delta) <= 270) { if (dragBlockOn) { return; } if (Math.Abs(delta) <= 180) { delta = (delta > 0) ? 90 : -90; } else { delta = (delta > 0) ? 270 : -270; } dragBlockOn = true; } else { dragBlockOn = false; } Double newToAngle = origAngle - (delta); Duration dur = new Duration(TimeSpan.FromSeconds(0.01)); ((DoubleAnimation)QuadrantRotation.Children[0]).From = currentAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).To = newToAngle; ((DoubleAnimation)QuadrantRotation.Children[0]).Duration = dur; Double moveProportion = Math.Abs(Math.Sin(4.0 * Math.PI * (newToAngle % 90) / 360.0)) * MasterGrid.ActualWidth * (Math.Sqrt(2.0) - 1) / 2.0; Double mult = 1.0; switch (this.Name.ToLower()) { case "upperright": case "lowerright": mult = 1.0; break; case "upperleft": case "lowerleft": mult = -1.0; break; } ((DoubleAnimation)QuadrantTranslation.Children[0]).From = currentX; ((DoubleAnimation)QuadrantTranslation.Children[0]).To = mult * moveProportion; ((DoubleAnimation)QuadrantTranslation.Children[0]).Duration = dur; switch (this.Name.ToLower()) { case "upperright": case "upperleft": mult = -1.0; break; case "lowerright": case "lowerleft": mult = 1.0; break; } ((DoubleAnimation)QuadrantTranslation.Children[1]).From = currentY; ((DoubleAnimation)QuadrantTranslation.Children[1]).To = mult * moveProportion; ((DoubleAnimation)QuadrantTranslation.Children[1]).Duration = dur; QuadrantRotation.ClearValue(Storyboard.BeginTimeProperty); QuadrantTranslation.ClearValue(Storyboard.BeginTimeProperty); QuadrantTranslation.AutoReverse = false; QuadrantTranslation.Begin(); QuadrantRotation.Begin(); } }