protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); switch (e.ChangedButton) { case MouseButton.Left: if (IsMouseCaptured) ReleaseMouseCapture(); if (dragSource == DragSource.Card) { e.Handled = true; dragSource = DragSource.None; if (isDragging) { isDragging = false; DragCardCompleted(); } break; } if (dragSource == DragSource.Target) { e.Handled = true; dragSource = DragSource.None; if (draggedArrow != null) { draggedArrow.RemoveFromLayer(); draggedArrow = null; } if (isDragging) { isDragging = false; } var target = Mouse.DirectlyOver as DependencyObject; while (target != null && !(target is CardControl)) { var parent = LogicalTreeHelper.GetParent(target); if (parent == null) parent = VisualTreeHelper.GetParent(target); target = parent; } if (target == this) Card.ToggleTarget(); else if (target != null && ((CardControl)target).Card.Group is Table) Card.Target(((CardControl)target).Card); } break; } }
public void CreateArrowTo(Player player, CardControl toCard) { var layer = AdornerLayer.GetAdornerLayer(this); var arrow = new ArrowAdorner(player, this); layer.Add(arrow); arrow.LinkToCard(toCard); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); e.Handled = true; Point pt = e.GetPosition(this); if (!isDragging) { // Check if the button was pressed over the card, and was not release on another control in the meantime // (possible if the cursor is near the border of the card) if (!cardDragPeacedOut && Mouse.LeftButton == MouseButtonState.Pressed && // Check if has moved enough to start a drag and drop (Math.Abs(pt.X - mousePt.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(pt.Y - mousePt.Y) > SystemParameters.MinimumVerticalDragDistance)) { if (dragSource == DragSource.Card) { DragCardStarted(); } // Fix: Card could be null if a keyboard shortut was used when the mouse button was pressed. else if (dragSource == DragSource.Target && Card != null) { if (Card.Group is Table) { isDragging = true; RaiseEvent(new CardEventArgs(CardHoveredEvent, this)); var layer = AdornerLayer.GetAdornerLayer(this); draggedArrow = new ArrowAdorner(Player.LocalPlayer, this); layer.Add(draggedArrow); } } } } else { if (dragSource == DragSource.Card) { var windowPt = e.GetPosition((IInputElement)Window.GetWindow(this).Content); DragMouseDelta(windowPt.X - mouseWindowPt.X, windowPt.Y - mouseWindowPt.Y); } else if (dragSource == DragSource.Target) DragTargetDelta(pt); } }