demotool/syncedit.hh

92 lines
2.2 KiB
C++

#pragma once
#include "sync.hh"
#include "undo.hh"
/*= GENERAL STRUCTURE FOR SYNC EDITOR UNDOS ==================================*/
class T_UndoSyncChanges : public A_UndoAction
{
protected:
struct T_CurveChange_
{
T_String inputId;
T_Optional< T_SyncCurve > before;
T_Optional< T_SyncCurve > after;
explicit T_CurveChange_( T_SyncCurve before ) noexcept
: inputId{ before.name } ,
before{ std::move( before ) } ,
after{ }
{}
T_CurveChange_( const bool ,
T_SyncCurve after ) noexcept
: inputId{ after.name } , before{ } ,
after{ std::move( after ) }
{}
T_CurveChange_( T_SyncCurve before ,
T_SyncCurve after ) noexcept
: inputId{ before.name } ,
before{ std::move( before ) } ,
after{ std::move( after ) }
{}
};
T_AutoArray< T_CurveChange_ , 4 , 32 > changes_;
public:
T_UndoSyncChanges( ) noexcept = default;
DEF_MOVE( T_UndoSyncChanges );
NO_COPY( T_UndoSyncChanges );
void undo( ) const noexcept override;
void redo( ) const noexcept override;
T_UndoSyncChanges& curveCreation(
T_SyncCurve curve ) noexcept;
T_UndoSyncChanges& curveDeletion(
T_SyncCurve curve ) noexcept;
T_UndoSyncChanges& curveReplacement(
T_SyncCurve before ,
T_SyncCurve after ) noexcept;
};
/*= DURATION CHANGES =========================================================*/
class T_UndoDurationChanges final : public T_UndoSyncChanges
{
private:
uint32_t unitsBefore_ , unitsAfter_;
float uSizeBefore_ , uSizeAfter_;
public:
T_UndoDurationChanges(
uint32_t units ,
uint32_t oldUnits ,
float unitSize ,
float oldUnitSize ) noexcept;
T_UndoDurationChanges( ) noexcept = delete;
DEF_MOVE( T_UndoDurationChanges );
NO_COPY( T_UndoDurationChanges );
void undo( ) const noexcept override;
void redo( ) const noexcept override;
};
/*= EDITION FUNCTIONS ========================================================*/
struct SyncEditor final
{
// Change the duration of the demo using the specified unit count and
// size. If scaleCurves is true and the unit size has changed, the
// curves' durations will be scaled so that the timings match as
// closely as possible.
static void SetDuration(
uint32_t units ,
float uSize ,
bool scaleCurves ) noexcept;
};