Ignore:
Timestamp:
02/15/15 21:33:48 (10 years ago)
Author:
epyon
Message:
  • gui hover and selected support
  • minor changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/gui_environment.cc

    r344 r351  
    2929{
    3030        m_area.dim( dimension( w->get_width(), w->get_height() ) );
    31        
    32         m_screen           = m_elements.create();
    33         element* screen    = m_elements.get( m_screen );
    34         screen->m_absolute = m_area;
    35         screen->m_relative = m_area;
    36 
    3731        m_renderer = new renderer( w );
     32        m_screen   = create_element( handle(), m_area );
    3833}
    3934
     
    5146{
    5247        if ( parent.is_nil() ) parent = m_screen;
     48
    5349        handle result = m_elements.create();
    5450        element* e    = m_elements.get( result );
     
    5854        if ( ar.ul.y < 0 ) { ar.ul.y += m_area.lr.y; ar.lr.y += m_area.lr.y; }
    5955
     56        e->m_child_count = 0;
     57        e->m_flags[ENABLED] = true;
     58        e->m_flags[VISIBLE] = true;
     59        e->m_flags[DIRTY]   = true;
     60        e->m_render_data    = nullptr;
    6061        e->m_absolute = ar;
    6162        e->m_relative = ar;
    62         add_child( parent, result );
     63
     64        if ( !parent.is_nil() ) // screen creation
     65                add_child( parent, result );
    6366        return result;
    6467}
     
    8386        if ( !el ) return;
    8487        //      el->on_update( elapsed );
    85         if ( el->m_visible )
     88        if ( el->m_flags[ENABLED] )
     89        {
     90                bool hover     = el->m_flags[HOVER];
     91                bool new_hover = el->m_absolute.contains( m_mouse_position );
     92                if ( hover != new_hover )
     93                {
     94                        el->m_flags[HOVER] = new_hover;
     95                        // gain loose hover event
     96                        m_renderer->on_hover_change( el, hover );
     97                }
     98        }
     99
     100        if ( el->m_flags[VISIBLE] )
    86101        {
    87102                for ( handle i : el->m_children )
     
    90105                }
    91106        }
    92         if ( el->m_dirty || el->m_render_data == nullptr )
     107        if ( el->m_flags[DIRTY] || el->m_render_data == nullptr )
    93108        {
    94109                m_renderer->redraw( el, elapsed );
    95                 el->m_dirty = false;
     110                el->m_flags[DIRTY] = false;
    96111        }
    97112}
     
    101116        element* el = m_elements.get( e );
    102117        if ( !el ) return;
    103         if ( el->m_visible )
     118        if ( el->m_flags[VISIBLE] )
    104119        {
    105120//              el->on_draw();
     
    160175}
    161176
    162 bool nv::gui::environment::process_io_event( const io_event& )
    163 {
     177bool nv::gui::environment::process_io_event( const io_event& ev )
     178{
     179        switch ( ev.type )
     180        {
     181//      case EV_KEY          :
     182        case EV_MOUSE_BUTTON :
     183                if ( ev.mbutton.pressed && ev.mbutton.button == MOUSE_LEFT )
     184                {
     185                        handle h = get_element( position( ev.mbutton.x, ev.mbutton.y ) );
     186                        set_selected( h );
     187                        return true;
     188                }
     189                return false;
     190        case EV_MOUSE_MOVE:
     191                m_mouse_position = position( ev.mmove.x, ev.mmove.y );
     192                return false;
     193//      case EV_MOUSE_WHEEL  :
     194        default:
     195                break;
     196        }
     197        return false;
     198}
     199
     200bool nv::gui::environment::set_selected( handle e )
     201{
     202        if ( e != m_selected )
     203        {
     204                element* eold = m_elements.get( m_selected );
     205                element* el   = m_elements.get( e );
     206                if ( eold )
     207                {
     208                        eold->m_flags[SELECTED] = false;
     209                        m_renderer->on_select_change( eold, false );
     210                }
     211                if ( el )
     212                {
     213                        el->m_flags[SELECTED] = true;
     214                        m_renderer->on_select_change( el, true );
     215                }
     216                m_selected = e;
     217                return true;
     218        }
    164219        return false;
    165220}
     
    179234{
    180235        element* el = m_elements.get(e);
    181         if ( !el && !el->m_visible ) return handle();
     236        if ( !el && !el->m_flags[VISIBLE] ) return handle();
    182237
    183238        handle result;
     
    206261                        parent->m_children.erase( it );
    207262                        parent->m_children.push_back( child );
    208                         parent->m_dirty = true;
     263                        parent->m_flags[DIRTY] = true;
    209264                }       
    210265        }
     
    222277                        parent->m_children.erase( it );
    223278                        parent->m_children.push_front( child );
    224                         parent->m_dirty = true;
     279                        parent->m_flags[DIRTY] = true;
    225280                }
    226281        }
     
    232287        if ( el )
    233288        {
    234                 el->m_dirty    = true;
    235                 el->m_relative = r;
     289                el->m_flags[DIRTY] = true;
     290                el->m_relative     = r;
    236291                recalculate_absolute( e );
    237292        }
     
    264319        if ( ep != nullptr )
    265320        {
    266                 ep->m_class = text;
    267                 ep->m_dirty = true;
     321                ep->m_class        = text;
     322                ep->m_flags[DIRTY] = true;
    268323        }
    269324}
     
    274329        if ( ep != nullptr )
    275330        {
    276                 ep->m_text = text;
    277                 ep->m_dirty = true;
     331                ep->m_text         = text;
     332                ep->m_flags[DIRTY] = true;
    278333        }
    279334}
Note: See TracChangeset for help on using the changeset viewer.