Commit 6addf420cb7c9760426bd6d1cdfd224b32c183b1

Authored by Paul Wisbey
1 parent 37f8d397

Resurrected PageTurnView demo

Change-Id: Ia4bd7029637a00c7b332adc4440f2cc730208c3c
com.samsung.dali-demo.xml
... ... @@ -308,6 +308,9 @@
308 308 <ui-application appid="bloom-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/bloom-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
309 309 <label>Bloom</label>
310 310 </ui-application>
  311 + <ui-application appid="page-turn-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/page-turn-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
  312 + <label>Page Turn</label>
  313 + </ui-application>
311 314  
312 315 <privileges>
313 316 <privilege>http://tizen.org/privilege/mediastorage</privilege>
... ...
demo/dali-demo.cpp
... ... @@ -47,6 +47,7 @@ int DALI_EXPORT_API main(int argc, char **argv)
47 47 demo.AddExample(Example("metaball-explosion.example", DALI_DEMO_STR_TITLE_METABALL_EXPLOSION));
48 48 demo.AddExample(Example("metaball-refrac.example", DALI_DEMO_STR_TITLE_METABALL_REFRAC));
49 49 demo.AddExample(Example("motion-blur.example", DALI_DEMO_STR_TITLE_MOTION_BLUR));
  50 + demo.AddExample(Example("page-turn-view.example", DALI_DEMO_STR_TITLE_PAGE_TURN));
50 51 demo.AddExample(Example("refraction-effect.example", DALI_DEMO_STR_TITLE_REFRACTION));
51 52 demo.AddExample(Example("renderer-stencil.example", DALI_DEMO_STR_TITLE_RENDERER_STENCIL));
52 53 demo.AddExample(Example("shadows-and-lights.example", DALI_DEMO_STR_TITLE_LIGHTS_AND_SHADOWS));
... ...
examples/page-turn-view/page-turn-view-example.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + *
  16 + */
  17 +
  18 +#include <dali/dali.h>
  19 +#include <dali-toolkit/dali-toolkit.h>
  20 +#include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
  21 +#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h>
  22 +#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h>
  23 +#include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-view.h>
  24 +
  25 +using namespace Dali;
  26 +using namespace Dali::Toolkit;
  27 +
  28 +namespace
  29 +{
  30 +
  31 +const char* BOOK_COVER_PORTRAIT = ( DEMO_IMAGE_DIR "book-portrait-cover.jpg" );
  32 +const char* BOOK_COVER_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover.jpg" );
  33 +const char* BOOK_COVER_BACK_LANDSCAPE = ( DEMO_IMAGE_DIR "book-landscape-cover-back.jpg" );
  34 +
  35 +const char* PAGE_IMAGES_PORTRAIT[] =
  36 +{
  37 + DEMO_IMAGE_DIR "book-portrait-p1.jpg",
  38 + DEMO_IMAGE_DIR "book-portrait-p2.jpg",
  39 + DEMO_IMAGE_DIR "book-portrait-p3.jpg",
  40 + DEMO_IMAGE_DIR "book-portrait-p4.jpg",
  41 + DEMO_IMAGE_DIR "book-portrait-p5.jpg",
  42 + DEMO_IMAGE_DIR "book-portrait-p6.jpg",
  43 + DEMO_IMAGE_DIR "book-portrait-p7.jpg",
  44 + DEMO_IMAGE_DIR "book-portrait-p8.jpg"
  45 +};
  46 +const unsigned int NUMBER_OF_PORTRAIT_IMAGE( sizeof(PAGE_IMAGES_PORTRAIT) / sizeof(PAGE_IMAGES_PORTRAIT[0]) );
  47 +
  48 +const char* PAGE_IMAGES_LANDSCAPE[] =
  49 +{
  50 + DEMO_IMAGE_DIR "book-landscape-p1.jpg",
  51 + DEMO_IMAGE_DIR "book-landscape-p2.jpg",
  52 + DEMO_IMAGE_DIR "book-landscape-p3.jpg",
  53 + DEMO_IMAGE_DIR "book-landscape-p4.jpg",
  54 + DEMO_IMAGE_DIR "book-landscape-p5.jpg",
  55 + DEMO_IMAGE_DIR "book-landscape-p6.jpg",
  56 + DEMO_IMAGE_DIR "book-landscape-p7.jpg",
  57 + DEMO_IMAGE_DIR "book-landscape-p8.jpg"
  58 +};
  59 +const unsigned int NUMBER_OF_LANDSCAPE_IMAGE( sizeof(PAGE_IMAGES_LANDSCAPE) / sizeof(PAGE_IMAGES_LANDSCAPE[0]) );
  60 +
  61 +enum DemoOrientation
  62 +{
  63 + PORTRAIT,
  64 + LANDSCAPE,
  65 + UNKNOWN
  66 +};
  67 +
  68 +}
  69 +
  70 +class PortraitPageFactory : public PageFactory
  71 +{
  72 + /**
  73 + * Query the number of pages available from the factory.
  74 + * The maximum available page has an ID of GetNumberOfPages()-1.
  75 + */
  76 + virtual unsigned int GetNumberOfPages()
  77 + {
  78 + return 5*NUMBER_OF_PORTRAIT_IMAGE + 1;
  79 + }
  80 +
  81 + /**
  82 + * Create texture to represent a page.
  83 + * @param[in] pageId The ID of the page to create.
  84 + * @return The texture.
  85 + */
  86 + virtual Texture NewPage( unsigned int pageId )
  87 + {
  88 + Texture texture;
  89 +
  90 + PixelData pixels;
  91 + if( pageId == 0 )
  92 + {
  93 + pixels = SyncImageLoader::Load( BOOK_COVER_PORTRAIT );
  94 + }
  95 + else
  96 + {
  97 + pixels = SyncImageLoader::Load( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] );
  98 + }
  99 +
  100 + if( pixels )
  101 + {
  102 + texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() );
  103 + texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() );
  104 + }
  105 +
  106 + return texture;
  107 + }
  108 +};
  109 +
  110 +class LandscapePageFactory : public PageFactory
  111 +{
  112 + /**
  113 + * Query the number of pages available from the factory.
  114 + * The maximum available page has an ID of GetNumberOfPages()-1.
  115 + */
  116 + virtual unsigned int GetNumberOfPages()
  117 + {
  118 + return 5*NUMBER_OF_LANDSCAPE_IMAGE / 2 + 1;
  119 + }
  120 +
  121 + /**
  122 + * Create texture to represent a page.
  123 + * @param[in] pageId The ID of the page to create.
  124 + * @return The texture.
  125 + */
  126 + virtual Texture NewPage( unsigned int pageId )
  127 + {
  128 + Texture texture;
  129 +
  130 + PixelData pixelsFront;
  131 + PixelData pixelsBack;
  132 +
  133 + if( pageId == 0 )
  134 + {
  135 + pixelsFront = SyncImageLoader::Load( BOOK_COVER_LANDSCAPE );
  136 + pixelsBack = SyncImageLoader::Load( BOOK_COVER_BACK_LANDSCAPE );
  137 + }
  138 + else
  139 + {
  140 + unsigned int imageId = (pageId-1)*2;
  141 + pixelsFront = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ imageId % NUMBER_OF_LANDSCAPE_IMAGE ] );
  142 + pixelsBack = SyncImageLoader::Load( PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] );
  143 + }
  144 +
  145 + if( pixelsFront && pixelsBack )
  146 + {
  147 + texture = Texture::New( TextureType::TEXTURE_2D, pixelsFront.GetPixelFormat(), pixelsFront.GetWidth()*2, pixelsFront.GetHeight() );
  148 + texture.Upload( pixelsFront, 0, 0, 0, 0, pixelsFront.GetWidth(), pixelsFront.GetHeight() );
  149 + texture.Upload( pixelsBack, 0, 0, pixelsFront.GetWidth(), 0, pixelsBack.GetWidth(), pixelsBack.GetHeight() );
  150 + }
  151 +
  152 + return texture;
  153 + }
  154 +};
  155 +
  156 +/**
  157 + * This example shows how to use the PageTurnView UI control
  158 + */
  159 +class PageTurnExample : public ConnectionTracker
  160 +{
  161 +public:
  162 +
  163 + PageTurnExample( Application &app );
  164 +
  165 + ~PageTurnExample();
  166 +
  167 + void OnInit( Application& app );
  168 +
  169 +private:
  170 +
  171 +
  172 + void OnWindowResized( Window::WindowSize size );
  173 +
  174 + void Rotate( DemoOrientation orientation );
  175 +
  176 + void OnKeyEvent(const KeyEvent& event);
  177 +
  178 +private:
  179 +
  180 + Application& mApplication;
  181 +
  182 + PageTurnView mPageTurnPortraitView;
  183 + PageTurnView mPageTurnLandscapeView;
  184 + PortraitPageFactory mPortraitPageFactory;
  185 + LandscapePageFactory mLandscapePageFactory;
  186 +
  187 + DemoOrientation mOrientation;
  188 +};
  189 +
  190 +PageTurnExample::PageTurnExample( Application &app )
  191 +: mApplication( app ),
  192 + mOrientation( UNKNOWN )
  193 +{
  194 + app.InitSignal().Connect( this, &PageTurnExample::OnInit );
  195 +}
  196 +
  197 +PageTurnExample::~PageTurnExample()
  198 +{
  199 +}
  200 +
  201 +/**
  202 + * The Init signal is received once (only) during the Application lifetime
  203 + */
  204 +void PageTurnExample::OnInit( Application& app )
  205 +{
  206 + Stage::GetCurrent().KeyEventSignal().Connect(this, &PageTurnExample::OnKeyEvent);
  207 +
  208 + Window window = app.GetWindow();
  209 + window.AddAvailableOrientation( Window::PORTRAIT );
  210 + window.AddAvailableOrientation( Window::LANDSCAPE );
  211 + window.AddAvailableOrientation( Window::PORTRAIT_INVERSE );
  212 + window.AddAvailableOrientation( Window::LANDSCAPE_INVERSE );
  213 + window.ResizedSignal().Connect( this, &PageTurnExample::OnWindowResized );
  214 +
  215 + Window::WindowSize size = window.GetSize();
  216 + Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
  217 +}
  218 +
  219 +void PageTurnExample::OnWindowResized( Window::WindowSize size )
  220 +{
  221 + Rotate( size.GetWidth() > size.GetHeight() ? LANDSCAPE : PORTRAIT );
  222 +}
  223 +
  224 +void PageTurnExample::Rotate( DemoOrientation orientation )
  225 +{
  226 + Stage stage = Stage::GetCurrent();
  227 + Vector2 stageSize = stage.GetSize();
  228 +
  229 + if( mOrientation != orientation )
  230 + {
  231 + mOrientation = orientation;
  232 +
  233 + if( PORTRAIT == orientation )
  234 + {
  235 + if( !mPageTurnPortraitView )
  236 + {
  237 + mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize );
  238 + mPageTurnPortraitView.SetParentOrigin( ParentOrigin::CENTER );
  239 + }
  240 +
  241 + if( mPageTurnLandscapeView )
  242 + {
  243 + stage.Remove( mPageTurnLandscapeView );
  244 + }
  245 + stage.Add( mPageTurnPortraitView );
  246 + }
  247 + else if( LANDSCAPE == orientation )
  248 + {
  249 + if( !mPageTurnLandscapeView )
  250 + {
  251 + mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(stageSize.x*0.5f, stageSize.y) );
  252 + mPageTurnLandscapeView.SetParentOrigin( ParentOrigin::CENTER );
  253 + }
  254 +
  255 + if( mPageTurnPortraitView )
  256 + {
  257 + stage.Remove( mPageTurnPortraitView );
  258 + }
  259 +
  260 + stage.Add( mPageTurnLandscapeView );
  261 + }
  262 + }
  263 +}
  264 +
  265 +/**
  266 + * Main key event handler
  267 + */
  268 +void PageTurnExample::OnKeyEvent(const KeyEvent& event)
  269 +{
  270 + if(event.state == KeyEvent::Down)
  271 + {
  272 + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
  273 + {
  274 + mApplication.Quit();
  275 + }
  276 + }
  277 +}
  278 +
  279 +// Entry point for applications
  280 +int main( int argc, char **argv )
  281 +{
  282 + Application app = Application::New(&argc, &argv);
  283 + PageTurnExample test ( app );
  284 +
  285 + app.MainLoop();
  286 +
  287 + return 0;
  288 +}
  289 +
... ...
resources/po/en_GB.po
... ... @@ -139,6 +139,9 @@ msgstr &quot;Native Image Source&quot;
139 139 msgid "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE"
140 140 msgstr "Negotiate Size"
141 141  
  142 +msgid "DALI_DEMO_STR_TITLE_PAGE_TURN"
  143 +msgstr "Page Turn"
  144 +
142 145 msgid "DALI_DEMO_STR_TITLE_PERF_SCROLL"
143 146 msgstr "Scrolling Performance"
144 147  
... ...
resources/po/en_US.po
... ... @@ -142,6 +142,9 @@ msgstr &quot;Native Image Source&quot;
142 142 msgid "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE"
143 143 msgstr "Negotiate Size"
144 144  
  145 +msgid "DALI_DEMO_STR_TITLE_PAGE_TURN"
  146 +msgstr "Page Turn"
  147 +
145 148 msgid "DALI_DEMO_STR_TITLE_PERF_SCROLL"
146 149 msgstr "Scrolling Performance"
147 150  
... ...
shared/dali-demo-strings.h
... ... @@ -83,6 +83,7 @@ extern &quot;C&quot;
83 83 #define DALI_DEMO_STR_TITLE_MOTION_STRETCH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_MOTION_STRETCH")
84 84 #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE")
85 85 #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE")
  86 +#define DALI_DEMO_STR_TITLE_PAGE_TURN dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PAGE_TURN")
86 87 #define DALI_DEMO_STR_TITLE_PBR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PBR")
87 88 #define DALI_DEMO_STR_TITLE_PERF_SCROLL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PERF_SCROLL")
88 89 #define DALI_DEMO_STR_TITLE_POINT_MESH dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POINT_MESH")
... ... @@ -179,6 +180,7 @@ extern &quot;C&quot;
179 180 #define DALI_DEMO_STR_TITLE_MOTION_STRETCH "Motion Stretch"
180 181 #define DALI_DEMO_STR_TITLE_NATIVE_IMAGE_SOURCE "Native Image Source"
181 182 #define DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE "Negotiate Size"
  183 +#define DALI_DEMO_STR_TITLE_PAGE_TURN "Page Turn"
182 184 #define DALI_DEMO_STR_TITLE_PBR "PBR"
183 185 #define DALI_DEMO_STR_TITLE_PERF_SCROLL "Scrolling Performance"
184 186 #define DALI_DEMO_STR_TITLE_POINT_MESH "Point Mesh"
... ...