Sync - Started working on UI overrides

This commit is contained in:
Emmanuel BENOîT 2017-11-16 09:55:56 +01:00
parent 7f3eed227b
commit 42b9b2bdb3
2 changed files with 192 additions and 10 deletions

115
sync.cc
View file

@ -358,11 +358,110 @@ uint32_t T_SyncValues::indexOf(
} }
/*= A_SyncOverride ===========================================================*/
A_SyncOverride::A_SyncOverride(
T_String type ) noexcept
: type_( std::move( type ) )
{ }
A_SyncOverride::~A_SyncOverride( ) { }
void A_SyncOverride::setup( ) noexcept
{
const auto ni( inputs_.size( ) );
assert( ni != 0 );
assert( inputPos_.size( ) == 0 );
inputPos_.ensureCapacity( ni );
for ( auto i = 0u ; i < ni ; i ++ ) {
// FIXME: insufficient; the manager should be made aware of
// the presence of an override for that value (and it should
// fail for missing values).
inputPos_.add( Globals::Sync( ).inputPos( inputs_[ ni ] ) );
}
}
/*= T_SyncOverrideSection ====================================================*/
T_SyncOverrideSection::T_SyncOverrideSection(
T_String title ) noexcept
: title( std::move( title ) )
{ }
void T_SyncOverrideSection::merge(
T_SyncOverrideSection& other ) noexcept
{
for ( auto& os : other.subsections ) {
section( os->title ).merge( *os );
}
for ( auto& ov : other.overrides ) {
overrides.add( std::move( ov ) );
}
}
void T_SyncOverrideSection::makeUI(
const bool topLevel ) noexcept
{
// FIXME: fuck that toOSString shit.
const bool display( topLevel
? ImGui::CollapsingHeader( (char*) title.toOSString( ).data( ) )
: ImGui::TreeNode( (char*) title.toOSString( ).data( ) ) );
if ( !display ) {
return;
}
for ( auto& os : subsections ) {
os->makeUI( false );
}
if ( subsections.size( ) && overrides.size( ) ) {
ImGui::Separator( );
}
for ( auto& ov : overrides ) {
ov->makeUI( );
}
if ( !topLevel ) {
ImGui::TreePop( );
}
}
T_SyncOverrideSection& T_SyncOverrideSection::section(
T_String const& name ) noexcept
{
for ( auto& ov : subsections ) {
if ( ov->title == name ) {
return *ov;
}
}
return *subsections[ subsections.add(
NewOwned< T_SyncOverrideSection >( name ) ) ];
}
T_SyncOverrideSection const* T_SyncOverrideSection::section(
T_String const& name ) const noexcept
{
for ( auto& ov : subsections ) {
if ( ov->title == name ) {
return ov.get( );
}
}
return nullptr;
}
/*= T_SyncManager ============================================================*/ /*= T_SyncManager ============================================================*/
T_SyncManager::T_SyncManager( ) T_SyncManager::T_SyncManager( )
: pConfig_( MakeCurvesParser_( ) ) : pConfig_( MakeCurvesParser_( ) ) ,
{ } pdOverrides_( "default" )
{
using namespace ebcl::SRD;
pdOverrides_.context( "default" )
<< ( Rule( ) << "category" << Text( ) << EnterContext( "category" ) );
pdOverrides_.context( "category" );
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@ -488,7 +587,17 @@ void T_SyncManager::updateValues( )
} }
} }
/*============================================================================*/ /*----------------------------------------------------------------------------*/
void T_SyncManager::registerOverride(
ebcl::T_SRDInputRule rule )
{
pdOverrides_.context( "category" ) << rule;
if ( pcOverrides_ ) {
pcOverrides_.clear( );
}
// pcOverrides_ = NewOwned< T_SRDParserConfig >( pdOverrides_ );
}
#if 0 #if 0
void T_SyncManager::makeUI( ) void T_SyncManager::makeUI( )

87
sync.hh
View file

@ -3,6 +3,7 @@
#include "utilities.hh" #include "utilities.hh"
#include <ebcl/SRDParserConfig.hh> #include <ebcl/SRDParserConfig.hh>
#include <ebcl/Sets.hh>
// Duration and current playing time // Duration and current playing time
@ -157,6 +158,71 @@ struct T_SyncValues
/*============================================================================*/ /*============================================================================*/
class A_SyncOverride;
using P_SyncOverride = T_OwnPtr< A_SyncOverride >;
struct T_SyncOverrideSection;
using P_SyncOverrideSection = T_OwnPtr< T_SyncOverrideSection >;
// Base class for overrides
class A_SyncOverride
{
private:
T_String type_;
protected:
ebcl::T_Set< T_String > inputs_{
ebcl::UseTag< ebcl::ArrayBacked< 8 > >( ) };
T_AutoArray< uint32_t , 8 > inputPos_;
bool enabled_{ false };
explicit A_SyncOverride( T_String type ) noexcept;
public:
virtual ~A_SyncOverride( ) = 0;
T_String const& type( ) const noexcept
{ return type_; }
ebcl::T_Set< T_String > const& inputNames( ) const noexcept
{ return inputs_; }
bool enabled( ) const noexcept
{ return enabled_; }
// Connect the required inputs to the sync manager. Called once
// the inputs have been added.
virtual void setup( ) noexcept;
// Draw the UI for that specific override.
virtual void makeUI( ) noexcept = 0;
};
// Overrides section
struct T_SyncOverrideSection
{
bool open{ false };
T_String title;
T_Array< P_SyncOverrideSection > subsections;
T_Array< P_SyncOverride > overrides;
T_SyncOverrideSection( ) = delete;
NO_COPY( T_SyncOverrideSection );
DEF_MOVE( T_SyncOverrideSection );
explicit T_SyncOverrideSection( T_String title ) noexcept;
void merge( T_SyncOverrideSection& other ) noexcept;
void makeUI( bool topLevel ) noexcept;
T_SyncOverrideSection& section(
T_String const& name ) noexcept;
T_SyncOverrideSection const* section(
T_String const& name ) const noexcept;
};
/*============================================================================*/
// Synchronisation manager; handles all the synchronization data and makes it // Synchronisation manager; handles all the synchronization data and makes it
// work together. // work together.
struct T_SyncManager struct T_SyncManager
@ -207,17 +273,24 @@ struct T_SyncManager
bool loadCurves_( bool& missing ); bool loadCurves_( bool& missing );
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Update // Overrides
public: public:
void registerOverride( ebcl::T_SRDInputRule rule );
// ---------------------------------------------------------------------
// Update
void updateCurveCaches( ); void updateCurveCaches( );
void updateValues( ); void updateValues( );
private: private:
ebcl::T_SRDParserConfig pConfig_; ebcl::T_SRDParserConfig pConfig_; // Parser config for curves
P_WatchedFiles watcher_; P_WatchedFiles watcher_; // Curves file watcher
T_SyncTime time_; T_SyncTime time_; // Duration/time information
T_SyncValues values_; T_SyncValues values_; // Value storage
T_SyncCurves curves_; T_SyncCurves curves_; // Curves storage
T_Array< P_SyncCurveCache > curveCaches_; T_Array< P_SyncCurveCache > curveCaches_; // Cache for curve segments
ebcl::T_SRDParserDefs pdOverrides_; // Parser definitions for UI overrides
ebcl::OP_SRDParserConfig pcOverrides_; // Parser configuration for UI overrides
}; };