X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=examples%2Fpage-turn-view%2Fpage-turn-view-example.cpp;h=7c40ef403f169853a4d3d1ff251bd74d3a83a974;hb=b7bac3bf4823689a0ea4d94a61c91a95e849c134;hp=945879ca564c5169f9e05879074f5dfef84b362c;hpb=9022d3f33d497602a88a1512d53c39006479a590;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 945879c..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,6 +17,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -24,6 +28,7 @@ #include #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -31,40 +36,55 @@ using namespace Dali::Toolkit; // LOCAL STUFF namespace { -const char* const CHANGE_IMAGE_ICON(DALI_IMAGE_DIR "icon-change.png"); -const char* const CHANGE_IMAGE_ICON_SELECTED( DALI_IMAGE_DIR "icon-change-selected.png" ); +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 @@ -78,21 +98,21 @@ class PortraitPageFactory : public PageFactory 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 ] ); } return page; @@ -101,6 +121,7 @@ class PortraitPageFactory : public PageFactory class LandscapePageFactory : public PageFactory { + /** * Query the number of pages available from the factory. * The maximum available page has an ID of GetNumberOfPages()-1. @@ -110,36 +131,32 @@ class LandscapePageFactory : public PageFactory 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); - 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 */ @@ -226,6 +243,9 @@ void PageTurnController::OnInit( Application& app ) 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(); @@ -345,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, DALI_DEMO_THEME_PATH); + Application app = Application::New(&argc, &argv, DEMO_THEME_PATH); PageTurnController test ( app ); app.MainLoop(); return 0; } -