// EXTERNAL INCLUDES
#include <dali/public-api/animation/animation.h>
-#include <dali/public-api/animation/active-constraint.h>
#include <dali/public-api/animation/constraint.h>
-#include <dali/public-api/events/hit-test-algorithm.h>
+#include <dali/devel-api/events/hit-test-algorithm.h>
#include <dali/public-api/object/type-registry.h>
-#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/devel-api/object/type-registry-helper.h>
#include <dali/public-api/render-tasks/render-task-list.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
+#include <dali-toolkit/internal/controls/page-turn-view/page-turn-effect.h>
+#include <dali-toolkit/internal/controls/page-turn-view/page-turn-book-spine-effect.h>
using namespace Dali;
mDirection = offset / mDistance;
}
- Vector2 operator()(const Vector2& current, const PropertyInput& panDisplacement)
+ void operator()( Vector2& current, const PropertyInputContainer& inputs )
{
- float displacement = panDisplacement.GetFloat();
+ float displacement = inputs[0]->GetFloat();
if( displacement < mDistance )
{
- return mOldCenter + mDirection * displacement;
+ current = mOldCenter + mDirection * displacement;
}
else
{
- return mNewCenter + Vector2(0.25f*(displacement-mDistance), 0.f);
+ current = mNewCenter + Vector2(0.25f*(displacement-mDistance), 0.f);
}
}
mStep = 1.f / pageWidth;
mSign = isTurnBack ? -1.0f : 1.0f;
mConst = isTurnBack ? -1.0f : 0.f;
- mRotation = isTurnBack ? Quaternion( -Math::PI, Vector3::YAXIS ) : Quaternion( 0.f, Vector3::YAXIS );
+ mRotation = isTurnBack ? Quaternion( Radian( -Math::PI ), Vector3::YAXIS ) : Quaternion( Radian(0.f), Vector3::YAXIS );
}
- Quaternion operator()( const Quaternion& current, const PropertyInput& panDisplacement )
+ void operator()( Quaternion& current, const PropertyInputContainer& inputs )
{
- float displacement = panDisplacement.GetFloat();
- float angle;
+ float displacement = inputs[0]->GetFloat();
if( displacement < mDistance)
{
- return mRotation;
+ current = mRotation;
}
else
{
float coef = std::max(-1.0f, mStep*(mDistance-displacement));
- angle = Math::PI*( mConst + mSign*coef );
- return Quaternion( angle, Vector3::YAXIS );
+ float angle = Math::PI * ( mConst + mSign * coef );
+ current = Quaternion( Radian( angle ), Vector3::YAXIS );
}
}
*/
struct CurrentCenterConstraint
{
- CurrentCenterConstraint( float pageWidth)
+ CurrentCenterConstraint( float pageWidth )
: mPageWidth( pageWidth )
{
mThres = pageWidth * PAGE_TURN_OVER_THRESHOLD_RATIO * 0.5f;
}
- Vector2 operator()( const Vector2& current, const PropertyInput& center, const PropertyInput& originalCenter )
+ void operator()( Vector2& current, const PropertyInputContainer& inputs )
{
- Vector2 centerPosition = center.GetVector2();
+ const Vector2& centerPosition = inputs[0]->GetVector2();
if( centerPosition.x > 0.f )
{
- return Vector2( mThres+centerPosition.x*0.5f , centerPosition.y);
+ current.x = mThres+centerPosition.x * 0.5f;
+ current.y = centerPosition.y;
}
else
{
- Vector2 centerOrigin = originalCenter.GetVector2();
+ const Vector2& centerOrigin = inputs[1]->GetVector2();
Vector2 direction = centerOrigin - Vector2(mThres, centerPosition.y);
float coef = 1.f+(centerPosition.x*2.f / mPageWidth);
// Todo: when coef <= 0, the page is flat, slow down the last moment of the page stretch by 10 times to avoid a small bounce
{
coef = (coef+0.225f)/10.0f;
}
- return centerOrigin - direction * coef;
+ current = centerOrigin - direction * coef;
}
}
: mThres( thres )
{}
- float operator()( const float current, const PropertyInput& currentCenter, const PropertyInput& originalCenter, const PropertyInput& panDisplacement)
+ void operator()( float& blurStrength, const PropertyInputContainer& inputs )
{
- float displacement = panDisplacement.GetFloat();
- float blurStrength;
+ float displacement = inputs[2]->GetFloat();
if( EqualsZero(displacement))
{
- Vector2 cur = currentCenter.GetVector2();
- Vector2 ori = originalCenter.GetVector2();
+ const Vector2& cur = inputs[0]->GetVector2();
+ const Vector2& ori = inputs[1]->GetVector2();
blurStrength = 5.f*(ori-cur).Length() / mThres;
}
else
}
blurStrength = blurStrength > 1.f ? 1.f : ( blurStrength < 0.f ? 0.f : blurStrength );
- return blurStrength;
}
float mThres;
const float PageTurnView::STATIC_PAGE_INTERVAL_DISTANCE = 1.0f;
PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& pageSize )
-: Control( REQUIRES_TOUCH_EVENTS ),
+: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ),
mPageFactory( pageFactory ),
mPageSize( pageSize ),
mTotalPageCount( 0 ),
void PageTurnView::OnInitialize()
{
// create the two book spine effect for static images, left and right side pages respectively
- mSpineEffectFront = PageTurnBookSpineEffect::New();
- mSpineEffectFront.SetIsBackImageVisible( false );
- mSpineEffectFront.SetPageWidth( mPageSize.width );
- mSpineEffectFront.SetShadowWidth( 0.f );
- mSpineEffectFront.SetSpineShadowParameter( mSpineShadowParameter );
-
- mSpineEffectBack = PageTurnBookSpineEffect::New();
- mSpineEffectBack.SetIsBackImageVisible( true );
- mSpineEffectBack.SetPageWidth( mPageSize.width );
- mSpineEffectBack.SetShadowWidth( 0.f );
- mSpineEffectBack.SetSpineShadowParameter( mSpineShadowParameter );
+ mSpineEffectFront = CreatePageTurnBookSpineEffect();
+ mSpineEffectFront.SetUniform("uIsBackImageVisible", false );
+ mSpineEffectFront.SetUniform("uPageWidth", mPageSize.width );
+ mSpineEffectFront.SetUniform("uShadowWidth", 0.f );
+ mSpineEffectFront.SetUniform("uSpineShadowParameter", mSpineShadowParameter );
+
+ mSpineEffectBack = CreatePageTurnBookSpineEffect();
+ mSpineEffectBack.SetUniform("uIsBackImageVisible", true );
+ mSpineEffectBack.SetUniform("uPageWidth", mPageSize.width );
+ mSpineEffectBack.SetUniform("uShadowWidth", 0.f );
+ mSpineEffectBack.SetUniform("uSpineShadowParameter", mSpineShadowParameter );
// create the page turn effect objects
for( int i = 0; i < MAXIMUM_TURNING_NUM; i++ )
{
- mTurnEffect[i] = Toolkit::PageTurnEffect::New( false );
+ mTurnEffect[i] = CreatePageTurnEffect( false );
mTurnEffect[i].SetProperty( ShaderEffect::Property::GRID_DENSITY, Property::Value( DEFAULT_GRID_DENSITY ) );
- mTurnEffect[i].SetPageSize( mPageSize );
- mTurnEffect[i].SetShadowWidth(0.f);
- mTurnEffect[i].SetSpineShadowParameter( mSpineShadowParameter );
+ mTurnEffect[i].SetUniform( "uPageSize", mPageSize );
+ mTurnEffect[i].SetUniform( "uShadowWidth", 0.f);
+ mTurnEffect[i].SetUniform( "uSpineShadowParameter", mSpineShadowParameter );
mIsAnimating[i] = false;
mIsSliding[i] = false;
mPropertyPanDisplacement[i] = Self().RegisterProperty("PAN_DISPLACEMENT_PROPERTY_"+i, 0.0f);
mSpineShadowParameter = spineShadowParameter;
// set spine shadow parameter to all the shader effects
- mSpineEffectFront.SetSpineShadowParameter( mSpineShadowParameter );
- mSpineEffectBack.SetSpineShadowParameter( mSpineShadowParameter );
+ mSpineEffectFront.SetUniform("uSpineShadowParameter", mSpineShadowParameter );
+ mSpineEffectBack.SetUniform("uSpineShadowParameter", mSpineShadowParameter );
for( int i = 0; i < MAXIMUM_TURNING_NUM; i++ )
{
- mTurnEffect[i].SetSpineShadowParameter( mSpineShadowParameter );
+ mTurnEffect[i].SetUniform("uSpineShadowParameter", mSpineShadowParameter );
}
}
}
mOriginalCenter = gesturePosition;
- mTurnEffect[mIndex].SetIsTurningBack( mIsTurnBack[ mPanActor] );
+ mTurnEffect[mIndex].SetUniform("uIsTurningBack", mIsTurnBack[ mPanActor] );
mPress = false;
mPageUpdated = false;
mDistanceBottomCorner = ( mOriginalCenter - Vector2( 0.0f, mPageSize.height ) ).Length();
mShadowView.Add( mPanActor );
SetShaderEffect( mPanActor, mTurnEffect[mIndex] );
- mTurnEffect[mIndex].SetOriginalCenter( mOriginalCenter );
+ mTurnEffect[mIndex].SetUniform("uOriginalCenter", mOriginalCenter );
mCurrentCenter = mOriginalCenter;
- mTurnEffect[mIndex].SetCurrentCenter( mCurrentCenter );
+ mTurnEffect[mIndex].SetUniform("uCurrentCenter", mCurrentCenter );
mPanDisplacement = 0.f;
mConstraints = true;
mPress = true;
mShadowView.RemoveConstraints();
Actor self = Self();
self.SetProperty( mPropertyPanDisplacement[mIndex], 0.f );
- Constraint shadowBlurStrengthConstraint = Constraint::New<float>( mShadowView.GetBlurStrengthPropertyIndex(),
- Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName())),
- Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetOriginalCenterPropertyName())),
- Source( self, mPropertyPanDisplacement[mIndex] ),
- ShadowBlurStrengthConstraint( mPageSize.width*PAGE_TURN_OVER_THRESHOLD_RATIO ) );
- mShadowView.ApplyConstraint( shadowBlurStrengthConstraint );
+
+ Constraint shadowBlurStrengthConstraint = Constraint::New<float>( mShadowView, mShadowView.GetBlurStrengthPropertyIndex(), ShadowBlurStrengthConstraint( mPageSize.width*PAGE_TURN_OVER_THRESHOLD_RATIO ) );
+ shadowBlurStrengthConstraint.AddSource( Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex("uCurrentCenter")) );
+ shadowBlurStrengthConstraint.AddSource( Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex("uOriginalCenter")) );
+ shadowBlurStrengthConstraint.AddSource( Source( self, mPropertyPanDisplacement[mIndex] ) );
+ shadowBlurStrengthConstraint.Apply();
}
}
else
/( offset.x*offset.x + offset.y*offset.y );
offset *= k;
Actor self = Self();
- Source source(self, mPropertyPanDisplacement[mIndex]);
- Property::Index shaderOriginalCenterPropertyIndex = mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetOriginalCenterPropertyName());
- Constraint originalCenterConstraint = Constraint::New<Vector2>( shaderOriginalCenterPropertyIndex ,
- source,
- OriginalCenterConstraint( mOriginalCenter, offset ));
- mTurnEffect[mIndex].ApplyConstraint( originalCenterConstraint );
+ Property::Index shaderOriginalCenterPropertyIndex = mTurnEffect[mIndex].GetPropertyIndex("uOriginalCenter");
+ Constraint originalCenterConstraint = Constraint::New<Vector2>( mTurnEffect[mIndex], shaderOriginalCenterPropertyIndex, OriginalCenterConstraint( mOriginalCenter, offset ));
+ originalCenterConstraint.AddSource( Source( self, mPropertyPanDisplacement[mIndex] ) );
+ originalCenterConstraint.Apply();
- Property::Index shaderCurrentCenterPropertyIndex = mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName());
- Constraint currentCenterConstraint = Constraint::New<Vector2>( shaderCurrentCenterPropertyIndex,
- Source(self, mPropertyCurrentCenter[mIndex]),
- Source(mTurnEffect[mIndex], shaderOriginalCenterPropertyIndex),
- CurrentCenterConstraint(mPageSize.width));
- mTurnEffect[mIndex].ApplyConstraint( currentCenterConstraint );
+ Property::Index shaderCurrentCenterPropertyIndex = mTurnEffect[mIndex].GetPropertyIndex("uCurrentCenter");
+ Constraint currentCenterConstraint = Constraint::New<Vector2>( mTurnEffect[mIndex], shaderCurrentCenterPropertyIndex, CurrentCenterConstraint(mPageSize.width));
+ currentCenterConstraint.AddSource( Source(self, mPropertyCurrentCenter[mIndex]) );
+ currentCenterConstraint.AddSource( Source(mTurnEffect[mIndex], shaderOriginalCenterPropertyIndex) );
+ currentCenterConstraint.Apply();
- GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint();
+ PageTurnApplyInternalConstraint(mTurnEffect[mIndex]);
float distance = offset.Length();
- Constraint rotationConstraint = Constraint::New<Quaternion>( Actor::Property::ORIENTATION,
- Source( self, mPropertyPanDisplacement[mIndex] ),
- RotationConstraint(distance, mPageSize.width, mIsTurnBack[mPanActor]));
- mPanActor.ApplyConstraint( rotationConstraint );
+ Constraint rotationConstraint = Constraint::New<Quaternion>( mPanActor, Actor::Property::ORIENTATION, RotationConstraint(distance, mPageSize.width, mIsTurnBack[mPanActor]));
+ rotationConstraint.AddSource( Source( self, mPropertyPanDisplacement[mIndex] ) );
+ rotationConstraint.Apply();
mConstraints = false;
}
{
mPanActor.RemoveConstraints();
mTurnEffect[mIndex].RemoveConstraints();
- mTurnEffect[mIndex].SetOriginalCenter( mOriginalCenter );
+ mTurnEffect[mIndex].SetUniform("uOriginalCenter",mOriginalCenter );
mConstraints = true;
mPanDisplacement = 0.f;
}
- mTurnEffect[mIndex].SetCurrentCenter( currentCenter );
+ mTurnEffect[mIndex].SetUniform("uCurrentCenter", currentCenter );
mCurrentCenter = currentCenter;
- GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint();
+ PageTurnApplyInternalConstraint(mTurnEffect[mIndex]);
}
}
}
float width = mPageSize.width*(1.f+PAGE_TURN_OVER_THRESHOLD_RATIO);
Animation animation = Animation::New( std::max(0.1f,PAGE_TURN_OVER_ANIMATION_DURATION * (1.0f - mPanDisplacement / width)) );
animation.AnimateTo( Property(self, mPropertyPanDisplacement[mIndex]),
- width,AlphaFunctions::EaseOutSine33);
+ width,AlphaFunction::EASE_OUT_SINE);
animation.AnimateTo( Property(self, mPropertyCurrentCenter[mIndex]),
- Vector2(-mPageSize.width, 0.5f*mPageSize.height), AlphaFunctions::EaseOutSine33);
+ Vector2(-mPageSize.width, 0.5f*mPageSize.height), AlphaFunction::EASE_OUT_SINE);
mAnimationActorPair[animation] = actor;
mAnimationIndexPair[animation] = mIndex;
animation.Play();
else // the pan finished position is far away from the spine, set up an animation to slide the page back instead of turning over
{
Animation animation= Animation::New( PAGE_SLIDE_BACK_ANIMATION_DURATION * (mOriginalCenter.x - mCurrentCenter.x) / mPageSize.width / PAGE_TURN_OVER_THRESHOLD_RATIO );
- animation.AnimateTo( Property( mTurnEffect[mIndex], mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName() ),
- mOriginalCenter, AlphaFunctions::Linear );
+ animation.AnimateTo( Property( mTurnEffect[mIndex], "uCurrentCenter" ),
+ mOriginalCenter, AlphaFunction::LINEAR );
mAnimationActorPair[animation] = actor;
mAnimationIndexPair[animation] = mIndex;
animation.Play();