Beispiel #1
0
    // GUIBASE_CALLBACK INTERFACE

    public override bool Callback(E_CallbackType type, object evt)
    {
        switch (type)
        {
        case E_CallbackType.E_CT_ON_TOUCH_END:
            if (OnSelectRow != null)
            {
                TouchEvent touch = (TouchEvent)evt;
                Vector2    point = touch.Position;
                point.y = Screen.height - point.y;
                for (int idx = 0; idx < m_Lines.Length; ++idx)
                {
                    GUIBase_Widget row = m_Lines[idx];
                    if (row.Visible == false)
                    {
                        continue;
                    }
                    if (row.IsMouseOver(point) == false)
                    {
                        continue;
                    }

                    OnSelectRow(row, idx, m_ItemOffset + idx);
                    break;
                }
            }
            if (OnProcessInput != null)             //send the events to the parent
            {
                TouchEvent touch = (TouchEvent)evt;
                if (m_Scrollbar != null)               //this event probably comes from scrollbar (because scrollbar is catching all touch events)
                {
                    touch.Id = -1;                     //and it doesn't have proper begin, this marks the event as 'faked'
                }
                IInputEvent inputEvent = (IInputEvent)touch;
                return(OnProcessInput(ref inputEvent));
            }
            return(true);

        default:
            return(false);
        }
    }
Beispiel #2
0
    //---------------------------------------------------------
    public override void ChildButtonReleased()
    {
        if (m_PopUpDelegate != null)
        {
            Vector2 eventPos = new Vector2();

            if (Input.touchCount != 0)
            {
                Touch t = Input.touches[0];

                eventPos.x = t.position.x;
                eventPos.y = t.position.y;
            }
            else
            {
                eventPos.x = Input.mousePosition.x;
                eventPos.y = Input.mousePosition.y;
            }

            eventPos.y = Screen.height - eventPos.y;

            // Find out if touch was released over one of popup buttons...
            for (int i = 0; i < m_PopUpButtons.Length; ++i)
            {
                if (m_PopUpButtons[i])
                {
                    GUIBase_Widget widget = m_PopUpButtons[i].Widget;

                    if (widget)
                    {
                        if (widget.IsMouseOver(eventPos))
                        {
                            // Call user's delegate
                            m_PopUpDelegate(i);
                            return;
                        }
                    }
                }
            }
        }
    }
Beispiel #3
0
 bool HitTest(GUIBase_Widget widget, Vector2 point)
 {
     point.y = Screen.height - point.y;
     return(widget != null?widget.IsMouseOver(point) : false);
 }
Beispiel #4
0
    // PRIVATE METHODS

    bool ForwardInputToRows(ref TouchEvent touch)
    {
        Vector3 point = touch.Position;

        point.y = Screen.height - point.y;

        bool hover    = m_RowsContainer.IsMouseOver(point);
        Row  hoverRow = hover ? HitTest(point) : null;
        bool refresh  = false;

        switch (touch.Phase)
        {
        case TouchPhase.Began:
            if (m_TouchId == -1)
            {
                refresh   = SelectRow(hoverRow);
                m_TouchId = touch.Id;
            }
            break;

        case TouchPhase.Canceled:
        case TouchPhase.Ended:
            if (m_TouchId == touch.Id)
            {
                if (m_TouchId == -1)                 //this is faked event from scrollbar (user clicked but didn't dragged)
                //we have to simulate the touch callbacks
                {
                    bool buttonPressed = false;
                    foreach (Row row in m_Rows)
                    {
                        if (row.IsSelected && row.IsVisible)
                        {
                            touch.Position = point;
                            buttonPressed  = row.ProcessTouchEnd(touch);
                            break;
                        }
                    }
                    if (!buttonPressed)
                    {
                        refresh = SelectRow(hoverRow);
                    }
                }
                m_TouchId = -1;
            }
            break;

        default:
            if (m_TouchId == touch.Id)
            {
                refresh = SelectRow(hoverRow);
            }
            break;
        }

        if (refresh == true)
        {
            RefreshRows();
        }

        return(refresh);
    }