Exemple #1
0
        protected internal override void ProcessTouchPressed()
        {
            float x = MathUtils.BringToBounds(0, baseWidth, Touch.GetX()
                                              - GetScreenX())
                      / baseWidth - 0.5f;
            float y = MathUtils.BringToBounds(0, baseHeight, Touch.GetY()
                                              - GetScreenY())
                      / baseHeight - 0.5f;

            if (x == 0 && y == 0)
            {
                return;
            }
            if (MathUtils.Abs(x) > MathUtils.Abs(y))
            {
                if (x > 0)
                {
                    this.isRight = true;
                    this.isClick = true;
                    this.centerX = offsetX + x + (baseWidth - dotWidth) / 2
                                   + dotWidth * 0.75f;
                    this.centerY = offsetY + y + (baseHeight - dotHeight) / 2;
                    if (listener != null)
                    {
                        listener.Right();
                    }
                }
                else if (x < 0)
                {
                    this.isLeft  = true;
                    this.isClick = true;
                    this.centerX = offsetX + x + (baseWidth - dotWidth) / 2
                                   - dotWidth * 0.75f;
                    this.centerY = offsetY + y + (baseHeight - dotHeight) / 2;
                    if (listener != null)
                    {
                        listener.Left();
                    }
                }
                else if (x == 0)
                {
                    FreeClick();
                }
            }
            else
            {
                if (y > 0)
                {
                    this.isDown  = true;
                    this.isClick = true;
                    this.centerX = offsetX + x + (baseWidth - dotWidth) / 2 - 1;
                    this.centerY = offsetY + y + (baseHeight - dotHeight) / 2
                                   + dotHeight * 0.75f;
                    if (listener != null)
                    {
                        listener.Down();
                    }
                }
                else if (y < 0)
                {
                    this.isUp    = true;
                    this.isClick = true;
                    this.centerX = offsetX + x + (baseWidth - dotWidth) / 2 - 1;
                    this.centerY = offsetY + y + (baseHeight - dotHeight) / 2
                                   - dotHeight * 0.75f;
                    if (listener != null)
                    {
                        listener.Up();
                    }
                }
                else if (y == 0)
                {
                    FreeClick();
                }
            }
        }