/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
// EXTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
-#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
// INTERNAL INCLUDES
#include "renderer-stencil-shaders.h"
const char * const CUBE_TEXTURE( DEMO_IMAGE_DIR "people-medium-1.jpg" );
const char * const FLOOR_TEXTURE( DEMO_IMAGE_DIR "wood.png" );
-// Scale dimensions: These values are relative to the stage size. EG. width = 0.32f * stageSize.
+// Scale dimensions: These values are relative to the window size. EG. width = 0.32f * windowSize.
const float CUBE_WIDTH_SCALE( 0.32f ); ///< The width (and height + depth) of the main and reflection cubes.
const Vector2 FLOOR_DIMENSION_SCALE( 0.67f, 0.017f ); ///< The width and height of the floor object.
*/
void Create( Application& application )
{
- Stage stage = Stage::GetCurrent();
+ Window window = application.GetWindow();
- // Hide the indicator bar
- application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
-
- // Creates the background image.
+ // Use a gradient visual to render the background gradient.
Toolkit::Control background = Dali::Toolkit::Control::New();
- background.SetAnchorPoint( Dali::AnchorPoint::CENTER );
- background.SetParentOrigin( Dali::ParentOrigin::CENTER );
+ background.SetProperty( Actor::Property::ANCHOR_POINT, Dali::AnchorPoint::CENTER );
+ background.SetProperty( Actor::Property::PARENT_ORIGIN, Dali::ParentOrigin::CENTER );
background.SetResizePolicy( Dali::ResizePolicy::FILL_TO_PARENT, Dali::Dimension::ALL_DIMENSIONS );
- Dali::Property::Map map;
- map["rendererType"] = "IMAGE";
- map["url"] = BACKGROUND_IMAGE;
- background.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
- stage.Add( background );
+
+ // Set up the background gradient.
+ Property::Array stopOffsets;
+ stopOffsets.PushBack( 0.0f );
+ stopOffsets.PushBack( 1.0f );
+ Property::Array stopColors;
+ stopColors.PushBack( Vector4( 0.17f, 0.24f, 0.35f, 1.0f ) ); // Dark, medium saturated blue ( top of screen)
+ stopColors.PushBack( Vector4( 0.45f, 0.70f, 0.80f, 1.0f ) ); // Medium bright, pastel blue (bottom of screen)
+ const float percentageWindowHeight = window.GetSize().GetHeight() * 0.7f;
+
+ background.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT )
+ .Add( Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets )
+ .Add( Toolkit::GradientVisual::Property::STOP_COLOR, stopColors )
+ .Add( Toolkit::GradientVisual::Property::START_POSITION, Vector2( 0.0f, -percentageWindowHeight ) )
+ .Add( Toolkit::GradientVisual::Property::END_POSITION, Vector2( 0.0f, percentageWindowHeight ) )
+ .Add( Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE ) );
+
+ window.Add( background );
// Create a TextLabel for the application title.
Toolkit::TextLabel label = Toolkit::TextLabel::New( APPLICATION_TITLE );
- label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
+ label.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
// Set the parent origin to a small percentage below the top (so the demo will scale for different resolutions).
- label.SetParentOrigin( Vector3( 0.5f, 0.03f, 0.5f ) );
+ label.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.03f, 0.5f ) );
label.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
label.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
label.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, TEXT_COLOR );
- stage.Add( label );
+ window.Add( label );
// Layer to hold the 3D scene.
Layer layer = Layer::New();
- layer.SetAnchorPoint( AnchorPoint::CENTER );
+ layer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
// Set the parent origin to a small percentage below the center (so the demo will scale for different resolutions).
- layer.SetParentOrigin( Vector3( 0.5f, 0.58f, 0.5f ) );
- layer.SetBehavior( Layer::LAYER_2D );
- layer.SetDepthTestDisabled( false );
- stage.Add( layer );
+ layer.SetProperty( Actor::Property::PARENT_ORIGIN, Vector3( 0.5f, 0.58f, 0.5f ) );
+ layer.SetProperty( Layer::Property::BEHAVIOR, Layer::LAYER_UI );
+ layer.SetProperty( Layer::Property::DEPTH_TEST, true );
+ window.Add( layer );
// Main cube:
// Make the demo scalable with different resolutions by basing
- // the cube size on a percentage of the stage size.
- float scaleSize( std::min( stage.GetSize().width, stage.GetSize().height ) );
+ // the cube size on a percentage of the window size.
+ Vector2 windowSize = window.GetSize();
+ float scaleSize( std::min( windowSize.width, windowSize.height ) );
float cubeWidth( scaleSize * CUBE_WIDTH_SCALE );
Vector3 cubeSize( cubeWidth, cubeWidth, cubeWidth );
// Create the geometry for the cube, and the texture.
mRotationAnimation.Play();
mBounceAnimation.Play();
- // Respond to a click anywhere on the stage
- stage.GetRootLayer().TouchSignal().Connect( this, &RendererStencilExample::OnTouch );
+ // Respond to a click anywhere on the window
+ window.GetRootLayer().TouchedSignal().Connect( this, &RendererStencilExample::OnTouch );
// Connect signals to allow Back and Escape to exit.
- stage.KeyEventSignal().Connect( this, &RendererStencilExample::OnKeyEvent );
+ window.KeyEventSignal().Connect( this, &RendererStencilExample::OnKeyEvent );
}
private:
Actor CreateMainCubeObject( Geometry& geometry, Vector3 size, TextureSet& textureSet )
{
Toolkit::Control container = Toolkit::Control::New();
- container.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
- container.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
- container.SetSize( size );
+ container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
+ container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+ container.SetProperty( Actor::Property::SIZE, Vector2( size ) );
container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
// Create a renderer from the geometry and add the texture.
Actor CreateFloorObject( Geometry& geometry, Vector3 size )
{
Toolkit::Control container = Toolkit::Control::New();
- container.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- container.SetParentOrigin( ParentOrigin::TOP_CENTER );
- container.SetSize( size );
+ container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+ container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+ container.SetProperty( Actor::Property::SIZE, Vector2( size ) );
container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
// Create a renderer from the geometry and add the texture.
Actor CreateStencilPlaneObject( Vector3 size )
{
Toolkit::Control container = Toolkit::Control::New();
- container.SetAnchorPoint( AnchorPoint::CENTER );
- container.SetParentOrigin( ParentOrigin::CENTER );
- container.SetSize( size );
+ container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+ container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+ container.SetProperty( Actor::Property::SIZE, Vector2( size ) );
container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
// We rotate the plane as the geometry is created flat in X & Y. We want it to span X & Z axis.
Actor CreateReflectionCubeObject( Vector3 size, TextureSet& textureSet )
{
Toolkit::Control container = Toolkit::Control::New();
- container.SetAnchorPoint( AnchorPoint::TOP_CENTER );
- container.SetParentOrigin( ParentOrigin::TOP_CENTER );
- container.SetSize( size );
+ container.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+ container.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+ container.SetProperty( Actor::Property::SIZE, Vector2( size ) );
container.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
// Create the cube geometry of unity size.
vertexFormat[NORMAL] = Property::VECTOR3;
vertexFormat[TEXTURE] = Property::VECTOR2;
- PropertyBuffer surfaceVertices = PropertyBuffer::New( vertexFormat );
+ VertexBuffer surfaceVertices = VertexBuffer::New( vertexFormat );
surfaceVertices.SetData( &vertices[0u], vertices.Size() );
Geometry geometry = Geometry::New();
*/
Renderer CreateRenderer( Geometry geometry, Vector3 dimensions, bool textured, Vector4 color )
{
- Stage stage = Stage::GetCurrent();
+ Window window = mApplication.GetWindow();
+ Vector2 windowSize = window.GetSize();
Shader shader;
if( textured )
shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
}
- // Here we modify the light position based on half the stage size as a pre-calculation step.
+ // Here we modify the light position based on half the window size as a pre-calculation step.
// This avoids the work having to be done in the shader.
- shader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, Vector3( -stage.GetSize().width / 2.0f, -stage.GetSize().width / 2.0f, 1000.0f ) );
+ shader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, Vector3( -windowSize.width / 2.0f, -windowSize.width / 2.0f, 1000.0f ) );
shader.RegisterProperty( COLOR_UNIFORM_NAME, color );
shader.RegisterProperty( OBJECT_DIMENSIONS_UNIFORM_NAME, dimensions );
* @param[in] touch The touch information
* @return True if the event has been handled
*/
- bool OnTouch( Actor actor, const TouchData& touch )
+ bool OnTouch( Actor actor, const TouchEvent& touch )
{
// Quit the application.
mApplication.Quit();
*/
void OnKeyEvent( const KeyEvent& event )
{
- if( event.state == KeyEvent::Down )
+ if( event.GetState() == KeyEvent::DOWN )
{
if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
{
Actor mCubes[2]; ///< The cube object containers
};
-
-/**
- * @brief Creates an instance of the example object and runs it.
- * @param[in] application The DALi application object
- */
-void RunExample( Application& application )
-{
- RendererStencilExample example( application );
-
- application.MainLoop();
-}
-
-/**
- * @brief Entry point for Linux & Tizen applications
- * @param[in] argc The executables argument count
- * @param[in] argv The executables argument vector
- * @return The executables exit code (0)
- */
int DALI_EXPORT_API main( int argc, char **argv )
{
Application application = Application::New( &argc, &argv );
-
- RunExample( application );
-
+ RendererStencilExample example( application );
+ application.MainLoop();
return 0;
}