From 037fea3101ed8b81578ac7c6c80cadac05403829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 20 Nov 2017 17:01:09 +0100 Subject: [PATCH] Sequencer - Moved existing view to separate file --- Makefile | 3 ++- main.cc | 16 ++++++++++--- sync.cc | 32 -------------------------- sync.hh | 8 +++---- syncview.cc | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ syncview.hh | 11 +++++++++ 6 files changed, 94 insertions(+), 41 deletions(-) create mode 100644 syncview.cc create mode 100644 syncview.hh diff --git a/Makefile b/Makefile index 3c23b9b..f613211 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,9 @@ COMMON = \ # END COMMON DEMO = \ - main.cc \ demo.cc \ + main.cc \ + syncview.cc \ # END DEMO PARSERCHECK = \ diff --git a/main.cc b/main.cc index 46cbbaf..43934fb 100644 --- a/main.cc +++ b/main.cc @@ -9,6 +9,7 @@ #include "ops.hh" #include "rendertarget.hh" #include "sync.hh" +#include "syncview.hh" using ebcl::T_Optional; @@ -34,6 +35,7 @@ struct T_Main ImVec2 prevSize; T_Optional< T_Demo > demo; + T_Optional< T_SyncView > sequencer; void initDemo( ); @@ -199,6 +201,7 @@ void T_Main::handleCapture( ) void T_Main::makeUI( ) { using namespace ImGui; + bool eSequencer{ sequencer }; if ( BeginMainMenuBar( ) ) { if ( BeginMenu( "File" ) ) { if ( MenuItem( "Quit" ) ) { @@ -213,8 +216,7 @@ void T_Main::makeUI( ) &Globals::ODbg( ).uiEnabled( ) ); MenuItemCheckbox( "Profiler" , &Globals::Profiler( ).uiEnabled( ) ); - MenuItemCheckbox( "Sequencer" , - &Globals::Sync( ).sequencerWindowEnabled( ) ); + MenuItemCheckbox( "Sequencer" , &eSequencer ); MenuItemCheckbox( "Shaders" , &Globals::Shaders( ).uiEnabled( ) ); EndMenu( ); @@ -222,11 +224,19 @@ void T_Main::makeUI( ) EndMainMenuBar( ); } + if ( eSequencer && !sequencer ) { + sequencer.setNew( ); + } else if ( !eSequencer && sequencer ) { + sequencer.clear( ); + } + Globals::Profiler( ).makeUI( ); Globals::ODbg( ).makeUI( ); Globals::Shaders( ).makeUI( ); Globals::Sync( ).makeOverridesWindow( ); - Globals::Sync( ).makeSequencerWindow( ); + if ( sequencer && !sequencer->display( ) ) { + sequencer.clear( ); + } } void T_Main::render( ) diff --git a/sync.cc b/sync.cc index 43046d8..91b2fa5 100644 --- a/sync.cc +++ b/sync.cc @@ -719,38 +719,6 @@ void T_SyncManager::setOverridesActive( /*------------------------------------------------------------------------------*/ -void T_SyncManager::makeSequencerWindow( ) -{ - if ( !tmWindow_ ) { - return; - } - - using namespace ImGui; - auto const& dspSize( GetIO( ).DisplaySize ); - SetNextWindowSize( ImVec2( dspSize.x , 150 ) , ImGuiSetCond_Appearing ); - SetNextWindowPos( ImVec2( 0 , dspSize.y - 150 ) , ImGuiSetCond_Appearing ); - Begin( "Sequencer" , &tmWindow_ , ImGuiWindowFlags_NoCollapse ); - - PushID( "playing" ); - if ( Button( playing_ ? "Stop" : "Play" ) ) { - playing_ = !playing_; - } - PopID( ); - - const float d( duration( ) ); - float tm( time( ) ); - SameLine( ); - PushID( "sequencer" ); - PushItemWidth( -1 ); - if ( SliderFloat( "" , &tm , 0 , d , "%.1fs" ) ) { - setTime( tm ); - playing_ = playing_ && !finished( ); - } - PopItemWidth( ); - PopID( ); - End( ); -} - void T_SyncManager::makeOverridesWindow( ) { if ( !ovWindow_ ) { diff --git a/sync.hh b/sync.hh index 7b084a6..a274ea9 100644 --- a/sync.hh +++ b/sync.hh @@ -297,6 +297,9 @@ struct T_SyncManager : public virtual A_MouseCtrl bool playing( ) const noexcept { return playing_; } + bool& playing( ) noexcept + { return playing_; } + bool finished( ) const noexcept { return time_.time >= time_.duration( ); } void updateTime( ) noexcept; @@ -352,10 +355,6 @@ struct T_SyncManager : public virtual A_MouseCtrl // --------------------------------------------------------------------- // User interface - bool& sequencerWindowEnabled( ) noexcept - { return tmWindow_; } - void makeSequencerWindow( ); - bool& overridesWindowEnabled( ) noexcept { return ovWindow_; } void makeOverridesWindow( ); @@ -389,7 +388,6 @@ struct T_SyncManager : public virtual A_MouseCtrl float lastFrame_{ 0 }; // Time of last frame T_SyncValues values_; // Value storage T_SyncCurves curves_; // Curves storage - bool tmWindow_{ false }; // Sequencer window T_Array< P_SyncCurveCache > curveCaches_; // Cache for curve segments bool ovWindow_{ false }; // Overrides window T_SyncOverrideSection soRoot_; // Root for overrides diff --git a/syncview.cc b/syncview.cc new file mode 100644 index 0000000..0b55199 --- /dev/null +++ b/syncview.cc @@ -0,0 +1,65 @@ +#include "externals.hh" +#include "syncview.hh" +#include "globals.hh" + +using namespace ebcl; + + +/*= T_SyncViewImpl_ ============================================================*/ +namespace { + +struct T_SyncViewImpl_ +{ + bool display( ) noexcept; +}; + + +bool T_SyncViewImpl_::display( ) noexcept +{ + using namespace ImGui; + auto const& dspSize( GetIO( ).DisplaySize ); + auto& sync( Globals::Sync( ) ); + + // Window set-up + SetNextWindowSize( ImVec2( dspSize.x , 150 ) , ImGuiSetCond_Appearing ); + SetNextWindowPos( ImVec2( 0 , dspSize.y - 150 ) , ImGuiSetCond_Appearing ); + bool displayed{ true }; + Begin( "Sequencer" , &displayed , ImGuiWindowFlags_NoCollapse ); + if ( !displayed ) { + return false; + } + + PushID( "playing" ); + if ( Button( sync.playing( ) ? "Stop" : "Play" ) ) { + sync.playing( ) = !sync.playing( ) && !sync.finished( ); + } + PopID( ); + + const float d( sync.duration( ) ); + float tm( sync.time( ) ); + SameLine( ); + PushID( "sequencer" ); + PushItemWidth( -1 ); + if ( SliderFloat( "" , &tm , 0 , d , "%.1fs" ) ) { + sync.setTime( tm ); + sync.playing( ) = sync.playing( ) && !sync.finished( ); + } + PopItemWidth( ); + PopID( ); + End( ); + + return true; +} + + +} // namespace +/*= T_SyncView =================================================================*/ + +T_SyncView::T_SyncView( ) noexcept + : A_PrivateImplementation( new T_SyncViewImpl_( ) ) +{ } + +bool T_SyncView::display( ) noexcept +{ + return p< T_SyncViewImpl_ >( ).display( ); +} diff --git a/syncview.hh b/syncview.hh new file mode 100644 index 0000000..d501294 --- /dev/null +++ b/syncview.hh @@ -0,0 +1,11 @@ +#pragma once +#include "sync.hh" + + +class T_SyncView : public ebcl::A_PrivateImplementation +{ + public: + T_SyncView( ) noexcept; + bool display( ) noexcept; +}; +