Ejemplo n.º 1
0
 /// <summary>
 /// Adds a control
 /// </summary>
 /// <param name="control">Control to be added</param>
 public void AddControl(GuiControl control)
 {
     m_controls.Add(control);
     ToFront(control);
 }
Ejemplo n.º 2
0
        public override void OnKeyboard(List<Keys> pressedKeys, List<Keys> releasedKeys, char pressedChar, int pressedKey, float elapsedTime)
        {
            base.OnKeyboard(pressedKeys, releasedKeys, pressedChar, pressedKey, elapsedTime);
            //if (pressedKey == (int)Keys.Tab)
            //{
            //    if (m_controlInFocus != null)
            //    {
            //        int i = (m_controls.IndexOf(m_controlInFocus) + 1) % m_controls.Count;
            //        m_controlInFocus = m_controls[i];
            //        ToFront(i);
            //    }
            //    else
            //    {
            //        if (m_controls.Count > 0)
            //            m_controlInFocus = m_controls[0];
            //    }
            //}
            //else
            //{
                if (m_controlInFocus != null)
                    m_controlInFocus.OnKeyboard(pressedKeys, releasedKeys, pressedChar, pressedKey, elapsedTime);
            //}

            //we check for controls that have to be closed
            for (int i = 0; i < m_controls.Count; i++)
            {
                if (m_controls[i].HasFinished)
                {
                    if (m_controls[i] == m_currentControl)
                        m_currentControl = null;
                    if (m_controls[i] == m_controlInFocus)
                        m_controlInFocus = null;
                    m_controls.RemoveAt(i);
                    GC.Collect(0);
                    i--;
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Removes a control
 /// </summary>
 /// <param name="control">Control to be added</param>
 public void RemoveControl(GuiControl control)
 {
     m_controls.Remove(control);
     if (m_controlInFocus == control)
         m_controlInFocus = null;
     if (m_currentControl == control)
         m_currentControl = null;
 }
Ejemplo n.º 4
0
 private void ToFront(GuiControl control)
 {
     m_controls.Remove(control);
     m_controls.Insert(0, control);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds a new control to the window.
 /// </summary>
 /// <param name="control"></param>
 public void AddControl(GuiControl control)
 {
     control.PositionDelta = this.Offset;
     m_controls.Add(control);
 }
Ejemplo n.º 6
0
        public override void OnMouse(Point position, int xDelta, int yDelta, int zDelta, bool[] pressedButtons, bool[] releasedButtons, float elapsedTime)
        {
            base.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);

            //if control is moving, we don't process anytrhing else
            if (m_currentControl != null && m_currentControl.LocksMouse)
            {
                m_currentControl.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);
            }
            else
            {
                if (m_currentControl != null)
                {
                    if (m_currentControl.ContainsPoint(position))
                    {
                        //m_currentControl.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);
                    }
                    else
                    {
                        m_currentControl.OnMouseLeave();
                        m_currentControl = null;
                    }
                }

                for (int i = 0; i < m_controls.Count; i++)
                {
                    if (m_controls[i].ContainsPoint(position))
                    {
                        if (m_controls[i] != m_currentControl)
                        {
                            if (m_currentControl != null)
                            {
                                m_currentControl.OnMouseLeave();
                            }
                            m_controls[i].OnMouseEnter();
                            //we have a new currentControl
                            m_currentControl = m_controls[i];
                        }
                        m_controls[i].OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);
                        break;
                    }
                }

                if (pressedButtons[0])
                {
                    //if there is a currentControl, we can set HasFocus property
                    if (m_currentControl != null && m_currentControl != m_controlInFocus)
                    {
                        if (m_controlInFocus != null)
                        {
                            m_controlInFocus.OnEndFocus();
                        }
                        m_currentControl.OnBeginFocus();
                        m_controlInFocus = m_currentControl;
                        //control in focus goes to the front of the list
                        ToFront(m_controls.IndexOf(m_controlInFocus));
                    }
                    //if there is no currentControl, but there is controlInFocus
                    //it means that focus has been lost
                    else if (m_controlInFocus != null && m_currentControl == null)
                    {
                        m_controlInFocus.OnEndFocus();
                        m_controlInFocus = null;
                    }

                }
            }

            //we check for controls that have to be closed
            for (int i = 0; i < m_controls.Count; i++)
            {
                if (m_controls[i].HasFinished)
                {
                    if (m_controls[i] == m_currentControl)
                        m_currentControl = null;
                    if (m_controls[i] == m_controlInFocus)
                        m_controlInFocus = null;
                    m_controls.RemoveAt(i);
                    GC.Collect(0);
                    i--;
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Removes a control from the window.
 /// </summary>
 /// <param name="control"></param>
 public void RemoveControl(GuiControl control)
 {
     m_controls.Remove(control);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// This method is called when control recieves focus.
 /// </summary>
 public override void OnMouseLeave()
 {
     base.OnMouseLeave();
     if (m_currentControl != null)
     {
         m_currentControl.OnMouseLeave();
         m_currentControl = null;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Processes mouse data.
        /// </summary>
        /// <param name="position">Mouse position</param>
        /// <param name="xDelta">x delta (in pixels)</param>
        /// <param name="yDelta">y delta (in pixels)</param>
        /// <param name="zDelta">Scroll delta (in ??)</param>
        /// <param name="pressedButtons">Pressed buttons (0-left button)</param>
        /// <param name="releasedButtons">Released buttons (0-left button)</param>
        /// <param name="elapsedTime">T0 since last frame</param>   
        public override void OnMouse(PointF position, float xDelta, float yDelta, int zDelta, bool[] pressedButtons, bool[] releasedButtons, float elapsedTime)
        {
            base.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);

            //first we translate mouse coords to window space
            //because all controls require it(except for windows)
            position.X -= m_usableRect.X;
            position.Y -= m_usableRect.Y;

            //if currentControl is moving, we don't process anything else
            if (m_currentControl != null && m_currentControl.LocksMouse)
            {
                m_currentControl.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);

                if (m_currentControl.LocksMouse == false)
                    this.LocksMouse = false;
                return;
            }

            //first we check if mouse was clicked on the title bar
            //if so,ten window is going to move
            if (pressedButtons[0])
            {
                if (m_isMoving)
                {
                    Move(xDelta, yDelta);
                    return;
                }
                else if (m_titleRect.Contains(position.X + m_usableRect.X, position.Y + m_usableRect.Y))
                {
                    if (m_closingCross.ContainsPoint(position))
                    {
                        Close();
                    }
                    m_isMoving = true;
                    LocksMouse = true;
                    Move(xDelta, yDelta);
                    return;
                }
            }
            //if we got this far, the window is not in moving state
            //so we perform normal control management
            m_isMoving = false;
            LocksMouse = false;

            if (m_currentControl != null)
            {
                if (m_currentControl.ContainsPoint(position))
                {
                    //m_currentControl.OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);
                }
                else
                {
                    m_currentControl.OnMouseLeave();
                    m_currentControl = null;
                }
            }

            for (int i = 0; i < m_controls.Count; i++)
            {
                if (m_controls[i].ContainsPoint(position) && !m_controls[i].IsDisabled)
                {
                    if (m_controls[i] != m_currentControl)
                    {
                        if (m_currentControl != null)
                        {
                            m_currentControl.OnMouseLeave();
                        }
                        m_controls[i].OnMouseEnter();
                        //we have a new currentControl
                        m_currentControl = m_controls[i];
                    }
                    m_controls[i].OnMouse(position, xDelta, yDelta, zDelta, pressedButtons, releasedButtons, elapsedTime);
                    break;
                }
            }

            if (pressedButtons[0])
            {
                //if there is a currentControl, we can set HasFocus property
                if (m_currentControl != null && m_currentControl != m_controlInFocus)
                {
                    if (m_controlInFocus != null)
                    {
                        m_controlInFocus.OnEndFocus();
                    }
                    if (m_currentControl.RecievesFocus)
                    {
                        m_currentControl.OnBeginFocus();
                        m_controlInFocus = m_currentControl;
                    }
                    else
                        m_controlInFocus = null;

                    //control in focus goes to the front of the list
                    //ToFront(m_controls.IndexOf(m_controlInFocus));
                }
                //if there is no currentControl, but there is controlInFocus
                //it means that focus has been lost
                else if (m_controlInFocus != null && m_currentControl == null)
                {
                    m_controlInFocus.OnEndFocus();
                    m_controlInFocus = null;
                }
            }
            //at the end we check if m_currentControl locks mouse
            //if so, then this window has to lock mouse too
            if (m_currentControl != null && m_currentControl.LocksMouse)
            {
                this.LocksMouse = true;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Processes keyboard data.
        /// </summary>
        /// <param name="pressedKeys">List of pressed keys</param>
        /// <param name="releasedKeys">List of released keys (since last frame)</param>
        /// <param name="pressedChar">Last pressed key as a character</param>
        /// <param name="pressedKey">Last pressed key as int</param>
        /// <param name="elapsedTime">T0 since last frame</param>
        public override void OnKeyboard(List<Keys> pressedKeys, List<Keys> releasedKeys, char pressedChar, int pressedKey, float elapsedTime)
        {
            base.OnKeyboard(pressedKeys, releasedKeys, pressedChar, pressedKey, elapsedTime);
            if (pressedKey == (int)Keys.Tab)
            {
                if (m_controlInFocus != null)
                {
                    //m_controlInFocus = null;
                    int b = m_controls.IndexOf(m_controlInFocus);
                    for (int i = 1; i < m_controls.Count-1 ; i++)
                    {
                        if (m_controls[(b + i) % m_controls.Count].RecievesFocus && !m_controls[(b + i) % m_controls.Count].IsDisabled)
                        {
                            m_controlInFocus.OnEndFocus();
                            m_controlInFocus = m_controls[(b + i) % m_controls.Count];
                            m_controlInFocus.OnBeginFocus();
                            break;
                        }
                    }

                }
                else
                {
                    if (m_controls.Count > 0)
                    {
                        for (int i = 0; i < m_controls.Count; i++)
                        {
                            if (m_controls[i].RecievesFocus && !m_controls[i % m_controls.Count].IsDisabled)
                            {
                                m_controlInFocus = m_controls[i];
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                if (m_controlInFocus != null && !m_controlInFocus.IsDisabled)
                {
                    m_controlInFocus.OnKeyboard(pressedKeys, releasedKeys, pressedChar, pressedKey, elapsedTime);
                }

            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// This method is called when this control loses focus. 
 /// </summary>
 public override void OnEndFocus()
 {
     base.OnEndFocus();
     if (m_controlInFocus != null)
     {
         m_controlInFocus.OnEndFocus();
         m_controlInFocus = null;
     }
 }