Example #1
0
        /*
         * Function called when an element is dropped inside the container.
         */
        private void OnCursorDrop(object sender, SurfaceDragDropEventArgs args)
        {
            SurfaceDragCursor droppingCursor = args.Cursor;

            // check if item is not already in the container
            if (!Items.Contains(droppingCursor.Data))
            {
                Point center = droppingCursor.GetPosition(this);
                center.X = ((center.X - 45) / this.ActualWidth) * 100;
                center.Y = ((center.Y - 65) / this.ActualHeight) * 100;
                ((SimpleCard)droppingCursor.Data).center = center;
                // Add item in the container
                ((ObservableCollection <SimpleCard>)ItemsSource).Add((SimpleCard)droppingCursor.Data);


                // set the properties of the item just dropped
                var svi = ItemContainerGenerator.ContainerFromItem(droppingCursor.Data) as ScatterViewItem;
                if (svi != null)
                {
                    svi.Center      = droppingCursor.GetPosition(this);
                    svi.Orientation = droppingCursor.GetOrientation(this);
                    svi.Height      = droppingCursor.Visual.ActualHeight;
                    svi.Width       = droppingCursor.Visual.ActualWidth;
                    svi.SetRelativeZIndex(RelativeScatterViewZIndex.Topmost);
                    svi.Orientation = 0;
                    svi.CanRotate   = false;
                    svi.CanScale    = false;
                }
            }
        }
Example #2
0
        private void OnMainDrag(object sender, InputEventArgs e)
        {
            FrameworkElement   findSource     = e.OriginalSource as FrameworkElement;
            SurfaceListBoxItem draggedElement = null;

            // Find the touched SurfaceListBoxItem object.
            while (draggedElement == null && findSource != null)
            {
                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
                {
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
                }
            }

            if (draggedElement == null)
            {
                return;
            }

            // Create the cursor visual.
            ContentControl cursorVisual = new ContentControl()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("CursorStyle") as Style
            };

            // Add a handler. This will enable the application to change the visual cues.
            SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);

            // Create a list of input devices. Add the touches that
            // are currently captured within the dragged element and
            // the current touch (if it isn't already in the list).
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);
            foreach (TouchDevice touch in draggedElement.TouchesCapturedWithin)
            {
                if (touch != e.Device)
                {
                    devices.Add(touch);
                }
            }

            // Get the drag source object
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            SurfaceDragCursor startDragOkay =
                SurfaceDragDrop.BeginDragDrop(
                    dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
                    draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
                    cursorVisual,               // The visual element of the cursor.
                    draggedElement.DataContext, // The data associated with the cursor.
                    devices,                    // The input devices that start dragging the cursor.
                    DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.

            // If the drag began successfully, set e.Handled to true.
            // Otherwise SurfaceListBoxItem captures the touch
            // and causes the drag operation to fail.
            e.Handled = (startDragOkay != null);
        }
Example #3
0
        private void OnCursorDrop(object sender, SurfaceDragDropEventArgs args)
        {
            SurfaceDragCursor droppingCursor = args.Cursor;

            if (!HandListBox.Items.Contains(droppingCursor.Data))
            {
                ((ObservableCollection <SimpleCard>)HandListBox.ItemsSource).Add((SimpleCard)droppingCursor.Data);
            }
        }
        private void OnDeckButtonCursorDrop(object sender, SurfaceDragDropEventArgs args)
        {
            SurfaceDragCursor droppingCursor = args.Cursor;

            if (!((VMGame)DataContext).Deck.Contains((SimpleCard)droppingCursor.Data))
            {
                ((VMGame)DataContext).Deck.Insert(0, (SimpleCard)droppingCursor.Data);
                ((VMGame)DataContext).DeckCount = "Deck " + ((VMGame)DataContext).Deck.Count;
            }
        }
        private void OnExileButtonCursorDrop(object sender, SurfaceDragDropEventArgs args)
        {
            SurfaceDragCursor droppingCursor = args.Cursor;

            if (!((VMGame)DataContext).Exile.Contains((SimpleCard)droppingCursor.Data))
            {
                ((VMGame)DataContext).Exile.Insert(0, (SimpleCard)droppingCursor.Data);
                ExileButton.Background = new ImageBrush {
                    ImageSource = ((SimpleCard)droppingCursor.Data).Bitmap
                };
            }
        }
Example #6
0
        private void StartDragDrop(ListBox sourceListBox, InputEventArgs e)
        {
            DependencyObject downSource = InputDeviceHelper.GetDragSource(e.Device);

            Debug.Assert(downSource != null);

            SurfaceListBoxItem draggedListBoxItem = GetVisualAncestor <SurfaceListBoxItem>(downSource);

            if (draggedListBoxItem == null)
            {
                return;
            }

            SimpleCard data = draggedListBoxItem.Content as SimpleCard;

            // Create a new ScatterViewItem as cursor visual.
            ScatterViewItem cursorVisual = new ScatterViewItem();

            cursorVisual.Style   = (Style)FindResource("ScatterItemStyle");
            cursorVisual.Content = data;

            IEnumerable <InputDevice> devices = null;

            TouchEventArgs touchEventArgs = e as TouchEventArgs;

            if (touchEventArgs != null)
            {
                devices = MergeInputDevices(draggedListBoxItem.TouchesCapturedWithin, e.Device);
            }
            else
            {
                devices = new List <InputDevice>(new InputDevice[] { e.Device });
            }

            SurfaceDragCursor cursor = SurfaceDragDrop.BeginDragDrop(HandListBox, draggedListBoxItem, cursorVisual, data, devices, DragDropEffects.All);

            // Reset the input device's state.

            InputDeviceHelper.ClearDeviceState(e.Device);

            ((ObservableCollection <SimpleCard>) this.HandListBox.ItemsSource).Remove(data);
        }
        private void DragSourcePreviewInputDeviceDown(object sender, InputEventArgs e)
        {
            FrameworkElement findSource     = e.OriginalSource as FrameworkElement;
            ScatterViewItem  draggedElement = null;

            // Find the ScatterViewItem object that is being touched.
            while (draggedElement == null && findSource != null)
            {
                if ((draggedElement = findSource as ScatterViewItem) == null)
                {
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
                }
            }

            if (draggedElement == null)
            {
                return;
            }

            DragableImageItem data = draggedElement.Content as DragableImageItem;

            // If the data has not been specified as draggable,
            // or the ScatterViewItem cannot move, return.
            if (data == null || !data.CanDrag || !draggedElement.CanMove)
            {
                return;
            }

            // Set the dragged element. This is needed in case the drag operation is canceled.
            data.DraggedElement = draggedElement;

            // Create the cursor visual.
            ContentControl cursorVisual = new ContentControl()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("CursorStyle") as Style
            };

            // Create a list of input devices,
            // and add the device passed to this event handler.
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);

            // If there are touch devices captured within the element,
            // add them to the list of input devices.
            foreach (InputDevice device in draggedElement.TouchesCapturedWithin)
            {
                if (device != e.Device)
                {
                    devices.Add(device);
                }
            }

            // Get the drag source object.
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            // Start the drag-and-drop operation.
            SurfaceDragCursor cursor =
                SurfaceDragDrop.BeginDragDrop(
                    // The ScatterView object that the cursor is dragged out from.
                    dragSource,
                    // The ScatterViewItem object that is dragged from the drag source.
                    draggedElement,
                    // The visual element of the cursor.
                    cursorVisual,
                    // The data attached with the cursor.
                    draggedElement.DataContext,
                    // The input devices that start dragging the cursor.
                    devices,
                    // The allowed drag-and-drop effects of the operation.
                    DragDropEffects.Move);

            // If the cursor was created, the drag-and-drop operation was successfully started.
            if (cursor != null)
            {
                // Hide the ScatterViewItem.
                draggedElement.Visibility = Visibility.Hidden;

                // This event has been handled.
                e.Handled = true;
            }
        }
        /*
         * Function called if the mouse button is down
         */
        private void OnDragSourcePreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement findSource     = e.OriginalSource as FrameworkElement;
            ScatterViewItem  draggedElement = null;

            // Find the ScatterViewItem object that is being touched.
            while (draggedElement == null && findSource != null)
            {
                if ((draggedElement = findSource as ScatterViewItem) == null)
                {
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
                }
            }
            // In case no element has been clicked
            if (draggedElement == null)
            {
                return;
            }


            SimpleCard data = draggedElement.Content as SimpleCard;

            // If the data has not been specified as draggable,
            // or the ScatterViewItem cannot move, return.
            if (data == null)
            {
                return;
            }

            // Create the cursor visual.
            ScatterViewItem cursorVisual = new ScatterViewItem()
            {
                Content = draggedElement.DataContext,
                Style   = FindResource("ScatterItemStyle") as Style
            };

            // Create a list of input devices. Add the touches that
            // are currently captured within the dragged element and
            // the current touch (if it isn't already in the list).
            List <InputDevice> devices = new List <InputDevice>();

            devices.Add(e.Device);
            foreach (TouchDevice touch in draggedElement.TouchesCapturedWithin)
            {
                if (touch != e.Device)
                {
                    devices.Add(touch);
                }
            }

            // Get the drag source object
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);

            SurfaceDragCursor startDragOkay =
                SurfaceDragDrop.BeginDragDrop(
                    dragSource,                 // The ScatterView object that the cursor is dragged out from.
                    draggedElement,             // The ScatterViewItem object that is dragged from the drag source.
                    cursorVisual,               // The visual element of the cursor.
                    draggedElement.DataContext, // The data attached with the cursor.
                    devices,                    // The input devices that start dragging the cursor.
                    DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.

            if (startDragOkay != null)
            {
                // Set e.Handled to true, otherwise the ScatterViewItem will capture the touch
                // and cause the BeginDragDrop to fail.
                e.Handled = true;
                // Hide the ScatterViewItem.
                draggedElement.Visibility = Visibility.Hidden;
            }

            // Remove the element from the container
            ((ObservableCollection <SimpleCard>) this.scatterView.ItemsSource).Remove(data);
        }
        void ProcessDropTarget(SurfaceDragCursor cursor, 
                               ObservableCollection<object> src, 
                               ObservableCollection<object> dst,
                               int NewResolutionCode)
        {
            if (cursorState == null)
                return;

            bool handled = false; 
            if (cursor.DragSource == cursor.CurrentTarget || src == null || dst==null)
            {
                DragCanceled();                
            }  
            else 
            {
                switch(cursorState.Operation)
                {
                    case DragCursorState.OperationType.None:
                        break;
                    case DragCursorState.OperationType.ResolveAgreement:
                        if (cursor.Data is ArgPoint)
                        {
                            ArgPoint ap = cursor.Data as ArgPoint;
                            if (src.Contains(ap))
                                src.Remove(ap);
                            dst.Add(ap);
                            ap.AgreementCode = NewResolutionCode;
                            handled = true;
                        }
                        else if (cursor.Data is BadgeFolder)
                        {
                            int ResolutionCode = -1;

                            if (cursor.CurrentTarget == unsolved)
                                ResolutionCode = (int)AgreementCode.UnsolvedAndGrouped;
                            else if(cursor.CurrentTarget == agreement)
                                ResolutionCode = (int)AgreementCode.AgreedAndGrouped;
                            else if(cursor.CurrentTarget == disagreement)
                                ResolutionCode = (int)AgreementCode.DisagreedAndGrouped;

                            if (ResolutionCode != -1)
                            {
                                BadgeFolder bf = cursor.Data as BadgeFolder;

                               // ScatterViewItem 
                                FrameworkElement itemContainer = (FrameworkElement)bf.Parent;
                                if (itemContainer != null && itemContainer.Parent is ScatterViewItem)
                                    itemContainer = (FrameworkElement)itemContainer.Parent;

                                if (itemContainer != null && itemContainer is ScatterViewItem)
                                {
                                    if (src.Contains(itemContainer))
                                    {
                                        src.Remove(itemContainer);
                                    }

                                    if (itemContainer is ContentControl)
                                    {
                                        if ((itemContainer as ContentControl).Content is Viewbox)
                                            ((itemContainer as ContentControl).Content as Viewbox).Child = null;

                                        (itemContainer as ContentControl).Content = null;
                                    }

                                    if(cursor.CurrentTarget==unsolved)
                                        dst.Add(CreateContainer(bf));
                                    else
                                        dst.Add(CreateSmallContainer(bf));

                                    foreach (ArgPoint ap in bf.model.ArgPoint)
                                        ap.AgreementCode = ResolutionCode;
                                    handled = true;
                                }
                            }
                        }
                        break;
                    case DragCursorState.OperationType.MoveToGroup:
                        if (cursorState.currentTarget is BadgeFolder && 
                            cursorState.draggedItem is ScatterViewItem &&
                            (cursorState.draggedItem as ScatterViewItem).Content is ArgPoint)
                        {
                            if(MoveToGroup((BadgeFolder)cursorState.currentTarget,
                                          (ArgPoint)(cursorState.draggedItem as ScatterViewItem).Content))
                                handled = true;
                        }
                        break;
                    case DragCursorState.OperationType.MoveFromGroup:
                        if (cursorState.DragSrc is BadgeFolder &&
                            cursorState.currentTarget == unsolved &&
                            (cursorState.draggedItem as ListBoxItem).Content is ArgPoint)
                        {
                            MoveFromGroup((BadgeFolder)cursorState.DragSrc, 
                                          (ArgPoint)(cursorState.draggedItem as ListBoxItem).Content);
                            handled = true;
                        }
                        break;
                    case DragCursorState.OperationType.MergeWith:
                        if ((cursorState.draggedItem as ScatterViewItem).Content is ArgPoint)
                        {
                            Badge target = (Badge)cursorState.currentTarget;
                            MergeTwoBadges((ArgPoint)target.DataContext, 
                                           (ArgPoint)(cursorState.draggedItem as ScatterViewItem).Content);
                            handled = true;
                        }
                        break;
                }
            }

            DragCanceled();

            if (handled)
            {
                CtxSingleton.SaveChangesIgnoreConflicts();
                
                //reset sviRotationBlocked to force-align new badges at next tick 
                sviRotationBlocked = false;

                HighlightOwnSmallBadges();

                _sharedClient.clienRt.SendNotifyStructureChanged(selectedTopic.Id);
            }

            dragDropTooltip.Content = "";
            cursorState = null;
        }