Exemplo n.º 1
0
 //! 处理输入
 public override bool HandleInput(UITouchInner touch)
 {
     if (PtInRect(touch.position))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_State    = State.Pressed;
                m_FingerId = touch.fingerId;

                m_Parent.SendEvent(this, (int)Command.Down, 0, 0);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            if (touch.fingerId == m_FingerId)
            {
                if (touch.phase == TouchPhase.Moved)
                {
                    //
                    float dx = touch.position.x - m_Center.x;
                    float dy = touch.position.y - m_Center.y;

                    if (dy >= 0)
                    {
                        Direction = Mathf.Atan2(dy, dx);
                    }
                    else
                    {
                        Direction = Mathf.Atan2(dy, dx) + 2 * Mathf.PI;
                    }

                    m_Parent.SendEvent(this, (int)Command.Rotate, m_Direction, 0);
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    m_State    = State.Normal;
                    m_FingerId = -1;

                    m_Parent.SendEvent(this, (int)Command.Up, 0, 0);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Exemplo n.º 3
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_State    = State.Pressed;
                m_FingerId = touch.fingerId;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            if (touch.fingerId == m_FingerId)
            {
                if (touch.phase == TouchPhase.Moved)
                {
                    if (PtInRect(touch.position))
                    {
                        m_State = State.Pressed;
                    }
                    else
                    {
                        m_State = State.Normal;
                    }
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    m_State    = State.Normal;
                    m_FingerId = -1;

                    if (PtInRect(touch.position))
                    {
                        m_Parent.SendEvent(this, (int)Command.Click, 0, 0);
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Exemplo n.º 4
0
 public override bool HandleInput(UITouchInner touch)
 {
     for (int i = m_Controls.Count - 1; i >= 0; --i)
     {
         UIControl control = (UIControl)m_Controls[i];
         if (control.Enable)
         {
             bool handle = control.HandleInput(touch);
             if (handle)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 5
0
 //! 处理输入
 public override bool HandleInput(UITouchInner touch)
 {
     if (touch.phase == TouchPhase.Began)
     {
         m_TouchFingerId = touch.fingerId;
     }
     else if (touch.phase == TouchPhase.Ended)
     {
         if (touch.fingerId == m_TouchFingerId && PtInRect(touch.position))
         {
             m_Parent.SendEvent(this, (int)Command.Click, 0, 0);
             m_TouchFingerId = -1;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
 //! 处理输入
 public virtual bool HandleInput(UITouchInner touch)
 {
     return(false);
 }
Exemplo n.º 7
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_State    = State.Pressed;
                m_FingerId = touch.fingerId;

                m_Parent.SendEvent(this, (int)Command.Down, 0, 0);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            if (touch.fingerId == m_FingerId)
            {
                if (touch.phase == TouchPhase.Moved)
                {
                    //
                    float dx = touch.position.x - m_Center.x;
                    float dy = touch.position.y - m_Center.y;

                    m_Distance = Mathf.Sqrt(dx * dx + dy * dy);
                    if ((m_MinDistance >= 0) && (m_Distance < m_MinDistance))
                    {
                        m_Distance = m_MinDistance;
                    }
                    if ((m_MaxDistance >= 0) && (m_Distance > m_MaxDistance))
                    {
                        m_Distance = m_MaxDistance;
                    }

                    if (dy >= 0)
                    {
                        m_Direction = Mathf.Atan2(dy, dx);
                    }
                    else
                    {
                        m_Direction = Mathf.Atan2(dy, dx) + 2 * Mathf.PI;
                    }

                    UpdatePosition();

                    m_Parent.SendEvent(this, (int)Command.Move, m_Direction, m_Distance);
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    m_State    = State.Normal;
                    m_FingerId = -1;

                    m_Distance = 0;
                    UpdatePosition();

                    m_Parent.SendEvent(this, (int)Command.Up, 0, 0);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Exemplo n.º 8
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_FingerId = touch.fingerId;

                //
                float dx = touch.position.x - m_Center.x;
                float dy = touch.position.y - m_Center.y;

                if (dy >= 0)
                {
                    m_TouchDirection = Mathf.Atan2(dy, dx);
                }
                else
                {
                    m_TouchDirection = Mathf.Atan2(dy, dx) + 2 * Mathf.PI;
                }

                m_Rotate = false;
            }

            return(false);
        }
        else
        {
            if (touch.fingerId != m_FingerId)
            {
                return(false);
            }

            if (!PtInRect(touch.position))
            {
                return(false);
            }

            if (touch.phase == TouchPhase.Moved)
            {
                //
                float dx = touch.position.x - m_Center.x;
                float dy = touch.position.y - m_Center.y;

                float direction;
                if (dy >= 0)
                {
                    direction = Mathf.Atan2(dy, dx);
                }
                else
                {
                    direction = Mathf.Atan2(dy, dx) + 2 * Mathf.PI;
                }

                float delta_direction = direction - m_TouchDirection;
                if (delta_direction < 0)
                {
                    delta_direction += 2 * Mathf.PI;
                }
                if (delta_direction > Mathf.PI)
                {
                    delta_direction = delta_direction - 2 * Mathf.PI;
                }

                if (m_Rotate)
                {
                    m_TouchDirection = direction;
                    m_Parent.SendEvent(this, (int)Command.Rotate, delta_direction, 0);
                }
                else
                {
                    float abs_delta_direction = (delta_direction >= 0) ? delta_direction : -delta_direction;

                    if (abs_delta_direction > m_MinRotate)
                    {
                        m_TouchDirection = direction;
                        m_Rotate         = true;

                        m_Parent.SendEvent(this, (int)Command.Begin, 0, 0);
                        m_Parent.SendEvent(this, (int)Command.Rotate, delta_direction, 0);
                    }
                    else
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                bool rotate = m_Rotate;

                m_FingerId       = -1;
                m_TouchDirection = 0;
                m_Rotate         = false;

                if (rotate)
                {
                    m_Parent.SendEvent(this, (int)Command.End, 0, 0);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
    }
Exemplo n.º 9
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_TouchInfo[m_FingerIndex].FingerId      = touch.fingerId;
                m_TouchInfo[m_FingerIndex].TouchPosition = touch.position;
                if (m_FingerIndex == 0)
                {
                    m_FingerIndex = 1;
                }
                else
                {
                    m_FingerIndex = 0;
                }

                if ((m_TouchInfo[0].FingerId != -1) && (m_TouchInfo[1].FingerId != -1))
                {
                    Vector2 d = m_TouchInfo[0].TouchPosition - m_TouchInfo[1].TouchPosition;
                    m_Distance = d.magnitude;
                    m_Zoom     = true;

                    m_Parent.SendEvent(this, (int)Command.Begin, 0, 0);
                }
            }

            return(false);
        }
        else if (touch.phase == TouchPhase.Moved)
        {
            if ((m_TouchInfo[0].FingerId == -1) || (m_TouchInfo[1].FingerId == -1))
            {
                return(false);
            }

            if (!PtInRect(touch.position))
            {
                return(false);
            }

            if (m_TouchInfo[0].FingerId == touch.fingerId)
            {
                m_TouchInfo[0].TouchPosition = touch.position;
            }
            else if (m_TouchInfo[1].FingerId == touch.fingerId)
            {
                m_TouchInfo[1].TouchPosition = touch.position;
            }
            else
            {
                return(false);
            }

            //
            Vector2 d        = m_TouchInfo[0].TouchPosition - m_TouchInfo[1].TouchPosition;
            float   distance = d.magnitude;
            float   delta    = distance - m_Distance;
            m_Distance = distance;

            m_Parent.SendEvent(this, (int)Command.Zoom, delta, 0);

            return(true);
        }
        else if (touch.phase == TouchPhase.Ended)
        {
            bool rc = false;

            for (int i = 0; i < 2; i++)
            {
                if (m_TouchInfo[i].FingerId == touch.fingerId)
                {
                    m_TouchInfo[i].FingerId = -1;
                    m_FingerIndex           = i;

                    if (m_Zoom)
                    {
                        m_Zoom = false;
                        m_Parent.SendEvent(this, (int)Command.End, 0, 0);
                        rc = true;
                    }
                }
            }

            return(rc);
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 10
0
    //! 处理输入
    public override bool HandleInput(UITouchInner touch)
    {
        /*
         * if (!PtInRect(touch.position) && touch.phase == TouchPhase.Ended)
         * {
         *  m_Parent.SendEvent(this, (int)Command.End, 0, 0);
         *  return false;
         * }
         */



        if (touch.phase == TouchPhase.Began)
        {
            if (PtInRect(touch.position))
            {
                m_FingerId      = touch.fingerId;
                m_TouchPosition = touch.position;
                m_Move          = false;
                m_Parent.SendEvent(this, (int)Command.Begin, touch.position.x, touch.position.y);
            }

            return(false);
        }
        else
        {
            if (touch.fingerId != m_FingerId)
            {
                return(false);
            }

            /*
             *          if (!PtInRect(touch.position))
             *          {
             *                  return false;
             *          }
             */


            if (touch.phase == TouchPhase.Moved)
            {
                float dx = touch.position.x - m_TouchPosition.x;
                float dy = touch.position.y - m_TouchPosition.y;

                if (m_Move)
                {
                    m_TouchPosition = touch.position;
                    m_Parent.SendEvent(this, (int)Command.Move, dx, dy);
                    m_Parent.SendEvent(this, (int)Command.MovePos, touch.position.x, touch.position.y);
                }
                else
                {
                    float abs_dx = (dx >= 0) ? dx : -dx;
                    float abs_dy = (dy >= 0) ? dy : -dy;

                    if ((abs_dx > m_MinX) || (abs_dy > m_MinY))
                    {
                        m_TouchPosition = touch.position;
                        m_Move          = true;
                        m_Parent.SendEvent(this, (int)Command.Move, dx, dy);
                    }
                    else
                    {
                    }
                }



                return(true);
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                bool move = m_Move;

                m_FingerId      = -1;
                m_TouchPosition = new Vector2(0, 0);
                m_Move          = false;

                //if (move)
                {
                    m_Parent.SendEvent(this, (int)Command.End, touch.position.x, touch.position.y);
                    return(false);
                }
                //else
                {
                    //	return false;
                }
            }

            return(false);
        }
    }