public void SelectStack(CardStack stack) { if (stack.Count > 0) { _currentAction = CardAction.Moving; int top = stack.GetTopOfSequentialRun(); _cardsInAction = stack.GetCards(); _cardsInAction.RemoveRange(0, top); _currentStack = stack.Index; } }
public StackExpandAnimation(Board board, CardStack stack, Point ptExpand) { _board = board; _startTime = DateTime.Now; var cardsInStack = stack.GetCards(); int top = stack.GetTopOfSequentialRun(); cardsInStack.RemoveRange(0, top); int rows = (cardsInStack.Count + (CardsPerRow - 1)) / CardsPerRow; int cols = (cardsInStack.Count < CardsPerRow ? cardsInStack.Count : CardsPerRow); var bounds = board.View.GetViewArea(); var cardSize = board.View.GetCardSize(); int spacing = (bounds.Width - cardSize.X * CardsPerRow) / (CardsPerRow - 1); spacing = Math.Min(spacing, 10); int xAnchor = ptExpand.X - cols / 2 * cardSize.X - (cols - 1) / 2 * spacing; xAnchor = Math.Max(xAnchor, 0); // Left edge collision xAnchor = Math.Min(xAnchor, bounds.Width - cardSize.X * cols - spacing * (cols - 1)); // Right edge collision int yAnchor = ptExpand.Y - cardSize.Y / 2; yAnchor = Math.Max(yAnchor, 0); // Top edge collision yAnchor = Math.Min(yAnchor, bounds.Height - cardSize.Y * rows - spacing * (rows - 1)); // Bottom edge collision CardAnimations = new List <CardAnimationView>(cardsInStack.Count); for (int i = 0; i < cardsInStack.Count; i++) { var card = cardsInStack[i]; card.View.Animating = true; var startPoint = board.View.GetLocationOfCardInStack(stack, i + top); int row = i / CardsPerRow; int col = i % CardsPerRow; int x = xAnchor + (cardSize.X + spacing) * col; int y = yAnchor + (cardSize.Y + spacing) * row; var destPoint = new Point(x, y); var animation = new CardAnimationView(card, 0, Duration, startPoint, destPoint, cardSize.X, cardSize.Y); CardAnimations.Add(animation); } _stopTime = DateTime.Now.AddSeconds(Duration); UpdateCardAnimations(); }
public void PickFromStack(CardStack stack, Point ptExpand) { if (stack.Count > 0) { int top = stack.GetTopOfSequentialRun(); if (top < stack.Count - 1) { Animation expandAnimation = new StackExpandAnimation(_board, stack, ptExpand) { OnAnimationCompleted = OnCompletedExpandAnimation }; _currentAnimations.Add(expandAnimation); } else { SelectStack(stack); } _currentStack = stack.Index; } }
public void StartDrag(Point pt) { CardStack cardStack = GetStackAtPoint(pt); if (cardStack != null && cardStack.Count > 0 && (_currentAction == CardAction.None || _currentAction == CardAction.Moving)) { _dragInfo = new DragInfo(); int top = cardStack.GetTopOfSequentialRun(); _dragInfo.CardsToDrag = cardStack.GetCards(); _dragInfo.CardsToDrag.RemoveRange(0, top); _dragInfo.Stack = cardStack.Index; Point cardOrigin = GetLocationOfCardInStack(cardStack, cardStack.Count - _dragInfo.CardsToDrag.Count); _dragInfo.StartPos = pt; _dragInfo.Offset = new Point(_dragInfo.StartPos.X - cardOrigin.X, _dragInfo.StartPos.Y - cardOrigin.Y); } }