상속: System.Windows.Controls.UserControl
예제 #1
0
        private void RemoveCardHandler(object sender, RoutedEventArgs e)
        {
            if (Card == null)
            {
                return;
            }

            // Three cases are possible.
            // 1. The container is unloaded (e.g. one closes a GroupWindow).
            //    This case is recognizable because GroupControl.IsLoaded is false.
            //    We have to remove our listeners.
            // 2. The card is been moved to another group.
            //    This is recognizable because GroupControl is null.
            //    We have to remove our listeners.
            // 3. The card index changes (e.g. it's moved to top/bottom of a pile).
            //    In this case WPF seems to unload and then reload the control at the correct position.
            //    But in some weird cases WPF seems to call Unload WITHOUT a matching Load,
            //    although the control ends up in the visual tree. E.g. when Moving several cards to the
            //    top of a pile at once, with the GroupWindow open.
            //    We can recognize this case because GroupControl.IsLoaded is true.
            //    In this case we *keep* the listeners attached!
            GroupControl groupCtrl = GroupControl;

            if (groupCtrl != null && groupCtrl.IsLoaded)
            {
                return;
            }

            Card.PropertyChanged -= PropertyChangeHandler;
            Card = null;
        }
예제 #2
0
        protected override void OnMouseDoubleClick(MouseButtonEventArgs e)
        {
            base.OnMouseDoubleClick(e);

            if (_isDragging)
            {
                return;
            }

            // Double-click ends any manipulation which may be in progress.
            // Otherwise bugs may happen (e.g. if the default action moves the card)
            if (IsMouseCaptured)
            {
                ReleaseMouseCapture();
            }
            _dragSource = DragSource.None;

            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }
            e.Handled = true;
            if (GroupControl != null)
            {
                GroupControl.ExecuteDefaultAction(Card);
            }
        }
예제 #3
0
        protected void DragCardCompleted()
        {
            // Release the card and its group
            foreach (Card c in DraggedCards)
            {
                c.ReleaseControl();
            }
            Card.Group.ReleaseControl();

            // Remove the visual feedback
            var mwc = _mainWin.Content as Visual;

            if (mwc != null)
            {
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(mwc);
                foreach (CardDragAdorner overlay in OverlayElements)
                {
                    layer.Remove(overlay);
                    overlay.Dispose();
                }
            }
            OverlayElements.Clear();

            // Raise CardOutEvent
            if (_lastDragTarget != null)
            {
                _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this));
                _lastDragTarget = null;
            }

            // Raise CardDroppedEvent
            IInputElement res = Mouse.DirectlyOver;

            if (res != null)
            {
                var args = new CardsEventArgs(Card, DraggedCards, CardDroppedEvent, this)
                {
                    MouseOffset = _mouseOffset,
                    FaceUp      = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                };
                res.RaiseEvent(args);
            }

            // Restore full opacity
            // FIX (jods): if the cards have been moved to another group, groupCtrl is null.
            //					     But in this case nothing has to be done opacity-wise since
            //					   the CardControls have been unloaded.
            GroupControl groupCtrl = GroupControl;

            if (groupCtrl != null)
            {
                foreach (CardControl cardCtrl in Selection.GetCardControls(groupCtrl, this))
                {
                    cardCtrl.Opacity = 1;
                }
            }

            DraggedCards.Clear();
        }
예제 #4
0
 public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl, CardControl empty)
 {
     if (IsEmpty())
         yield return empty;
     else
         foreach (CardControl cardCtrl in GetCardControls(ctrl))
             yield return cardCtrl;
 }
예제 #5
0
 protected override void OnContextMenuOpening(ContextMenuEventArgs e)
 {
     e.Handled = true;
     if (Mouse.Captured != null)
     {
         return;                         // don't open during drag and drop operations
     }
     base.OnContextMenuOpening(e);
     GroupControl.ShowContextMenu(Card);
 }
예제 #6
0
 public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl)
 {
     if (IsEmpty()) yield break;
       var groupCards = ctrl.Group.Cards;
       var generator = ctrl.GetItemContainerGenerator();
     for (int i = 0; i < groupCards.Count; ++i)
         if (groupCards[i].Selected)
         {
             var container = generator.ContainerFromIndex(i);
             var cardCtrl = (CardControl)System.Windows.Media.VisualTreeHelper.GetChild(container, 0);
             yield return cardCtrl;
         }
 }
예제 #7
0
 public static IEnumerable<CardControl> GetCardControls(GroupControl ctrl)
 {
     if (IsEmpty()) yield break;
     ObservableCollection<Card> groupCards = ctrl.Group.Cards;
     ItemContainerGenerator generator = ctrl.GetItemContainerGenerator();
     for (int i = 0; i < groupCards.Count; ++i)
         if (groupCards[i].Selected)
         {
             DependencyObject container = generator.ContainerFromIndex(i);
             var cardCtrl = (CardControl) VisualTreeHelper.GetChild(container, 0);
             yield return cardCtrl;
         }
 }
예제 #8
0
파일: Selection.cs 프로젝트: wlk0/OCTGN
 public static IEnumerable <CardControl> GetCardControls(GroupControl ctrl, CardControl empty)
 {
     if (IsEmpty())
     {
         yield return(empty);
     }
     else
     {
         foreach (CardControl cardCtrl in GetCardControls(ctrl))
         {
             yield return(cardCtrl);
         }
     }
 }
예제 #9
0
파일: Selection.cs 프로젝트: wlk0/OCTGN
        public static IEnumerable <CardControl> GetCardControls(GroupControl ctrl)
        {
            if (IsEmpty())
            {
                yield break;
            }
            ObservableCollection <Card> groupCards = ctrl.Group.Cards;
            ItemContainerGenerator      generator  = ctrl.GetItemContainerGenerator();

            for (int i = 0; i < groupCards.Count; ++i)
            {
                if (groupCards[i].Selected)
                {
                    DependencyObject container = generator.ContainerFromIndex(i);
                    var cardCtrl = (CardControl)VisualTreeHelper.GetChild(container, 0);
                    yield return(cardCtrl);
                }
            }
        }
예제 #10
0
        private void AnimateTurn(bool newIsUp)
        {
            TimeSpan     delay = TimeSpan.Zero;
            GroupControl group = GroupControl;

            if (group != null)
            {
                delay = TimeSpan.FromMilliseconds(group.GetTurnAnimationDelay());
            }
            var animY = new DoubleAnimation(1.1, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.HoldEnd)
            {
                BeginTime = delay
            };
            var anim = new DoubleAnimation(0, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.HoldEnd)
            {
                BeginTime = delay
            };

            anim.Completed += Turned;
            turn.BeginAnimation(ScaleTransform.ScaleYProperty, animY);
            turn.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
        }