예제 #1
0
        protected override void OnPanning(MR.Gestures.PanEventArgs e)
        {
            base.OnPanning(e);

            TranslationX += e.DeltaDistance.X;
            TranslationY += e.DeltaDistance.Y;
        }
        private void Grid_Panned(object sender, MR.Gestures.PanEventArgs e)
        {
            if (dragging && draggingObject != null)
            {
                // drop object

                // remove clone
                theGrid.Children.Remove(cloneContainer);

                // make draggingObject visible again
                draggingObject.Opacity = 1;

                // change Items in ViewModel
                var draggingItem = VM.Items[originalIndex];
                VM.Items.RemoveAt(originalIndex);
                VM.Items.Insert(currentIndex, draggingItem);

                // tell VM that the order changed
                VM.DroppedCommand.Execute(draggingObject.BindingContext);
            }

            dragging       = false;
            draggingObject = null;
            clone          = null;
            cloneContainer = null;
        }
예제 #3
0
        protected override void OnPanning(MR.Gestures.PanEventArgs e)
        {
            base.OnPanning(e);

            //These two lines is what does the animations. TotalDistance is what made the animation smooth
            TranslationX += e.DeltaDistance.X;
            TranslationY += e.DeltaDistance.Y;
        }
 private void ContentPage_Panning(object sender, MR.Gestures.PanEventArgs e)
 {
     if (last == null)
     {
         ((ViewModels.CustomEventArgsViewModel)BindingContext).AddText($"starting pan gesture, DeltaDistance={e.DeltaDistance.X}/{e.DeltaDistance.Y}, TotalDistance={e.TotalDistance.X}/{e.TotalDistance.Y}, Velocity={e.Velocity.X}/{e.Velocity.Y}");
     }
     last = e;
 }
        protected override void OnPanning(MR.Gestures.PanEventArgs e)
        {
            base.OnPanning(e);

            if (Device.OS == TargetPlatform.WinPhone)
            {
                TranslationX += e.DeltaDistance.X * Scale;                              // unfortunately this has to be specified differently on WinPhone
                TranslationY += e.DeltaDistance.Y * Scale;                              // another bug in Xamarin Forms IMHO
            }
            else
            {
                TranslationX += e.DeltaDistance.X;
                TranslationY += e.DeltaDistance.Y;
            }
        }
예제 #6
0
        protected override void OnPanning(MR.Gestures.PanEventArgs e)
        {
            base.OnPanning(e);

            if (Device.RuntimePlatform == Device.WinPhone)
            {
                TranslationX += e.DeltaDistance.X * Scale;                              // unfortunately this has to be specified differently on WinPhone
                TranslationY += e.DeltaDistance.Y * Scale;                              // another bug in Xamarin Forms IMHO
            }                                                                           // TODO: remove when WinPhone has been obsoleted
            else
            {
                TranslationX += e.DeltaDistance.X;
                TranslationY += e.DeltaDistance.Y;
            }
        }
예제 #7
0
 protected override void OnPanning(MR.Gestures.PanEventArgs e)
 {
     base.OnPanning(e);
     Debug.WriteLine("in OnPanning");
     //TranslationX += e.DeltaDistance.X;
     //TranslationY += e.DeltaDistance.Y;
     //if (e.Center.X > 400)
     //{
     //    Debug.WriteLine("right swipe");
     //}
     //if (e.Center.X < 100)
     //{
     //    Debug.WriteLine("left swipe");
     //}
     //Debug.WriteLine(e.Center);
 }
        //This is called after panning is done, to update the block that got dropped
        void updateBlockDragged(object sender, MR.Gestures.PanEventArgs e)
        {
            if (finalXCord == -1 || finalYCord == -1)
            {
                return;
            }

            int finalCoordinatePoint = Int32.Parse(finalYCord.ToString() + finalXCord.ToString());

            string stringFinPoint = finalCoordinatePoint.ToString();

            //the only way the string is length 1 is if the point is in the first row causing the first number of int to be 0
            if (stringFinPoint.Length == 1)
            {
                stringFinPoint = "0" + stringFinPoint;
            }

            var label = e.Sender as MR.Gestures.Label;

            //Here we are getting the coordinates from the view model because for whatever reason we can't accurately get the coordinates through the file behind xaml
            initXCord = TicTacToeViewModel.initXCord;
            initYCord = TicTacToeViewModel.inityCord;

            finalXCord = TicTacToeViewModel.finalXCord;
            finalYCord = TicTacToeViewModel.finalYCord;

            //If the user doesn't have an image selected we can't put back the block to its final position
            if (label == null)
            {
                return;
            }

            //This sets the block thats getting dragged to its final spot it was dropped in
            int row    = Int32.Parse(stringFinPoint[0].ToString());
            int column = Int32.Parse(stringFinPoint[1].ToString());

            label.SetValue(Grid.RowProperty, row);
            label.SetValue(Grid.ColumnProperty, column);
            label.TranslationX = finalXCord;
            label.TranslationY = finalYCord;

            //resets everything after getting dropped
            TicTacToeViewModel.inityCord  = -1;
            TicTacToeViewModel.finalYCord = -1;
            TicTacToeViewModel.initXCord  = -1;
            TicTacToeViewModel.finalXCord = -1;
        }
        //Used to get the final point
        protected override void OnPanning(MR.Gestures.PanEventArgs e)
        {
            base.OnPanning(e);

            if (initXCord == -1 || inityCord == -1)
            {
                return;
            }

            finalXCord = (int)(e.Touches[0].X * 3 / e.ViewPosition.Width);
            finalYCord = (int)(e.Touches[0].Y * 3 / e.ViewPosition.Height);

            finalCoordinatesString = finalYCord.ToString() + finalXCord.ToString();

            //Checks if point isn't valid, if it isn't valid set them -1 since thats how we check them in GridXaml.
            if (initXCord < 0 || initXCord > 2 || inityCord < 0 || inityCord > 2 || finalXCord < 0 || finalXCord > 2 || finalYCord < 0 || finalYCord > 2)
            {
                initXCord              = -1;
                inityCord              = -1;
                finalXCord             = -1;
                finalYCord             = -1;
                finalCoordinatesString = "-1";
            }
        }
        private void Grid_Panning(object sender, MR.Gestures.PanEventArgs e)
        {
            if (!dragging && draggingObject != null)
            {
                // start dragging

                VM.StartDraggingCommand.Execute(draggingObject.BindingContext);

                dragging = true;

                originalIndex = currentIndex = theFlexLayout.Children.IndexOf(draggingObject);

                var draggingItem = (DragAndDropViewModel.ItemViewModel)draggingObject.BindingContext;

                // create a clone which looks like the draggingObject

                clone = new Frame()
                {
                    BindingContext = draggingObject.BindingContext,

                    BackgroundColor = draggingItem.Color,
                    CornerRadius    = draggingObject.CornerRadius,
                    BorderColor     = Color.Red,

                    Content = new Label()
                    {
                        Text = draggingItem.Text,
                        HorizontalOptions = LayoutOptions.Center,
                    }
                };

                // get position and size of the object
                (x, y) = GetAbsolutePosition(draggingObject);
                w      = draggingObject.Width;
                h      = draggingObject.Height;

                // add clone to the page at the same position as the draggingObject but on top
                cloneContainer = new AbsoluteLayout();
                cloneContainer.Children.Add(clone, new Rectangle(x, y, w, h));
                theGrid.Children.Add(cloneContainer);

                // make the draggingObject invisible, but the gap should be there
                draggingObject.Opacity = 0;
            }

            if (dragging && draggingObject != null)
            {
                // drag the clone
                x += e.DeltaDistance.X;
                y += e.DeltaDistance.Y;

                AbsoluteLayout.SetLayoutBounds(clone, new Rectangle(x, y, w, h));

                // check if the child under the touch coordinates changed
                var newIndex = GetChildAt(e.Touches[0]);
                if (newIndex == -1)
                {
                    newIndex = originalIndex;
                }

                if (newIndex != currentIndex)
                {
                    // child under touch changed

                    // -> move the draggingObject (=the gap) to the new position
                    theFlexLayout.Children.RemoveAt(currentIndex);
                    theFlexLayout.Children.Insert(newIndex, draggingObject);

                    currentIndex = newIndex;
                }
            }
        }
        //This function is basically used to do the animation as we are panning
        void Image_Panning(object sender, MR.Gestures.PanEventArgs e)
        {
            initXCord  = TicTacToeViewModel.initXCord;
            initYCord  = TicTacToeViewModel.inityCord;
            finalXCord = TicTacToeViewModel.finalXCord;
            finalYCord = TicTacToeViewModel.finalYCord;

            if (initXCord == -1 || initYCord == -1)
            {
                return;
            }

            int initialPoint = Int32.Parse(initYCord.ToString() + initXCord.ToString());

            //Here we are initializing the variable s to the image that we are controlling/panning
            var label = e.Sender as MR.Gestures.Label;

            if (label == null)
            {
                return;
            }

            MainGrid.RaiseChild(label);

            //These two lines is what does the animations. TotalDistance is what made the animation smooth. += Is what assigns a handler to an event
            label.TranslationX += e.TotalDistance.X;
            label.TranslationY += e.TotalDistance.Y;

            //This sets up once we try to trade images to bring it back to its original spot, due to it going past the grid length which kept causing bugs.
            if (e.ViewPosition.Y > MainGrid.Height)
            {
                TicTacToeViewModel.finalXCord = TicTacToeViewModel.initXCord;
                TicTacToeViewModel.finalYCord = TicTacToeViewModel.inityCord;
                return;
            }

            if (finalXCord < 0 || finalYCord < 0)
            {
                return;
            }

            int finalPoint = Int32.Parse(finalYCord.ToString() + finalXCord.ToString());

            //We are rotating the rest of the blocks as we are panning a block.
            if (initialPoint > finalPoint && prevFinalPoint != finalPoint)
            {
                shiftRightAnimation(initialPoint, finalPoint, label);
            }
            else if (initialPoint < finalPoint && prevFinalPoint != finalPoint)
            {
                shiftLeftAnimation(initialPoint, finalPoint, label);
            }

            prevFinalPoint = finalPoint;

            //This is used to update the initial point so it stops blocks from shifting that don't need to be shifted, therefore causeing overlap, page 246 of BuJo
            string initialUpdatedStringPoint = prevFinalPoint.ToString();;

            if (initialUpdatedStringPoint.Length == 1)
            {
                initialUpdatedStringPoint = "0" + initialUpdatedStringPoint;
            }

            TicTacToeViewModel.inityCord = Int32.Parse(initialUpdatedStringPoint[0].ToString());
            TicTacToeViewModel.initXCord = Int32.Parse(initialUpdatedStringPoint[1].ToString());
        }
 void Cell_Panned(object sender, MR.Gestures.PanEventArgs e)
 {
     ((TextOnlyViewModel)BindingContext).AddText("Cell_Panned method called");
 }
 private void ContentPage_Panned(object sender, MR.Gestures.PanEventArgs e)
 {
     last = null;
 }