From 6addf420cb7c9760426bd6d1cdfd224b32c183b1 Mon Sep 17 00:00:00 2001
From: Paul Wisbey
Date: Thu, 18 Jul 2019 14:50:04 +0100
Subject: [PATCH] Resurrected PageTurnView demo
Change-Id: Ia4bd7029637a00c7b332adc4440f2cc730208c3c
---
com.samsung.dali-demo.xml | 3 +
demo/dali-demo.cpp | 1 +
examples/page-turn-view/page-turn-view-example.cpp | 289 +++++++++++++++++++++
resources/po/en_GB.po | 3 +
resources/po/en_US.po | 3 +
shared/dali-demo-strings.h | 2 +
6 files changed, 301 insertions(+)
create mode 100644 examples/page-turn-view/page-turn-view-example.cpp
diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml
index c0ea54a..a9bc5d8 100644
--- a/com.samsung.dali-demo.xml
+++ b/com.samsung.dali-demo.xml
@@ -308,6 +308,9 @@
+
+
+
http://tizen.org/privilege/mediastorage
diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp
index 70da658..b720769 100644
--- a/demo/dali-demo.cpp
+++ b/demo/dali-demo.cpp
@@ -47,6 +47,7 @@ int DALI_EXPORT_API main(int argc, char **argv)
demo.AddExample(Example("metaball-explosion.example", DALI_DEMO_STR_TITLE_METABALL_EXPLOSION));
demo.AddExample(Example("metaball-refrac.example", DALI_DEMO_STR_TITLE_METABALL_REFRAC));
demo.AddExample(Example("motion-blur.example", DALI_DEMO_STR_TITLE_MOTION_BLUR));
+ demo.AddExample(Example("page-turn-view.example", DALI_DEMO_STR_TITLE_PAGE_TURN));
demo.AddExample(Example("refraction-effect.example", DALI_DEMO_STR_TITLE_REFRACTION));
demo.AddExample(Example("renderer-stencil.example", DALI_DEMO_STR_TITLE_RENDERER_STENCIL));
demo.AddExample(Example("shadows-and-lights.example", DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS));
diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp
new file mode 100644
index 0000000..1bb1411
--- /dev/null
+++ b/examples/page-turn-view/page-turn-view-example.cpp
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2019 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.
+ *
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace
+{
+
+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[] =
+{
+ 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",
+ DEMO_IMAGE_DIR "book-portrait-p6.jpg",
+ DEMO_IMAGE_DIR "book-portrait-p7.jpg",
+ DEMO_IMAGE_DIR "book-portrait-p8.jpg"
+};
+const unsigned int NUMBER_OF_PORTRAIT_IMAGE( sizeof(PAGE_IMAGES_PORTRAIT) / sizeof(PAGE_IMAGES_PORTRAIT[0]) );
+
+const char* PAGE_IMAGES_LANDSCAPE[] =
+{
+ 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]) );
+
+enum DemoOrientation
+{
+ PORTRAIT,
+ LANDSCAPE,
+ UNKNOWN
+};
+
+}
+
+class PortraitPageFactory : 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_PORTRAIT_IMAGE + 1;
+ }
+
+ /**
+ * Create texture to represent a page.
+ * @param[in] pageId The ID of the page to create.
+ * @return The texture.
+ */
+ virtual Texture NewPage( unsigned int pageId )
+ {
+ Texture texture;
+
+ PixelData pixels;
+ if( pageId == 0 )
+ {
+ pixels = SyncImageLoader::Load( BOOK_COVER_PORTRAIT );
+ }
+ else
+ {
+ pixels = SyncImageLoader::Load( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] );
+ }
+
+ if( pixels )
+ {
+ texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
+ texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
+ }
+
+ return texture;
+ }
+};
+
+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;
+ }
+
+ /**
+ * Create texture to represent a page.
+ * @param[in] pageId The ID of the page to create.
+ * @return The texture.
+ */
+ virtual Texture NewPage( unsigned int pageId )
+ {
+ Texture texture;
+
+ PixelData pixelsFront;
+ PixelData pixelsBack;
+
+ if( pageId == 0 )
+ {
+ pixelsFront = SyncImageLoader::Load( BOOK_COVER_LANDSCAPE );
+ pixelsBack = SyncImageLoader::Load( BOOK_COVER_BACK_LANDSCAPE );
+ }
+ else
+ {
+ unsigned int imageId = (pageId-1)*2;
+ pixelsFront = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ] );
+ pixelsBack = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] );
+ }
+
+ if( pixelsFront && pixelsBack )
+ {
+ texture = Texture::New( TextureType::TEXTURE_2D, pixelsFront.GetPixelFormat(), pixelsFront.GetWidth()*2, pixelsFront.GetHeight() );
+ texture.Upload( pixelsFront, 0, 0, 0, 0, pixelsFront.GetWidth(), pixelsFront.GetHeight() );
+ texture.Upload( pixelsBack, 0, 0, pixelsFront.GetWidth(), 0, pixelsBack.GetWidth(), pixelsBack.GetHeight() );
+ }
+
+ return texture;
+ }
+};
+
+/**
+ * This example shows how to use the PageTurnView UI control
+ */
+class PageTurnExample : public ConnectionTracker
+{
+public:
+
+ PageTurnExample( Application &app );
+
+ ~PageTurnExample();
+
+ void OnInit( Application& app );
+
+private:
+
+
+ void OnWindowResized( Window::WindowSize size );
+
+ void Rotate( DemoOrientation orientation );
+
+ void OnKeyEvent(const KeyEvent& event);
+
+private:
+
+ Application& mApplication;
+
+ PageTurnView mPageTurnPortraitView;
+ PageTurnView mPageTurnLandscapeView;
+ PortraitPageFactory mPortraitPageFactory;
+ LandscapePageFactory mLandscapePageFactory;
+
+ DemoOrientation mOrientation;
+};
+
+PageTurnExample::PageTurnExample( Application &app )
+: mApplication( app ),
+ mOrientation( UNKNOWN )
+{
+ app.InitSignal().Connect( this, &PageTurnExample::OnInit );
+}
+
+PageTurnExample::~PageTurnExample()
+{
+}
+
+/**
+ * The Init signal is received once (only) during the Application lifetime
+ */
+void PageTurnExample::OnInit( Application& app )
+{
+ Stage::GetCurrent().KeyEventSignal().Connect(this, &PageTurnExample::OnKeyEvent);
+
+ Window window = app.GetWindow();
+ window.AddAvailableOrientation( Window::PORTRAIT );
+ window.AddAvailableOrientation( Window::LANDSCAPE );
+ window.AddAvailableOrientation( Window::PORTRAIT_INVERSE );
+ window.AddAvailableOrientation( Window::LANDSCAPE_INVERSE );
+ window.ResizedSignal().Connect( this, &PageTurnExample::OnWindowResized );
+
+ Window::WindowSize size = window.GetSize();
+ Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
+}
+
+void PageTurnExample::OnWindowResized( Window::WindowSize size )
+{
+ Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
+}
+
+void PageTurnExample::Rotate( DemoOrientation orientation )
+{
+ Stage stage = Stage::GetCurrent();
+ Vector2 stageSize = stage.GetSize();
+
+ if( mOrientation != orientation )
+ {
+ mOrientation = orientation;
+
+ if( PORTRAIT == orientation )
+ {
+ if( !mPageTurnPortraitView )
+ {
+ mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize );
+ mPageTurnPortraitView.SetParentOrigin( ParentOrigin::CENTER );
+ }
+
+ if( mPageTurnLandscapeView )
+ {
+ stage.Remove( mPageTurnLandscapeView );
+ }
+ stage.Add( mPageTurnPortraitView );
+ }
+ else if( LANDSCAPE == orientation )
+ {
+ if( !mPageTurnLandscapeView )
+ {
+ mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(stageSize.x*0.5f, stageSize.y) );
+ mPageTurnLandscapeView.SetParentOrigin( ParentOrigin::CENTER );
+ }
+
+ if( mPageTurnPortraitView )
+ {
+ stage.Remove( mPageTurnPortraitView );
+ }
+
+ stage.Add( mPageTurnLandscapeView );
+ }
+ }
+}
+
+/**
+ * Main key event handler
+ */
+void PageTurnExample::OnKeyEvent(const KeyEvent& event)
+{
+ if(event.state == KeyEvent::Down)
+ {
+ if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
+ {
+ mApplication.Quit();
+ }
+ }
+}
+
+// Entry point for applications
+int main( int argc, char **argv )
+{
+ Application app = Application::New(&argc, &argv);
+ PageTurnExample test ( app );
+
+ app.MainLoop();
+
+ return 0;
+}
+
diff --git a/resources/po/en_GB.po b/resources/po/en_GB.po
index d51cd5e..dc284c4 100755
--- a/resources/po/en_GB.po
+++ b/resources/po/en_GB.po
@@ -139,6 +139,9 @@ msgstr "Native Image Source"
msgid "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE"
msgstr "Negotiate Size"
+msgid "DALI_DEMO_STR_TITLE_PAGE_TURN"
+msgstr "Page Turn"
+
msgid "DALI_DEMO_STR_TITLE_PERF_SCROLL"
msgstr "Scrolling Performance"
diff --git a/resources/po/en_US.po b/resources/po/en_US.po
index ea1c39e..aded425 100755
--- a/resources/po/en_US.po
+++ b/resources/po/en_US.po
@@ -142,6 +142,9 @@ msgstr "Native Image Source"
msgid "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE"
msgstr "Negotiate Size"
+msgid "DALI_DEMO_STR_TITLE_PAGE_TURN"
+msgstr "Page Turn"
+
msgid "DALI_DEMO_STR_TITLE_PERF_SCROLL"
msgstr "Scrolling Performance"
diff --git a/shared/dali-demo-strings.h b/shared/dali-demo-strings.h
index 6678f87..48ad510 100644
--- a/shared/dali-demo-strings.h
+++ b/shared/dali-demo-strings.h
@@ -83,6 +83,7 @@ extern "C"
#define DALI_DEMO_STR_TITLE_MOTION_STRETCH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_STRETCH")
#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE")
#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE")
+#define DALI_DEMO_STR_TITLE_PAGE_TURN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN")
#define DALI_DEMO_STR_TITLE_PBR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PBR")
#define DALI_DEMO_STR_TITLE_PERF_SCROLL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PERF_SCROLL")
#define DALI_DEMO_STR_TITLE_POINT_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POINT_MESH")
@@ -179,6 +180,7 @@ extern "C"
#define DALI_DEMO_STR_TITLE_MOTION_STRETCH "Motion Stretch"
#define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source"
#define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size"
+#define DALI_DEMO_STR_TITLE_PAGE_TURN "Page Turn"
#define DALI_DEMO_STR_TITLE_PBR "PBR"
#define DALI_DEMO_STR_TITLE_PERF_SCROLL "Scrolling Performance"
#define DALI_DEMO_STR_TITLE_POINT_MESH "Point Mesh"
--
2.7.4