Exemplo n.º 1
0
        //=========================================================================================
        /// <summary> 
        /// Chooses the current widget that is to be in focus. Picks the first widget that has the 
        /// 'DefaultFocus' flag set to true, or if that fails the first focusable widget.
        /// </summary>
        //=========================================================================================
        private void ChooseFocusWidget()
        {
            // Lock the objects list:

            m_data.Lock();

                // Clear the current focus widget:

                m_focus_widget = null;

                // Run through the list of widgets and try to find a default focus one:

                Dictionary<int,GuiWidget>.Enumerator e = m_data.Objects.GetEnumerator();

                    while ( e.MoveNext() )
                    {
                        // See if this is a default focus widget:

                        if ( e.Current.Value.DefaultFocus )
                        {
                            // Found our focus widget: set

                            m_focus_widget = e.Current.Value;

                            // Call the gained focus event:

                            m_focus_widget.OnFocusGained();

                            // Abort search

                            m_data.Unlock(); return;
                        }
                    }

                // Ok: run through the list of widgets that can have focus and try to pick one

                e = m_data.Objects.GetEnumerator();

                    while ( e.MoveNext() )
                    {
                        // See if this is a default focus widget:

                        if ( e.Current.Value.CanFocus )
                        {
                            // Found our focus widget: set

                            m_focus_widget = e.Current.Value;

                            // Call the gained focus event:

                            m_focus_widget.OnFocusGained();

                            // Abort search

                            m_data.Unlock(); return;
                        }
                    }

            // Unlock the objects list:

            m_data.Unlock();
        }
Exemplo n.º 2
0
        //=========================================================================================
        /// <summary> 
        /// Makes focus shift in the direction specified if allowed.
        /// </summary>
        //=========================================================================================
        public void TraverseFocus( FocusTraversalDirection direction )
        {
            // See if there is a focus widget: we can do nowt if there is none

            if ( m_focus_widget != null )
            {
                // Ok: see what direction we have to move in

                switch ( direction )
                {
                    // Move focus to the left:

                    case FocusTraversalDirection.LEFT:
                    {
                        // Try to find the next widget to focus on:

                        GuiWidget next_focus_widget = m_search.FindByName( m_focus_widget.LeftWidget );

                        // If found then switch focus:

                        if ( next_focus_widget != null )
                        {
                            // Switch focus:

                            m_focus_widget.OnFocusLost();  m_focus_widget = next_focus_widget;

                            // Call focus gained on new widget:

                            m_focus_widget.OnFocusGained();
                        }

                    }   break;

                    case FocusTraversalDirection.RIGHT:
                    {
                        // Try to find the next widget to focus on:

                        GuiWidget next_focus_widget = m_search.FindByName( m_focus_widget.RightWidget );

                        // If found then switch focus:

                        if ( next_focus_widget != null )
                        {
                            // Switch focus:

                            m_focus_widget.OnFocusLost();  m_focus_widget = next_focus_widget;

                            // Call focus gained on new widget:

                            m_focus_widget.OnFocusGained();
                        }

                    }   break;

                    case FocusTraversalDirection.ABOVE:
                    {
                        // Try to find the next widget to focus on:

                        GuiWidget next_focus_widget = m_search.FindByName( m_focus_widget.AboveWidget );

                        // If found then switch focus:

                        if ( next_focus_widget != null )
                        {
                            // Switch focus:

                            m_focus_widget.OnFocusLost();  m_focus_widget = next_focus_widget;

                            // Call focus gained on new widget:

                            m_focus_widget.OnFocusGained();
                        }

                    }   break;

                    case FocusTraversalDirection.BELOW:
                    {
                        // Try to find the next widget to focus on:

                        GuiWidget next_focus_widget = m_search.FindByName( m_focus_widget.BelowWidget );

                        // If found then switch focus:

                        if ( next_focus_widget != null )
                        {
                            // Switch focus:

                            m_focus_widget.OnFocusLost();  m_focus_widget = next_focus_widget;

                            // Call focus gained on new widget:

                            m_focus_widget.OnFocusGained();
                        }

                    }   break;

                }   // end switch ( direction )
            }
        }