/*
- * 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.
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/image-atlas/image-atlas.h>
+#include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
+#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h>
+#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h>
+#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-view.h>
#include <assert.h>
#include <cstdlib>
#include <iostream>
#include "shared/view.h"
+#include "shared/utility.h"
using namespace Dali;
using namespace Dali::Toolkit;
// 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 = ( 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* 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[] =
{
};
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
return 10*NUMBER_OF_PORTRAIT_IMAGE + 1;
}
/**
- * Create an image to represent a page.
+ * Create an texture to represent a page.
* @param[in] pageId The ID of the page to create.
- * @return An image, 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 Image NewPage( unsigned int pageId )
+ virtual Texture NewPage( unsigned int pageId )
{
- Image page;
+ Texture page;
if( pageId == 0 )
{
- page = ResourceImage::New( BOOK_COVER_PORTRAIT );
+ page = DemoHelper::LoadTexture( BOOK_COVER_PORTRAIT );
}
else
{
- page = 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;
return 10*NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1;
}
/**
- * Create an image to represent a page.
+ * Create an texture to represent a page.
* @param[in] pageId The ID of the page to create.
- * @return An image, 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 Image NewPage( unsigned int pageId )
+ virtual Texture NewPage( unsigned int pageId )
{
- if( mImageSize.GetWidth() == 0u || mImageSize.GetHeight() == 0u )
- {
- mImageSize = ResourceImage::GetImageSize(BOOK_COVER_LANDSCAPE);
- }
-
- ImageAtlas atlas = ImageAtlas::New( mImageSize.GetWidth()*2u, mImageSize.GetHeight(), Pixel::RGB888 );
- Vector4 textureRect;
+ Texture page;
if( pageId == 0 )
{
- atlas.Upload( textureRect, BOOK_COVER_LANDSCAPE, mImageSize );
- atlas.Upload( textureRect, BOOK_COVER_BACK_LANDSCAPE, mImageSize );
+ page = LoadTextures( BOOK_COVER_LANDSCAPE, BOOK_COVER_BACK_LANDSCAPE );
}
else
{
unsigned int imageId = (pageId-1)*2;
- atlas.Upload( textureRect, PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ], mImageSize );
- atlas.Upload( textureRect, PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ], mImageSize );
+ page = LoadTextures( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ], PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] );
}
- return atlas.GetAtlas();
+ return page;
}
-
- ImageDimensions mImageSize;
};
/**
* 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
*/
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();