remove DynamicThemeMetric
This commit is contained in:
@@ -266,133 +266,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Like ThemeMetric, but allows evaluating Lua expressions each time. This is
|
|
||||||
* fast, since we only compile the expression once. To evaluate every time,
|
|
||||||
* return a function instead of a value.
|
|
||||||
*
|
|
||||||
* This is just as fast as ThemeMetric when the value is not a function.
|
|
||||||
*/
|
|
||||||
template <class T>
|
|
||||||
class DynamicThemeMetric : public IThemeMetric
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
RString m_sGroup;
|
|
||||||
RString m_sName;
|
|
||||||
mutable T m_currentValue;
|
|
||||||
bool m_bIsLoaded;
|
|
||||||
LuaReference m_Value;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/* Initializing with no group and name is allowed; if you do this, you must
|
|
||||||
* call Load() to set them. This is done to allow initializing cached metrics
|
|
||||||
* in one place for classes that don't receive their m_sName in the constructor
|
|
||||||
* (everything except screens). */
|
|
||||||
DynamicThemeMetric( const RString& sGroup = "", const RString& sName = "" ):
|
|
||||||
m_sGroup( sGroup ),
|
|
||||||
m_sName( sName ),
|
|
||||||
m_bIsLoaded( false )
|
|
||||||
{
|
|
||||||
m_currentValue = T();
|
|
||||||
ThemeManager::Subscribe( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicThemeMetric( const ThemeMetric<T> &cpy ):
|
|
||||||
IThemeMetric( cpy ),
|
|
||||||
m_sGroup( cpy.m_sGroup ),
|
|
||||||
m_sName( cpy.m_sName ),
|
|
||||||
m_currentValue( cpy.m_currentValue ),
|
|
||||||
m_bIsLoaded( cpy.m_bIsLoaded ),
|
|
||||||
m_Value( cpy.m_Value )
|
|
||||||
{
|
|
||||||
ThemeManager::Subscribe( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
~DynamicThemeMetric()
|
|
||||||
{
|
|
||||||
ThemeManager::Unsubscribe( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Load( const RString &sGroup, const RString& sName )
|
|
||||||
{
|
|
||||||
m_sGroup = sGroup;
|
|
||||||
m_sName = sName;
|
|
||||||
Read();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeGroup( const RString &sGroup )
|
|
||||||
{
|
|
||||||
m_sGroup = sGroup;
|
|
||||||
Read();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Read()
|
|
||||||
{
|
|
||||||
if( m_sName != "" && THEME && THEME->IsThemeLoaded() )
|
|
||||||
{
|
|
||||||
Lua *L = LUA->Get();
|
|
||||||
|
|
||||||
THEME->GetMetric( m_sGroup, m_sName, m_Value );
|
|
||||||
|
|
||||||
m_Value.PushSelf( L );
|
|
||||||
if( lua_type(L, -1) == LUA_TFUNCTION )
|
|
||||||
{
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_Value.Unset();
|
|
||||||
LuaHelpers::Pop( L, m_currentValue );
|
|
||||||
}
|
|
||||||
|
|
||||||
LUA->Release(L);
|
|
||||||
|
|
||||||
m_bIsLoaded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
m_Value.Unset();
|
|
||||||
m_bIsLoaded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& GetValue() const
|
|
||||||
{
|
|
||||||
ASSERT( m_sName != "" );
|
|
||||||
ASSERT( m_bIsLoaded );
|
|
||||||
|
|
||||||
/* If the value is a function, evaluate it every time. */
|
|
||||||
if( m_Value.IsSet() )
|
|
||||||
{
|
|
||||||
Lua *L = LUA->Get();
|
|
||||||
|
|
||||||
// call function with 0 arguments and 1 result
|
|
||||||
m_Value.PushSelf( L );
|
|
||||||
lua_call(L, 0, 1);
|
|
||||||
ASSERT( !lua_isnil(L, -1) );
|
|
||||||
LuaHelpers::Pop( L, m_currentValue );
|
|
||||||
LUA->Release(L);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_currentValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
operator const T& () const
|
|
||||||
{
|
|
||||||
return GetValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsLoaded() const { return m_bIsLoaded; }
|
|
||||||
|
|
||||||
//Hacks for VC6 for all boolean operators.
|
|
||||||
bool operator ! () const { return !GetValue(); }
|
|
||||||
bool operator && ( const T& input ) const { return GetValue() && input; }
|
|
||||||
bool operator || ( const T& input ) const { return GetValue() || input; }
|
|
||||||
bool operator == ( const T& input ) const { return GetValue() == input; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user