X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fpage-turn-view%2Fpage-turn-view-impl.cpp;h=b55b7579e992a14d3137783f710574969608f826;hp=078be1cacf5310dfe8e9879dcf2b1fb8a9e95911;hb=f17aee578d095c3a7c53355fbff3259070883de3;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp index 078be1c..b55b757 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp @@ -1,31 +1,42 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include +// EXTERNAL INCLUDES +#include +#include +#include +#include +#include +#include + // INTERNAL INCLUDES #include using namespace Dali; -namespace //unnamed namespace +namespace //Unnamed namespace { // To register type -TypeRegistration mType( typeid(Toolkit::PageTurnView), typeid(Toolkit::Control), NULL ); + +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PageTurnView, Toolkit::Control, NULL ) +DALI_TYPE_REGISTRATION_END() // default grid density for page turn effect, 10 pixels by 10 pixels const float DEFAULT_GRID_DENSITY(10.0f); @@ -68,17 +79,17 @@ struct OriginalCenterConstraint 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); } } @@ -102,22 +113,21 @@ struct RotationConstraint 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 ); } } @@ -136,22 +146,23 @@ struct RotationConstraint */ 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 @@ -159,7 +170,7 @@ struct CurrentCenterConstraint { coef = (coef+0.225f)/10.0f; } - return centerOrigin - direction * coef; + current = centerOrigin - direction * coef; } } @@ -173,14 +184,13 @@ struct ShadowBlurStrengthConstraint : 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 @@ -189,7 +199,6 @@ struct ShadowBlurStrengthConstraint } blurStrength = blurStrength > 1.f ? 1.f : ( blurStrength < 0.f ? 0.f : blurStrength ); - return blurStrength; } float mThres; @@ -250,16 +259,22 @@ const int PageTurnView::NUMBER_OF_CACHED_PAGES = NUMBER_OF_CACHED_PAGES_EACH_SID const float PageTurnView::STATIC_PAGE_INTERVAL_DISTANCE = 1.0f; PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& pageSize ) -: ControlImpl( true ), +: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ), mPageFactory( pageFactory ), mPageSize( pageSize ), + mTotalPageCount( 0 ), mIsEditMode( false ), + mNeedOffscreenRendering( false ), mPanning( false ), mSpineShadowParameter( DEFAULT_SPINE_SHADOW_PARAMETER ), mCurrentPageIndex( 0 ), mIndex( 0 ), mPress( false ), mPageUpdated( true ), + mDistanceUpCorner( 0.f ), + mDistanceBottomCorner( 0.f ), + mPanDisplacement( 0.f ), + mConstraints( false ), mPageTurnStartedSignal(), mPageTurnFinishedSignal(), mPagePanStartedSignal(), @@ -296,7 +311,7 @@ void PageTurnView::OnInitialize() for( int i = 0; i < MAXIMUM_TURNING_NUM; i++ ) { mTurnEffect[i] = Toolkit::PageTurnEffect::New( false ); - mTurnEffect[i].SetProperty( ShaderEffect::GRID_DENSITY, Property::Value( DEFAULT_GRID_DENSITY ) ); + 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 ); @@ -350,7 +365,6 @@ void PageTurnView::SetupRenderTasks() mCameraActor.SetParentOrigin(ParentOrigin::CENTER); mCameraActor.SetPositionInheritanceMode( DONT_INHERIT_POSITION ); mCameraActor.SetInheritScale( false ); - mCameraActor.SetInvertYAxis(false); Self().Add(mCameraActor); RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList(); @@ -364,7 +378,7 @@ void PageTurnView::SetupRenderTasks() Self().Add( mPageSourceActor[i] ); mPageSourceActor[i].SetSensitive( false ); - mRenderedPage[i] = FrameBufferImage::New( mControlSize.width, mControlSize.height, Pixel::RGB8888, Image::Unused ); + mRenderedPage[i] = FrameBufferImage::New( mControlSize.width, mControlSize.height, Pixel::RGB8888, Image::UNUSED ); mOffscreenTask[i] = taskList.CreateTask(); mOffscreenTask[i].SetRefreshRate( RenderTask::REFRESH_ONCE ); mOffscreenTask[i].SetCameraActor(mCameraActor); @@ -441,8 +455,6 @@ void PageTurnView::OnControlStageDisconnection() void PageTurnView::OnControlSizeSet( const Vector3& size ) { - // disable the SetSize of the control from the application - Self().SetSize( mControlSize ); } void PageTurnView::SetSpineShadowParameter( const Vector2& spineShadowParameter ) @@ -654,7 +666,7 @@ void PageTurnView::RefreshCurrentPage() RenderPage( mCurrentPageIndex ); } -void PageTurnView::OnPan( PanGesture gesture ) +void PageTurnView::OnPan( const PanGesture& gesture ) { if( mIsEditMode ) { @@ -790,12 +802,12 @@ void PageTurnView::PanContinuing( const Vector2& gesturePosition ) mShadowView.RemoveConstraints(); Actor self = Self(); self.SetProperty( mPropertyPanDisplacement[mIndex], 0.f ); - Constraint shadowBlurStrengthConstraint = Constraint::New( 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( mShadowView, mShadowView.GetBlurStrengthPropertyIndex(), ShadowBlurStrengthConstraint( mPageSize.width*PAGE_TURN_OVER_THRESHOLD_RATIO ) ); + shadowBlurStrengthConstraint.AddSource( Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetCurrentCenterPropertyName())) ); + shadowBlurStrengthConstraint.AddSource( Source(mTurnEffect[mIndex], mTurnEffect[mIndex].GetPropertyIndex(mTurnEffect[mIndex].PageTurnEffect::GetOriginalCenterPropertyName())) ); + shadowBlurStrengthConstraint.AddSource( Source( self, mPropertyPanDisplacement[mIndex] ) ); + shadowBlurStrengthConstraint.Apply(); } } else @@ -857,28 +869,24 @@ void PageTurnView::PanContinuing( const Vector2& gesturePosition ) /( 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( shaderOriginalCenterPropertyIndex , - source, - OriginalCenterConstraint( mOriginalCenter, offset )); - mTurnEffect[mIndex].ApplyConstraint( originalCenterConstraint ); + Constraint originalCenterConstraint = Constraint::New( 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( shaderCurrentCenterPropertyIndex, - Source(self, mPropertyCurrentCenter[mIndex]), - Source(mTurnEffect[mIndex], shaderOriginalCenterPropertyIndex), - CurrentCenterConstraint(mPageSize.width)); - mTurnEffect[mIndex].ApplyConstraint( currentCenterConstraint ); + Constraint currentCenterConstraint = Constraint::New( mTurnEffect[mIndex], shaderCurrentCenterPropertyIndex, CurrentCenterConstraint(mPageSize.width)); + currentCenterConstraint.AddSource( Source(self, mPropertyCurrentCenter[mIndex]) ); + currentCenterConstraint.AddSource( Source(mTurnEffect[mIndex], shaderOriginalCenterPropertyIndex) ); + currentCenterConstraint.Apply(); GetImpl( mTurnEffect[mIndex] ).ApplyInternalConstraint(); float distance = offset.Length(); - Constraint rotationConstraint = Constraint::New( Actor::ROTATION, - Source( self, mPropertyPanDisplacement[mIndex] ), - RotationConstraint(distance, mPageSize.width, mIsTurnBack[mPanActor])); - mPanActor.ApplyConstraint( rotationConstraint ); + Constraint rotationConstraint = Constraint::New( mPanActor, Actor::Property::ORIENTATION, RotationConstraint(distance, mPageSize.width, mIsTurnBack[mPanActor])); + rotationConstraint.AddSource( Source( self, mPropertyPanDisplacement[mIndex] ) ); + rotationConstraint.Apply(); mConstraints = false; } @@ -917,7 +925,7 @@ void PageTurnView::PanFinished( const Vector2& gesturePosition, float gestureSpe mPagePanFinishedSignal.Emit( handle ); - Actor actor = mPanActor; + ImageActor actor = mPanActor; if(mPress) { if(!mConstraints) // if with constraints, the pan finished position is near spine, set up an animation to turn the page over @@ -943,9 +951,9 @@ void PageTurnView::PanFinished( const Vector2& gesturePosition, float gestureSpe 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(); @@ -955,7 +963,7 @@ void PageTurnView::PanFinished( const Vector2& gesturePosition, float gestureSpe { 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 ); + mOriginalCenter, AlphaFunction::LINEAR ); mAnimationActorPair[animation] = actor; mAnimationIndexPair[animation] = mIndex; animation.Play(); @@ -977,7 +985,7 @@ void PageTurnView::PanFinished( const Vector2& gesturePosition, float gestureSpe void PageTurnView::TurnedOver( Animation& animation ) { - Actor actor = mAnimationActorPair[animation]; + ImageActor actor = mAnimationActorPair[animation]; mIsTurnBack[actor] = !mIsTurnBack[actor]; actor.RemoveConstraints(); mRootOnScreen.Add(actor); @@ -996,7 +1004,7 @@ void PageTurnView::TurnedOver( Animation& animation ) void PageTurnView::SliddenBack( Animation& animation ) { - Actor actor = mAnimationActorPair[animation]; + ImageActor actor = mAnimationActorPair[animation]; mRootOnScreen.Add(actor); int index = mAnimationIndexPair[animation]; mIsSliding[index] = false; @@ -1026,14 +1034,9 @@ void PageTurnView::OrganizePageDepth() } } -void PageTurnView::SetShaderEffect( Actor actor, ShaderEffect shaderEffect ) +void PageTurnView::SetShaderEffect( ImageActor actor, ShaderEffect shaderEffect ) { - actor.SetShaderEffect( shaderEffect ); - - if( actor.GetChildCount() > 0 ) - { - actor.GetChildAt( 0 ).SetShaderEffect(shaderEffect); - } + SetShaderEffectRecursively( actor, shaderEffect ); } Toolkit::PageTurnView::PageTurnSignal& PageTurnView::PageTurnStartedSignal()