2017-11-20 17:01:09 +01:00
|
|
|
#include "externals.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
|
2017-11-23 23:05:14 +01:00
|
|
|
#include "common.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
#include "c-sync.hh"
|
|
|
|
#include "c-syncedit.hh"
|
|
|
|
|
2017-11-23 22:44:20 +01:00
|
|
|
#include "ui.hh"
|
2017-11-23 22:51:50 +01:00
|
|
|
#include "ui-app.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
#include "ui-sequencer.hh"
|
2017-11-23 14:43:15 +01:00
|
|
|
#include "ui-utilities.hh"
|
2017-11-20 21:54:46 +01:00
|
|
|
|
2017-11-28 07:12:43 +01:00
|
|
|
#include "ui-imgui-sdl.hh"
|
|
|
|
|
2017-11-20 21:54:46 +01:00
|
|
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
|
|
|
#include <imgui_internal.h>
|
2017-11-20 17:01:09 +01:00
|
|
|
|
|
|
|
using namespace ebcl;
|
|
|
|
|
2017-11-21 22:23:34 +01:00
|
|
|
namespace {
|
2017-11-22 14:14:49 +01:00
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
/*= VARIOUS HELPERS ==========================================================*/
|
2017-11-22 14:14:49 +01:00
|
|
|
|
|
|
|
bool FakeTab_(
|
|
|
|
char const* const name ,
|
|
|
|
const bool disabled ,
|
|
|
|
const float width = 0.f )
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
if ( disabled ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PushDisabled( );
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
2017-11-22 14:14:49 +01:00
|
|
|
const bool rv( Button( name , ImVec2{ width , 0.f } ) );
|
|
|
|
if ( disabled ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PopDisabled( );
|
2017-11-22 16:17:24 +01:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
void TimeToString_(
|
|
|
|
char* const buffer ,
|
|
|
|
const size_t bSize ,
|
|
|
|
const float time ) noexcept
|
|
|
|
{
|
|
|
|
const float msf{ fmod( time , 1.f ) };
|
|
|
|
const float sf{ fmod( time - msf , 60.f ) };
|
|
|
|
snprintf( buffer , bSize , "%02d:%02d.%03d" ,
|
|
|
|
uint32_t( ( time - msf - sf ) / 60.f ) ,
|
|
|
|
uint32_t( sf ) , uint32_t( msf * 1000.f ) );
|
|
|
|
}
|
|
|
|
|
2017-11-20 17:01:09 +01:00
|
|
|
|
2017-11-22 14:14:49 +01:00
|
|
|
/*= T_ChangeDurationDialog_ ==================================================*/
|
|
|
|
|
|
|
|
class T_ChangeDurationDialog_ : public A_ModalDialog
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const uint32_t units0_;
|
|
|
|
const float uSize0_;
|
|
|
|
const uint32_t uPerMinute0_;
|
|
|
|
uint32_t units_;
|
|
|
|
float uSize_;
|
|
|
|
uint32_t uPerMinute_;
|
|
|
|
bool scale_{ true };
|
|
|
|
|
|
|
|
protected:
|
2017-11-23 12:24:40 +01:00
|
|
|
uint8_t drawDialog( ) noexcept override;
|
|
|
|
bool onButton( uint8_t id ) noexcept override;
|
2017-11-22 14:14:49 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
T_ChangeDurationDialog_(
|
|
|
|
uint32_t units ,
|
|
|
|
float uSize ) noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
T_ChangeDurationDialog_::T_ChangeDurationDialog_(
|
|
|
|
const uint32_t units ,
|
|
|
|
const float uSize ) noexcept
|
|
|
|
: A_ModalDialog{ "Set demo duration...##duration-dialog" } ,
|
|
|
|
units0_{ units } , uSize0_{ std::max( 1.f / 60.f , uSize ) } ,
|
|
|
|
uPerMinute0_{ uint32_t( ImClamp( roundf( 60.f / uSize0_ ) , 1.f , 3600.f ) ) } ,
|
|
|
|
units_{ units0_ } , uSize_{ uSize0_ } , uPerMinute_{ uPerMinute0_ }
|
|
|
|
{
|
|
|
|
setInitialSize( 300.f , 180.f );
|
2017-11-23 12:24:40 +01:00
|
|
|
addButton( "OK" );
|
|
|
|
addButton( "Cancel" );
|
2017-11-22 14:14:49 +01:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:24:40 +01:00
|
|
|
uint8_t T_ChangeDurationDialog_::drawDialog( ) noexcept
|
2017-11-22 14:14:49 +01:00
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
|
|
|
|
int tUnits( units_ );
|
|
|
|
if ( DragInt( "Duration##units" , &tUnits , .1f , 1 , INT32_MAX , "%.0f unit(s)" ) ) {
|
|
|
|
units_ = uint32_t( std::min( INT32_MAX , std::max( 1 , tUnits ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
float tDuration( units_ * uSize_ );
|
|
|
|
if ( DragFloat( "##seconds" , &tDuration , 1.f , .001f , FLT_MAX , "%.3f second(s)" ) ) {
|
|
|
|
units_ = std::min( uint32_t( INT32_MAX ) , std::max( 1u ,
|
|
|
|
uint32_t( roundf( tDuration / uSize_ ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
int tUsize( floorf( uSize_ * 1000.f ) );
|
|
|
|
if ( SliderInt( "Units" , &tUsize , 16 , 2000 , "%.0f ms" ) ) {
|
|
|
|
const float pDur{ uSize_ * units_ };
|
|
|
|
uSize_ = std::min( 2.f , std::max( 1.f / 60.f ,
|
|
|
|
.001f * tUsize ) );
|
|
|
|
uPerMinute_ = roundf( 60.f / uSize_ );
|
|
|
|
units_ = uint32_t( roundf( pDur / uSize_ ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
int tPerMin( uPerMinute_ );
|
|
|
|
if ( SliderInt( "Units/minute" , &tPerMin , 30 , 3600 ) ) {
|
|
|
|
const float pDur{ uSize_ * units_ };
|
|
|
|
uPerMinute_ = std::max( 30u , std::min( 3600u , uint32_t( tPerMin ) ) );
|
|
|
|
uSize_ = 60.f / uPerMinute_;
|
|
|
|
units_ = uint32_t( roundf( pDur / uSize_ ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( uPerMinute0_ == uPerMinute_ ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PushDisabled( );
|
2017-11-22 14:14:49 +01:00
|
|
|
}
|
|
|
|
Checkbox( "Scale curves" , &scale_ );
|
|
|
|
if ( uPerMinute0_ == uPerMinute_ ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PopDisabled( );
|
2017-11-22 14:14:49 +01:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:24:40 +01:00
|
|
|
const bool eo{ units_ != units0_ || uPerMinute_ != uPerMinute0_ };
|
|
|
|
return eo ? 3 : 2;
|
2017-11-22 14:14:49 +01:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:24:40 +01:00
|
|
|
bool T_ChangeDurationDialog_::onButton(
|
|
|
|
const uint8_t button ) noexcept
|
2017-11-22 14:14:49 +01:00
|
|
|
{
|
2017-11-23 12:24:40 +01:00
|
|
|
if ( button == 0 ) {
|
|
|
|
SyncEditor::SetDuration( units_ ,
|
|
|
|
uPerMinute_ != uPerMinute0_ ? uSize_ : uSize0_ ,
|
|
|
|
scale_ );
|
|
|
|
}
|
|
|
|
return true;
|
2017-11-22 14:14:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= T_SyncViewImpl_ ==========================================================*/
|
2017-11-20 17:01:09 +01:00
|
|
|
|
|
|
|
struct T_SyncViewImpl_
|
|
|
|
{
|
2017-11-25 16:30:46 +01:00
|
|
|
static constexpr float SeqHeaderHeight = 24.f;
|
|
|
|
static constexpr float BarWidth = 40.f;
|
|
|
|
static constexpr float TrackHeight = 15.f;
|
|
|
|
static constexpr float TrackPadding = 2.f;
|
2017-11-25 22:02:17 +01:00
|
|
|
static constexpr float PointRadius = ( TrackHeight - 2.f ) * .5f;
|
|
|
|
static constexpr float PointRadiusSqr = PointRadius * PointRadius;
|
2017-11-20 21:54:46 +01:00
|
|
|
|
2017-11-20 17:01:09 +01:00
|
|
|
bool display( ) noexcept;
|
2017-11-21 22:23:34 +01:00
|
|
|
|
2017-11-22 17:24:22 +01:00
|
|
|
private:
|
2017-11-25 22:02:17 +01:00
|
|
|
// Track display data
|
|
|
|
struct T_TrackDisplay
|
|
|
|
{
|
|
|
|
T_String id;
|
|
|
|
bool isOverride;
|
|
|
|
ImRect area;
|
|
|
|
uint32_t dispSegs;
|
|
|
|
uint32_t firstSeg;
|
|
|
|
};
|
|
|
|
struct T_TrackSegDisplay
|
|
|
|
{
|
|
|
|
uint32_t track;
|
|
|
|
uint32_t seg;
|
|
|
|
ImRect area;
|
|
|
|
uint32_t dispPoints;
|
|
|
|
uint32_t firstPoint;
|
|
|
|
};
|
|
|
|
struct T_TrackPointDisplay
|
|
|
|
{
|
|
|
|
uint32_t seg;
|
|
|
|
uint32_t index;
|
|
|
|
ImVec2 center;
|
|
|
|
enum {
|
|
|
|
START ,
|
|
|
|
MIDDLE ,
|
|
|
|
END
|
|
|
|
} mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Description for mouse locations in the sequencer window
|
|
|
|
enum class E_MousePosType
|
|
|
|
{
|
|
|
|
NONE ,
|
|
|
|
TRACK ,
|
|
|
|
SEGMENT ,
|
|
|
|
POINT
|
|
|
|
};
|
|
|
|
struct T_MousePos
|
|
|
|
{
|
|
|
|
E_MousePosType type;
|
|
|
|
uint32_t index;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Type of sub-windows
|
|
|
|
enum E_SubWindow {
|
|
|
|
SW_NONE ,
|
2017-11-25 23:37:07 +01:00
|
|
|
SW_INPUT_SELECTOR ,
|
2017-11-25 22:02:17 +01:00
|
|
|
SW_OVERRIDE_SELECTOR ,
|
2017-11-26 10:14:00 +01:00
|
|
|
SW_TRACK ,
|
2017-11-25 23:37:07 +01:00
|
|
|
SW_SEGMENT ,
|
2017-11-26 17:39:17 +01:00
|
|
|
SW_POINT ,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Type of change in progress
|
|
|
|
enum class E_ChangeType {
|
|
|
|
NONE ,
|
|
|
|
POINT_DND ,
|
|
|
|
POINT_VALUE ,
|
2017-11-25 22:02:17 +01:00
|
|
|
};
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
// Make sure all displayed inputs/overrides still exist
|
|
|
|
void checkTracks( ) noexcept;
|
|
|
|
// Make sure the currently selected track/segment/point is still valid
|
|
|
|
void checkSelection( ) noexcept;
|
|
|
|
// Display the toolbar
|
2017-11-22 16:17:24 +01:00
|
|
|
void displayToolbar( ) noexcept;
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Sequencer widget methods
|
|
|
|
|
2017-11-20 21:54:46 +01:00
|
|
|
void sequencerWidget( ) noexcept;
|
2017-11-26 10:14:00 +01:00
|
|
|
void computeMetrics( float innerWidth ) noexcept;
|
2017-11-20 21:54:46 +01:00
|
|
|
void sequencerHeader( ImRect const& bb ) noexcept;
|
2017-11-25 22:02:17 +01:00
|
|
|
void sequencerBody( ImRect const& bb ) noexcept;
|
|
|
|
void sequencerTracks(
|
2017-11-25 16:30:46 +01:00
|
|
|
float& hue ,
|
|
|
|
ImRect& bb ,
|
|
|
|
ImRect const& container ) noexcept;
|
2017-11-25 22:02:17 +01:00
|
|
|
void sequencerTrack(
|
2017-11-25 16:30:46 +01:00
|
|
|
float& hue ,
|
|
|
|
ImRect const& bb ,
|
|
|
|
ImRect const& container ,
|
|
|
|
T_String const& name ,
|
|
|
|
T_SyncCurve const* curve ) noexcept;
|
2017-11-21 13:43:01 +01:00
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
void displayTooltips(
|
|
|
|
const float time ) noexcept;
|
2017-11-26 13:46:46 +01:00
|
|
|
bool handlePointDrag(
|
|
|
|
const float mPixels ,
|
|
|
|
bool mouseDown ) noexcept;
|
2017-11-25 22:02:17 +01:00
|
|
|
|
|
|
|
T_MousePos getMousePos( ) const noexcept;
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Track selector
|
|
|
|
void displayTrackSelectorWindow( ) noexcept;
|
|
|
|
void displayInputSelector( ) noexcept;
|
2017-11-22 07:38:27 +01:00
|
|
|
void displayOverrideSelector( ) noexcept;
|
2017-11-21 22:23:34 +01:00
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
void displayTrackWindow( ) noexcept;
|
2017-11-25 23:37:07 +01:00
|
|
|
void displaySegmentWindow( ) noexcept;
|
2017-11-26 17:39:17 +01:00
|
|
|
void displayPointWindow( ) noexcept;
|
2017-11-25 23:37:07 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-11-22 17:24:22 +01:00
|
|
|
// Colors, sizes, etc.
|
|
|
|
const uint32_t ColFrame{ ImGui::GetColorU32( ImVec4{ 0 , 0 , 0 , .8 } ) };
|
|
|
|
const uint32_t ColHeader{ ImGui::GetColorU32( ImVec4{ .5 , .5 , .5 , .8 } ) };
|
|
|
|
const uint32_t ColHeaderText{ ImGui::GetColorU32( ImVec4{ 0 , 0 , 0 , 1 } ) };
|
|
|
|
const uint32_t ColMain{ ImGui::GetColorU32( ImVec4{ .4 , .4 , .4 , .8 } ) };
|
|
|
|
const uint32_t ColSelection{ ImGui::GetColorU32( ImVec4{ .8 , 1 , .8 , .2 } ) };
|
2017-11-26 13:46:46 +01:00
|
|
|
const uint32_t ColPointNormal{ ImGui::GetColorU32( ImVec4{ 0 , 0 , 0 , .25 } ) };
|
|
|
|
const uint32_t ColPointSelected{ ImGui::GetColorU32( ImVec4{ 0 , 0 , 0 , .75 } ) };
|
2017-11-22 17:24:22 +01:00
|
|
|
const ImVec2 BtSize{ 20 , 0 };
|
|
|
|
|
|
|
|
// Sequencer settings
|
|
|
|
float zoomLevel{ 0.f };
|
|
|
|
float startPos{ 0.f };
|
|
|
|
bool followTime{ true };
|
|
|
|
|
2017-11-21 22:23:34 +01:00
|
|
|
// Misc stuff
|
|
|
|
T_StringBuilder stringBuffer; // XXX damn this shit to fucking hell
|
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
// Computed metrics
|
2017-11-27 13:54:06 +01:00
|
|
|
bool checkLockMode{ false };
|
|
|
|
float vScroll{ 0 };
|
2017-11-21 13:43:01 +01:00
|
|
|
float barWidth;
|
|
|
|
float cursorPos;
|
|
|
|
uint32_t startBar;
|
|
|
|
float startBarPos;
|
|
|
|
float timePerBar;
|
2017-11-21 15:48:34 +01:00
|
|
|
float totalPixels;
|
|
|
|
float startPixel;
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
// Track display
|
|
|
|
T_Array< T_TrackDisplay > dspTracks;
|
|
|
|
T_Array< T_TrackSegDisplay > dspSegments;
|
|
|
|
T_Array< T_TrackPointDisplay > dspPoints;
|
|
|
|
|
2017-11-21 15:48:34 +01:00
|
|
|
// Zoom area selection
|
|
|
|
bool zoomInProgress{ false };
|
|
|
|
float firstZoomPixel;
|
|
|
|
float curZoomPixel;
|
2017-11-21 22:23:34 +01:00
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
// Selected item
|
|
|
|
T_String selId{ };
|
|
|
|
bool selIsOverride;
|
2017-11-26 10:14:00 +01:00
|
|
|
T_Optional< uint32_t > selSegment;
|
2017-11-25 23:37:07 +01:00
|
|
|
T_Optional< uint32_t > selPoint;
|
2017-11-26 13:46:46 +01:00
|
|
|
bool selPointDnD{ false };
|
|
|
|
float selPointDnDStart , selPointDnDCur;
|
2017-11-26 17:39:17 +01:00
|
|
|
|
|
|
|
// Original and copy of curve being modified
|
|
|
|
E_ChangeType selUpdate{ E_ChangeType::NONE };
|
|
|
|
T_Optional< T_SyncCurve > selUpdatingOriginal;
|
|
|
|
T_Optional< T_SyncCurve > selUpdatingCopy;
|
2017-11-25 23:37:07 +01:00
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
// Sub-windows
|
2017-11-21 22:23:34 +01:00
|
|
|
E_SubWindow sub{ SW_NONE };
|
2017-11-25 22:02:17 +01:00
|
|
|
|
|
|
|
// Curve selection
|
2017-11-22 07:38:27 +01:00
|
|
|
T_KeyValueTable< T_String , bool > sCurves;
|
|
|
|
T_Set< T_String > sOverrides;
|
2017-11-21 22:23:34 +01:00
|
|
|
T_String curveFinder;
|
2017-11-20 17:01:09 +01:00
|
|
|
};
|
|
|
|
|
2017-11-21 15:48:34 +01:00
|
|
|
constexpr float T_SyncViewImpl_::BarWidth;
|
|
|
|
|
2017-11-22 14:14:49 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-11-20 17:01:09 +01:00
|
|
|
|
|
|
|
bool T_SyncViewImpl_::display( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
|
|
|
|
// Window set-up
|
2017-11-21 16:30:15 +01:00
|
|
|
SetNextWindowSize( ImVec2( dspSize.x , dspSize.y * .34f ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( 0 , dspSize.y * .66f ) , ImGuiSetCond_Appearing );
|
2017-11-20 17:01:09 +01:00
|
|
|
bool displayed{ true };
|
2017-11-20 21:54:46 +01:00
|
|
|
Begin( "Sequencer" , &displayed , ImGuiWindowFlags_NoCollapse
|
|
|
|
| ImGuiWindowFlags_NoScrollWithMouse );
|
2017-11-20 17:01:09 +01:00
|
|
|
if ( !displayed ) {
|
2017-11-20 21:54:46 +01:00
|
|
|
End( );
|
2017-11-20 17:01:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
checkTracks( );
|
|
|
|
checkSelection( );
|
2017-11-22 16:17:24 +01:00
|
|
|
displayToolbar( );
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
// Sequencer widget
|
2017-11-22 16:17:24 +01:00
|
|
|
PushItemWidth( -1 );
|
|
|
|
sequencerWidget( );
|
|
|
|
PopItemWidth( );
|
|
|
|
End( );
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
// Close sub-window if e.g. selection has changed
|
|
|
|
switch( sub ) {
|
|
|
|
case SW_POINT:
|
|
|
|
if ( !selPoint ) {
|
|
|
|
sub = SW_SEGMENT;
|
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
case SW_SEGMENT:
|
|
|
|
if ( !selSegment ) {
|
|
|
|
sub = SW_TRACK;
|
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
case SW_TRACK:
|
|
|
|
if ( !selId ) {
|
|
|
|
sub = SW_NONE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display selected sub-window
|
2017-11-22 16:17:24 +01:00
|
|
|
switch ( sub ) {
|
|
|
|
case SW_NONE:
|
|
|
|
break;
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
case SW_INPUT_SELECTOR:
|
2017-11-22 16:17:24 +01:00
|
|
|
case SW_OVERRIDE_SELECTOR:
|
2017-11-25 23:37:07 +01:00
|
|
|
displayTrackSelectorWindow( );
|
|
|
|
break;
|
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
case SW_TRACK:
|
|
|
|
displayTrackWindow( );
|
|
|
|
break;
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
case SW_SEGMENT:
|
|
|
|
displaySegmentWindow( );
|
2017-11-22 16:17:24 +01:00
|
|
|
break;
|
2017-11-26 17:39:17 +01:00
|
|
|
|
|
|
|
case SW_POINT:
|
|
|
|
displayPointWindow( );
|
|
|
|
break;
|
2017-11-21 17:32:52 +01:00
|
|
|
}
|
2017-11-22 16:17:24 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
void T_SyncViewImpl_::checkTracks( ) noexcept
|
2017-11-22 17:24:22 +01:00
|
|
|
{
|
2017-11-23 23:05:14 +01:00
|
|
|
auto& sync{ Common::Sync( ) };
|
2017-11-22 17:24:22 +01:00
|
|
|
|
|
|
|
// Check for "dead" overrides
|
|
|
|
{
|
|
|
|
bool ovRemoved{ false };
|
|
|
|
for ( auto i = 0u ; i < sOverrides.size( ) ; ) {
|
|
|
|
if ( sync.overrideExists( sOverrides[ i ] ) ) {
|
|
|
|
i ++;
|
|
|
|
} else {
|
|
|
|
sOverrides.remove( sOverrides[ i ] );
|
|
|
|
ovRemoved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !ovRemoved ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all curves that come from overrides
|
|
|
|
for ( auto i = 0u ; i < sCurves.size( ) ; ) {
|
|
|
|
if ( sCurves.values( )[ i ] ) {
|
|
|
|
sCurves.remove( sCurves.keys( )[ i ] );
|
|
|
|
} else {
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-add curves for the remaining overrides
|
|
|
|
const auto no{ sOverrides.size( ) };
|
|
|
|
for ( auto i = 0u ; i < no ; i ++ ) {
|
|
|
|
auto const* od{ sync.getOverride( sOverrides[ i ] ) };
|
|
|
|
assert( od );
|
|
|
|
const auto ni{ od->inputNames( ).size( ) };
|
|
|
|
for ( auto j = 0u ; j < ni ; j ++ ) {
|
|
|
|
const bool ok{ sCurves.add( od->inputNames( )[ j ] , true ) };
|
|
|
|
assert( ok ); (void) ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 07:12:04 +01:00
|
|
|
void T_SyncViewImpl_::checkSelection( ) noexcept
|
|
|
|
{
|
|
|
|
if ( !selId ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert( !selIsOverride ); // XXX
|
|
|
|
auto const* const curve{ Common::Sync( ).getCurve( selId ) };
|
|
|
|
|
|
|
|
// Missing curve
|
|
|
|
if ( !curve ) {
|
|
|
|
// Remove segment/point selection
|
|
|
|
if ( selSegment ) {
|
|
|
|
selSegment.clear( );
|
|
|
|
selPoint.clear( );
|
|
|
|
}
|
|
|
|
// If there's no matching input, unselect the track
|
|
|
|
if ( !Common::Sync( ).hasInput( selId ) ) {
|
|
|
|
selId = T_String{};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No segment selected? We're ok.
|
|
|
|
if ( !selSegment ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check segment and point
|
|
|
|
if ( *selSegment >= curve->segments.size( ) ) {
|
|
|
|
selSegment.clear( );
|
|
|
|
selPoint.clear( );
|
|
|
|
} else if ( selPoint && *selPoint >= curve->segments[
|
|
|
|
*selSegment ].values.size( ) ) {
|
|
|
|
selPoint.clear( );
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we were doing something with the curve, get rid of that too
|
|
|
|
if ( selUpdate != E_ChangeType::NONE ) {
|
|
|
|
selUpdate = E_ChangeType::NONE;
|
|
|
|
selUpdatingCopy.clear( );
|
|
|
|
selUpdatingOriginal.clear( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 16:17:24 +01:00
|
|
|
void T_SyncViewImpl_::displayToolbar( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
2017-11-23 23:05:14 +01:00
|
|
|
auto& sync( Common::Sync( ) );
|
2017-11-22 16:17:24 +01:00
|
|
|
|
2017-11-24 12:05:40 +01:00
|
|
|
if ( sync.playing( ) ) {
|
|
|
|
UI::Main( ).actionButton( "Stop" );
|
|
|
|
} else {
|
|
|
|
UI::Main( ).actionButton( "Play" );
|
2017-11-21 13:43:01 +01:00
|
|
|
}
|
2017-11-21 17:32:52 +01:00
|
|
|
|
2017-11-21 12:27:23 +01:00
|
|
|
SameLine( );
|
2017-11-21 17:32:52 +01:00
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
if ( ToolbarButton( ICON_FA_BACKWARD , BtSize , "Rewind to 00:00.000" ) ) {
|
2017-11-21 17:32:52 +01:00
|
|
|
sync.setTime( 0 );
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
ToolbarSeparator( );
|
2017-11-21 12:27:23 +01:00
|
|
|
|
2017-11-21 17:32:52 +01:00
|
|
|
Text( ICON_FA_SEARCH );
|
|
|
|
bool zoomHovered{ IsItemHovered( ) };
|
|
|
|
SameLine( );
|
|
|
|
PushItemWidth( 100 );
|
|
|
|
SliderFloat( "##zoom" , &zoomLevel , 0 , 1 , "%.2f" );
|
|
|
|
if ( zoomHovered || IsItemHovered( ) ) {
|
|
|
|
BeginTooltip( );
|
|
|
|
Text( "Zoom level" );
|
|
|
|
EndTooltip( );
|
|
|
|
}
|
|
|
|
PopItemWidth( );
|
|
|
|
|
|
|
|
SameLine( );
|
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
if ( ToolbarButton( followTime ? ICON_FA_LOCK : ICON_FA_UNLOCK , BtSize ,
|
2017-11-22 16:17:24 +01:00
|
|
|
followTime ? "Follows the current position.\nClick to untie."
|
|
|
|
: "Not tied to the current position.\nClick to follow." ) ) {
|
2017-11-21 17:32:52 +01:00
|
|
|
followTime = !followTime;
|
|
|
|
}
|
2017-11-20 17:01:09 +01:00
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
ToolbarSeparator( );
|
2017-11-21 22:23:34 +01:00
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
if ( ToolbarButton( ICON_FA_CLOCK_O , BtSize , "Change duration and time units." ) ) {
|
2017-11-23 22:51:50 +01:00
|
|
|
UI::Main( ).pushDialog( NewOwned< T_ChangeDurationDialog_ >(
|
2017-11-22 14:14:49 +01:00
|
|
|
sync.durationUnits( ) , sync.durationUnitSize( ) ) );
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
ToolbarSeparator( );
|
2017-11-22 14:14:49 +01:00
|
|
|
|
2017-11-23 14:43:15 +01:00
|
|
|
if ( ToolbarButton( ICON_FA_LINE_CHART , BtSize ,
|
2017-11-22 16:17:24 +01:00
|
|
|
"Select curves or sets thereof to display & edit." ) ) {
|
2017-11-25 23:37:07 +01:00
|
|
|
const bool displaySelector{ sub == SW_INPUT_SELECTOR
|
2017-11-21 22:23:34 +01:00
|
|
|
|| sub == SW_OVERRIDE_SELECTOR };
|
2017-11-25 23:37:07 +01:00
|
|
|
sub = displaySelector ? SW_NONE : SW_INPUT_SELECTOR;
|
2017-11-21 22:23:34 +01:00
|
|
|
curveFinder = T_String{};
|
|
|
|
}
|
2017-11-20 17:01:09 +01:00
|
|
|
}
|
|
|
|
|
2017-11-21 22:23:34 +01:00
|
|
|
/*------------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-20 21:54:46 +01:00
|
|
|
void T_SyncViewImpl_::sequencerWidget( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
|
|
|
|
const auto width{ CalcItemWidth( ) };
|
2017-11-27 13:54:06 +01:00
|
|
|
auto* const win{ GetCurrentWindow( ) };
|
2017-11-20 21:54:46 +01:00
|
|
|
const auto seqId{ win->GetID( "##sequencer" ) };
|
|
|
|
|
2017-11-27 13:54:06 +01:00
|
|
|
const ImVec2 cPos{ win->DC.CursorPos };
|
|
|
|
const ImVec2 ws{ GetWindowContentRegionMax( ) };
|
2017-11-20 21:54:46 +01:00
|
|
|
|
|
|
|
auto& style( ImGui::GetStyle( ) );
|
2017-11-27 13:54:06 +01:00
|
|
|
const float widgetWidth{ width - style.ScrollbarSize };
|
|
|
|
const ImRect bbHeader{
|
|
|
|
cPos ,
|
|
|
|
cPos + ImVec2( widgetWidth , SeqHeaderHeight )
|
|
|
|
};
|
|
|
|
const ImRect bbDisplay{
|
|
|
|
ImVec2{ cPos.x , bbHeader.Max.y } ,
|
|
|
|
ImVec2{ cPos.x + widgetWidth ,
|
|
|
|
GetWindowPos( ).y + ws.y
|
|
|
|
- style.FramePadding.y * 2
|
|
|
|
- style.ScrollbarSize }
|
|
|
|
};
|
2017-11-20 21:54:46 +01:00
|
|
|
const ImRect bbAll{ bbHeader.Min , bbDisplay.Max };
|
|
|
|
|
|
|
|
ItemSize( bbAll , style.FramePadding.y );
|
|
|
|
if ( !ItemAdd( bbAll , seqId ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-21 15:48:34 +01:00
|
|
|
const bool hovered{ ItemHoverable( bbAll , seqId ) };
|
2017-11-27 13:54:06 +01:00
|
|
|
computeMetrics( std::max( 0.f , widgetWidth - 2.f ) );
|
2017-11-20 21:54:46 +01:00
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
BeginGroup( );
|
|
|
|
const auto hdrId{ win->GetID( "##header" ) };
|
|
|
|
const auto dspId{ win->GetID( "##display" ) };
|
2017-11-21 15:48:34 +01:00
|
|
|
PushID( seqId );
|
2017-11-27 13:54:06 +01:00
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
if ( ItemAdd( bbHeader , hdrId ) ) {
|
|
|
|
PushID( hdrId );
|
|
|
|
sequencerHeader( bbHeader );
|
|
|
|
PopID( );
|
|
|
|
}
|
|
|
|
if ( bbDisplay.Min.y < bbDisplay.Max.y && ItemAdd( bbDisplay , dspId ) ) {
|
|
|
|
PushID( dspId );
|
2017-11-25 22:02:17 +01:00
|
|
|
sequencerBody( bbDisplay );
|
2017-11-21 13:43:01 +01:00
|
|
|
PopID( );
|
|
|
|
}
|
2017-11-27 13:54:06 +01:00
|
|
|
|
|
|
|
// Vertical scrollbar - tracks
|
|
|
|
const float totalHeight{ sCurves.size( ) * ( TrackHeight + TrackPadding * 2.f ) };
|
|
|
|
if ( vScroll > totalHeight - bbDisplay.GetHeight( ) ) {
|
|
|
|
vScroll = ImMax( 0.f , totalHeight - bbDisplay.GetHeight( ) );
|
|
|
|
}
|
|
|
|
// FIXME overrides
|
|
|
|
UserScrollbar( false , totalHeight , bbDisplay.GetHeight( ) , &vScroll ,
|
|
|
|
bbHeader.GetTR( ) , bbAll.GetHeight( ) );
|
|
|
|
|
|
|
|
// Horizontal scrollbar - time
|
|
|
|
auto& sync( Common::Sync( ) );
|
|
|
|
float rsPos = startPixel;
|
|
|
|
if ( UserScrollbar( true , totalPixels , widgetWidth , &rsPos ,
|
|
|
|
bbDisplay.GetBL( ) , bbDisplay.GetWidth( ) ) ) {
|
|
|
|
startPos = sync.durationUnits( ) * rsPos / totalPixels;
|
|
|
|
checkLockMode = true;
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:48:34 +01:00
|
|
|
PopID( );
|
2017-11-25 22:02:17 +01:00
|
|
|
EndGroup( );
|
2017-11-21 15:48:34 +01:00
|
|
|
|
|
|
|
auto& io( GetIO( ) );
|
|
|
|
if ( hovered && ( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) ) {
|
|
|
|
SetActiveID( seqId , win );
|
|
|
|
FocusWindow( win );
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool active( GetCurrentContext( )->ActiveId == seqId );
|
2017-11-25 22:02:17 +01:00
|
|
|
const float mPixels{ io.MousePos.x - bbAll.Min.x + startPixel };
|
|
|
|
const float mTime{ mPixels * sync.duration( ) / totalPixels };
|
|
|
|
|
|
|
|
if ( !active ) {
|
|
|
|
if ( !hovered ) {
|
|
|
|
return;
|
2017-11-21 15:48:34 +01:00
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
if ( io.MouseWheel != 0 ) {
|
2017-11-27 18:42:08 +01:00
|
|
|
if ( io.KeyShift ) {
|
|
|
|
zoomLevel = ImSaturate( zoomLevel + .025 * io.MouseWheel );
|
|
|
|
} else {
|
2017-11-28 07:12:43 +01:00
|
|
|
vScroll = ImClamp( vScroll - 3.f * io.MouseWheel ,
|
|
|
|
0.f ,
|
|
|
|
ImMax( 0.f , totalHeight - bbDisplay.GetHeight( ) ) );
|
2017-11-27 18:42:08 +01:00
|
|
|
}
|
2017-11-21 15:48:34 +01:00
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
if ( bbDisplay.Contains( io.MousePos ) ) {
|
|
|
|
displayTooltips( mTime );
|
2017-11-21 15:48:34 +01:00
|
|
|
}
|
2017-11-28 07:12:43 +01:00
|
|
|
if ( ImGuiIO_MouseHorizWheel != 0 ) {
|
|
|
|
startPos = ImClamp(
|
|
|
|
sync.durationUnits( )
|
|
|
|
* ( startPixel - 20.f * ImGuiIO_MouseHorizWheel )
|
|
|
|
/ totalPixels ,
|
|
|
|
0.f , sync.durationUnits( ) );
|
|
|
|
checkLockMode = true;
|
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
return;
|
2017-11-21 15:48:34 +01:00
|
|
|
}
|
2017-11-21 13:43:01 +01:00
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
if ( zoomInProgress && !io.MouseDown[ 1 ] ) {
|
2017-11-25 22:02:17 +01:00
|
|
|
zoomInProgress = false;
|
2017-11-27 13:54:06 +01:00
|
|
|
checkLockMode = true;
|
2017-11-25 22:02:17 +01:00
|
|
|
const auto zMin{ std::min( firstZoomPixel , curZoomPixel ) } ,
|
|
|
|
zMax{ std::max( firstZoomPixel , curZoomPixel ) } ,
|
|
|
|
diff{ zMax - zMin };
|
|
|
|
if ( diff > 4 ) {
|
|
|
|
const float u( sync.durationUnits( ) );
|
|
|
|
startPos = zMin * u / totalPixels;
|
|
|
|
if ( ( width - 2.f ) / u >= BarWidth ) {
|
|
|
|
zoomLevel = 0;
|
|
|
|
} else {
|
|
|
|
const auto length{ std::min( u , diff * u / totalPixels ) };
|
|
|
|
const auto ppu{ std::min( ( width - 2 ) / length , BarWidth ) };
|
|
|
|
zoomLevel = ( ppu - BarWidth ) / ( BarWidth - width / u ) + 1;
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 07:12:43 +01:00
|
|
|
} else if ( zoomInProgress && io.MouseDown[ 1 ] ) {
|
|
|
|
curZoomPixel = mPixels;
|
|
|
|
return;
|
2017-11-25 22:02:17 +01:00
|
|
|
}
|
|
|
|
|
2017-11-26 13:46:46 +01:00
|
|
|
if ( selPointDnD && handlePointDrag( mPixels , io.MouseDown[ 0 ] ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
if ( !( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) ) {
|
|
|
|
ClearActiveID( );
|
2017-11-25 23:37:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto mp{ getMousePos( ) };
|
|
|
|
if ( mp.type == E_MousePosType::NONE ) {
|
|
|
|
if ( io.MouseDown[ 0 ] ) {
|
|
|
|
sync.setTime( mTime );
|
|
|
|
}
|
|
|
|
if ( io.MouseDown[ 1 ] ) {
|
2017-11-28 07:12:43 +01:00
|
|
|
firstZoomPixel = mPixels;
|
|
|
|
zoomInProgress = true;
|
2017-11-25 23:37:07 +01:00
|
|
|
curZoomPixel = mPixels;
|
|
|
|
|
|
|
|
}
|
2017-11-26 10:14:00 +01:00
|
|
|
} else if ( mp.type == E_MousePosType::TRACK ) {
|
|
|
|
auto const& dTrack{ dspTracks[ mp.index ] };
|
|
|
|
if ( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) {
|
|
|
|
selId = dTrack.id;
|
|
|
|
selIsOverride = dTrack.isOverride;
|
2017-11-26 11:57:26 +01:00
|
|
|
selSegment = decltype( selSegment ){};
|
|
|
|
selPoint = decltype( selPoint ){};
|
2017-11-26 10:14:00 +01:00
|
|
|
sub = E_SubWindow::SW_TRACK;
|
|
|
|
}
|
2017-11-25 23:37:07 +01:00
|
|
|
} else if ( mp.type == E_MousePosType::SEGMENT ) {
|
|
|
|
auto const& dSeg{ dspSegments[ mp.index ] };
|
|
|
|
auto const& dTrack{ dspTracks[ dSeg.track ] };
|
|
|
|
if ( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) {
|
|
|
|
selId = dTrack.id;
|
|
|
|
selIsOverride = dTrack.isOverride;
|
|
|
|
selSegment = dSeg.seg;
|
2017-11-26 11:57:26 +01:00
|
|
|
selPoint = decltype( selPoint ){};
|
2017-11-25 23:37:07 +01:00
|
|
|
sub = E_SubWindow::SW_SEGMENT;
|
|
|
|
}
|
2017-11-26 13:46:46 +01:00
|
|
|
} else if ( mp.type == E_MousePosType::POINT ) {
|
|
|
|
auto const& dPoint{ dspPoints[ mp.index ] };
|
|
|
|
auto const& dSeg{ dspSegments[ dPoint.seg ] };
|
|
|
|
auto const& dTrack{ dspTracks[ dSeg.track ] };
|
|
|
|
if ( io.MouseDown[ 0 ] || io.MouseDown[ 1 ] ) {
|
|
|
|
selId = dTrack.id;
|
|
|
|
selIsOverride = dTrack.isOverride;
|
|
|
|
selSegment = dSeg.seg;
|
|
|
|
selPoint = dPoint.index;
|
|
|
|
selPointDnD = io.MouseDown[ 0 ] && dPoint.index != 0;
|
|
|
|
if ( selPointDnD ) {
|
2017-11-26 17:39:17 +01:00
|
|
|
assert( selUpdate == E_ChangeType::NONE );
|
2017-11-26 13:46:46 +01:00
|
|
|
selPointDnDStart = selPointDnDCur = mPixels;
|
2017-11-26 17:39:17 +01:00
|
|
|
selUpdatingOriginal = *sync.getCurve( dTrack.id ); // XXX
|
|
|
|
selUpdate = E_ChangeType::POINT_DND;
|
2017-11-26 13:46:46 +01:00
|
|
|
}
|
2017-11-26 17:39:17 +01:00
|
|
|
sub = E_SubWindow::SW_POINT;
|
2017-11-26 13:46:46 +01:00
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
}
|
2017-11-21 13:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncViewImpl_::computeMetrics(
|
|
|
|
const float innerWidth ) noexcept
|
|
|
|
{
|
2017-11-23 23:05:14 +01:00
|
|
|
auto& sync( Common::Sync( ) );
|
2017-11-20 21:54:46 +01:00
|
|
|
const uint32_t units{ sync.durationUnits( ) };
|
2017-11-21 12:27:23 +01:00
|
|
|
zoomLevel = ImSaturate( zoomLevel );
|
|
|
|
const float zoom1Pixels{ std::max( units * BarWidth , innerWidth ) };
|
2017-11-21 15:48:34 +01:00
|
|
|
totalPixels = zoomLevel * ( zoom1Pixels - innerWidth ) + innerWidth;
|
2017-11-21 12:27:23 +01:00
|
|
|
const uint32_t totalBars{ [=](){
|
|
|
|
const float b{ std::max( std::min( totalPixels / BarWidth , float( units ) ) , 1.f ) };
|
|
|
|
const float mod{ fmod( b , 1.f ) };
|
|
|
|
return uint32_t( b + ( mod ? ( 1 - mod ) : 0 ) );
|
|
|
|
}() };
|
|
|
|
const float unitsPerBar{ float( units ) / totalBars };
|
2017-11-21 13:43:01 +01:00
|
|
|
barWidth = totalPixels / totalBars;
|
2017-11-21 12:27:23 +01:00
|
|
|
const float absCursorPos{ sync.time( ) * totalPixels / sync.duration( ) };
|
|
|
|
if ( followTime ) {
|
|
|
|
const float dispUnits{ innerWidth * units / totalPixels };
|
|
|
|
const float uSize{ sync.durationUnitSize( ) };
|
|
|
|
const float endPos{ std::min( startPos + dispUnits , float( units ) ) };
|
|
|
|
startPos = endPos - dispUnits;
|
|
|
|
const float spp{ startPos * totalPixels / units };
|
|
|
|
const float epp{ endPos * totalPixels / units };
|
|
|
|
if ( absCursorPos < spp || absCursorPos > epp ) {
|
2017-11-27 13:54:06 +01:00
|
|
|
if ( checkLockMode ) {
|
2017-11-21 15:48:34 +01:00
|
|
|
followTime = false;
|
|
|
|
} else {
|
|
|
|
startPos = std::max( 0.f , sync.time( ) / uSize - unitsPerBar * .5f );
|
|
|
|
}
|
2017-11-21 12:27:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const float unadjustedStartPixel{ totalPixels * startPos / units };
|
|
|
|
if ( unadjustedStartPixel + innerWidth > totalPixels ) {
|
|
|
|
startPos = std::max( 0.f , totalPixels - innerWidth );
|
|
|
|
}
|
2017-11-21 15:48:34 +01:00
|
|
|
startPixel = totalPixels * startPos / units;
|
2017-11-21 13:43:01 +01:00
|
|
|
startBar = [=](){
|
2017-11-21 12:27:23 +01:00
|
|
|
const float b{ startPixel * totalBars / totalPixels };
|
|
|
|
const float mod{ fmod( b , 1.f ) };
|
|
|
|
return uint32_t( std::max( 0 , int32_t( b - ( mod ? mod : 1 ) ) ) );
|
2017-11-21 13:43:01 +01:00
|
|
|
}();
|
|
|
|
startBarPos = startBar * barWidth - startPixel;
|
|
|
|
cursorPos = absCursorPos - startPixel;
|
|
|
|
timePerBar = unitsPerBar * sync.durationUnitSize( );
|
2017-11-21 12:27:23 +01:00
|
|
|
assert( startBarPos <= 0 );
|
|
|
|
assert( totalPixels >= innerWidth );
|
2017-11-21 15:48:34 +01:00
|
|
|
|
2017-11-27 13:54:06 +01:00
|
|
|
checkLockMode = false;
|
2017-11-20 21:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncViewImpl_::sequencerHeader(
|
|
|
|
ImRect const& bb ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto* const dl( GetWindowDrawList( ) );
|
2017-11-21 13:43:01 +01:00
|
|
|
const ImRect inner{ bb.Min + ImVec2{ 1 , 1 } , bb.Max - ImVec2{ 1 , 1 } };
|
2017-11-20 21:54:46 +01:00
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
dl->AddRectFilled( inner.Min , inner.Max , ColHeader );
|
2017-11-20 21:54:46 +01:00
|
|
|
dl->AddRect( bb.Min , bb.Max , ColFrame );
|
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
if ( cursorPos >= 0 && cursorPos <= inner.GetWidth( ) ) {
|
|
|
|
auto* const dl( GetWindowDrawList( ) );
|
|
|
|
dl->AddLine( inner.Min + ImVec2{ cursorPos , 0 } ,
|
|
|
|
ImVec2{ inner.Min.x + cursorPos , inner.Max.y - 1 } ,
|
|
|
|
GetColorU32( ImVec4{ 1 , 1 , 1 , .5 } ) );
|
|
|
|
}
|
|
|
|
|
2017-11-23 22:51:50 +01:00
|
|
|
PushFont( UI::Main( ).smallFont( ) );
|
2017-11-21 13:43:01 +01:00
|
|
|
PushStyleColor( ImGuiCol_Text , ColHeaderText );
|
|
|
|
auto pos{ startBarPos };
|
|
|
|
auto bar{ startBar };
|
|
|
|
const auto max{ bb.GetWidth( ) + barWidth - 2.f };
|
|
|
|
char buffer[ 12 ];
|
|
|
|
while ( pos < max ) {
|
|
|
|
const ImVec2 taStart{ inner.Min + ImVec2{ pos - barWidth * .5f , 0 } };
|
|
|
|
const ImVec2 taEnd{ taStart + ImVec2{ barWidth , inner.Max.y - inner.Min.y } };
|
|
|
|
|
|
|
|
const float time{ bar * timePerBar };
|
2017-11-25 22:02:17 +01:00
|
|
|
TimeToString_( buffer , sizeof( buffer ) , time );
|
2017-11-21 13:43:01 +01:00
|
|
|
RenderTextClipped( taStart , taEnd , buffer , nullptr , nullptr ,
|
2017-11-25 09:31:08 +01:00
|
|
|
ImVec2{ .5f , .05f + ( ( bar % 2 ) ? .9f : 0.f ) } , &inner );
|
2017-11-21 13:43:01 +01:00
|
|
|
pos += barWidth;
|
|
|
|
bar ++;
|
|
|
|
}
|
2017-11-20 21:54:46 +01:00
|
|
|
PopStyleColor( );
|
|
|
|
PopFont( );
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
void T_SyncViewImpl_::sequencerBody(
|
2017-11-21 12:27:23 +01:00
|
|
|
ImRect const& bb ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto* const dl( GetWindowDrawList( ) );
|
2017-11-21 13:43:01 +01:00
|
|
|
const ImRect inner{ bb.Min + ImVec2{ 1 , 1 } , bb.Max - ImVec2{ 1 , 1 } };
|
2017-11-21 12:27:23 +01:00
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
dl->AddRectFilled( inner.Min , inner.Max , ColMain );
|
|
|
|
dl->AddRect( bb.Min , bb.Max , ColFrame );
|
2017-11-21 15:48:34 +01:00
|
|
|
if ( zoomInProgress ) {
|
|
|
|
const float z0{ ImClamp( firstZoomPixel - startPixel + inner.Min.x , inner.Min.x , inner.Max.x ) } ,
|
|
|
|
z1{ ImClamp( curZoomPixel - startPixel + bb.Min.x , inner.Min.x , inner.Max.x ) };
|
|
|
|
const float zMin{ std::min( z0 , z1 ) } , zMax{ std::max( z0 , z1 ) };
|
|
|
|
if ( zMin != zMax ) {
|
|
|
|
dl->AddRectFilled( ImVec2{ zMin , inner.Min.y } ,
|
|
|
|
ImVec2{ zMax , inner.Max.y } ,
|
|
|
|
ColSelection );
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 13:43:01 +01:00
|
|
|
|
|
|
|
auto pos{ startBarPos };
|
|
|
|
auto bar{ startBar };
|
|
|
|
const auto max{ bb.GetWidth( ) + barWidth - 2.f };
|
|
|
|
while ( pos < max ) {
|
|
|
|
if ( pos >= 0 && pos < inner.GetWidth( ) ) {
|
|
|
|
dl->AddLine( bb.Min + ImVec2{ pos , 0 } ,
|
|
|
|
ImVec2{ inner.Min.x + pos , inner.Max.y } ,
|
|
|
|
0xff000000 );
|
|
|
|
}
|
|
|
|
pos += barWidth;
|
|
|
|
bar ++;
|
|
|
|
}
|
|
|
|
|
2017-11-22 20:28:12 +01:00
|
|
|
// Display the curve / override controls
|
2017-11-25 23:37:07 +01:00
|
|
|
dspTracks.clear( );
|
|
|
|
dspSegments.clear( );
|
|
|
|
dspPoints.clear( );
|
2017-11-22 20:28:12 +01:00
|
|
|
if ( sCurves.size( ) != 0 ) {
|
2017-11-25 16:30:46 +01:00
|
|
|
|
|
|
|
ImRect subBb{ inner };
|
2017-11-27 13:54:06 +01:00
|
|
|
subBb.Min.y += TrackPadding - vScroll;
|
2017-11-25 16:30:46 +01:00
|
|
|
subBb.Max.y = subBb.Min.y + TrackHeight;
|
|
|
|
|
|
|
|
float hue{ 0.12f };
|
|
|
|
|
2017-11-22 20:28:12 +01:00
|
|
|
// TODO: display overrides
|
2017-11-25 22:02:17 +01:00
|
|
|
sequencerTracks( hue , subBb , inner );
|
2017-11-22 20:28:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-21 13:43:01 +01:00
|
|
|
if ( cursorPos >= 0 && cursorPos <= inner.GetWidth( ) ) {
|
|
|
|
auto* const dl( GetWindowDrawList( ) );
|
|
|
|
dl->AddLine( inner.Min + ImVec2{ cursorPos , -1 } ,
|
|
|
|
ImVec2{ inner.Min.x + cursorPos , inner.Max.y - 1 } ,
|
|
|
|
0xffffffff );
|
|
|
|
}
|
2017-11-21 12:27:23 +01:00
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
void T_SyncViewImpl_::sequencerTracks(
|
2017-11-25 16:30:46 +01:00
|
|
|
float& hue ,
|
|
|
|
ImRect& subBb ,
|
|
|
|
ImRect const& container ) noexcept
|
2017-11-22 20:28:12 +01:00
|
|
|
{
|
2017-11-23 23:05:14 +01:00
|
|
|
auto& sync{ Common::Sync( ) };
|
2017-11-22 20:28:12 +01:00
|
|
|
const auto nc{ sCurves.size( ) };
|
|
|
|
for ( auto i = 0u ; i < nc ; i ++ ) {
|
|
|
|
if ( sCurves.values( )[ i ] ) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-25 16:30:46 +01:00
|
|
|
|
|
|
|
auto const& name{ sCurves.keys( )[ i ] };
|
|
|
|
auto* const curve{ sync.getCurve( name ) };
|
2017-11-25 22:02:17 +01:00
|
|
|
sequencerTrack( hue , subBb , container , name , curve );
|
2017-11-25 16:30:46 +01:00
|
|
|
subBb.Min.y += TrackHeight + 2 * TrackPadding;
|
|
|
|
subBb.Max.y += TrackHeight + 2 * TrackPadding;
|
|
|
|
hue = fmodf( hue + .17f , 1.f );
|
2017-11-22 20:28:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
void T_SyncViewImpl_::sequencerTrack(
|
2017-11-25 16:30:46 +01:00
|
|
|
float& hue ,
|
|
|
|
ImRect const& bb ,
|
|
|
|
ImRect const& container ,
|
2017-11-25 22:02:17 +01:00
|
|
|
T_String const& id ,
|
2017-11-25 16:30:46 +01:00
|
|
|
T_SyncCurve const* curve ) noexcept
|
2017-11-22 20:28:12 +01:00
|
|
|
{
|
2017-11-25 22:02:17 +01:00
|
|
|
// Don't display if the track is fully hidden
|
2017-11-25 16:30:46 +01:00
|
|
|
if ( !container.Overlaps( bb ) ) {
|
2017-11-25 22:02:17 +01:00
|
|
|
return;
|
2017-11-25 16:30:46 +01:00
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
|
|
|
|
// Add track display record
|
|
|
|
const auto dTrackIdx{ dspTracks.size( ) };
|
|
|
|
auto& dTrack{ dspTracks.addNew( ) };
|
|
|
|
dTrack.id = id;
|
|
|
|
dTrack.isOverride = false;
|
|
|
|
dTrack.dispSegs = 0;
|
|
|
|
dTrack.firstSeg = dspSegments.size( );
|
|
|
|
dTrack.area = bb;
|
2017-11-25 16:30:46 +01:00
|
|
|
|
|
|
|
// Compute colors
|
2017-11-25 22:02:17 +01:00
|
|
|
using namespace ImGui;
|
2017-11-26 11:57:26 +01:00
|
|
|
const bool sCurve{ selId && !selIsOverride && selId == id };
|
|
|
|
const float scv{ sCurve ? 1.f : .7f };
|
|
|
|
const auto bgColor{ ColorHSVAToU32( hue , .25f , scv , .25f ) } ,
|
|
|
|
borderColor{ ColorHSVAToU32( hue , .5f , scv , 1.f ) };
|
|
|
|
const uint32_t segColors[] = {
|
|
|
|
ColorHSVAToU32( hue - .03f , .4f , .7f , 1.f ) ,
|
|
|
|
ColorHSVAToU32( hue + .03f , .4f , .7f , 1.f ) ,
|
2017-11-25 16:30:46 +01:00
|
|
|
ColorHSVAToU32( hue - .03f , .4f , 1.f , 1.f ) ,
|
|
|
|
ColorHSVAToU32( hue + .03f , .4f , 1.f , 1.f ) ,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Draw the bar itself
|
|
|
|
const ImRect bar{
|
|
|
|
ImVec2{ ImFloor( bb.Min.x ) ,
|
|
|
|
ImFloor( ImMax( container.Min.y , bb.Min.y ) ) } ,
|
|
|
|
ImVec2{ ImFloor( bb.Max.x ) - 1 ,
|
|
|
|
ImFloor( ImMin( container.Max.y , bb.Max.y ) ) }
|
|
|
|
};
|
2017-11-25 22:02:17 +01:00
|
|
|
auto* const dl{ GetWindowDrawList( ) };
|
2017-11-25 16:30:46 +01:00
|
|
|
dl->AddRectFilled( bar.Min , bar.Max , bgColor );
|
|
|
|
if ( container.Contains( bb.GetTL( ) ) ) {
|
|
|
|
dl->AddLine( bar.GetTL( ) , bar.GetTR( ) , borderColor );
|
|
|
|
}
|
|
|
|
if ( container.Contains( bb.GetBL( ) ) ) {
|
|
|
|
dl->AddLine( bar.GetBL( ) , bar.GetBR( ) , borderColor );
|
|
|
|
}
|
|
|
|
// Left only has a border if this is the start
|
|
|
|
if ( startPos == 0.f ) {
|
|
|
|
dl->AddLine( bar.GetTL( ) , bar.GetBL( ) , borderColor );
|
|
|
|
}
|
|
|
|
// Right has a border if the end is being displayed.
|
|
|
|
if ( startPixel + container.GetWidth( ) >= totalPixels ) {
|
|
|
|
dl->AddLine( bar.GetTR( ) , bar.GetBR( ) , borderColor );
|
|
|
|
}
|
|
|
|
dl->PushClipRect( bar.Min , bar.Max );
|
|
|
|
|
|
|
|
// If there's a curve, go through all segments
|
|
|
|
const auto units{ Common::Sync( ).durationUnits( ) };
|
2017-11-26 17:39:17 +01:00
|
|
|
const bool useCopy{ sCurve && curve && selUpdatingCopy };
|
2017-11-26 13:46:46 +01:00
|
|
|
const auto nSeg{ curve
|
2017-11-26 17:39:17 +01:00
|
|
|
? ( useCopy ? *selUpdatingCopy : *curve ).segments.size( )
|
2017-11-26 13:46:46 +01:00
|
|
|
: 0u };
|
2017-11-25 16:30:46 +01:00
|
|
|
uint32_t segStart{ 0 };
|
|
|
|
for ( auto i = 0u ; i < nSeg ; i ++ ) {
|
2017-11-26 17:39:17 +01:00
|
|
|
auto const& seg{ ( useCopy ? *selUpdatingCopy : *curve ).segments[ i ] };
|
2017-11-25 16:30:46 +01:00
|
|
|
const auto segDur{ [&](){
|
|
|
|
auto t{ 0u };
|
|
|
|
for ( auto d : seg.durations ) {
|
|
|
|
t += d;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}() };
|
|
|
|
const float xStart{ ImFloor( container.Min.x + ( segStart - startPos ) * totalPixels / units ) };
|
|
|
|
const float xEnd{ xStart + ImFloor( segDur * totalPixels / units ) };
|
|
|
|
const ImRect segFull{
|
|
|
|
ImVec2{ xStart , bar.Min.y + 1 } ,
|
|
|
|
ImVec2{ xEnd , bar.Max.y }
|
|
|
|
};
|
|
|
|
segStart += segDur;
|
|
|
|
if ( !segFull.Overlaps( bar ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
// Add segment to displayed list
|
2017-11-26 11:57:26 +01:00
|
|
|
const bool sSegment{ sCurve && selSegment && *selSegment == i };
|
|
|
|
const auto color{ segColors[ i % 2 + ( sSegment ? 2 : 0 ) ] };
|
2017-11-25 22:02:17 +01:00
|
|
|
auto dSegIdx{ dspSegments.size( ) };
|
|
|
|
auto& dSeg{ dspSegments.addNew( ) };
|
|
|
|
dSeg.area = segFull;
|
|
|
|
dSeg.track = dTrackIdx;
|
|
|
|
dSeg.seg = i;
|
|
|
|
dSeg.dispPoints = 0;
|
|
|
|
dSeg.firstPoint = dspPoints.size( );
|
|
|
|
dTrack.dispSegs ++;
|
|
|
|
|
|
|
|
// Draw segment
|
2017-11-25 16:30:46 +01:00
|
|
|
const ImRect segBar{
|
|
|
|
ImVec2{ ImMax( bar.Min.x , segFull.Min.x ) , segFull.Min.y } ,
|
|
|
|
ImVec2{ ImMin( bar.Max.x , segFull.Max.x ) , segFull.Max.y }
|
|
|
|
};
|
|
|
|
dl->AddRectFilled( segBar.Min , segBar.Max , color );
|
|
|
|
dl->PushClipRect( segBar.Min , segBar.Max );
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
// Handle points
|
2017-11-25 16:30:46 +01:00
|
|
|
const auto nd{ seg.durations.size( ) };
|
2017-11-25 22:02:17 +01:00
|
|
|
const auto ym{ bb.Min.y + PointRadius + 1 };
|
2017-11-25 16:30:46 +01:00
|
|
|
auto cDur{ 0 };
|
|
|
|
for ( auto j = 0u ; j < nd + 1 ; j ++ ) {
|
|
|
|
const ImVec2 ctr{
|
|
|
|
std::roundf( xStart + cDur * totalPixels / units ) ,
|
|
|
|
ym
|
|
|
|
};
|
2017-11-26 13:46:46 +01:00
|
|
|
const bool sPoint{ sSegment && selPoint && *selPoint == j };
|
|
|
|
dl->AddCircleFilled( ctr , PointRadius ,
|
|
|
|
sPoint ? ColPointSelected : ColPointNormal );
|
2017-11-25 16:30:46 +01:00
|
|
|
cDur += j < nd ? seg.durations[ j ] : 0;
|
2017-11-25 22:02:17 +01:00
|
|
|
|
|
|
|
// Add point record
|
|
|
|
auto& dPoint{ dspPoints.addNew( ) };
|
|
|
|
dPoint.center = ctr;
|
|
|
|
dPoint.index = j;
|
|
|
|
dPoint.mode =
|
|
|
|
j == 0 ? T_TrackPointDisplay::START : (
|
|
|
|
j == nd ? T_TrackPointDisplay::END :
|
|
|
|
T_TrackPointDisplay::MIDDLE );
|
|
|
|
dPoint.seg = dSegIdx;
|
|
|
|
dSeg.dispPoints ++;
|
2017-11-25 16:30:46 +01:00
|
|
|
}
|
|
|
|
dl->PopClipRect( );
|
2017-11-25 22:02:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dl->PopClipRect( );
|
|
|
|
}
|
2017-11-25 16:30:46 +01:00
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void T_SyncViewImpl_::displayTooltips(
|
|
|
|
const float time ) noexcept
|
|
|
|
{
|
|
|
|
auto mp{ getMousePos( ) };
|
|
|
|
if ( mp.type == E_MousePosType::NONE ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Track / segment / point from mouse info
|
|
|
|
auto const& track( [&](){
|
|
|
|
if ( mp.type == E_MousePosType::POINT ) {
|
|
|
|
return dspTracks[ dspSegments[
|
|
|
|
dspPoints[ mp.index ].seg ].track ];
|
|
|
|
}
|
|
|
|
if ( mp.type == E_MousePosType::SEGMENT ) {
|
|
|
|
return dspTracks[ dspSegments[ mp.index ].track ];
|
|
|
|
}
|
|
|
|
return dspTracks[ mp.index ];
|
|
|
|
}() );
|
|
|
|
auto const* const seg( [&]() -> T_TrackSegDisplay const* {
|
|
|
|
if ( mp.type == E_MousePosType::TRACK ) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if ( mp.type == E_MousePosType::SEGMENT ) {
|
|
|
|
return &dspSegments[ mp.index ];
|
|
|
|
}
|
|
|
|
return &dspSegments[ dspPoints[ mp.index ].seg ];
|
|
|
|
}() );
|
|
|
|
auto const* const point( [&]() -> T_TrackPointDisplay const* {
|
|
|
|
if ( mp.type != E_MousePosType::POINT ) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &dspPoints[ mp.index ];
|
|
|
|
}() );
|
|
|
|
|
|
|
|
// Curve from track
|
2017-11-27 09:12:51 +01:00
|
|
|
auto& sync{ Common::Sync( ) };
|
|
|
|
T_SyncCurve const* const curve{ sync.getCurve( track.id ) };
|
2017-11-25 22:02:17 +01:00
|
|
|
assert( mp.type == E_MousePosType::TRACK || curve != nullptr );
|
|
|
|
|
|
|
|
// Time offset
|
|
|
|
const float dTime( [&](){
|
|
|
|
if ( point ) {
|
|
|
|
auto tDur{ .0f };
|
|
|
|
for ( auto i = 0u ; i <= seg->seg ; i ++ ) {
|
|
|
|
auto const& s{ curve->segments[ i ] };
|
|
|
|
auto const nd{ i == seg->seg
|
|
|
|
? point->index
|
|
|
|
: s.durations.size( ) };
|
|
|
|
for ( auto j = 0u ; j < nd ; j ++ ) {
|
|
|
|
tDur += s.durations[ j ];
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 09:12:51 +01:00
|
|
|
return tDur * sync.durationUnitSize( );
|
2017-11-25 22:02:17 +01:00
|
|
|
}
|
|
|
|
return time;
|
|
|
|
}() );
|
2017-11-27 09:12:51 +01:00
|
|
|
const float dUTime{ dTime / sync.durationUnitSize( ) };
|
2017-11-25 22:02:17 +01:00
|
|
|
char buffer[ 12 ];
|
|
|
|
TimeToString_( buffer , sizeof( buffer ) , dTime );
|
|
|
|
|
2017-11-27 09:12:51 +01:00
|
|
|
const float value{ point
|
|
|
|
? curve->segments[ seg->seg ].values[ point->index ]
|
|
|
|
: ( curve ? curve->computeValue( dUTime )
|
|
|
|
: sync.inputs( )[ sync.inputPos( track.id ) ] ) };
|
2017-11-25 22:02:17 +01:00
|
|
|
|
|
|
|
stringBuffer.clear( ) << track.id << " (input)\n";
|
|
|
|
if ( mp.type == E_MousePosType::TRACK ) {
|
|
|
|
stringBuffer << "No segment";
|
|
|
|
} else {
|
|
|
|
auto const& s{ curve->segments[ seg->seg ] };
|
|
|
|
if ( mp.type == E_MousePosType::SEGMENT ) {
|
|
|
|
stringBuffer << "Segment type: " << s.type;
|
|
|
|
} else {
|
|
|
|
stringBuffer << "On " << s.type << " segment, index " << point->index;
|
2017-11-25 16:30:46 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-25 22:02:17 +01:00
|
|
|
stringBuffer << "\nTime: " << buffer << "\nValue: " << value;
|
2017-11-25 16:30:46 +01:00
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
using namespace ImGui;
|
|
|
|
stringBuffer << '\0';
|
|
|
|
BeginTooltip( );
|
|
|
|
Text( "%s" , stringBuffer.data( ) );
|
|
|
|
EndTooltip( );
|
|
|
|
}
|
|
|
|
|
2017-11-26 13:46:46 +01:00
|
|
|
bool T_SyncViewImpl_::handlePointDrag(
|
|
|
|
const float mPixels ,
|
|
|
|
bool mouseDown ) noexcept
|
|
|
|
{
|
|
|
|
auto& sync( Common::Sync( ) );
|
|
|
|
|
|
|
|
selPointDnDCur = mPixels;
|
|
|
|
const float diff{ selPointDnDCur - selPointDnDStart };
|
|
|
|
const int32_t diffUnits{ int32_t( round( diff * sync.durationUnits( ) / totalPixels ) ) };
|
|
|
|
const bool moved{ fabsf( diff ) >= 2 && abs( diffUnits ) > 0 };
|
|
|
|
|
|
|
|
// Update the point as necessary
|
|
|
|
if ( moved ) {
|
2017-11-26 17:39:17 +01:00
|
|
|
selUpdatingCopy = selUpdatingOriginal; // XXX
|
|
|
|
auto& seg{ selUpdatingCopy->segments[ *selSegment ] };
|
2017-11-26 13:46:46 +01:00
|
|
|
if ( *selPoint == seg.durations.size( ) ) {
|
|
|
|
// We're dragging the end point
|
|
|
|
// XXX make it work "normally"
|
|
|
|
seg.durations.last( ) = std::max( 1 ,
|
|
|
|
diffUnits + int32_t( seg.durations.last( ) ) );
|
|
|
|
} else {
|
|
|
|
// We're dragging some other point, move units
|
|
|
|
// from one side to the other
|
|
|
|
assert( *selPoint > 0 );
|
|
|
|
auto& d0{ seg.durations[ *selPoint - 1 ] };
|
|
|
|
auto& d1{ seg.durations[ *selPoint ] };
|
|
|
|
const int32_t mmNeg( 1 - d0 ) , mmPos( d1 - 1 );
|
|
|
|
const int32_t diff{ diffUnits < mmNeg ? mmNeg
|
|
|
|
: ( diffUnits > mmPos ? mmPos : diffUnits ) };
|
|
|
|
d0 += diff;
|
|
|
|
d1 -= diff;
|
|
|
|
}
|
2017-11-26 17:39:17 +01:00
|
|
|
sync.setCurve( *selUpdatingCopy );
|
2017-11-26 13:46:46 +01:00
|
|
|
} else {
|
2017-11-26 17:39:17 +01:00
|
|
|
selUpdatingCopy.clear( );
|
2017-11-26 13:46:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( mouseDown ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-26 17:39:17 +01:00
|
|
|
assert( selUpdate == E_ChangeType::POINT_DND );
|
|
|
|
selUpdate = E_ChangeType::NONE;
|
2017-11-26 13:46:46 +01:00
|
|
|
selPointDnD = false;
|
2017-11-26 17:39:17 +01:00
|
|
|
sync.setCurve( std::move( *selUpdatingOriginal ) );
|
|
|
|
selUpdatingOriginal.clear( );
|
2017-11-26 13:46:46 +01:00
|
|
|
if ( moved ) {
|
2017-11-26 17:39:17 +01:00
|
|
|
SyncEditor::ReplaceCurve( std::move( *selUpdatingCopy ) );
|
|
|
|
selUpdatingCopy.clear( );
|
2017-11-26 13:46:46 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-25 22:02:17 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
T_SyncViewImpl_::T_MousePos T_SyncViewImpl_::getMousePos( ) const noexcept
|
|
|
|
{
|
|
|
|
auto const& mp{ ImGui::GetIO( ).MousePos };
|
|
|
|
for ( auto i = 0u ; i < dspTracks.size( ) ; i ++ ) {
|
|
|
|
auto const& track{ dspTracks[ i ] };
|
|
|
|
if ( !track.area.Contains( mp ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for ( auto j = 0u ; j < track.dispSegs ; j ++ ) {
|
|
|
|
auto const& seg{ dspSegments[ track.firstSeg + j ] };
|
|
|
|
if ( !seg.area.Contains( mp ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for ( auto k = 0u ; k < seg.dispPoints ; k ++ ) {
|
|
|
|
auto const& p{ dspPoints[ seg.firstPoint + k ] };
|
|
|
|
if ( ImLengthSqr( mp - p.center ) <= PointRadiusSqr ) {
|
|
|
|
return T_MousePos{ E_MousePosType::POINT ,
|
|
|
|
seg.firstPoint + k };
|
|
|
|
}
|
|
|
|
}
|
2017-11-25 23:37:07 +01:00
|
|
|
return T_MousePos{ E_MousePosType::SEGMENT ,
|
|
|
|
track.firstSeg + j };
|
2017-11-25 22:02:17 +01:00
|
|
|
}
|
|
|
|
return T_MousePos{ E_MousePosType::TRACK , i };
|
|
|
|
}
|
|
|
|
return T_MousePos{ E_MousePosType::NONE , 0 };
|
2017-11-22 20:28:12 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 14:14:49 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-11-21 22:23:34 +01:00
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
void T_SyncViewImpl_::displayTrackSelectorWindow( ) noexcept
|
2017-11-21 22:23:34 +01:00
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
|
|
|
|
// Window set-up
|
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( dspSize.x * .75f , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
bool displayed{ true };
|
|
|
|
Begin( "Display curves" , &displayed , ImGuiWindowFlags_NoCollapse );
|
|
|
|
if ( !displayed ) {
|
|
|
|
End( );
|
|
|
|
sub = SW_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Tabs"
|
|
|
|
const ImVec2 ws( GetWindowContentRegionMax( ) );
|
|
|
|
auto const& style( GetStyle( ) );
|
|
|
|
const float innerWidth{ ws.x - 2 * style.FramePadding.x };
|
|
|
|
constexpr float nButtons{ 2.f };
|
|
|
|
const float buttonWidth{ std::max( 50.f ,
|
|
|
|
( innerWidth - nButtons * style.FramePadding.x ) / nButtons ) };
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
if ( FakeTab_( "Individual inputs" , sub == SW_INPUT_SELECTOR , buttonWidth ) ) {
|
|
|
|
sub = SW_INPUT_SELECTOR;
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
|
|
|
SameLine( 0 );
|
|
|
|
if ( FakeTab_( "Overrides" , sub == SW_OVERRIDE_SELECTOR , buttonWidth ) ) {
|
|
|
|
sub = SW_OVERRIDE_SELECTOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Content
|
|
|
|
switch ( sub ) {
|
2017-11-25 23:37:07 +01:00
|
|
|
case SW_INPUT_SELECTOR:
|
|
|
|
displayInputSelector( );
|
2017-11-21 22:23:34 +01:00
|
|
|
break;
|
|
|
|
case SW_OVERRIDE_SELECTOR:
|
2017-11-22 07:38:27 +01:00
|
|
|
displayOverrideSelector( );
|
2017-11-21 22:23:34 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf( stderr , "unexpected bullshit in sync view\n" );
|
|
|
|
std::abort( );
|
|
|
|
}
|
|
|
|
End( );
|
|
|
|
}
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
void T_SyncViewImpl_::displayInputSelector( ) noexcept
|
2017-11-21 22:23:34 +01:00
|
|
|
{
|
|
|
|
using namespace ImGui;
|
2017-11-23 23:05:14 +01:00
|
|
|
T_Array< T_String > names{ Common::Sync( ).inputNames( ) };
|
2017-11-21 22:23:34 +01:00
|
|
|
|
|
|
|
// Search box; FIXME, this is utterly hacky
|
|
|
|
stringBuffer.clear( ) << curveFinder;
|
|
|
|
while ( stringBuffer.size( ) < 100 ) {
|
|
|
|
stringBuffer << '\0';
|
|
|
|
}
|
|
|
|
Text( ICON_FA_SEARCH );
|
|
|
|
SameLine( );
|
|
|
|
PushItemWidth( -1 );
|
|
|
|
if ( InputText( "##find" , const_cast< char* >( stringBuffer.data( ) ) ,
|
|
|
|
stringBuffer.size( ) ) ) {
|
|
|
|
curveFinder = T_String{ stringBuffer.data( ) ,
|
|
|
|
uint32_t( strlen( stringBuffer.data( ) ) ) };
|
|
|
|
}
|
|
|
|
PopItemWidth( );
|
|
|
|
if ( curveFinder ) {
|
|
|
|
for ( auto i = 0u ; i < names.size( ) ; ) {
|
|
|
|
auto const& n( names[ i ] );
|
|
|
|
if ( n.find( curveFinder ) == -1 ) {
|
|
|
|
names.removeSwap( i );
|
|
|
|
} else {
|
|
|
|
i ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
names.sort( );
|
|
|
|
|
|
|
|
// The list
|
|
|
|
ImGui::BeginChild( "content" );
|
|
|
|
for ( auto const& n : names ) {
|
2017-11-22 07:38:27 +01:00
|
|
|
const bool present{ sCurves.contains( n ) };
|
|
|
|
const bool overriden{ present && *sCurves.get( n ) };
|
2017-11-21 22:23:34 +01:00
|
|
|
|
|
|
|
if ( overriden ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PushDisabled( );
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool select{ present };
|
|
|
|
stringBuffer.clear( ) << n << '\0';
|
|
|
|
if ( Checkbox( stringBuffer.data( ) , &select ) ) {
|
|
|
|
if ( select ) {
|
2017-11-22 07:38:27 +01:00
|
|
|
sCurves.add( n , false );
|
2017-11-21 22:23:34 +01:00
|
|
|
} else {
|
2017-11-22 07:38:27 +01:00
|
|
|
sCurves.remove( n );
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( overriden ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PopDisabled( );
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-22 07:38:27 +01:00
|
|
|
EndChild( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncViewImpl_::displayOverrideSelector( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
|
|
|
|
BeginChild( "content" );
|
2017-11-23 23:05:14 +01:00
|
|
|
Common::Sync( ).visitOverrides( [&]( T_SyncOverrideVisitor::T_Element element , const bool exit ) {
|
2017-11-22 07:38:27 +01:00
|
|
|
if ( element.hasType< T_SyncOverrideSection* >( ) ) {
|
|
|
|
auto const& sos{ *element.value< T_SyncOverrideSection* >( ) };
|
|
|
|
if ( sos.title == "*root*" ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( exit ) {
|
|
|
|
TreePop( );
|
|
|
|
} else {
|
|
|
|
return TreeNodeEx( &sos.cTitle[ 0 ] ,
|
|
|
|
ImGuiTreeNodeFlags_DefaultOpen );
|
|
|
|
}
|
|
|
|
} else if ( exit ) {
|
|
|
|
auto const& ov{ *element.value< A_SyncOverride* >( ) };
|
|
|
|
auto const& id{ ov.id( ) };
|
|
|
|
auto const& in{ ov.inputNames( ) };
|
|
|
|
const bool present{ sOverrides.contains( id ) };
|
|
|
|
const bool hasCurves{ !present && [&](){
|
|
|
|
for ( auto i = 0u ; i < in.size( ) ; i ++ ) {
|
|
|
|
if ( sCurves.contains( in[ i ] ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}() };
|
|
|
|
|
|
|
|
if ( hasCurves ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PushDisabled( );
|
2017-11-22 07:38:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool select{ present };
|
|
|
|
if ( Checkbox( ov.title( ) , &select ) ) {
|
|
|
|
if ( select ) {
|
|
|
|
sOverrides.add( id );
|
|
|
|
for ( auto i = 0u ; i < in.size( ) ; i ++ ) {
|
|
|
|
sCurves.add( in[ i ] , true );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sOverrides.remove( id );
|
|
|
|
for ( auto i = 0u ; i < in.size( ) ; i ++ ) {
|
|
|
|
sCurves.remove( in[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasCurves ) {
|
2017-11-23 14:43:15 +01:00
|
|
|
PopDisabled( );
|
2017-11-22 07:38:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
EndChild( );
|
2017-11-21 22:23:34 +01:00
|
|
|
}
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
void T_SyncViewImpl_::displayTrackWindow( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
|
|
|
|
// Window set-up
|
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( dspSize.x * .75f , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
bool displayed{ true };
|
|
|
|
Begin( "Selected track" , &displayed , ImGuiWindowFlags_NoCollapse );
|
|
|
|
if ( !displayed ) {
|
|
|
|
End( );
|
|
|
|
sub = SW_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the curve
|
|
|
|
auto& sync{ Common::Sync( ) };
|
|
|
|
auto const* const curve{ sync.getCurve( selId ) };
|
|
|
|
|
|
|
|
Text( "Curve:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%s" , selId.toOSString( ).data( ) );
|
|
|
|
if ( !sync.hasInput( selId ) ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "No matching input" );
|
|
|
|
}
|
|
|
|
|
|
|
|
Text( "Segments:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d" , curve ? curve->segments.size( ) : 0 );
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
// Compute total duration
|
|
|
|
const uint32_t duration{ [&](){
|
|
|
|
uint32_t t{ 0 };
|
|
|
|
if ( !curve ) {
|
|
|
|
return 0u;
|
|
|
|
}
|
|
|
|
for ( auto const& s : curve->segments ) {
|
|
|
|
for ( auto const& d : s.durations ) {
|
|
|
|
t += d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}() };
|
|
|
|
const float tDuration{ duration * sync.durationUnitSize( ) };
|
|
|
|
|
|
|
|
Text( "Duration:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , duration );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tDuration );
|
|
|
|
|
|
|
|
const float dDuration{ sync.duration( ) };
|
|
|
|
if ( tDuration == 0.f ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "Empty track" );
|
|
|
|
} else if ( tDuration == dDuration ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "Covers the whole demo" );
|
|
|
|
} else if ( tDuration > dDuration ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "Longer than the demo" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( curve && !curve->segments.empty( ) ) || tDuration < dDuration ) {
|
|
|
|
Separator( );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( curve && !curve->segments.empty( ) ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Clear" , ImVec2{ -1 , 0 } ) ) {
|
|
|
|
SyncEditor::DeleteCurve( selId );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( tDuration < dDuration ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Append segment" , ImVec2{ -1 , 0 } ) ) {
|
|
|
|
const uint32_t ns{ std::max( 1u ,
|
|
|
|
( sync.durationUnits( ) - duration ) / 2 ) };
|
|
|
|
SyncEditor::AppendSegment( selId , ns );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
End( );
|
|
|
|
}
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
void T_SyncViewImpl_::displaySegmentWindow( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
|
|
|
|
// Window set-up
|
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( dspSize.x * .75f , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
bool displayed{ true };
|
|
|
|
Begin( "Selected segment" , &displayed , ImGuiWindowFlags_NoCollapse );
|
|
|
|
if ( !displayed ) {
|
|
|
|
End( );
|
|
|
|
sub = SW_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
const uint32_t sid{ *selSegment };
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
Text( "Curve:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%s" , selId.toOSString( ).data( ) );
|
|
|
|
|
|
|
|
Text( "Index:" );
|
|
|
|
SameLine( 110 );
|
2017-11-26 10:14:00 +01:00
|
|
|
Text( "%d" , sid );
|
2017-11-25 23:37:07 +01:00
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
// Access curve and segment
|
2017-11-25 23:37:07 +01:00
|
|
|
auto& sync{ Common::Sync( ) };
|
2017-11-26 10:14:00 +01:00
|
|
|
auto const* const curve{ sync.getCurve( selId ) };
|
|
|
|
auto const& segment{ curve->segments[ sid ] };
|
2017-11-25 23:37:07 +01:00
|
|
|
|
|
|
|
// Find start and duration
|
|
|
|
uint32_t start{ 0 } , duration{ 0 };
|
2017-11-26 10:14:00 +01:00
|
|
|
for ( auto i = 0u ; i <= sid ; i ++ ) {
|
2017-11-25 23:37:07 +01:00
|
|
|
auto const& s{ curve->segments[ i ] };
|
2017-11-26 10:14:00 +01:00
|
|
|
auto& tgt{ i == sid ? duration : start };
|
2017-11-25 23:37:07 +01:00
|
|
|
for ( auto d : s.durations ) {
|
|
|
|
tgt += d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const float tStart{ sync.durationUnitSize( ) * start } ,
|
|
|
|
tDuration{ sync.durationUnitSize( ) * duration };
|
|
|
|
|
|
|
|
Text( "Start:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , start );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tStart );
|
|
|
|
|
|
|
|
Text( "End:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , start + duration );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tStart + tDuration );
|
|
|
|
|
|
|
|
Text( "Duration:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , duration );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tDuration );
|
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
// Generate the combo box's data
|
|
|
|
static constexpr T_SyncSegment::E_SegmentType types[] = {
|
|
|
|
T_SyncSegment::LINEAR , T_SyncSegment::RAMP , T_SyncSegment::SMOOTH
|
|
|
|
};
|
|
|
|
stringBuffer.clear( );
|
|
|
|
for ( auto t : types ) {
|
|
|
|
stringBuffer << t << '\0';
|
|
|
|
}
|
|
|
|
stringBuffer << '\0';
|
|
|
|
Text( "Type:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
PushItemWidth( -1 );
|
|
|
|
int t{ int( segment.type ) };
|
|
|
|
const bool change{ Combo( "##type" , &t , stringBuffer.data( ) ) };
|
|
|
|
PopItemWidth( );
|
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
Text( "Points:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d" , segment.values.size( ) );
|
|
|
|
|
|
|
|
// Find min/max
|
|
|
|
float sMin{ FLT_MAX } , sMax{ -FLT_MAX };
|
|
|
|
for ( auto v : segment.values ) {
|
|
|
|
sMin = ImMin( sMin , v );
|
|
|
|
sMax = ImMax( sMax , v );
|
|
|
|
}
|
|
|
|
|
|
|
|
Text( "Min. value:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%f" , sMin );
|
|
|
|
|
|
|
|
Text( "Max. value:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%f" , sMax );
|
|
|
|
|
2017-11-26 10:14:00 +01:00
|
|
|
Separator( );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Delete segment" , ImVec2{ -1 , 0 } ) ) {
|
|
|
|
if ( curve->segments.size( ) > 1 ) {
|
|
|
|
selSegment = ( sid == 0 ? 0 : ( sid - 1 ) );
|
|
|
|
} else {
|
2017-11-26 11:57:26 +01:00
|
|
|
selSegment = decltype( selSegment ){};
|
2017-11-26 10:14:00 +01:00
|
|
|
}
|
|
|
|
SyncEditor::DeleteSegment( selId , sid );
|
|
|
|
}
|
|
|
|
|
2017-11-25 23:37:07 +01:00
|
|
|
if ( change ) {
|
2017-11-26 10:14:00 +01:00
|
|
|
SyncEditor::SetSegmentType( *curve , sid ,
|
2017-11-26 09:17:29 +01:00
|
|
|
T_SyncSegment::E_SegmentType( t ) );
|
2017-11-25 23:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
End( );
|
|
|
|
}
|
|
|
|
|
2017-11-26 17:39:17 +01:00
|
|
|
void T_SyncViewImpl_::displayPointWindow( ) noexcept
|
|
|
|
{
|
|
|
|
using namespace ImGui;
|
|
|
|
auto const& dspSize( GetIO( ).DisplaySize );
|
|
|
|
|
|
|
|
// Window set-up
|
|
|
|
SetNextWindowSize( ImVec2( dspSize.x * .25f , dspSize.y * .66f - 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
SetNextWindowPos( ImVec2( dspSize.x * .75f , 20 ) , ImGuiSetCond_Appearing );
|
|
|
|
bool displayed{ true };
|
|
|
|
Begin( "Selected point" , &displayed , ImGuiWindowFlags_NoCollapse );
|
|
|
|
if ( !displayed ) {
|
|
|
|
End( );
|
|
|
|
sub = SW_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Access curve, segment and point
|
|
|
|
const uint32_t sid{ *selSegment };
|
|
|
|
const uint32_t pid{ *selPoint };
|
|
|
|
auto& sync{ Common::Sync( ) };
|
|
|
|
auto const* const curve{ selUpdatingCopy
|
|
|
|
? selUpdatingCopy.target( )
|
|
|
|
: sync.getCurve( selId ) };
|
|
|
|
auto const& segment{ curve->segments[ sid ] };
|
|
|
|
|
|
|
|
Text( "Curve:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%s" , selId.toOSString( ).data( ) );
|
|
|
|
|
|
|
|
Text( "Segment index:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d" , sid );
|
|
|
|
|
|
|
|
Text( "Point index:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d / %d" , pid , segment.durations.size( ) );
|
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
// Find start and duration
|
|
|
|
uint32_t segStart{ 0 } , pointPosRel{ 0 };
|
|
|
|
for ( auto i = 0u ; i <= sid ; i ++ ) {
|
|
|
|
auto const& s{ curve->segments[ i ] };
|
|
|
|
auto& tgt{ i == sid ? pointPosRel : segStart };
|
|
|
|
const auto end{ i == sid ? pid : s.durations.size( ) };
|
|
|
|
for ( auto j = 0u ; j < end ; j ++ ) {
|
|
|
|
tgt += s.durations[ j ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const uint32_t pointPosAbs{ segStart + pointPosRel };
|
|
|
|
const float tPointPosAbs{ sync.durationUnitSize( ) * pointPosAbs } ,
|
|
|
|
tPointPosRel{ sync.durationUnitSize( ) * pointPosRel };
|
|
|
|
|
|
|
|
Text( "Absolute:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , pointPosAbs );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tPointPosAbs );
|
|
|
|
|
|
|
|
Text( "Relative:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%d units" , pointPosRel );
|
|
|
|
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
Text( "%.3f seconds" , tPointPosRel );
|
|
|
|
|
|
|
|
Separator( );
|
|
|
|
|
|
|
|
Text( "Value:" );
|
|
|
|
SameLine( 110 );
|
|
|
|
float value{ segment.values[ pid ] };
|
|
|
|
PushItemWidth( -1 );
|
|
|
|
DragFloat( "##value" , &value , .01f , 0 , 0 , "%.6f" );
|
|
|
|
const bool changed{ IsItemActive( ) };
|
|
|
|
PopItemWidth( );
|
|
|
|
|
|
|
|
const bool canUseButtons{ !changed && selUpdate == E_ChangeType::NONE };
|
2017-11-26 18:20:22 +01:00
|
|
|
const auto canInsertBefore{ pid != 0
|
|
|
|
&& segment.durations[ pid - 1 ] > 1 };
|
|
|
|
const auto canInsertAfter{ pid != segment.durations.size( )
|
|
|
|
&& segment.durations[ pid ] > 1 };
|
2017-11-26 17:39:17 +01:00
|
|
|
if ( pid != 0 && pid != segment.durations.size( ) ) {
|
|
|
|
Separator( );
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Delete point" , ImVec2{ -1 , 0 } ) && canUseButtons ) {
|
2017-11-26 18:20:22 +01:00
|
|
|
SyncEditor::DeletePoint( selId , sid , pid );
|
2017-11-26 17:39:17 +01:00
|
|
|
selPoint.clear( );
|
|
|
|
sub = SW_SEGMENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( canInsertAfter || canInsertBefore ) {
|
|
|
|
Separator( );
|
|
|
|
if ( canInsertBefore ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Insert before" , ImVec2{ -1 , 0 } ) && canUseButtons ) {
|
2017-11-26 18:20:22 +01:00
|
|
|
SyncEditor::InsertPoint( selId , sid , pid );
|
2017-11-26 17:39:17 +01:00
|
|
|
(*selPoint) ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( canInsertAfter ) {
|
|
|
|
Text( " " );
|
|
|
|
SameLine( 110 );
|
|
|
|
if ( Button( "Insert after" , ImVec2{ -1 , 0 } ) && canUseButtons ) {
|
2017-11-26 18:20:22 +01:00
|
|
|
SyncEditor::InsertPoint( selId , sid , pid + 1 );
|
2017-11-26 17:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( changed ) {
|
|
|
|
if ( selUpdate == E_ChangeType::NONE ) {
|
|
|
|
selUpdatingOriginal = *curve;
|
|
|
|
selUpdatingCopy = *curve;
|
|
|
|
selUpdate = E_ChangeType::POINT_VALUE;
|
|
|
|
} else {
|
|
|
|
assert( selUpdate == E_ChangeType::POINT_VALUE );
|
|
|
|
}
|
|
|
|
selUpdatingCopy->segments[ sid ].values[ pid ] = value;
|
|
|
|
sync.setCurve( *selUpdatingCopy );
|
|
|
|
} else if ( selUpdate == E_ChangeType::POINT_VALUE ) {
|
|
|
|
selUpdate = E_ChangeType::NONE;
|
|
|
|
sync.setCurve( *selUpdatingOriginal );
|
|
|
|
SyncEditor::ReplaceCurve( std::move( *selUpdatingCopy ) );
|
|
|
|
selUpdatingCopy.clear( );
|
|
|
|
}
|
|
|
|
|
|
|
|
End( );
|
|
|
|
}
|
|
|
|
|
2017-11-22 14:14:49 +01:00
|
|
|
} // namespace <anon>
|
|
|
|
|
2017-11-20 17:01:09 +01:00
|
|
|
|
2017-11-22 14:14:49 +01:00
|
|
|
/*= T_SyncView ===============================================================*/
|
2017-11-20 17:01:09 +01:00
|
|
|
|
|
|
|
T_SyncView::T_SyncView( ) noexcept
|
|
|
|
: A_PrivateImplementation( new T_SyncViewImpl_( ) )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool T_SyncView::display( ) noexcept
|
|
|
|
{
|
|
|
|
return p< T_SyncViewImpl_ >( ).display( );
|
|
|
|
}
|