[3.0] Updates after removal of experimental API
[platform/core/uifw/dali-demo.git] / examples / new-window / new-window-example.cpp
1 /*
2  * Copyright (c) 2016 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 // EXTERNAL INCLUDES
18 #include <dali/devel-api/images/texture-set-image.h>
19 #include <dali/public-api/rendering/renderer.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
22 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
23
24 #include <cstdio>
25 #include <iostream>
26
27 // INTERNAL INCLUDES
28 #include "shared/view.h"
29 #include "shared/utility.h"
30
31 using namespace Dali;
32 using namespace Dali::Toolkit;
33
34 class NewWindowController;
35
36 namespace
37 {
38 const char * const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-2.jpg" );
39 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
40 const char * const LOSE_CONTEXT_IMAGE( DEMO_IMAGE_DIR "icon-cluster-wobble.png" );
41 const char * const LOSE_CONTEXT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-cluster-wobble-selected.png" );
42 const char * const BASE_IMAGE( DEMO_IMAGE_DIR "gallery-large-14.jpg" );
43 const char * const EFFECT_IMAGE( DEMO_IMAGE_DIR "gallery-large-18.jpg" );
44 const char * const LOGO_IMAGE(DEMO_IMAGE_DIR "dali-logo.png");
45
46 const float EXPLOSION_DURATION(1.2f);
47 const unsigned int EMIT_INTERVAL_IN_MS(40);
48 const float TRACK_DURATION_IN_MS(970);
49
50 Application gApplication;
51 NewWindowController* gNewWindowController(NULL);
52
53 #define MAKE_SHADER(A)#A
54
55 const char* VERTEX_COLOR_MESH = MAKE_SHADER(
56 attribute mediump vec3  aPosition;\n
57 attribute lowp    vec3  aColor;\n
58 uniform   mediump mat4  uMvpMatrix;\n
59 uniform   mediump vec3  uSize;\n
60 varying   lowp    vec3  vColor;\n
61 \n
62 void main()\n
63 {\n
64   gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n
65   vColor = aColor;\n
66 }\n
67 );
68
69 const char* FRAGMENT_COLOR_MESH = MAKE_SHADER(
70 uniform lowp vec4  uColor;\n
71 varying lowp vec3  vColor;\n
72 \n
73 void main()\n
74 {\n
75   gl_FragColor = vec4(vColor,1.0)*uColor;
76 }\n
77 );
78
79 const char* VERTEX_TEXTURE_MESH = MAKE_SHADER(
80 attribute mediump vec3  aPosition;\n
81 attribute highp   vec2  aTexCoord;\n
82 uniform   mediump mat4  uMvpMatrix;\n
83 uniform   mediump vec3  uSize;\n
84 varying   mediump vec2  vTexCoord;\n
85 \n
86 void main()\n
87 {\n
88   gl_Position = uMvpMatrix * vec4( aPosition*uSize, 1.0 );\n
89   vTexCoord = aTexCoord;\n
90 }\n
91 );
92
93 const char* FRAGMENT_TEXTURE_MESH = MAKE_SHADER(
94 varying mediump vec2  vTexCoord;\n
95 uniform lowp    vec4  uColor;\n
96 uniform sampler2D     sTexture;\n
97 \n
98 void main()\n
99 {\n
100   gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
101 }\n
102 );
103
104 const char* FRAGMENT_BLEND_SHADER = MAKE_SHADER(
105 varying mediump vec2  vTexCoord;\n
106 uniform sampler2D sTexture;\n
107 uniform sampler2D sEffect;\n
108 uniform mediump float alpha;\n
109 \n
110 void main()\n
111 {\n
112   mediump vec4 fragColor = texture2D(sTexture, vTexCoord);\n
113   mediump vec4 fxColor   = texture2D(sEffect, vTexCoord);\n
114   gl_FragColor = mix(fragColor,fxColor, alpha);\n
115 }\n
116 );
117
118 }; // anonymous namespace
119
120
121 class NewWindowController : public ConnectionTracker
122 {
123 public:
124   NewWindowController( Application& app );
125   void Create( Application& app );
126   void Destroy( Application& app );
127
128   void AddBubbles( Actor& parentActor, const Vector2& stageSize);
129   void AddMeshActor( Actor& parentActor );
130   void AddBlendingImageActor( Actor& parentActor );
131   void AddTextLabel( Actor& parentActor );
132
133   ImageView CreateBlurredMirrorImage(const char* imageName);
134   FrameBufferImage CreateFrameBufferForImage( const char* imageName, Property::Map& shaderEffect, const Vector3& rgbDelta );
135   void SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction );
136   Geometry CreateMeshGeometry();
137   Dali::Property::Map CreateColorModifierer();
138
139   static void NewWindow(void);
140
141   bool OnTrackTimerTick();
142   void OnKeyEvent(const KeyEvent& event);
143   bool OnLoseContextButtonClicked( Toolkit::Button button );
144   void OnContextLost();
145   void OnContextRegained();
146
147 private:
148   Application                mApplication;
149   TextLabel                  mTextActor;
150
151   Toolkit::Control           mView;                              ///< The View instance.
152   Toolkit::ToolBar           mToolBar;                           ///< The View's Toolbar.
153   TextLabel                  mTitleActor;                        ///< The Toolbar's Title.
154   Layer                      mContentLayer;                      ///< Content layer (scrolling cluster content)
155   Toolkit::PushButton        mLoseContextButton;
156
157   Toolkit::BubbleEmitter     mEmitter;
158   Timer                      mEmitTrackTimer;
159   bool                       mNeedNewAnimation;
160   unsigned int               mAnimateComponentCount;
161   Animation                  mEmitAnimation;
162 };
163
164
165 NewWindowController::NewWindowController( Application& application )
166 : mApplication(application),
167   mNeedNewAnimation(true)
168 {
169   mApplication.InitSignal().Connect(this, &NewWindowController::Create);
170   mApplication.TerminateSignal().Connect(this, &NewWindowController::Destroy);
171 }
172
173 void NewWindowController::Create( Application& app )
174 {
175   Stage stage = Stage::GetCurrent();
176   stage.SetBackgroundColor(Color::YELLOW);
177
178   stage.KeyEventSignal().Connect(this, &NewWindowController::OnKeyEvent);
179
180   // The Init signal is received once (only) during the Application lifetime
181
182   // Hide the indicator bar
183   mApplication.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
184
185   mContentLayer = DemoHelper::CreateView( app,
186                                           mView,
187                                           mToolBar,
188                                           "",
189                                           TOOLBAR_IMAGE,
190                                           "Context recovery" );
191
192   Size stageSize = stage.GetSize();
193   ImageView backgroundActor = ImageView::New( BACKGROUND_IMAGE, Dali::ImageDimensions( stageSize.x, stageSize.y ) );
194   backgroundActor.SetParentOrigin( ParentOrigin::CENTER );
195   mContentLayer.Add(backgroundActor);
196
197   // Point the default render task at the view
198   RenderTaskList taskList = stage.GetRenderTaskList();
199   RenderTask defaultTask = taskList.GetTask( 0u );
200   if ( defaultTask )
201   {
202     defaultTask.SetSourceActor( mView );
203   }
204
205   mLoseContextButton = Toolkit::PushButton::New();
206   mLoseContextButton.SetUnselectedImage( LOSE_CONTEXT_IMAGE );
207   mLoseContextButton.SetSelectedImage( LOSE_CONTEXT_IMAGE_SELECTED );
208   mLoseContextButton.ClickedSignal().Connect( this, &NewWindowController::OnLoseContextButtonClicked );
209   mToolBar.AddControl( mLoseContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
210
211   Actor logoLayoutActor = Actor::New();
212   logoLayoutActor.SetParentOrigin(ParentOrigin::CENTER);
213   logoLayoutActor.SetPosition(0.0f, -200.0f, 0.0f);
214   logoLayoutActor.SetScale(0.5f);
215   backgroundActor.Add(logoLayoutActor);
216
217   ImageView imageView = ImageView::New( LOGO_IMAGE );
218   imageView.SetName("daliLogo");
219   imageView.SetParentOrigin(ParentOrigin::CENTER);
220   imageView.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER);
221   logoLayoutActor.Add(imageView);
222
223   ImageView mirrorImageView = CreateBlurredMirrorImage(LOGO_IMAGE);
224   mirrorImageView.SetParentOrigin(ParentOrigin::TOP_CENTER);
225   mirrorImageView.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER);
226   logoLayoutActor.Add(mirrorImageView);
227
228   AddBubbles( backgroundActor, stage.GetSize());
229   AddMeshActor( backgroundActor );
230   AddBlendingImageActor( backgroundActor );
231   AddTextLabel( backgroundActor );
232
233   stage.ContextLostSignal().Connect(this, &NewWindowController::OnContextLost);
234   stage.ContextRegainedSignal().Connect(this, &NewWindowController::OnContextRegained);
235 }
236
237 void NewWindowController::Destroy( Application& app )
238 {
239   UnparentAndReset(mTextActor);
240 }
241
242 void NewWindowController::AddBubbles( Actor& parentActor, const Vector2& stageSize)
243 {
244   mEmitter = Toolkit::BubbleEmitter::New( stageSize,
245                                           DemoHelper::LoadImage( DEMO_IMAGE_DIR "bubble-ball.png" ),
246                                           200, Vector2( 5.0f, 5.0f ) );
247
248   Image background = DemoHelper::LoadImage(BACKGROUND_IMAGE);
249   mEmitter.SetBackground( background, Vector3(0.5f, 0.f,0.5f) );
250   mEmitter.SetBubbleDensity( 9.f );
251   Actor bubbleRoot = mEmitter.GetRootActor();
252   parentActor.Add( bubbleRoot );
253   bubbleRoot.SetParentOrigin(ParentOrigin::CENTER);
254   bubbleRoot.SetZ(0.1f);
255
256   mEmitTrackTimer = Timer::New( EMIT_INTERVAL_IN_MS );
257   mEmitTrackTimer.TickSignal().Connect(this, &NewWindowController::OnTrackTimerTick);
258   mEmitTrackTimer.Start();
259 }
260
261 void NewWindowController::AddMeshActor( Actor& parentActor )
262 {
263   Geometry meshGeometry = CreateMeshGeometry();
264
265   // Create a coloured mesh
266   Shader shaderColorMesh = Shader::New( VERTEX_COLOR_MESH, FRAGMENT_COLOR_MESH );
267   Renderer colorMeshRenderer = Renderer::New( meshGeometry, shaderColorMesh );
268
269   Actor colorMeshActor = Actor::New();
270   colorMeshActor.AddRenderer( colorMeshRenderer );
271   colorMeshActor.SetSize( 175.f,175.f, 175.f );
272   colorMeshActor.SetParentOrigin( ParentOrigin::CENTER );
273   colorMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER);
274   colorMeshActor.SetPosition(Vector3(0.0f, 50.0f, 0.0f));
275   colorMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS );
276   colorMeshActor.SetName("ColorMeshActor");
277
278  // Create a textured mesh
279   Texture effectTexture = DemoHelper::LoadTexture(EFFECT_IMAGE);
280   Shader shaderTextureMesh = Shader::New( VERTEX_TEXTURE_MESH, FRAGMENT_TEXTURE_MESH );
281   TextureSet textureSet = TextureSet::New();
282   textureSet.SetTexture( 0u, effectTexture );
283   Renderer textureMeshRenderer = Renderer::New( meshGeometry, shaderTextureMesh );
284   textureMeshRenderer.SetTextures( textureSet );
285
286   Actor textureMeshActor = Actor::New();
287   textureMeshActor.AddRenderer( textureMeshRenderer );
288   textureMeshActor.SetSize( 175.f,175.f, 175.f );
289   textureMeshActor.SetParentOrigin( ParentOrigin::CENTER );
290   textureMeshActor.SetAnchorPoint(AnchorPoint::TOP_CENTER);
291   textureMeshActor.SetPosition(Vector3(0.0f, 200.0f, 0.0f));
292   textureMeshActor.SetOrientation( Degree(75.f), Vector3::XAXIS );
293   textureMeshActor.SetName("TextureMeshActor");
294
295   Layer layer3d = Layer::New();
296   layer3d.SetParentOrigin( ParentOrigin::CENTER );
297   layer3d.SetAnchorPoint( AnchorPoint::CENTER );
298   layer3d.SetBehavior(Layer::LAYER_3D);
299
300   layer3d.Add( colorMeshActor );
301   layer3d.Add( textureMeshActor );
302   parentActor.Add(layer3d);
303 }
304
305 void NewWindowController::AddBlendingImageActor( Actor& parentActor )
306 {
307   Property::Map colorModifier = CreateColorModifierer();
308
309   FrameBufferImage fb2 = CreateFrameBufferForImage( EFFECT_IMAGE, colorModifier, Vector3( 0.5f, 0.5f, 0.5f ) );
310
311   ImageView tmpActor = ImageView::New(fb2);
312   parentActor.Add(tmpActor);
313   tmpActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT);
314   tmpActor.SetAnchorPoint(AnchorPoint::TOP_RIGHT);
315   tmpActor.SetPosition(Vector3(0.0f, 150.0f, 0.0f));
316   tmpActor.SetScale(0.25f);
317
318   // create blending shader effect
319   Property::Map customShader;
320   customShader[ "fragmentShader" ] = FRAGMENT_BLEND_SHADER;
321   Property::Map map;
322   map[ "shader" ] = customShader;
323
324   ImageView blendActor = ImageView::New( BASE_IMAGE );
325   blendActor.SetProperty( ImageView::Property::IMAGE, map );
326   blendActor.RegisterProperty( "alpha", 0.5f );
327
328   blendActor.SetParentOrigin(ParentOrigin::CENTER_RIGHT);
329   blendActor.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
330   blendActor.SetPosition(Vector3(0.0f, 100.0f, 0.0f));
331   blendActor.SetSize(140, 140);
332   parentActor.Add(blendActor);
333
334   TextureSet textureSet = blendActor.GetRendererAt(0u).GetTextures();
335   TextureSetImage( textureSet, 1u, fb2 );
336 }
337
338 void NewWindowController::AddTextLabel( Actor& parentActor )
339 {
340   mTextActor = TextLabel::New("Some text");
341   mTextActor.SetParentOrigin(ParentOrigin::CENTER);
342   mTextActor.SetColor(Color::RED);
343   mTextActor.SetName("PushMe text");
344   parentActor.Add( mTextActor );
345 }
346
347 ImageView NewWindowController::CreateBlurredMirrorImage(const char* imageName)
348 {
349   Image image = DemoHelper::LoadImage(imageName);
350
351   Vector2 FBOSize = Vector2( image.GetWidth(), image.GetHeight() );
352   FrameBufferImage fbo = FrameBufferImage::New( FBOSize.width, FBOSize.height, Pixel::RGBA8888);
353
354   GaussianBlurView gbv = GaussianBlurView::New(5, 2.0f, Pixel::RGBA8888, 0.5f, 0.5f, true);
355   gbv.SetBackgroundColor(Color::TRANSPARENT);
356   gbv.SetUserImageAndOutputRenderTarget( image, fbo );
357   gbv.SetSize(FBOSize);
358   Stage::GetCurrent().Add(gbv);
359   gbv.ActivateOnce();
360
361   ImageView blurredActor = ImageView::New(fbo);
362   blurredActor.SetSize(FBOSize);
363   blurredActor.SetScale(1.0f, -1.0f, 1.0f);
364   return blurredActor;
365 }
366
367 FrameBufferImage NewWindowController::CreateFrameBufferForImage(const char* imageName, Property::Map& shaderEffect, const Vector3& rgbDelta )
368 {
369   Stage stage = Stage::GetCurrent();
370   Uint16Pair intFboSize = ResourceImage::GetImageSize( imageName );
371   Vector2 FBOSize = Vector2(intFboSize.GetWidth(), intFboSize.GetHeight());
372
373   FrameBufferImage framebuffer = FrameBufferImage::New(FBOSize.x, FBOSize.y );
374
375   RenderTask renderTask = stage.GetRenderTaskList().CreateTask();
376
377   ImageView imageView = ImageView::New( imageName );
378   imageView.SetName("Source image actor");
379   imageView.SetProperty( ImageView::Property::IMAGE, shaderEffect );
380   imageView.RegisterProperty( "uRGBDelta", rgbDelta );
381
382   imageView.SetParentOrigin(ParentOrigin::CENTER);
383   imageView.SetAnchorPoint(AnchorPoint::CENTER);
384   imageView.SetScale(1.0f, -1.0f, 1.0f);
385   stage.Add(imageView); // Not in default image view
386
387   CameraActor cameraActor = CameraActor::New(FBOSize);
388   cameraActor.SetParentOrigin(ParentOrigin::CENTER);
389   cameraActor.SetFieldOfView(Math::PI*0.25f);
390   cameraActor.SetNearClippingPlane(1.0f);
391   cameraActor.SetAspectRatio(FBOSize.width / FBOSize.height);
392   cameraActor.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
393   cameraActor.SetPosition(0.0f, 0.0f, ((FBOSize.height * 0.5f) / tanf(Math::PI * 0.125f)));
394   stage.Add(cameraActor);
395
396   renderTask.SetSourceActor(imageView);
397   renderTask.SetInputEnabled(false);
398   renderTask.SetTargetFrameBuffer(framebuffer);
399   renderTask.SetCameraActor( cameraActor );
400   renderTask.SetClearColor( Color::TRANSPARENT );
401   renderTask.SetClearEnabled( true );
402   renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
403
404   return framebuffer;
405 }
406
407 void NewWindowController::SetUpBubbleEmission( const Vector2& emitPosition, const Vector2& direction)
408 {
409   if( mNeedNewAnimation )
410   {
411     float duration = Random::Range(1.f, 1.5f);
412     mEmitAnimation = Animation::New( duration );
413     mNeedNewAnimation = false;
414     mAnimateComponentCount = 0;
415   }
416
417   mEmitter.EmitBubble( mEmitAnimation, emitPosition, direction, Vector2(10,10) );
418
419   mAnimateComponentCount++;
420
421   if( mAnimateComponentCount % 6 ==0 )
422   {
423     mEmitAnimation.Play();
424     mNeedNewAnimation = true;
425   }
426 }
427
428 Geometry NewWindowController::CreateMeshGeometry()
429 {
430   // Create vertices and specify their color
431   struct Vertex
432   {
433     Vector3 position;
434     Vector2 textureCoordinates;
435     Vector3 color;
436   };
437
438   Vertex vertexData[5] = {
439     { Vector3(  0.0f,  0.0f, 0.5f ), Vector2(0.5f, 0.5f), Vector3(1.0f, 1.0f, 1.0f) },
440     { Vector3( -0.5f, -0.5f, 0.0f ), Vector2(0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f) },
441     { Vector3(  0.5f, -0.5f, 0.0f ), Vector2(1.0f, 0.0f), Vector3(1.0f, 1.0f, 0.0f) },
442     { Vector3( -0.5f,  0.5f, 0.0f ), Vector2(0.0f, 1.0f), Vector3(0.0f, 1.0f, 0.0f) },
443     { Vector3(  0.5f,  0.5f, 0.0f ), Vector2(1.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f) }  };
444
445   Property::Map vertexFormat;
446   vertexFormat["aPosition"] = Property::VECTOR3;
447   vertexFormat["aTexCoord"] = Property::VECTOR2;
448   vertexFormat["aColor"] = Property::VECTOR3;
449   PropertyBuffer vertices = PropertyBuffer::New( vertexFormat );
450   vertices.SetData( vertexData, 5 );
451
452   // Specify all the faces
453   unsigned short indexData[12] = { 0,1,3,0,2,4,0,3,4,0,2,1 };
454
455   // Create the geometry object
456   Geometry geometry = Geometry::New();
457   geometry.AddVertexBuffer( vertices );
458   geometry.SetIndexBuffer( &indexData[0], 12 );
459
460   return geometry;
461 }
462
463 Dali::Property::Map NewWindowController::CreateColorModifierer()
464 {
465  const char* fragmentShader ( DALI_COMPOSE_SHADER (
466    precision highp float;\n
467    uniform vec3 uRGBDelta;\n
468    uniform float uIgnoreAlpha;\n
469    \n
470    varying mediump vec2 vTexCoord;\n
471    uniform sampler2D sTexture;\n
472    \n
473    float rand(vec2 co) \n
474    {\n
475      return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); \n}
476    \n
477    void main() {\n
478      vec4 color = texture2D(sTexture, vTexCoord); \n
479      // modify the hsv Value
480      color.rgb += uRGBDelta * rand(vTexCoord); \n
481      // if the new vale exceeds one, then decrease it
482      color.rgb -= max(color.rgb*2.0 - vec3(2.0), 0.0);\n
483      // if the new vale drops below zero, then increase it
484      color.rgb -= min(color.rgb*2.0, 0.0);\n
485      gl_FragColor = color; \n
486    }\n
487  ) );
488
489  Property::Map map;
490  Property::Map customShader;
491  customShader[ "fragmentShader" ] = fragmentShader;
492  map[ "shader" ] = customShader;
493
494  return map;
495 }
496
497 void NewWindowController::NewWindow(void)
498 {
499   PositionSize posSize(0, 0, 720, 1280);
500   gApplication.ReplaceWindow(posSize, "NewWindow"); // Generates a new window
501 }
502
503 bool NewWindowController::OnLoseContextButtonClicked( Toolkit::Button button )
504 {
505   // Add as an idle callback to avoid ProcessEvents being recursively called.
506   mApplication.AddIdle( MakeCallback( NewWindowController::NewWindow ) );
507   return true;
508 }
509
510 bool NewWindowController::OnTrackTimerTick()
511 {
512   static int time=0;
513   const float radius(250.0f);
514
515   time += EMIT_INTERVAL_IN_MS;
516   float modTime = time / TRACK_DURATION_IN_MS;
517   float angle = 2.0f*Math::PI*modTime;
518
519   Vector2 position(radius*cosf(angle), radius*-sinf(angle));
520   Vector2 aimPos(radius*2*sinf(angle), radius*2*-cosf(angle));
521   Vector2 direction = aimPos-position;
522   Vector2 stageSize = Stage::GetCurrent().GetSize();
523
524   SetUpBubbleEmission( stageSize*0.5f+position, direction );
525   SetUpBubbleEmission( stageSize*0.5f+position*0.75f, direction );
526   SetUpBubbleEmission( stageSize*0.5f+position*0.7f, direction );
527
528   return true;
529 }
530
531 void NewWindowController::OnKeyEvent(const KeyEvent& event)
532 {
533   if(event.state == KeyEvent::Down)
534   {
535     if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
536     {
537       mApplication.Quit();
538     }
539   }
540 }
541
542 void NewWindowController::OnContextLost()
543 {
544   printf("Stage reporting context loss\n");
545 }
546
547 void NewWindowController::OnContextRegained()
548 {
549   printf("Stage reporting context regain\n");
550 }
551
552 void RunTest(Application& app)
553 {
554   gNewWindowController = new NewWindowController(app);
555   app.MainLoop(Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
556 }
557
558 // Entry point for Linux & Tizen applications
559 //
560 int DALI_EXPORT_API main(int argc, char **argv)
561 {
562   gApplication = Application::New(&argc, &argv, DEMO_THEME_PATH);
563   RunTest(gApplication);
564
565   return 0;
566 }