public void onAnimationCompleted(object sender, EventArgs e) { if (--completedLeft == 0 && animationCallbackObject != null) { storyboard.Stop(); if (animType == AnimType.COMPLEX) { animationCallbackObject.animationFinished(dx, dy); } else { animationCallbackObject.animationFinishedSimple(); } animationCallbackObject = null; } }
public void startMoveTwoPiecesAnimation(int prevElementX, int prevElementY, IAnimationCallback callback) { selectionRect.Visibility = Visibility.Collapsed; animationCallbackObject = callback; completedLeft = 2; storyboard.Children.Clear(); Canvas.SetZIndex(cell[prevElementX, prevElementY], 2); Canvas.SetZIndex(cell[selFromX, selFromY], 0); TimeSpan duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); animationX[prevElementX, prevElementY].From = ((TranslateTransform)cell[prevElementX, prevElementY].RenderTransform).X; animationX[prevElementX, prevElementY].To = (selFromX - prevElementX) * cellWidth; animationX[prevElementX, prevElementY].By = animationX[prevElementX, prevElementY].From > animationX[prevElementX, prevElementY].To ? -1 : 1; animationX[prevElementX, prevElementY].Duration = duration; animationY[prevElementX, prevElementY].From = ((TranslateTransform)cell[prevElementX, prevElementY].RenderTransform).Y; animationY[prevElementX, prevElementY].To = (selFromY - prevElementY) * cellHeight; animationY[prevElementX, prevElementY].By = animationY[prevElementX, prevElementY].From > animationY[prevElementX, prevElementY].To ? -1 : 1; animationY[prevElementX, prevElementY].Duration = duration; animationX[selFromX, selFromY].From = ((TranslateTransform)cell[selFromX, selFromY].RenderTransform).X; animationX[selFromX, selFromY].To = (prevElementX - selFromX) * cellWidth; animationX[selFromX, selFromY].By = animationX[selFromX, selFromY].From > animationX[selFromX, selFromY].To ? -1 : 1; animationX[selFromX, selFromY].Duration = duration; animationY[selFromX, selFromY].From = ((TranslateTransform)cell[selFromX, selFromY].RenderTransform).Y; animationY[selFromX, selFromY].To = (prevElementY - selFromY) * cellHeight; animationY[selFromX, selFromY].By = animationY[selFromX, selFromY].From > animationY[selFromX, selFromY].To ? -1 : 1; animationY[selFromX, selFromY].Duration = duration; storyboard.Children.Add(animationX[selFromX, selFromY]); storyboard.Children.Add(animationY[selFromX, selFromY]); storyboard.Children.Add(animationX[prevElementX, prevElementY]); storyboard.Children.Add(animationY[prevElementX, prevElementY]); animType = AnimType.TWO_PIECES; storyboard.Begin(); }
public CameraUpdateMessage(CameraUpdate update, TimeSpan? duration, IAnimationCallback callback) { Update = update; Duration = duration; Callback = callback; }
public void startMoveAnimation(IAnimationCallback callback) { selectionRect.Visibility = Visibility.Collapsed; animationCallbackObject = callback; completedLeft = 0; storyboard.Children.Clear(); determineNewPosShift(ref dx, ref dy); if (dx == 0 && dy == 0) { TimeSpan duration; if (dx < 0) { duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); } else { duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION / 4); } for (int i = selFromX; i <= selToX; ++i) { for (int j = selFromY; j <= selToY; ++j) { animationX[i, j].From = ((TranslateTransform)cell[i, j].RenderTransform).X; animationX[i, j].To = 0; animationX[i, j].By = animationX[i, j].From > 0 ? -1 : 1; animationX[i, j].Duration = duration; animationY[i, j].From = ((TranslateTransform)cell[i, j].RenderTransform).Y; animationY[i, j].To = 0; animationY[i, j].By = animationY[i, j].From > 0 ? -1 : 1; animationY[i, j].Duration = duration; storyboard.Children.Add(animationX[i, j]); storyboard.Children.Add(animationY[i, j]); completedLeft += 2; } } animType = AnimType.COMPLEX; storyboard.Begin(); return; } int targetX, targetY; if (Math.Abs(dx) > selToX - selFromX || Math.Abs(dy) > selToY - selFromY) { TimeSpan duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); for (int y = selFromY; y <= selToY; ++y) { targetY = y + dy; for (int x = selFromX; x <= selToX; ++x) { targetX = x + dx; animationX[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).X; animationX[x, y].To = dx * cellWidth; animationX[x, y].By = animationX[x, y].From > animationX[x, y].To ? -1 : 1; animationX[x, y].Duration = duration; animationY[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).Y; animationY[x, y].To = dy * cellHeight; animationY[x, y].By = animationY[x, y].From > animationY[x, y].To ? -1 : 1; animationY[x, y].Duration = duration; animationX[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).X; animationX[targetX, targetY].To = -dx * cellWidth; animationX[targetX, targetY].By = animationX[targetX, targetY].From > animationX[targetX, targetY].To ? -1 : 1; animationX[targetX, targetY].Duration = duration; animationY[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).Y; animationY[targetX, targetY].To = -dy * cellHeight; animationY[targetX, targetY].By = animationY[targetX, targetY].From > animationY[targetX, targetY].To ? -1 : 1; animationY[targetX, targetY].Duration = duration; Canvas.SetZIndex(cell[targetX, targetY], 0); storyboard.Children.Add(animationX[x, y]); storyboard.Children.Add(animationY[x, y]); storyboard.Children.Add(animationX[targetX, targetY]); storyboard.Children.Add(animationY[targetX, targetY]); completedLeft += 4; } } } else { TimeSpan duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); for (int y = selFromY; y <= selToY; ++y) { targetY = y + dy; for (int x = selFromX; x <= selToX; ++x) { targetX = x + dx; animationX[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).X; animationX[x, y].To = dx * cellWidth; animationX[x, y].By = animationX[x, y].From > animationX[x, y].To ? -1 : 1; animationX[x, y].Duration = duration; animationY[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).Y; animationY[x, y].To = dy * cellHeight; animationY[x, y].By = animationY[x, y].From > animationY[x, y].To ? -1 : 1; animationY[x, y].Duration = duration; storyboard.Children.Add(animationX[x, y]); storyboard.Children.Add(animationY[x, y]); completedLeft += 2; int dsttmpX = -1; int dsttmpY = -1; if (targetY < selFromY || targetY > selToY) { dsttmpX = targetX - dx; dsttmpY = targetY; if (targetY < selFromY) { dsttmpY += selToY - selFromY + 1; } if (targetY > selToY) { dsttmpY -= selToY - selFromY + 1; } } else if (targetX > selToX || targetX < selFromX) { dsttmpX = targetX; dsttmpY = targetY; if (targetX > selToX) { dsttmpX = targetX - selToX + selFromX - 1; } if (targetX < selFromX) { dsttmpX = targetX + selToX - selFromX + 1; } } if (dsttmpX != -1 && dsttmpY != -1) { Canvas.SetZIndex(cell[targetX, targetY], 0); animationX[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).X; animationX[targetX, targetY].To = (dsttmpX - targetX) * cellWidth; animationX[targetX, targetY].By = animationX[targetX, targetY].From > animationX[targetX, targetY].To ? -1 : 1; animationX[targetX, targetY].Duration = duration; animationY[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).Y; animationY[targetX, targetY].To = (dsttmpY - targetY) * cellHeight; animationY[targetX, targetY].By = animationY[targetX, targetY].From > animationY[targetX, targetY].To ? -1 : 1; animationY[targetX, targetY].Duration = duration; storyboard.Children.Add(animationX[targetX, targetY]); storyboard.Children.Add(animationY[targetX, targetY]); completedLeft += 2; } } } } animType = AnimType.COMPLEX; storyboard.Begin(); }
public void onAnimationCompleted(object sender, EventArgs e) { if (--completedLeft == 0 && animationCallbackObject != null) { storyboard.Stop(); if (animType == AnimType.COMPLEX) animationCallbackObject.animationFinished(dx, dy); else animationCallbackObject.animationFinishedSimple(); animationCallbackObject = null; } }
public void startMoveAnimation(IAnimationCallback callback) { selectionRect.Visibility = Visibility.Collapsed; animationCallbackObject = callback; completedLeft = 0; storyboard.Children.Clear(); determineNewPosShift(ref dx, ref dy); if (dx == 0 && dy == 0) { TimeSpan duration; if (dx < 0) duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); else duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION / 4); for (int i = selFromX; i <= selToX; ++i) for (int j = selFromY; j <= selToY; ++j) { animationX[i, j].From = ((TranslateTransform)cell[i, j].RenderTransform).X; animationX[i, j].To = 0; animationX[i, j].By = animationX[i, j].From > 0 ? -1 : 1; animationX[i, j].Duration = duration; animationY[i, j].From = ((TranslateTransform)cell[i, j].RenderTransform).Y; animationY[i, j].To = 0; animationY[i, j].By = animationY[i, j].From > 0 ? -1 : 1; animationY[i, j].Duration = duration; storyboard.Children.Add(animationX[i, j]); storyboard.Children.Add(animationY[i, j]); completedLeft += 2; } animType = AnimType.COMPLEX; storyboard.Begin(); return; } int targetX, targetY; if (Math.Abs(dx) > selToX - selFromX || Math.Abs(dy) > selToY - selFromY) { TimeSpan duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); for (int y = selFromY; y <= selToY; ++y) { targetY = y + dy; for (int x = selFromX; x <= selToX; ++x) { targetX = x + dx; animationX[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).X; animationX[x, y].To = dx * cellWidth; animationX[x, y].By = animationX[x, y].From > animationX[x, y].To ? -1 : 1; animationX[x, y].Duration = duration; animationY[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).Y; animationY[x, y].To = dy * cellHeight; animationY[x, y].By = animationY[x, y].From > animationY[x, y].To ? -1 : 1; animationY[x, y].Duration = duration; animationX[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).X; animationX[targetX, targetY].To = -dx * cellWidth; animationX[targetX, targetY].By = animationX[targetX, targetY].From > animationX[targetX, targetY].To ? -1 : 1; animationX[targetX, targetY].Duration = duration; animationY[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).Y; animationY[targetX, targetY].To = -dy * cellHeight; animationY[targetX, targetY].By = animationY[targetX, targetY].From > animationY[targetX, targetY].To ? -1 : 1; animationY[targetX, targetY].Duration = duration; Canvas.SetZIndex(cell[targetX, targetY], 0); storyboard.Children.Add(animationX[x, y]); storyboard.Children.Add(animationY[x, y]); storyboard.Children.Add(animationX[targetX, targetY]); storyboard.Children.Add(animationY[targetX, targetY]); completedLeft += 4; } } } else { TimeSpan duration = TimeSpan.FromMilliseconds(ANIMATION_DURATION); for (int y = selFromY; y <= selToY; ++y) { targetY = y + dy; for (int x = selFromX; x <= selToX; ++x) { targetX = x + dx; animationX[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).X; animationX[x, y].To = dx * cellWidth; animationX[x, y].By = animationX[x, y].From > animationX[x, y].To ? -1 : 1; animationX[x, y].Duration = duration; animationY[x, y].From = ((TranslateTransform)cell[x, y].RenderTransform).Y; animationY[x, y].To = dy * cellHeight; animationY[x, y].By = animationY[x, y].From > animationY[x, y].To ? -1 : 1; animationY[x, y].Duration = duration; storyboard.Children.Add(animationX[x, y]); storyboard.Children.Add(animationY[x, y]); completedLeft += 2; int dsttmpX = -1; int dsttmpY = -1; if (targetY < selFromY || targetY > selToY) { dsttmpX = targetX - dx; dsttmpY = targetY; if (targetY < selFromY) { dsttmpY += selToY - selFromY + 1; } if (targetY > selToY) { dsttmpY -= selToY - selFromY + 1; } } else if (targetX > selToX || targetX < selFromX) { dsttmpX = targetX; dsttmpY = targetY; if (targetX > selToX) { dsttmpX = targetX - selToX + selFromX - 1; } if (targetX < selFromX) { dsttmpX = targetX + selToX - selFromX + 1; } } if (dsttmpX != -1 && dsttmpY != -1) { Canvas.SetZIndex(cell[targetX, targetY], 0); animationX[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).X; animationX[targetX, targetY].To = (dsttmpX - targetX) * cellWidth; animationX[targetX, targetY].By = animationX[targetX, targetY].From > animationX[targetX, targetY].To ? -1 : 1; animationX[targetX, targetY].Duration = duration; animationY[targetX, targetY].From = ((TranslateTransform)cell[targetX, targetY].RenderTransform).Y; animationY[targetX, targetY].To = (dsttmpY - targetY) * cellHeight; animationY[targetX, targetY].By = animationY[targetX, targetY].From > animationY[targetX, targetY].To ? -1 : 1; animationY[targetX, targetY].Duration = duration; storyboard.Children.Add(animationX[targetX, targetY]); storyboard.Children.Add(animationY[targetX, targetY]); completedLeft += 2; } } } } animType = AnimType.COMPLEX; storyboard.Begin(); }