Beispiel #1
0
        public CrossWordPage()
        {
            InitializeComponent();
            BindingContext = new CrossWordDrawLineViewModel(canvas);
            gridButtonSize = App.ScreenWidth / gridMatrixSize;

            wordList.Add("ABC");
            wordList.Add("DE");
            wordList.Add("AEI");

            CreateGrid();
            CreateCanvas();
            AddButtons();
            clearCanvasButton.Clicked += ClearCanvasButton_Clicked;
        }
Beispiel #2
0
        private void OnTouch(object sender, Android.Views.View.TouchEventArgs args)
        {
            // Two object common to all the events
            Android.Views.View senderView  = sender as Android.Views.View;
            MotionEvent        motionEvent = args.Event;
            // Get the pointer index
            int pointerIndex = motionEvent.ActionIndex;

            // Get the id that identifies a finger over the course of its progress
            int id = motionEvent.GetPointerId(pointerIndex);

            senderView.GetLocationOnScreen(twoIntArray);
            Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                  twoIntArray[1] + motionEvent.GetY(pointerIndex));

            // Use ActionMasked here rather than Action to reduce the number of possibilities
            switch (args.Event.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                Console.WriteLine("GridBuuttonRenderer");

                //CrossWordDrawLineViewModel.touchPressed = new SKPoint(twoIntArray[0] + motionEvent.GetX(pointerIndex),
                //twoIntArray[1] + motionEvent.GetY(pointerIndex));

                CrossWordDrawLineViewModel.changeLineColor = false;
                CrossWordDrawLineViewModel.changeLineColorMethod();
                CrossWordDrawLineViewModel.touchPressed = GetPressedViewCenterPoint(senderView);

                FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true);

                idToEffectDictionary.Add(id, this);

                capture = libTouchEffect.Capture;
                break;

            case MotionEventActions.Move:
                // Multiple Move events are bundled, so handle them in a loop
                for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++)
                {
                    id = motionEvent.GetPointerId(pointerIndex);

                    if (capture)
                    {
                        senderView.GetLocationOnScreen(twoIntArray);


                        screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                        twoIntArray[1] + motionEvent.GetY(pointerIndex));

                        FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
                    }
                    else
                    {
                        CrossWordDrawLineViewModel.changeLineColor = false;
                        CheckForBoundaryHop(id, screenPointerCoords);
                        new MessageCenterHelper().SendMessageMenu(null);

                        if (idToEffectDictionary[id] != null)
                        {
                            FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true);
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
                if (capture)
                {
                    FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
                }
                else
                {
                    CheckForBoundaryHop(id, screenPointerCoords);
                    //CrossWordDrawLineViewModel.touchReleased = new SKPoint((float)screenPointerCoords.X, (float)screenPointerCoords.Y);

                    CrossWordDrawLineViewModel.changeLineColor = false;
                    new MessageCenterHelper().SendMessageMenu(null);

                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false);
                    }
                }
                idToEffectDictionary.Remove(id);
                break;

            case MotionEventActions.Cancel:
                if (capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                }
                else
                {
                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
                    }
                }
                idToEffectDictionary.Remove(id);
                break;
            }
        }