Changeset 440 for trunk/src/gui/gui_style.cc
- Timestamp:
- 07/23/15 21:16:01 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/gui_style.cc
r433 r440 7 7 #include "nv/gui/gui_style.hh" 8 8 9 #include "nv/gui/gui_environment.hh" 9 10 #include <nv/lua/lua_raw.hh> 10 11 … … 12 13 using namespace nv::gui; 13 14 14 style::style()15 {16 }17 18 15 void style::load_style( const string_view& filename ) 19 16 { 17 NV_ASSERT_ALWAYS( m_env, "Environment not set in style!" ); 20 18 m_lua.do_file( filename ); 21 19 } 22 20 23 bool style::get( element* e, const char* centry, const char* cselector, std::string& s )21 bool style::get( element* e, const string_view& centry, const string_view& cselector, string128& s ) 24 22 { 25 23 lua::stack_guard guard( m_lua ); 26 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false; 27 s = lua_tostring( m_lua, -1 ); 24 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TSTRING ) ) return false; 25 // TODO: create lua_tostringbuffer< size > 26 s.assign( lua_tostring( m_lua, -1 ) ); 28 27 return true; 29 28 } 30 29 31 bool style::get( element* e, const char* centry, const char*cselector, vec4& vec )30 bool style::get( element* e, const string_view& centry, const string_view& cselector, vec4& vec ) 32 31 { 33 32 lua::stack_guard guard( m_lua ); 34 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false;33 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TTABLE ) ) return false; 35 34 vec = vec4(); 36 35 for ( int i = 0; i < 4; ++i ) … … 44 43 } 45 44 46 bool style::get( element* e, const char* centry, const char*cselector, int& i )45 bool style::get( element* e, const string_view& centry, const string_view& cselector, int& i ) 47 46 { 48 47 lua::stack_guard guard( m_lua ); 49 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;48 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false; 50 49 i = static_cast< int >( lua_tointeger( m_lua, -1 ) ); 51 50 return true; 52 51 } 53 52 54 bool style::get( element* e, const char* centry, const char*cselector, double& d )53 bool style::get( element* e, const string_view& centry, const string_view& cselector, double& d ) 55 54 { 56 55 lua::stack_guard guard( m_lua ); 57 if ( !resolve( e->m_id .c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;56 if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false; 58 57 d = lua_tonumber( m_lua, -1 ); 59 58 return true; … … 64 63 } 65 64 66 bool style::find_entry( const char* cselector, const char*centry, int type )65 bool style::find_entry( const string_view& cselector, const string_view& centry, int type ) 67 66 { 68 67 if ( lua_istable( m_lua, -1 ) ) 69 68 { 70 if ( cselector)69 if ( !cselector.empty() ) 71 70 { 72 lua_getfield( m_lua, -1, cselector );71 lua_getfield( m_lua, -1, cselector.data() ); 73 72 if ( lua_istable( m_lua, -1 ) ) 74 73 { 75 lua_getfield( m_lua, -1, centry );74 lua_getfield( m_lua, -1, centry.data() ); 76 75 if ( lua_type( m_lua, -1 ) == type ) 77 76 { … … 83 82 } 84 83 85 lua_getfield( m_lua, -1, centry );84 lua_getfield( m_lua, -1, centry.data() ); 86 85 if ( lua_type( m_lua, -1 ) == type ) return true; 87 86 } … … 89 88 } 90 89 91 bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char*centry, int type )90 bool style::resolve( shash64 cid, shash64 cclass, const string_view& cselector, const string_view& centry, int type ) 92 91 { 93 92 lua_getglobal( m_lua, "default" ); … … 95 94 96 95 // check id 97 lua_getfield( m_lua, -1, cid ); 98 if ( find_entry( cselector, centry, type ) ) return true; 99 lua_settop( m_lua, global ); 100 96 string_view id( m_env->get_string( cid ) ); 97 if ( !id.empty() ) 98 { 99 lua_getfield( m_lua, -1, id.data() ); 100 if ( find_entry( cselector, centry, type ) ) return true; 101 lua_settop( m_lua, global ); 102 } 101 103 // check class 102 lua_getfield( m_lua, -1, cclass ); 103 if ( find_entry( cselector, centry, type ) ) return true; 104 lua_settop( m_lua, global ); 104 string_view klass( m_env->get_string( cclass ) ); 105 if ( !klass.empty() ) 106 { 107 lua_getfield( m_lua, -1, klass.data() ); 108 if ( find_entry( cselector, centry, type ) ) return true; 109 lua_settop( m_lua, global ); 110 } 105 111 106 112 // check entry
Note: See TracChangeset
for help on using the changeset viewer.