Skip to content

Commit ee599c3

Browse files
author
hoshiryu
committed
fix editor ;
1 parent 8f6f2a1 commit ee599c3

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

src/GuiBase/KeyFrameEditor/KeyFrameEditorFrame.cpp

+60-55
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <iostream>
1111

1212
#include <Core/Animation/KeyFramedValue.hpp>
13+
#include <Core/Animation/KeyFramedValueInterpolators.hpp>
1314
#include <Core/Math/Interpolation.hpp>
1415
#include <Core/Utils/Color.hpp>
1516
#include <Core/Utils/Log.hpp>
@@ -20,11 +21,9 @@
2021

2122
static constexpr int CTRL_PT_RAD = 5;
2223

24+
using namespace Ra::Core::Animation;
2325
using namespace Ra::Core::Utils;
2426

25-
template <typename T>
26-
using KeyFramedValue = Ra::Core::Animation::KeyFramedValue<T>;
27-
2827
namespace Ra::GuiBase {
2928

3029
KeyFrameEditorFrame::KeyFrameEditorFrame( QWidget* parent ) : QFrame( parent ) {
@@ -297,32 +296,32 @@ void KeyFrameEditorFrame::onSetCursorToNextKeyFrame() {
297296
} \
298297
}
299298

300-
#define drawSampled( drawFunc ) \
301-
{ \
302-
int p; \
303-
Scalar t0 = *times.begin(); \
304-
for ( auto t1 : times ) \
305-
{ \
306-
fromTimeToPixel( t1, p ); \
307-
if ( p < sliderH ) \
308-
{ \
309-
std::exchange( t0, t1 ); \
310-
continue; \
311-
} \
312-
fromTimeToPixel( t0, p ); \
313-
if ( p > sliderH + areaWidth ) \
314-
{ \
315-
std::exchange( t0, t1 ); \
316-
continue; \
317-
} \
318-
const int N = int( ( t1 - t0 ) / stepT ); \
319-
for ( Scalar t = t0; t <= t1; t += 1_ra / N ) \
320-
{ \
321-
fromTimeToPixel( t, p ); \
322-
drawFunc( p, kf->at( t ) ); \
323-
} \
324-
std::exchange( t0, t1 ); \
325-
} \
299+
#define drawSampled( drawFunc, type ) \
300+
{ \
301+
int p; \
302+
Scalar t0 = *times.begin(); \
303+
for ( auto t1 : times ) \
304+
{ \
305+
fromTimeToPixel( t1, p ); \
306+
if ( p < sliderH ) \
307+
{ \
308+
std::exchange( t0, t1 ); \
309+
continue; \
310+
} \
311+
fromTimeToPixel( t0, p ); \
312+
if ( p > sliderH + areaWidth ) \
313+
{ \
314+
std::exchange( t0, t1 ); \
315+
continue; \
316+
} \
317+
const int N = int( ( t1 - t0 ) / stepT ); \
318+
for ( Scalar t = t0; t <= t1; t += 1_ra / N ) \
319+
{ \
320+
fromTimeToPixel( t, p ); \
321+
drawFunc( p, kf->at( t, linearInterpolate<type> ) ); \
322+
} \
323+
std::exchange( t0, t1 ); \
324+
} \
326325
}
327326

328327
void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
@@ -483,33 +482,33 @@ void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
483482
fromValueToPixel( v, y );
484483
path[0].lineTo( QPoint( x, y ) );
485484
};
486-
drawSampled( drawScalar );
485+
drawSampled( drawScalar, Scalar );
487486
}
488487
}
489488
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
490489
{
491490
if ( m_displayCurve[0] || m_displayCurve[1] )
492-
{ drawSampled( drawVector( Ra::Core::Vector2, 2 ) ); }
491+
{ drawSampled( drawVector( Ra::Core::Vector2, 2 ), Ra::Core::Vector2 ); }
493492
}
494493
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector3>*>( m_value ) )
495494
{
496495
if ( m_displayCurve[0] || m_displayCurve[1] || m_displayCurve[2] )
497-
{ drawSampled( drawVector( Ra::Core::Vector3, 3 ) ); }
496+
{ drawSampled( drawVector( Ra::Core::Vector3, 3 ), Ra::Core::Vector3 ); }
498497
}
499498
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector4>*>( m_value ) )
500499
{
501500
if ( m_displayCurve[0] || m_displayCurve[1] || m_displayCurve[2] || m_displayCurve[3] )
502-
{ drawSampled( drawVector( Ra::Core::Vector4, 4 ) ); }
501+
{ drawSampled( drawVector( Ra::Core::Vector4, 4 ), Ra::Core::Vector4 ); }
503502
}
504503
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Utils::Color>*>( m_value ) )
505504
{
506505
if ( m_displayCurve[0] || m_displayCurve[1] || m_displayCurve[2] || m_displayCurve[3] )
507-
{ drawSampled( drawVector( Ra::Core::Utils::Color, 4 ) ); }
506+
{ drawSampled( drawVector( Ra::Core::Utils::Color, 4 ), Ra::Core::Utils::Color ); }
508507
}
509508
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Quaternion>*>( m_value ) )
510509
{
511510
if ( m_displayCurve[0] || m_displayCurve[1] || m_displayCurve[2] || m_displayCurve[3] )
512-
{ drawSampled( drawQuaternion ); }
511+
{ drawSampled( drawQuaternion, Ra::Core::Quaternion ); }
513512
}
514513
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Transform>*>( m_value ) )
515514
{
@@ -541,7 +540,7 @@ void KeyFrameEditorFrame::paintEvent( QPaintEvent* ) {
541540
path[9].lineTo( QPoint( x, y ) );
542541
}
543542
};
544-
drawSampled( drawTransform );
543+
drawSampled( drawTransform, Ra::Core::Transform );
545544
}
546545
}
547546

@@ -729,17 +728,20 @@ void KeyFrameEditorFrame::mouseMoveEvent( QMouseEvent* event ) {
729728
if ( auto kf = dynamic_cast<KeyFramedValue<bool>*>( m_value ) )
730729
{
731730
kf->insertKeyFrame( time, int( std::max( value, 0_ra ) ) );
732-
m_curveControlPoints[uint( i )][uint( j )].y() = kf->at( time );
731+
m_curveControlPoints[uint( i )][uint( j )].y() =
732+
kf->at( time, linearInterpolate<bool> );
733733
}
734734
if ( auto kf = dynamic_cast<KeyFramedValue<int>*>( m_value ) )
735735
{
736736
kf->insertKeyFrame( time, int( value ) );
737-
m_curveControlPoints[uint( i )][uint( j )].y() = kf->at( time );
737+
m_curveControlPoints[uint( i )][uint( j )].y() =
738+
kf->at( time, linearInterpolate<int> );
738739
}
739740
if ( auto kf = dynamic_cast<KeyFramedValue<Scalar>*>( m_value ) )
740741
{
741742
kf->insertKeyFrame( time, value );
742-
m_curveControlPoints[uint( i )][uint( j )].y() = kf->at( time );
743+
m_curveControlPoints[uint( i )][uint( j )].y() =
744+
kf->at( time, linearInterpolate<Scalar> );
743745
}
744746
if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
745747
{
@@ -855,21 +857,21 @@ Scalar KeyFrameEditorFrame::nearestStep( Scalar time ) const {
855857
return newCursor;
856858
}
857859

858-
#define registerValue() \
859-
m_curveControlPoints[0].reserve( times.size() ); \
860-
for ( auto t : times ) \
861-
{ \
862-
m_curveControlPoints[0].push_back( {t, kf->at( t )} ); \
860+
#define registerValue( type ) \
861+
m_curveControlPoints[0].reserve( times.size() ); \
862+
for ( auto t : times ) \
863+
{ \
864+
m_curveControlPoints[0].push_back( {t, kf->at( t, linearInterpolate<type> )} ); \
863865
}
864866

865-
#define registerVector( N ) \
867+
#define registerVector( N, type ) \
866868
for ( size_t i = 0; i < N; ++i ) \
867869
{ \
868870
m_curveControlPoints[i].reserve( times.size() ); \
869871
} \
870872
for ( auto t : times ) \
871873
{ \
872-
const auto f = kf->at( t ); \
874+
const auto f = kf->at( t, linearInterpolate<type> ); \
873875
for ( uint i = 0; i < N; ++i ) \
874876
m_curveControlPoints[i].push_back( {t, f( i )} ); \
875877
}
@@ -910,7 +912,8 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
910912
m_curveControlPoints[0].reserve( times.size() );
911913
for ( auto t : times )
912914
{
913-
m_curveControlPoints[0].push_back( {t, ( kf->at( t ) ? 1 : 0 )} );
915+
m_curveControlPoints[0].push_back(
916+
{t, ( kf->at( t, linearInterpolate<bool> ) ? 1 : 0 )} );
914917
}
915918

916919
if ( m_ui != nullptr )
@@ -921,7 +924,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
921924
}
922925
else if ( auto kf = dynamic_cast<KeyFramedValue<int>*>( m_value ) )
923926
{
924-
registerValue();
927+
registerValue( int );
925928

926929
if ( m_ui != nullptr )
927930
{
@@ -931,7 +934,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
931934
}
932935
else if ( auto kf = dynamic_cast<KeyFramedValue<Scalar>*>( m_value ) )
933936
{
934-
registerValue();
937+
registerValue( Scalar );
935938

936939
if ( m_ui != nullptr )
937940
{
@@ -941,7 +944,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
941944
}
942945
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector2>*>( m_value ) )
943946
{
944-
registerVector( 2 );
947+
registerVector( 2, Ra::Core::Vector2 );
945948

946949
if ( m_ui != nullptr )
947950
{
@@ -953,7 +956,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
953956
}
954957
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector3>*>( m_value ) )
955958
{
956-
registerVector( 3 );
959+
registerVector( 3, Ra::Core::Vector3 );
957960

958961
if ( m_ui != nullptr )
959962
{
@@ -967,7 +970,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
967970
}
968971
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Vector4>*>( m_value ) )
969972
{
970-
registerVector( 4 );
973+
registerVector( 4, Ra::Core::Vector4 );
971974

972975
if ( m_ui != nullptr )
973976
{
@@ -983,7 +986,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
983986
}
984987
else if ( auto kf = dynamic_cast<KeyFramedValue<Ra::Core::Utils::Color>*>( m_value ) )
985988
{
986-
registerVector( 4 );
989+
registerVector( 4, Ra::Core::Utils::Color );
987990

988991
if ( m_ui != nullptr )
989992
{
@@ -1004,7 +1007,9 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
10041007
m_curveControlPoints[6].reserve( times.size() );
10051008
for ( auto t : times )
10061009
{
1007-
const auto f = kf->at( t ).matrix().eulerAngles( 0, 1, 2 );
1010+
const auto f = kf->at( t, linearInterpolate<Ra::Core::Quaternion> )
1011+
.matrix()
1012+
.eulerAngles( 0, 1, 2 );
10081013
m_curveControlPoints[4].push_back( {t, f.x()} );
10091014
m_curveControlPoints[5].push_back( {t, f.y()} );
10101015
m_curveControlPoints[6].push_back( {t, f.z()} );
@@ -1025,7 +1030,7 @@ void KeyFrameEditorFrame::registerKeyFrames( bool newValue ) {
10251030
}
10261031
for ( auto t : times )
10271032
{
1028-
const auto f = kf->at( t );
1033+
const auto f = kf->at( t, linearInterpolate<Ra::Core::Transform> );
10291034
const auto T = f.translation();
10301035
Ra::Core::Matrix3 R, S;
10311036
f.computeRotationScaling( &R, &S );

0 commit comments

Comments
 (0)