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 dependencyObject = Mouse.DirectlyOver as DependencyObject; while (dependencyObject != null && !(dependencyObject is CardControl)) { DependencyObject parent = LogicalTreeHelper.GetParent(dependencyObject) ?? VisualTreeHelper.GetParent(dependencyObject); dependencyObject = parent; } if (dependencyObject == this) { Card.ToggleTarget(); } else if (dependencyObject != null && ((CardControl)dependencyObject).Card.Group is Table) { Card.Target(((CardControl)dependencyObject).Card); } } break; } }
public void CreateArrowTo(Player player, CardControl toCard) { AdornerLayer 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 (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 && Card.Group is Table) { _isDragging = true; RaiseEvent(new CardEventArgs(CardHoveredEvent, this)); AdornerLayer layer = AdornerLayer.GetAdornerLayer(this); _draggedArrow = new ArrowAdorner(Player.LocalPlayer, this); layer.Add(_draggedArrow); } } } else { switch (_dragSource) { case DragSource.Card: { Window window = Window.GetWindow(this); if (window != null) { Point windowPt = e.GetPosition((IInputElement)window.Content); DragMouseDelta(windowPt.X - _mouseWindowPt.X, windowPt.Y - _mouseWindowPt.Y); } } break; case DragSource.Target: DragTargetDelta(pt); break; } } }
public void CreateArrowTo(Player player, CardControl toCard) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(this); var arrow = new ArrowAdorner(player, this); layer.Add(arrow); arrow.LinkToCard(toCard); }
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 dependencyObject = Mouse.DirectlyOver as DependencyObject; while (dependencyObject != null && !(dependencyObject is CardControl)) { DependencyObject parent = LogicalTreeHelper.GetParent(dependencyObject) ?? VisualTreeHelper.GetParent(dependencyObject); dependencyObject = parent; } if (dependencyObject == this) Card.ToggleTarget(); else if (dependencyObject != null && ((CardControl) dependencyObject).Card.Group is Table) Card.Target(((CardControl) dependencyObject).Card); } break; } }
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 (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 && Card.Group is Table) { _isDragging = true; RaiseEvent(new CardEventArgs(CardHoveredEvent, this)); AdornerLayer layer = AdornerLayer.GetAdornerLayer(this); _draggedArrow = new ArrowAdorner(Player.LocalPlayer, this); layer.Add(_draggedArrow); } } } else { switch (_dragSource) { case DragSource.Card: { Window window = Window.GetWindow(this); if (window != null) { Point windowPt = e.GetPosition((IInputElement) window.Content); DragMouseDelta(windowPt.X - _mouseWindowPt.X, windowPt.Y - _mouseWindowPt.Y); } } break; case DragSource.Target: DragTargetDelta(pt); break; } } }
private void MouseButtonUpAction(MouseButtonEventArgs e) { base.OnMouseUp(e); var shouldFireEvent = true; switch (e.ChangedButton) { case MouseButton.Left: if (IsMouseCaptured) ReleaseMouseCapture(); if (_dragSource == DragSource.Card) { shouldFireEvent = false; e.Handled = true; _dragSource = DragSource.None; if (!_isDragging) { Program.GameEngine.EventProxy.OnCardClick(Card, (int)e.ChangedButton, downKeys); } DragCardCompleted(); break; } if (_dragSource == DragSource.Target) { shouldFireEvent = false; e.Handled = true; _dragSource = DragSource.None; if (_draggedArrow != null) { _draggedArrow.RemoveFromLayer(); _draggedArrow = null; } if (_isDragging) { _isDragging = false; } var dependencyObject = Mouse.DirectlyOver as DependencyObject; while (dependencyObject != null && !(dependencyObject is CardControl)) { DependencyObject parent = LogicalTreeHelper.GetParent(dependencyObject) ?? VisualTreeHelper.GetParent(dependencyObject); dependencyObject = parent; } if (dependencyObject == this) Card.ToggleTarget(); else if (dependencyObject != null && ((CardControl)dependencyObject).Card.Group is Table) Card.Target(((CardControl)dependencyObject).Card); } break; } if (shouldFireEvent) Program.GameEngine.EventProxy.OnCardClick(Card, (int)e.ChangedButton, downKeys); }