Exemplo n.º 1
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (e.Action == MotionEventActions.Up)
            {
                Button          = DPadButtons.None;
                timer.AutoReset = false;
                timer.Stop();
                CreateCroppedBitmap();
                Invalidate();
            }
            else if (e.Action == MotionEventActions.Down)
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                currentEvent    = e;
                timer.AutoReset = true;
                timer.Start();
                double distance = Math.Sqrt(
                    Math.Pow(DPadCenter.X - e.GetX(), 2) + Math.Pow(DPadCenter.Y - e.GetY(), 2));

                if (distance > MiddleButtonRadius)
                {
                    if (distance < DPadBounds.Width() / 2)
                    {
                        int X = ((int)e.GetX() - DPadCenter.X), Y = -((int)e.GetY() - DPadCenter.Y);

                        double angle = 90 + RadianToDegree(angleBetween(new Android.Graphics.Point(X, Y), new Android.Graphics.Point(0, 0)));
                        angle = Rotated ? angle : angle + 45;

                        if ((angle >= 45) && (angle <= 135))
                        {
                            this.notifyButtonClick(DPadButtons.Up);
                        }
                        else if ((angle >= 135) && (angle <= 225))
                        {
                            this.notifyButtonClick(DPadButtons.Left);
                        }
                        else if ((angle >= 225) && (angle <= 315))
                        {
                            this.notifyButtonClick(DPadButtons.Down);
                        }
                        else
                        {
                            this.notifyButtonClick(DPadButtons.Right);
                        }
                    }
                }
                else
                {
                    this.notifyButtonClick(DPadButtons.Middle);
                }
                Console.WriteLine(st.ElapsedMilliseconds);
                CreateCroppedBitmap();
                Invalidate();
                st.Stop();
            }
            return(base.OnTouchEvent(e));
        }
Exemplo n.º 2
0
        protected override async void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            await LoadBitmap();

            Log.Debug("DPAD Height", DPadBounds.Height().ToString());
            CreateCroppedBitmap();
            Invalidate();
            base.OnLayout(changed, left, top, right, bottom);
        }