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_style.cc

    r350 r351  
    2121}
    2222
    23 bool style::get( element* e, const char* centry, std::string& s )
     23bool style::get( element* e, const char* centry, const char* cselector, std::string& s )
    2424{
    2525        lua::stack_guard guard( m_lua );
    26         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TSTRING ) ) return false;
     26        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false;
    2727        s = lua_tostring( m_lua, -1 );
    2828        return true;
    2929}
    3030
    31 bool style::get( element* e, const char* centry, vec4& vec )
     31bool style::get( element* e, const char* centry, const char* cselector, vec4& vec )
    3232{
    3333        lua::stack_guard guard( m_lua );
    34         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TTABLE ) ) return false;
     34        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false;
    3535        vec = vec4();
    3636        for (size_t i = 0; i < 4; ++i )
     
    4444}
    4545
    46 bool style::get( element* e, const char* centry, int& i )
     46bool style::get( element* e, const char* centry, const char* cselector, int& i )
    4747{
    4848        lua::stack_guard guard( m_lua );
    49         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TNUMBER ) ) return false;
     49        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
    5050        i = static_cast< int >( lua_tointeger( m_lua, -1 ) );
    5151        return true;
    5252}
    5353
    54 bool style::get( element* e, const char* centry, double& d )
     54bool style::get( element* e, const char* centry, const char* cselector, double& d )
    5555{
    5656        lua::stack_guard guard( m_lua );
    57         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), centry, LUA_TNUMBER ) ) return false;
     57        if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
    5858        d = lua_tonumber( m_lua, -1 );
    5959        return true;
     
    6464}
    6565
    66 bool style::resolve( const char* cid, const char* cclass, const char* centry, int type )
     66bool style::find_entry( const char* cselector, const char* centry, int type )
     67{
     68        if ( lua_istable( m_lua, -1 ) )
     69        {
     70                if ( cselector )
     71                {
     72                        lua_getfield( m_lua, -1, cselector );
     73                        if ( lua_istable( m_lua, -1 ) )
     74                        {
     75                                lua_getfield( m_lua, -1, centry );
     76                                if ( lua_type( m_lua, -1 ) == type )
     77                                {
     78                                        return true;
     79                                }
     80                                lua_pop( m_lua, 1 );
     81                        }
     82                        lua_pop( m_lua, 1 );
     83                }
     84
     85                lua_getfield( m_lua, -1, centry );
     86                if ( lua_type( m_lua, -1 ) == type ) return true;
     87        }
     88        return false;
     89}
     90
     91bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type )
    6792{
    6893        lua_getglobal( m_lua, "default" );
     
    7196        // check id
    7297        lua_getfield( m_lua, -1, cid );
    73         if ( lua_istable( m_lua, -1 ) )
    74         {
    75                 lua_getfield( m_lua, -1, centry );
    76                 if ( lua_type( m_lua, -1 ) == type ) return true;
    77         }
     98        if ( find_entry( cselector, centry, type ) ) return true;
    7899        lua_settop( m_lua, global );
    79100
    80101        // check class
    81102        lua_getfield( m_lua, -1, cclass );
    82         if ( lua_istable( m_lua, -1 ) )
    83         {
    84                 lua_getfield( m_lua, -1, centry );
    85                 if ( lua_type( m_lua, -1 ) == type ) return true;
    86         }
     103        if ( find_entry( cselector, centry, type ) ) return true;
    87104        lua_settop( m_lua, global );
    88105
    89106        // check entry
    90         lua_getfield( m_lua, -1, centry );
    91         if ( lua_type( m_lua, -1 ) == type ) return true;
     107        if ( find_entry( cselector, centry, type ) ) return true;
    92108        return false;
    93109}
Note: See TracChangeset for help on using the changeset viewer.