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=df3bf6fc8ae92e0a07f3f4b902abc2cc6f595831;hp=a0d5d9f3de9ae877807aa69a1b26ef445bd5ee43;hb=f546dd5d83a968e573f8f053a01ce43df32c71a0;hpb=ef5357cfd908303f109e1e0b0648e8997efe1a2f 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 a0d5d9f..df3bf6f 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,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -22,31 +22,22 @@ #include // for strcmp #include #include -#include #include -#include +#include #include // INTERNAL INCLUDES +#include #include #include -#include - -// headers needed for backward compatibility of PageFactory::NewPage(pageId) API -#include +#include +#include +#include using namespace Dali; namespace //Unnamed namespace { -// broken image is loaded if there is no valid image provided for the page -const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png"); - -// names of shader property map -const char * const CUSTOM_SHADER( "shader" ); -const char * const CUSTOM_VERTEX_SHADER( "vertexShader" ); -const char * const CUSTOM_FRAGMENT_SHADER( "fragmentShader" ); - // properties set on shader, these properties have the constant value in regardless of the page status const char * const PROPERTY_SPINE_SHADOW ( "uSpineShadowParameter" ); // uniform for both spine and turn effect @@ -61,13 +52,13 @@ const char * const PROPERTY_PAN_CENTER( "panCenter" );// property used to constr // default grid density for page turn effect, 20 pixels by 20 pixels const float DEFAULT_GRID_DENSITY(20.0f); -// to bent the page, the minimal horizontal pan start position is pageSize.x * MINIMUM_START_POSITION_RATIO +// to bent the page, the minimal horizontal pan start position is viewPageSize.x * MINIMUM_START_POSITION_RATIO const float MINIMUM_START_POSITION_RATIO(0.6f); -// the maximum vertical displacement of pan gesture, if exceed, will reduce it: pageSize.y * MAXIMUM_VERTICAL_MOVEMENT_RATIO +// the maximum vertical displacement of pan gesture, if exceed, will reduce it: viewPageSize.y * MAXIMUM_VERTICAL_MOVEMENT_RATIO const float MAXIMUM_VERTICAL_MOVEMENT_RATIO(0.15f); -// when the x component of pan position reaches pageSize.x * PAGE_TURN_OVER_THRESHOLD_RATIO, page starts to turn over +// when the x component of pan position reaches viewPageSize.x * PAGE_TURN_OVER_THRESHOLD_RATIO, page starts to turn over const float PAGE_TURN_OVER_THRESHOLD_RATIO(0.5f); // duration of animation, shorter for faster speed @@ -247,7 +238,7 @@ BaseHandle Create() // Setup properties, signals and actions using the type-registry. DALI_TYPE_REGISTRATION_BEGIN( Toolkit::PageTurnView, Toolkit::Control, Create ); -DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "pageSize", VECTOR2, PAGE_SIZE ) +DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "viewPageSize", VECTOR2, VIEW_PAGE_SIZE ) DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "currentPageId", INTEGER, CURRENT_PAGE_ID ) DALI_PROPERTY_REGISTRATION( Toolkit, PageTurnView, "spineShadow", VECTOR2, SPINE_SHADOW ) @@ -273,9 +264,9 @@ PageTurnView::Page::Page() : isTurnBack( false ) { actor = Actor::New(); - actor.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - actor.SetParentOrigin( ParentOrigin::CENTER_LEFT ); - actor.SetVisible( false ); + actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); + actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_LEFT ); + actor.SetProperty( Actor::Property::VISIBLE, false ); propertyPanDisplacement = actor.RegisterProperty( PROPERTY_PAN_DISPLACEMENT, 0.f ); propertyPanCenter = actor.RegisterProperty(PROPERTY_PAN_CENTER, Vector2::ZERO); @@ -287,14 +278,13 @@ PageTurnView::Page::Page() propertyTurnDirection = actor.RegisterProperty(PROPERTY_TURN_DIRECTION, -1.f); } -void PageTurnView::Page::SetImage( Image image ) +void PageTurnView::Page::SetTexture( Texture texture ) { if( !textureSet ) { textureSet = TextureSet::New(); } - - textureSet.SetImage( 0u, image ); + textureSet.SetTexture( 0u, texture ); } void PageTurnView::Page::UseEffect(Shader newShader) @@ -320,7 +310,7 @@ void PageTurnView::Page::UseEffect(Shader newShader, Geometry geometry) } renderer.SetTextures( textureSet ); - renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, Renderer::DEPTH_WRITE_ON ); + renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON ); actor.AddRenderer( renderer ); } } @@ -351,10 +341,10 @@ void PageTurnView::Page::SetCurrentCenter( const Vector2& value ) actor.SetProperty( propertyCurrentCenter, value ); } -PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& pageSize ) -: Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS ) ), +PageTurnView::PageTurnView( PageFactory& pageFactory, const Vector2& viewPageSize ) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), mPageFactory( &pageFactory ), - mPageSize( pageSize ), + mPageSize( viewPageSize ), mSpineShadowParameter( DEFAULT_SPINE_SHADOW_PARAMETER ), mDistanceUpCorner( 0.f ), mDistanceBottomCorner( 0.f ), @@ -393,20 +383,20 @@ void PageTurnView::OnInitialize() // create the grid geometry for pages uint16_t width = static_cast(mPageSize.width / DEFAULT_GRID_DENSITY + 0.5f); uint16_t height = static_cast(mPageSize.height / DEFAULT_GRID_DENSITY + 0.5f); - mGeometry = RendererFactoryCache::CreateGridGeometry( Uint16Pair( width, height ) ); + mGeometry = VisualFactoryCache::CreateGridGeometry( Uint16Pair( width, height ) ); mPages.reserve( NUMBER_OF_CACHED_PAGES ); for( int i = 0; i < NUMBER_OF_CACHED_PAGES; i++ ) { mPages.push_back( Page() ); - mPages[i].actor.SetSize( mPageSize ); + mPages[i].actor.SetProperty( Actor::Property::SIZE, mPageSize ); Self().Add( mPages[i].actor ); } - // create the layer for turning images + // create the layer for turning pages mTurningPageLayer = Layer::New(); - mTurningPageLayer.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - mTurningPageLayer.SetBehavior(Layer::LAYER_3D); + mTurningPageLayer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT ); + mTurningPageLayer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_3D ); mTurningPageLayer.Raise(); // Set control size and the parent origin of page layers @@ -419,29 +409,34 @@ void PageTurnView::OnInitialize() for( int i = 0; i < NUMBER_OF_CACHED_PAGES_EACH_SIDE; i++ ) { AddPage( i ); - mPages[i].actor.SetZ( -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); + mPages[i].actor.SetProperty( Actor::Property::POSITION_Z, -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); } - mPages[0].actor.SetVisible(true); + mPages[0].actor.SetProperty( Actor::Property::VISIBLE,true); // enable the pan gesture which is attached to the control - EnableGestureDetection(Gesture::Type(Gesture::Pan)); + EnableGestureDetection(GestureType::Value(GestureType::PAN)); + + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::PAGE_TAB_LIST ) ); + } ); } Shader PageTurnView::CreateShader( const Property::Map& shaderMap ) { Shader shader; - Property::Value* shaderValue = shaderMap.Find( CUSTOM_SHADER ); + Property::Value* shaderValue = shaderMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); Property::Map shaderSource; if( shaderValue && shaderValue->Get( shaderSource ) ) { std::string vertexShader; - Property::Value* vertexShaderValue = shaderSource.Find( CUSTOM_VERTEX_SHADER ); + Property::Value* vertexShaderValue = shaderSource.Find( Toolkit::Visual::Shader::Property::VERTEX_SHADER, CUSTOM_VERTEX_SHADER ); if( !vertexShaderValue || !vertexShaderValue->Get( vertexShader ) ) { DALI_LOG_ERROR("PageTurnView::CreateShader failed: vertex shader source is not available.\n"); } std::string fragmentShader; - Property::Value* fragmentShaderValue = shaderSource.Find( CUSTOM_FRAGMENT_SHADER ); + Property::Value* fragmentShaderValue = shaderSource.Find( Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, CUSTOM_FRAGMENT_SHADER ); if( !fragmentShaderValue || !fragmentShaderValue->Get( fragmentShader ) ) { DALI_LOG_ERROR("PageTurnView::CreateShader failed: fragment shader source is not available.\n"); @@ -459,22 +454,22 @@ Shader PageTurnView::CreateShader( const Property::Map& shaderMap ) void PageTurnView::SetupShadowView() { mShadowView = Toolkit::ShadowView::New( 0.25f, 0.25f ); - Vector3 origin = mTurningPageLayer.GetCurrentParentOrigin(); - mShadowView.SetParentOrigin( origin ); - mShadowView.SetAnchorPoint( origin ); + Vector3 origin = mTurningPageLayer.GetCurrentProperty< Vector3 >( Actor::Property::PARENT_ORIGIN ); + mShadowView.SetProperty( Actor::Property::PARENT_ORIGIN, origin ); + mShadowView.SetProperty( Actor::Property::ANCHOR_POINT, origin ); mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f); mShadowView.SetShadowColor(DEFAULT_SHADOW_COLOR); mShadowPlaneBackground = Actor::New(); - mShadowPlaneBackground.SetParentOrigin( ParentOrigin::CENTER ); - mShadowPlaneBackground.SetSize( mControlSize ); + mShadowPlaneBackground.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mShadowPlaneBackground.SetProperty( Actor::Property::SIZE, mControlSize ); Self().Add( mShadowPlaneBackground ); mShadowView.SetShadowPlaneBackground( mShadowPlaneBackground ); mPointLight = Actor::New(); - mPointLight.SetAnchorPoint( origin ); - mPointLight.SetParentOrigin( origin ); - mPointLight.SetPosition( 0.f, 0.f, mPageSize.width*POINT_LIGHT_HEIGHT_RATIO ); + mPointLight.SetProperty( Actor::Property::ANCHOR_POINT, origin ); + mPointLight.SetProperty( Actor::Property::PARENT_ORIGIN, origin ); + mPointLight.SetProperty( Actor::Property::POSITION, Vector3( 0.f, 0.f, mPageSize.width*POINT_LIGHT_HEIGHT_RATIO )); Self().Add( mPointLight ); mShadowView.SetPointLight( mPointLight ); @@ -482,14 +477,14 @@ void PageTurnView::SetupShadowView() mShadowView.Activate(); } -void PageTurnView::OnStageConnection( int depth ) +void PageTurnView::OnSceneConnection( int depth ) { - Control::OnStageConnection( depth ); - SetupShadowView(); + + Control::OnSceneConnection( depth ); } -void PageTurnView::OnStageDisconnection() +void PageTurnView::OnSceneDisconnection() { if(mShadowView) { @@ -502,28 +497,28 @@ void PageTurnView::OnStageDisconnection() // make sure the status of the control is updated correctly when the pan gesture is interrupted StopTurning(); - Control::OnStageDisconnection(); + Control::OnSceneDisconnection(); } -void PageTurnView::SetPageSize( const Vector2& pageSize ) +void PageTurnView::SetPageSize( const Vector2& viewPageSize ) { - mPageSize = pageSize; + mPageSize = viewPageSize; if( mPointLight ) { - mPointLight.SetPosition( 0.f, 0.f, mPageSize.width*POINT_LIGHT_HEIGHT_RATIO ); + mPointLight.SetProperty( Actor::Property::POSITION, Vector3( 0.f, 0.f, mPageSize.width*POINT_LIGHT_HEIGHT_RATIO )); } for( size_t i=0; i 0 ) { - mPages[(pageId-1)%NUMBER_OF_CACHED_PAGES].actor.SetVisible(true); + mPages[(pageId-1)%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,true); } // set ordered depth to the stacked pages OrganizePageDepth(); @@ -589,13 +584,9 @@ void PageTurnView::AddPage( int pageIndex ) { int index = pageIndex % NUMBER_OF_CACHED_PAGES; - Image newPageImage; - newPageImage = mPageFactory->NewPage( pageIndex ); - - if( !newPageImage ) // load the broken image - { - newPageImage = ResourceImage::New( BROKEN_IMAGE_URL ); - } + Texture newPage; + newPage = mPageFactory->NewPage( pageIndex ); + DALI_ASSERT_ALWAYS( newPage && "must pass in valid texture" ); bool isLeftSide = ( pageIndex < mCurrentPageIndex ); if( mPages[index].isTurnBack != isLeftSide ) @@ -604,14 +595,14 @@ void PageTurnView::AddPage( int pageIndex ) } float degree = isLeftSide ? 180.f :0.f; - mPages[index].actor.SetOrientation( Degree( degree ), Vector3::YAXIS ); - mPages[index].actor.SetVisible( false ); + mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( degree ), Vector3::YAXIS ) ); + mPages[index].actor.SetProperty( Actor::Property::VISIBLE, false ); mPages[index].UseEffect( mSpineEffectShader, mGeometry ); - mPages[index].SetImage( newPageImage ); + mPages[index].SetTexture( newPage ); // For Portrait, nothing to do // For Landscape, set the parent origin to CENTER - OnAddPage( mPages[index].actor, isLeftSide ); + OnAddPage( mPages[index].actor, isLeftSide ); } } @@ -620,26 +611,27 @@ void PageTurnView::RemovePage( int pageIndex ) if( pageIndex > -1 && pageIndex < mTotalPageCount) { int index = pageIndex % NUMBER_OF_CACHED_PAGES; - mPages[index].actor.SetVisible(false); + mPages[index].actor.SetProperty( Actor::Property::VISIBLE,false); } } void PageTurnView::OnPan( const PanGesture& gesture ) { // the pan gesture is attached to control itself instead of each page - switch( gesture.state ) + switch( gesture.GetState() ) { - case Gesture::Started: + case GestureState::STARTED: { // check whether the undergoing turning page number already reaches the maximum allowed if( mPageUpdated && mAnimatingCount< MAXIMUM_TURNING_NUM && mSlidingCount < 1 ) { - SetPanActor( gesture.position ); // determine which page actor is panned + const Vector2& position = gesture.GetPosition(); + SetPanActor( position ); // determine which page actor is panned if( mTurningPageIndex != -1 && mPages[mTurningPageIndex % NUMBER_OF_CACHED_PAGES].actor.GetParent() != Self()) // if the page is added to turning layer,it is undergoing an animation currently { mTurningPageIndex = -1; } - PanStarted( SetPanPosition( gesture.position ) ); // pass in the pan position in the local page coordinate + PanStarted( SetPanPosition( position ) ); // pass in the pan position in the local page coordinate } else { @@ -647,19 +639,19 @@ void PageTurnView::OnPan( const PanGesture& gesture ) } break; } - case Gesture::Continuing: + case GestureState::CONTINUING: { - PanContinuing( SetPanPosition( gesture.position ) ); // pass in the pan position in the local page coordinate + PanContinuing( SetPanPosition( gesture.GetPosition() ) ); // pass in the pan position in the local page coordinate break; } - case Gesture::Finished: - case Gesture::Cancelled: + case GestureState::FINISHED: + case GestureState::CANCELLED: { - PanFinished( SetPanPosition( gesture.position ), gesture.GetSpeed() ); + PanFinished( SetPanPosition( gesture.GetPosition() ), gesture.GetSpeed() ); break; } - case Gesture::Clear: - case Gesture::Possible: + case GestureState::CLEAR: + case GestureState::POSSIBLE: default: { break; @@ -727,7 +719,7 @@ void PageTurnView::PanContinuing( const Vector2& gesturePosition ) int id = mTurningPageIndex + (mPages[mIndex].isTurnBack ? -1 : 1); if( id >=0 && id < mTotalPageCount ) { - mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(true); + mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,true); } mShadowView.RemoveConstraints(); @@ -919,13 +911,13 @@ void PageTurnView::TurnedOver( Animation& animation ) mAnimationPageIdPair.erase( animation ); float degree = mPages[index].isTurnBack ? 180.f : 0.f; - mPages[index].actor.SetOrientation( Degree(degree), Vector3::YAXIS ); + mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree(degree), Vector3::YAXIS ) ); mPages[index].UseEffect( mSpineEffectShader ); int id = pageId + (mPages[index].isTurnBack ? -1 : 1); if( id >=0 && id < mTotalPageCount ) { - mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(false); + mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,false); } OnTurnedOver( mPages[index].actor, mPages[index].isTurnBack ); @@ -949,7 +941,7 @@ void PageTurnView::SliddenBack( Animation& animation ) int id = pageId + (mPages[index].isTurnBack ? -1 : 1); if( id >=0 && id < mTotalPageCount ) { - mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetVisible(false); + mPages[id%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::VISIBLE,false); } // Guard against destruction during signal emission @@ -963,11 +955,11 @@ void PageTurnView::OrganizePageDepth() { if(mCurrentPageIndex+i < mTotalPageCount) { - mPages[( mCurrentPageIndex+i )%NUMBER_OF_CACHED_PAGES].actor.SetZ( -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); + mPages[( mCurrentPageIndex+i )%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::POSITION_Z, -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); } if( mCurrentPageIndex >= i + 1 ) { - mPages[( mCurrentPageIndex-i-1 )%NUMBER_OF_CACHED_PAGES].actor.SetZ( -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); + mPages[( mCurrentPageIndex-i-1 )%NUMBER_OF_CACHED_PAGES].actor.SetProperty( Actor::Property::POSITION_Z, -static_cast( i )*STATIC_PAGE_INTERVAL_DISTANCE ); } } } @@ -984,7 +976,7 @@ void PageTurnView::StopTurning() mPages[ index ].actor.RemoveConstraints(); mPages[ index ].UseEffect( mSpineEffectShader ); float degree = mTurningPageIndex==mCurrentPageIndex ? 0.f :180.f; - mPages[index].actor.SetOrientation( Degree(degree), Vector3::YAXIS ); + mPages[index].actor.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree(degree), Vector3::YAXIS ) ); mPageUpdated = true; } @@ -1059,7 +1051,7 @@ void PageTurnView::SetProperty( BaseObject* object, Property::Index index, const switch( index ) { - case Toolkit::PageTurnView::Property::PAGE_SIZE: + case Toolkit::PageTurnView::Property::VIEW_PAGE_SIZE: { pageTurnViewImpl.SetPageSize( value.Get() ); break; @@ -1090,7 +1082,7 @@ Property::Value PageTurnView::GetProperty( BaseObject* object, Property::Index i switch( index ) { - case Toolkit::PageTurnView::Property::PAGE_SIZE: + case Toolkit::PageTurnView::Property::VIEW_PAGE_SIZE: { value = pageTurnViewImpl.GetPageSize(); break;