X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fpage-turn-view%2Fpage-turn-view-example.cpp;h=7c40ef403f169853a4d3d1ff251bd74d3a83a974;hb=b7bac3bf4823689a0ea4d94a61c91a95e849c134;hp=33498cd80585c4344259447e4344f9169092b986;hpb=74177c1264be054639ac4bcd2a462e97129be516;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index 33498cd..7c40ef4 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -17,12 +17,18 @@ #include #include +#include +#include +#include +#include + #include #include #include #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -30,37 +36,55 @@ using namespace Dali::Toolkit; // LOCAL STUFF namespace { +const char* const CHANGE_IMAGE_ICON(DEMO_IMAGE_DIR "icon-change.png"); +const char* const CHANGE_IMAGE_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" ); + // The content amount of one page between portrait and landscape view are different // set a ratio to modify the current page number when the rotation is changed const float PAGE_NUMBER_CORRESPONDING_RATIO(1.25f); -const char* BOOK_COVER_PORTRAIT = ( DALI_IMAGE_DIR "book-portrait-cover.jpg" ); -const char* BOOK_COVER_LANDSCAPE = ( DALI_IMAGE_DIR "book-landscape-cover.jpg" ); -const char* BOOK_COVER_BACK_LANDSCAPE = ( DALI_IMAGE_DIR "book-landscape-cover-back.jpg" ); +const char* BOOK_COVER_PORTRAIT( DEMO_IMAGE_DIR "book-portrait-cover.jpg" ); +const char* BOOK_COVER_LANDSCAPE( DEMO_IMAGE_DIR "book-landscape-cover.jpg" ); +const char* BOOK_COVER_BACK_LANDSCAPE( DEMO_IMAGE_DIR "book-landscape-cover-back.jpg" ); const char* PAGE_IMAGES_PORTRAIT[] = { - DALI_IMAGE_DIR "book-portrait-p1.jpg", - DALI_IMAGE_DIR "book-portrait-p2.jpg", - DALI_IMAGE_DIR "book-portrait-p3.jpg", - DALI_IMAGE_DIR "book-portrait-p4.jpg", - DALI_IMAGE_DIR "book-portrait-p5.jpg" + DEMO_IMAGE_DIR "book-portrait-p1.jpg", + DEMO_IMAGE_DIR "book-portrait-p2.jpg", + DEMO_IMAGE_DIR "book-portrait-p3.jpg", + DEMO_IMAGE_DIR "book-portrait-p4.jpg", + DEMO_IMAGE_DIR "book-portrait-p5.jpg" }; const unsigned int NUMBER_OF_PORTRAIT_IMAGE( sizeof(PAGE_IMAGES_PORTRAIT) / sizeof(PAGE_IMAGES_PORTRAIT[0]) ); const char* PAGE_IMAGES_LANDSCAPE[] = { - DALI_IMAGE_DIR "book-landscape-p1.jpg", - DALI_IMAGE_DIR "book-landscape-p2.jpg", - DALI_IMAGE_DIR "book-landscape-p3.jpg", - DALI_IMAGE_DIR "book-landscape-p4.jpg", - DALI_IMAGE_DIR "book-landscape-p5.jpg", - DALI_IMAGE_DIR "book-landscape-p6.jpg", - DALI_IMAGE_DIR "book-landscape-p7.jpg", - DALI_IMAGE_DIR "book-landscape-p8.jpg" + DEMO_IMAGE_DIR "book-landscape-p1.jpg", + DEMO_IMAGE_DIR "book-landscape-p2.jpg", + DEMO_IMAGE_DIR "book-landscape-p3.jpg", + DEMO_IMAGE_DIR "book-landscape-p4.jpg", + DEMO_IMAGE_DIR "book-landscape-p5.jpg", + DEMO_IMAGE_DIR "book-landscape-p6.jpg", + DEMO_IMAGE_DIR "book-landscape-p7.jpg", + DEMO_IMAGE_DIR "book-landscape-p8.jpg" }; const unsigned int NUMBER_OF_LANDSCAPE_IMAGE( sizeof(PAGE_IMAGES_LANDSCAPE) / sizeof(PAGE_IMAGES_LANDSCAPE[0]) ); +Texture LoadTextures( const char* imagePath1, const char* imagePath2 ) +{ + PixelData pixelData1 = DemoHelper::LoadPixelData( imagePath1, ImageDimensions(), FittingMode::DEFAULT, SamplingMode::DEFAULT ); + PixelData pixelData2 = DemoHelper::LoadPixelData( imagePath2, ImageDimensions(), FittingMode::DEFAULT, SamplingMode::DEFAULT ); + + unsigned int width = pixelData1.GetWidth() + pixelData2.GetWidth(); + unsigned int height = pixelData1.GetHeight() > pixelData2.GetHeight() ? pixelData1.GetHeight() : pixelData2.GetHeight(); + + Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, width, height ); + texture.Upload( pixelData1 ); + texture.Upload( pixelData2, 0u, 0u, pixelData1.GetWidth(), 0u, pixelData2.GetWidth(), pixelData2.GetHeight() ); + + return texture; +} + }// end LOCAL STUFF class PortraitPageFactory : public PageFactory @@ -71,76 +95,68 @@ class PortraitPageFactory : public PageFactory */ virtual unsigned int GetNumberOfPages() { - return 5*NUMBER_OF_PORTRAIT_IMAGE + 1; + return 10*NUMBER_OF_PORTRAIT_IMAGE + 1; } /** - * Create an image actor to represent a page. + * Create an texture to represent a page. * @param[in] pageId The ID of the page to create. - * @return An image actor, or an uninitialized pointer if the ID is out of range. + * @return A texture, or an uninitialized handle if the ID is out of range. */ - virtual Actor NewPage( unsigned int pageId ) + virtual Texture NewPage( unsigned int pageId ) { - ImageActor page; + Texture page; if( pageId == 0 ) { - page = ImageActor::New( ResourceImage::New( BOOK_COVER_PORTRAIT ) ); + page = DemoHelper::LoadTexture( BOOK_COVER_PORTRAIT ); } else { - page = ImageActor::New( ResourceImage::New( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ) ); + page = DemoHelper::LoadTexture( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ); } - page.SetRelayoutEnabled( false ); - return page; } }; class LandscapePageFactory : public PageFactory { + /** * Query the number of pages available from the factory. * The maximum available page has an ID of GetNumberOfPages()-1. */ virtual unsigned int GetNumberOfPages() { - return 5*NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1; + return 10*NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1; } /** - * Create an image actor to represent a page. + * Create an texture to represent a page. * @param[in] pageId The ID of the page to create. - * @return An image actor, or an uninitialized pointer if the ID is out of range. + * @return A texture, or an uninitialized handle if the ID is out of range. */ - virtual Actor NewPage( unsigned int pageId ) + virtual Texture NewPage( unsigned int pageId ) { - ImageActor pageFront; - ImageActor pageBack; + Texture page; if( pageId == 0 ) { - pageFront = ImageActor::New( ResourceImage::New( BOOK_COVER_LANDSCAPE ) ); - pageBack = ImageActor::New( ResourceImage::New( BOOK_COVER_BACK_LANDSCAPE ) ); + page = LoadTextures( BOOK_COVER_LANDSCAPE, BOOK_COVER_BACK_LANDSCAPE ); } else { unsigned int imageId = (pageId-1)*2; - pageFront = ImageActor::New( ResourceImage::New( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ] ) ); - pageBack = ImageActor::New( ResourceImage::New( PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] ) ); + page = LoadTextures( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ], PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] ); } - pageFront.Add(pageBack); - - pageFront.SetRelayoutEnabled( false ); - pageBack.SetRelayoutEnabled( false ); - return pageFront; + return page; } }; /** * This example shows how to use the page turn UI control to implement the page-turn demo * The effect follows the pan gesture to animate the page - * Pan the image inwards, the page will bent, - * Depends on the distance of the panning, the image might turn over or slide back + * Pan the page inwards, the page will bent, + * Depends on the distance of the panning, the page might turn over or slide back * Also, in portrait view, the pan gesture outwards from position near the spine could turn the previous page back * Allows to turn multiple pages one by one quickly towards the same direction, multiple animations are launched in this case */ @@ -156,12 +172,9 @@ public: private: /** - * This method gets called when the screen is rotated, switch between portrait and landscape views - * param [in] view The view receiving the orientation change signal - * param [in] animation The Orientation Rotating animation - * param [in] orientation The current screen orientation + * This method gets called when the button is clicked, switch between portrait and landscape views */ - void OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation ); + bool OnButtonClicked(Toolkit::Button button); /** * Main key event handler @@ -201,7 +214,7 @@ private: private: Application& mApplication; - View mView; + Layer mButtonLayer; PageTurnView mPageTurnPortraitView; PageTurnView mPageTurnLandscapeView; @@ -228,83 +241,87 @@ void PageTurnController::OnInit( Application& app ) { // The Init signal is received once ( only ) during the Application lifetime - DemoHelper::RequestThemeChange(); - Stage::GetCurrent().KeyEventSignal().Connect(this, &PageTurnController::OnKeyEvent); + // Hide the indicator bar + app.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + Stage stage = Stage::GetCurrent(); Vector2 stageSize = stage.GetSize(); - // Create default View. - mView = View::New(); - mView.SetRelayoutEnabled( false ); - stage.Add( mView ); - - Dali::Window winHandle = app.GetWindow(); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE ); - winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE ); - winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE ); - // FIXME - //app.GetOrientation().ChangedSignal().Connect( &mView, &View::OrientationChanged ); - // view will response to orientation change to display portrait or landscape views - mView.OrientationAnimationStartedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted ); - - mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize ); - mPageTurnPortraitView.SetRelayoutEnabled( false ); - mPageTurnPortraitView.SetSpineShadowParameter( Vector2(70.f, 30.f) ); + mButtonLayer = Layer::New(); + mButtonLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER ); + mButtonLayer.SetParentOrigin( Dali::ParentOrigin::CENTER ); + mButtonLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + Toolkit::PushButton button = Toolkit::PushButton::New(); + button.SetAnchorPoint( AnchorPoint::TOP_RIGHT ); + button.SetParentOrigin( ParentOrigin::TOP_RIGHT ); + button.SetUnselectedImage( CHANGE_IMAGE_ICON ); + button.SetSelectedImage( CHANGE_IMAGE_ICON_SELECTED ); + button.SetLeaveRequired( true ); + button.SetScale(1.5f); + button.PressedSignal().Connect( this, &PageTurnController::OnButtonClicked ); + stage.Add( mButtonLayer ); + mButtonLayer.Add(button); + + Vector2 bookSize( stageSize.x > stageSize.y ? stageSize.y : stageSize.x, + stageSize.x > stageSize.y ? stageSize.x : stageSize.y ); + + mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, bookSize ); + mPageTurnPortraitView.SetParentOrigin( ParentOrigin::CENTER ); + mPageTurnPortraitView.SetAnchorPoint( AnchorPoint::CENTER ); + mPageTurnPortraitView.SetProperty( PageTurnView::Property::SPINE_SHADOW, Vector2(70.f, 30.f) ); mPageTurnPortraitView.PageTurnStartedSignal().Connect( this, &PageTurnController::OnPageStartedTurn ); mPageTurnPortraitView.PageTurnFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedTurn ); mPageTurnPortraitView.PagePanStartedSignal().Connect( this, &PageTurnController::OnPageStartedPan ); mPageTurnPortraitView.PagePanFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedPan ); - mPageTurnPortraitView.SetPositionInheritanceMode( USE_PARENT_POSITION ); - mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(stageSize.y*0.5f, stageSize.x) ); - mPageTurnLandscapeView.SetRelayoutEnabled( false ); + mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(bookSize.y*0.5f, bookSize.x) ); + mPageTurnLandscapeView.SetParentOrigin( ParentOrigin::CENTER ); + mPageTurnLandscapeView.SetAnchorPoint( AnchorPoint::CENTER ); mPageTurnLandscapeView.PageTurnStartedSignal().Connect( this, &PageTurnController::OnPageStartedTurn ); mPageTurnLandscapeView.PageTurnFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedTurn ); mPageTurnLandscapeView.PagePanStartedSignal().Connect( this, &PageTurnController::OnPageStartedPan ); mPageTurnLandscapeView.PagePanFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedPan ); - mPageTurnLandscapeView.SetPositionInheritanceMode( USE_PARENT_POSITION ); - mView.Add(mPageTurnPortraitView); + if( stageSize.x > stageSize.y ) + { + stage.Add(mPageTurnLandscapeView); + mPageTurnPortraitView.SetOrientation(Degree(90.f), Vector3::ZAXIS); + mIsPortrait = false; + } + else + { + stage.Add(mPageTurnPortraitView); + mPageTurnLandscapeView.SetOrientation(Degree(90.f), Vector3::ZAXIS); + mIsPortrait = true; + } + + mButtonLayer.RaiseToTop(); } -void PageTurnController::OnOrientationAnimationStarted( View view, Animation& animation, const Orientation& orientation ) +bool PageTurnController::OnButtonClicked(Toolkit::Button button) { - switch( orientation.GetDegrees() ) + if( mIsPortrait ) { - // portrait view, display page in the right side only - case 0: - case 180: - { - if( !mIsPortrait ) - { - mView.Remove( mPageTurnLandscapeView ); - mView.Add( mPageTurnPortraitView ); - int currentPage = floor( static_cast(mPageTurnLandscapeView.GetCurrentPage()) * PAGE_NUMBER_CORRESPONDING_RATIO ); - mPageTurnPortraitView.GoToPage( currentPage ); - mIsPortrait = true; - } - break; - } - // display pages in both sides - case 90: - case 270: - { - if( mIsPortrait ) - { - mView.Remove( mPageTurnPortraitView ); - mView.Add( mPageTurnLandscapeView ); - int currentPage = ceil( static_cast(mPageTurnPortraitView.GetCurrentPage()) / PAGE_NUMBER_CORRESPONDING_RATIO ); - mPageTurnLandscapeView.GoToPage( currentPage ); - mIsPortrait = false; - } - break; - } - default: - break; + mPageTurnPortraitView.Unparent(); + Stage::GetCurrent().Add( mPageTurnLandscapeView ); + int pageId = mPageTurnPortraitView.GetProperty( PageTurnView::Property::CURRENT_PAGE_ID ).Get(); + int currentPage = ceil( static_cast(pageId) / PAGE_NUMBER_CORRESPONDING_RATIO ); + mPageTurnLandscapeView.SetProperty(PageTurnView::Property::CURRENT_PAGE_ID, currentPage ); + } + else + { + mPageTurnLandscapeView.Unparent(); + Stage::GetCurrent().Add( mPageTurnPortraitView ); + int pageId = mPageTurnLandscapeView.GetProperty( PageTurnView::Property::CURRENT_PAGE_ID ).Get(); + int currentPage = floor(pageId * PAGE_NUMBER_CORRESPONDING_RATIO ); + mPageTurnPortraitView.SetProperty(PageTurnView::Property::CURRENT_PAGE_ID, currentPage ); } + + mIsPortrait = !mIsPortrait; + mButtonLayer.RaiseToTop(); + return true; } /** @@ -348,13 +365,12 @@ void PageTurnController::OnPageFinishedPan( PageTurnView pageTurnView ) } // Entry point for applications -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { - Application app = Application::New(&argc, &argv); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); PageTurnController test ( app ); app.MainLoop(); return 0; } -