2017-11-23 22:44:20 +01:00
|
|
|
#include "externals.hh"
|
2017-11-23 23:05:14 +01:00
|
|
|
#include "common.hh"
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui.hh"
|
|
|
|
#include "ui-actions.hh"
|
2017-11-23 22:51:50 +01:00
|
|
|
#include "ui-app.hh"
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui-overrides.hh"
|
|
|
|
#include "ui-sync.hh"
|
|
|
|
#include "ui-utilities.hh"
|
|
|
|
|
|
|
|
|
2017-11-29 14:08:25 +01:00
|
|
|
/*= T_SyncInputData_ =========================================================*/
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class T_SyncInputData_ : public sov::A_SyncData
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
T_AutoArray< float* , 16 > ptr_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setFromOverride( A_SyncOverride const& sov ) noexcept;
|
|
|
|
|
|
|
|
float operator[]( uint32_t index ) const noexcept override;
|
2017-11-29 16:07:20 +01:00
|
|
|
bool set( uint32_t index , float value ) noexcept override;
|
2017-11-29 14:08:25 +01:00
|
|
|
|
|
|
|
T_OwnPtr< sov::A_SyncData > clone( ) const noexcept override;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void T_SyncInputData_::setFromOverride(
|
|
|
|
A_SyncOverride const& sov ) noexcept
|
|
|
|
{
|
|
|
|
auto const& iPos{ sov.inputPositions() };
|
|
|
|
const auto np{ iPos.size( ) };
|
|
|
|
ptr_.ensureCapacity( np );
|
|
|
|
ptr_.clear( );
|
|
|
|
|
|
|
|
auto& inputs{ Common::Sync( ).inputs( ) };
|
|
|
|
for ( auto i = 0u ; i < np ; i ++ ) {
|
|
|
|
ptr_.add( &inputs[ iPos[ i ] ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float T_SyncInputData_::operator[](
|
|
|
|
const uint32_t index ) const noexcept
|
|
|
|
{
|
|
|
|
return *ptr_[ index ];
|
|
|
|
}
|
|
|
|
|
2017-11-29 16:07:20 +01:00
|
|
|
bool T_SyncInputData_::set(
|
|
|
|
const uint32_t index ,
|
|
|
|
const float value ) noexcept
|
2017-11-29 14:08:25 +01:00
|
|
|
{
|
2017-11-29 16:07:20 +01:00
|
|
|
*ptr_[ index ] = value;
|
|
|
|
return true;
|
2017-11-29 14:08:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
T_OwnPtr< sov::A_SyncData > T_SyncInputData_::clone( ) const noexcept
|
|
|
|
{
|
|
|
|
return NewOwned< T_SyncInputData_ >( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace <anon>
|
2017-11-23 22:44:20 +01:00
|
|
|
/*= T_UISync =================================================================*/
|
|
|
|
|
|
|
|
T_UISync::T_UISync( )
|
|
|
|
{
|
2017-11-24 11:34:17 +01:00
|
|
|
UI::Main( ).addAction( T_UIAction{ "Save curves" , []() {
|
2017-11-23 23:05:14 +01:00
|
|
|
if ( Common::Sync( ).curvesFileChanged( ) ) {
|
2017-11-23 22:51:50 +01:00
|
|
|
UI::Main( ).msgbox(
|
2017-11-23 22:44:20 +01:00
|
|
|
"Curves file changed" ,
|
|
|
|
"The file containing the curves has been modified "
|
|
|
|
"on the disk. These changes will be overwritten. "
|
|
|
|
"Do you want to continue?" ,
|
|
|
|
[]( auto b ) {
|
|
|
|
if ( b == T_MessageBox::BT_YES ) {
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).saveCurves( );
|
2017-11-23 22:44:20 +01:00
|
|
|
}
|
|
|
|
} , { T_MessageBox::BT_YES , T_MessageBox::BT_NO } );
|
|
|
|
} else {
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).saveCurves( );
|
2017-11-23 22:44:20 +01:00
|
|
|
}
|
2017-11-24 11:34:17 +01:00
|
|
|
} }.setEnabledCheck( []() {
|
2017-11-23 23:05:14 +01:00
|
|
|
return Common::Sync( ).curvesModified( );
|
2017-11-23 22:44:20 +01:00
|
|
|
} ).setIcon( ICON_FA_FLOPPY_O )
|
2017-11-24 11:48:08 +01:00
|
|
|
.setShortcut( T_KeyboardShortcut{ 's' , E_KbdMod::CTRL } ) );
|
2017-11-23 22:44:20 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-11-24 11:34:17 +01:00
|
|
|
UI::Main( ).addAction( T_UIAction{ "Reload curves" , []() {
|
2017-11-23 22:51:50 +01:00
|
|
|
UI::Main( ).msgbox(
|
2017-11-23 22:44:20 +01:00
|
|
|
"Reload curves?" ,
|
|
|
|
"Changes you made to the curves will be lost. Do you "
|
|
|
|
"want to continue?" ,
|
|
|
|
[]( auto b ) {
|
|
|
|
if ( b == T_MessageBox::BT_YES ) {
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).loadCurves( );
|
2017-11-23 22:44:20 +01:00
|
|
|
}
|
|
|
|
} , { T_MessageBox::BT_YES , T_MessageBox::BT_NO } );
|
2017-11-24 11:34:17 +01:00
|
|
|
} }.setEnabledCheck( []() {
|
2017-11-23 23:05:14 +01:00
|
|
|
return Common::Sync( ).curvesModified( );
|
2017-11-23 22:44:20 +01:00
|
|
|
} ).setIcon( ICON_FA_DOWNLOAD )
|
|
|
|
.setShortcut( T_KeyboardShortcut{ 'r' ,
|
2017-11-24 11:48:08 +01:00
|
|
|
{ E_KbdMod::CTRL , E_KbdMod::SHIFT } } ) );
|
2017-11-23 22:44:20 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const auto addui{ [this]( char const* type , F_Override ov ) {
|
|
|
|
const bool ok{ sovuis_.add( T_String{ type } , std::move( ov ) ) };
|
|
|
|
assert( ok ); (void)ok;
|
|
|
|
} };
|
|
|
|
addui( "float" , sov::UIFloat );
|
|
|
|
addui( "float2" , sov::UIFloat2 );
|
|
|
|
addui( "float3" , sov::UIFloat3 );
|
|
|
|
addui( "float4" , sov::UIFloat4 );
|
|
|
|
addui( "int" , sov::UIInteger );
|
|
|
|
addui( "int2" , sov::UIInteger2 );
|
|
|
|
addui( "int3" , sov::UIInteger3 );
|
|
|
|
addui( "int4" , sov::UIInteger4 );
|
|
|
|
addui( "cg" , sov::UIColorGrading );
|
|
|
|
addui( "cam" , sov::UICamera );
|
|
|
|
}
|
|
|
|
|
2017-11-24 09:51:05 +01:00
|
|
|
T_UISync::~T_UISync( )
|
|
|
|
{
|
|
|
|
UI::Main( ).clearMouseDelegate( );
|
|
|
|
}
|
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool HandleOverrideSection_(
|
|
|
|
T_SyncOverrideSection& sos ,
|
|
|
|
bool exit ,
|
|
|
|
T_AutoArray< bool , 32 >& stack )
|
|
|
|
{
|
|
|
|
if ( exit ) {
|
|
|
|
assert( !stack.empty( ) );
|
|
|
|
if ( stack.last( ) && stack.size( ) > 1 ) {
|
|
|
|
ImGui::TreePop( );
|
|
|
|
}
|
|
|
|
stack.removeLast( );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool display( stack.empty( )
|
|
|
|
? ImGui::CollapsingHeader( &sos.cTitle[ 0 ] )
|
|
|
|
: ImGui::TreeNode( &sos.cTitle[ 0 ] ) );
|
|
|
|
stack.add( display );
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HandleOverride_(
|
|
|
|
A_SyncOverride& ov ,
|
2017-11-29 14:08:25 +01:00
|
|
|
T_SyncInputData_& data ,
|
2017-11-23 22:44:20 +01:00
|
|
|
uint32_t& counter ,
|
|
|
|
T_StringBuilder& sb ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
|
|
|
|
bool& enabled{ ov.enabled( ) };
|
|
|
|
if ( Checkbox( &ov.title( )[ 0 ] , &enabled ) ) {
|
|
|
|
auto const& ipos( ov.inputPositions( ) );
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).setOverridesActive( ov.enabled( ) ,
|
2017-11-23 22:44:20 +01:00
|
|
|
ipos.size( ) , &ipos[ 0 ] );
|
|
|
|
}
|
|
|
|
if ( !enabled ) {
|
|
|
|
PushDisabled( );
|
|
|
|
}
|
|
|
|
Indent( );
|
|
|
|
PushItemWidth( -1 );
|
2017-11-29 14:08:25 +01:00
|
|
|
data.setFromOverride( ov );
|
|
|
|
(UI::Sync( ).uiFor( ov ))( ov , data , counter , sb );
|
2017-11-23 22:44:20 +01:00
|
|
|
PopItemWidth( );
|
|
|
|
Unindent( );
|
|
|
|
if ( !enabled ) {
|
|
|
|
PopDisabled( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace <anon>
|
|
|
|
|
|
|
|
T_UISync::F_Override T_UISync::uiFor(
|
|
|
|
A_SyncOverride& target ) const noexcept
|
|
|
|
{
|
|
|
|
auto const* const rv{ sovuis_.get( target.type( ) ) };
|
2017-11-29 14:08:25 +01:00
|
|
|
return rv ? *rv : []( A_SyncOverride& , sov::A_SyncData& ,
|
|
|
|
uint32_t& , T_StringBuilder& ) {
|
2017-11-23 22:44:20 +01:00
|
|
|
ImGui::Text( "(missing UI)" );
|
2017-11-29 16:07:20 +01:00
|
|
|
return false;
|
2017-11-23 22:44:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_UISync::makeOverridesWindow( )
|
|
|
|
{
|
|
|
|
if ( !ovWindow_ ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( 0 , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
Begin( "Input overrides" , &ovWindow_ ,
|
|
|
|
ImGuiWindowFlags_NoCollapse );
|
|
|
|
|
2017-11-29 14:08:25 +01:00
|
|
|
T_AutoArray< bool , 32 > stack;
|
|
|
|
T_SyncInputData_ data;
|
2017-11-23 22:44:20 +01:00
|
|
|
T_StringBuilder temp;
|
|
|
|
uint32_t counter{ 0 };
|
|
|
|
bool found{ false };
|
|
|
|
using T_Ove_ = T_SyncOverrideVisitor::T_Element;
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).visitOverrides( [&]( T_Ove_ element , bool exit ) {
|
2017-11-23 22:44:20 +01:00
|
|
|
// Display sections
|
|
|
|
if ( element.hasType< T_SyncOverrideSection* >( ) ) {
|
|
|
|
auto& sos( *element.value< T_SyncOverrideSection* >( ) );
|
|
|
|
if ( sos.title == "*root*" ) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-26 18:55:23 +01:00
|
|
|
found = true;
|
2017-11-23 22:44:20 +01:00
|
|
|
return HandleOverrideSection_( sos , exit , stack );
|
|
|
|
}
|
|
|
|
if ( exit ) {
|
|
|
|
HandleOverride_( *element.value< A_SyncOverride* >( ) ,
|
2017-11-29 14:08:25 +01:00
|
|
|
data , counter , temp );
|
2017-11-23 22:44:20 +01:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( !found ) {
|
|
|
|
Text( "No overrides have been defined." );
|
|
|
|
}
|
|
|
|
|
|
|
|
End( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-24 10:08:41 +01:00
|
|
|
void T_UISync::updateTime( ) noexcept
|
|
|
|
{
|
|
|
|
auto& s{ Common::Sync( ) };
|
|
|
|
if ( s.playing( ) ) {
|
|
|
|
const float time( SDL_GetTicks( ) * 1e-3f );
|
|
|
|
if ( playingPrevious_ ) {
|
|
|
|
s.timeDelta( time - lastFrame_ );
|
|
|
|
}
|
|
|
|
lastFrame_ = time;
|
|
|
|
}
|
|
|
|
playingPrevious_ = s.playing( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-24 09:51:05 +01:00
|
|
|
void T_UISync::delegateMouse(
|
|
|
|
T_String const& id ,
|
|
|
|
P_MouseCtrl delegate ) noexcept
|
|
|
|
{
|
|
|
|
mouseDelegateName_ = id;
|
|
|
|
mouseDelegate_ = std::move( delegate );
|
|
|
|
UI::Main( ).setMouseDelegate( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_UISync::clearMouseDelegate( ) noexcept
|
|
|
|
{
|
|
|
|
mouseDelegateName_ = T_String{ };
|
|
|
|
mouseDelegate_ = P_MouseCtrl{ };
|
|
|
|
UI::Main( ).clearMouseDelegate( );
|
|
|
|
}
|
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
void T_UISync::handleDragAndDrop(
|
|
|
|
ImVec2 const& move ,
|
2017-11-24 11:48:08 +01:00
|
|
|
T_KbdMods modifiers ,
|
2017-11-23 22:44:20 +01:00
|
|
|
T_MouseButtons buttons ) noexcept
|
|
|
|
{
|
|
|
|
if ( mouseDelegate_ ) {
|
|
|
|
mouseDelegate_->handleDragAndDrop( move , modifiers , buttons );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_UISync::handleWheel(
|
|
|
|
const float wheel ,
|
2017-11-24 11:48:08 +01:00
|
|
|
T_KbdMods modifiers ,
|
2017-11-23 22:44:20 +01:00
|
|
|
T_MouseButtons buttons ) noexcept
|
|
|
|
{
|
|
|
|
if ( mouseDelegate_ ) {
|
|
|
|
mouseDelegate_->handleWheel( wheel , modifiers , buttons );
|
|
|
|
}
|
|
|
|
}
|