/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * 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.
// EXTERNAL INCLUDES
#include <algorithm>
-#include <sstream>
-#include <unistd.h>
#include <dali/devel-api/images/distance-field.h>
#include <dali-toolkit/devel-api/shader-effects/alpha-discard-effect.h>
#include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
// INTERNAL INCLUDES
-#include "shared/view.h"
+#include "shared/execute-process.h"
#include "shared/utility.h"
+#include "shared/view.h"
using namespace Dali;
using namespace Dali::Toolkit;
{
const std::string LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" );
-const std::string TILE_BACKGROUND(DEMO_IMAGE_DIR "item-background.9.png");
-const std::string TILE_BACKGROUND_ALPHA( DEMO_IMAGE_DIR "demo-tile-texture.9.png" );
-const std::string TILE_FOCUS( DEMO_IMAGE_DIR "tile-focus.9.png" );
// Keyboard focus effect constants.
const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f; ///< The total duration of the keyboard focus animation
-const float KEYBOARD_FOCUS_START_SCALE = 1.05f; ///< The starting scale of the focus highlight
-const float KEYBOARD_FOCUS_END_SCALE = 1.18f; ///< The end scale of the focus highlight
-const float KEYBOARD_FOCUS_END_ALPHA = 0.7f; ///< The end alpha of the focus highlight
-const float KEYBOARD_FOCUS_INITIAL_FADE_PERCENTAGE = 0.16f; ///< The duration of the initial fade (from translucent to the end-alpha) as a percentage of the overal animation duration.
-const Vector3 startScale( KEYBOARD_FOCUS_START_SCALE, KEYBOARD_FOCUS_START_SCALE, KEYBOARD_FOCUS_START_SCALE ); ///< @see KEYBOARD_FOCUS_START_SCALE
-const Vector3 endScale( KEYBOARD_FOCUS_END_SCALE, KEYBOARD_FOCUS_END_SCALE, KEYBOARD_FOCUS_END_SCALE ); ///< @see KEYBOARD_FOCUS_END_SCALE
-const float initialFadeDuration = KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_INITIAL_FADE_PERCENTAGE; ///< @see KEYBOARD_FOCUS_INITIAL_FADE_PERCENTAGE
+const int32_t KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT = 5; ///< The number of loops for the keyboard focus animation
+const float KEYBOARD_FOCUS_FINAL_SCALE_FLOAT = 1.05f; ///< The final scale of the focus highlight
+const float KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT = 1.18f; ///< The scale of the focus highlight during the animation
+const float KEYBOARD_FOCUS_FINAL_ALPHA = 0.7f; ///< The final alpha of the focus highlight
+const float KEYBOARD_FOCUS_ANIMATING_ALPHA = 0.0f; ///< The alpha of the focus highlight during the animation
+const float KEYBOARD_FOCUS_FADE_PERCENTAGE = 0.16f; ///< The duration of the fade (from translucent to the final-alpha) as a percentage of the overall animation duration
+const Vector3 KEYBOARD_FOCUS_FINAL_SCALE( KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT, KEYBOARD_FOCUS_FINAL_SCALE_FLOAT ); ///< @see KEYBOARD_FOCUS_START_SCALE_FLOAT
+const Vector3 FOCUS_INDICATOR_ANIMATING_SCALE( KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT, KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT ); ///< @see KEYBOARD_FOCUS_END_SCALE_FLOAT
+const float KEYBOARD_FOCUS_MID_KEY_FRAME_TIME = KEYBOARD_FOCUS_ANIMATION_DURATION - ( KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_FADE_PERCENTAGE ); ///< Time of the mid key-frame
const float TILE_LABEL_PADDING = 8.0f; ///< Border between edge of tile and the example text
const float BUTTON_PRESS_ANIMATION_TIME = 0.35f; ///< Time to perform button scale effect.
const float EFFECT_SNAP_DURATION = 0.66f; ///< Scroll Snap Duration for Effects
const float EFFECT_FLICK_DURATION = 0.5f; ///< Scroll Flick Duration for Effects
const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
-const Vector4 TILE_COLOR( 0.4f, 0.6f, 0.9f, 0.6f );
-const Vector4 BUBBLE_COLOR[] =
+const char * const BUBBLE_COLOR_STYLE_NAME[] =
{
- Vector4( 0.3255f, 0.3412f, 0.6353f, 0.32f ),
- Vector4( 0.3647f, 0.7569f, 0.8157f, 0.32f ),
- Vector4( 0.3804f, 0.7412f, 0.6510f, 0.32f ),
- Vector4( 1.f, 1.f, 1.f, 0.13f )
+ "BubbleColor1",
+ "BubbleColor2",
+ "BubbleColor3",
+ "BubbleColor4"
};
-const int NUMBER_OF_BUBBLE_COLOR( sizeof(BUBBLE_COLOR) / sizeof(BUBBLE_COLOR[0]) );
+const int NUMBER_OF_BUBBLE_COLORS( sizeof( BUBBLE_COLOR_STYLE_NAME ) / sizeof( BUBBLE_COLOR_STYLE_NAME[ 0 ] ) );
const char * const SHAPE_IMAGE_TABLE[] =
{
const int NUMBER_OF_SHAPE_IMAGES( sizeof( SHAPE_IMAGE_TABLE ) / sizeof( SHAPE_IMAGE_TABLE[0] ) );
const int NUM_BACKGROUND_IMAGES = 18;
-const float BACKGROUND_SWIPE_SCALE = 0.025f;
const float BACKGROUND_SPREAD_SCALE = 1.5f;
-const float SCALE_MOD = 1000.0f * Math::PI * 2.0f;
-const float SCALE_SPEED = 10.0f;
-const float SCALE_SPEED_SIN = 0.1f;
const unsigned int BACKGROUND_ANIMATION_DURATION = 15000; // 15 secs
-const Vector4 BACKGROUND_COLOR( 0.3569f, 0.5451f, 0.7294f, 1.0f );
-
const float BUBBLE_MIN_Z = -1.0;
const float BUBBLE_MAX_Z = 0.0f;
-// This shader takes a texture.
-// An alpha discard is performed.
-// The shader uses the tiles position within the scroll-view page and the scroll-views rotation position to create a parallax effect.
-const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
- varying mediump vec2 vTexCoord;
- uniform lowp vec4 uColor;
- uniform sampler2D sTexture;
- uniform mediump vec3 uCustomPosition;
-
- void main()
- {
- if( texture2D( sTexture, vTexCoord ).a <= 0.0001 )
- {
- discard;
- }
-
- mediump vec2 wrapTexCoord = vec2( ( vTexCoord.x / 4.0 ) + ( uCustomPosition.x / 4.0 ) + ( uCustomPosition.z / 2.0 ), vTexCoord.y / 4.0 );
- mediump vec4 color = texture2D( sTexture, wrapTexCoord );
- mediump float positionWeight = ( uCustomPosition.y + 0.3 ) * color.r * 2.0;
-
- gl_FragColor = vec4( positionWeight, positionWeight, positionWeight, 0.9 ) * uColor + vec4( uColor.xyz, 0.0 );
- }
-);
+const char * const DEMO_BUILD_DATE = __DATE__ " " __TIME__;
/**
* Creates the background image
ApplyCubeEffectToPages();
Dali::Window winHandle = application.GetWindow();
- winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT );
- winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE );
- winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
- winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
+
+ if( stageSize.width <= stageSize.height )
+ {
+ winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT );
+ winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE );
+ winHandle.AddAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
+ winHandle.RemoveAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
+ }
+ else
+ {
+ winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE );
+ winHandle.RemoveAvailableOrientation( Dali::Window::PORTRAIT );
+ winHandle.AddAvailableOrientation( Dali::Window::LANDSCAPE_INVERSE );
+ winHandle.RemoveAvailableOrientation( Dali::Window::PORTRAIT_INVERSE );
+ }
// Set initial orientation
unsigned int degrees = 0;
void DaliTableView::CreateFocusEffect()
{
// Hook the required signals to manage the focus.
- KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
- KeyboardFocusManager::Get().FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
+ auto keyboardFocusManager = KeyboardFocusManager::Get();
+ keyboardFocusManager.PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
+ keyboardFocusManager.FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
// Loop to create both actors for the focus highlight effect.
for( unsigned int i = 0; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i )
{
- mFocusEffect[i].actor = ImageView::New( TILE_FOCUS );
+ mFocusEffect[i].actor = ImageView::New();
+ mFocusEffect[i].actor.SetStyleName( "FocusActor" );
mFocusEffect[i].actor.SetParentOrigin( ParentOrigin::CENTER );
mFocusEffect[i].actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
mFocusEffect[i].actor.SetInheritScale( false );
mFocusEffect[i].actor.SetColorMode( USE_OWN_COLOR );
- // Setup initial values pre-animation.
- mFocusEffect[i].actor.SetScale( startScale );
- mFocusEffect[i].actor.SetOpacity( 0.0f );
+ KeyFrames alphaKeyFrames = KeyFrames::New();
+ alphaKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_ALPHA );
+ alphaKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, KEYBOARD_FOCUS_ANIMATING_ALPHA );
+ alphaKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_ALPHA );
- // Create and setup the animation to do the following:
- // 1) Initial fade in over short period of time
- // 2) Zoom in (larger) and fade out simultaneously over longer period of time.
- mFocusEffect[i].animation = Animation::New( KEYBOARD_FOCUS_ANIMATION_DURATION );
+ KeyFrames scaleKeyFrames = KeyFrames::New();
+ scaleKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_SCALE );
+ scaleKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, FOCUS_INDICATOR_ANIMATING_SCALE );
+ scaleKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_SCALE );
- mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), KEYBOARD_FOCUS_END_ALPHA, AlphaFunction::LINEAR, TimePeriod( 0.0f, initialFadeDuration ) );
- mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::SCALE ), endScale, AlphaFunction::LINEAR, TimePeriod( initialFadeDuration, KEYBOARD_FOCUS_ANIMATION_DURATION - initialFadeDuration ) );
- mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::LINEAR, TimePeriod( initialFadeDuration, KEYBOARD_FOCUS_ANIMATION_DURATION - initialFadeDuration ) );
+ mFocusEffect[i].animation = Animation::New( KEYBOARD_FOCUS_ANIMATION_DURATION );
+ mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), alphaKeyFrames );
+ mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::SCALE ), scaleKeyFrames );
- mFocusEffect[i].animation.SetLooping( true );
+ mFocusEffect[i].animation.SetLoopCount( KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT );
}
// Parent the secondary effect from the primary.
mFocusEffect[0].actor.Add( mFocusEffect[1].actor );
+ keyboardFocusManager.SetFocusIndicatorActor( mFocusEffect[0].actor );
+
+ // Connect to the on & off stage signals of the indicator which represents when it is enabled & disabled respectively
+ mFocusEffect[0].actor.OnStageSignal().Connect( this, &DaliTableView::OnFocusIndicatorEnabled );
+ mFocusEffect[0].actor.OffStageSignal().Connect( this, &DaliTableView::OnFocusIndicatorDisabled );
+}
+
+void DaliTableView::OnFocusIndicatorEnabled( Actor /* actor */ )
+{
// Play the animation on the 1st glow object.
mFocusEffect[0].animation.Play();
- // Stagger the animation on the 2st glow object half way through.
+
+ // Stagger the animation on the 2nd glow object half way through.
mFocusEffect[1].animation.PlayFrom( KEYBOARD_FOCUS_ANIMATION_DURATION / 2.0f );
+}
- KeyboardFocusManager::Get().SetFocusIndicatorActor( mFocusEffect[0].actor );
+void DaliTableView::OnFocusIndicatorDisabled( Dali::Actor /* actor */ )
+{
+ // Stop the focus effect animations
+ for( auto i = 0u; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i )
+ {
+ mFocusEffect[ i ].animation.Stop();
+ }
}
void DaliTableView::ApplyCubeEffectToPages()
Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Vector2& position )
{
- Actor focusableTile = Actor::New();
+ Toolkit::ImageView focusableTile = ImageView::New();
+
+ focusableTile.SetStyleName( "DemoTile" );
focusableTile.SetParentOrigin( ParentOrigin::CENTER );
focusableTile.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
focusableTile.SetSizeModeFactor( sizeMultiplier );
// Set the tile to be keyboard focusable
focusableTile.SetKeyboardFocusable( true );
- Toolkit::ImageView tileContent = ImageView::New();
- tileContent.SetParentOrigin( ParentOrigin::CENTER );
- tileContent.SetAnchorPoint( AnchorPoint::CENTER );
- tileContent.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-
- // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
+ // Register a property with the ImageView. This allows us to inject the scroll-view position into the shader.
Property::Value value = Vector3( 0.0f, 0.0f, 0.0f );
- Property::Index propertyIndex = tileContent.RegisterProperty( "uCustomPosition", value );
-
- // Add a shader to the image (details in shader source).
- Property::Map customShader;
- customShader[ Visual::Shader::Property::FRAGMENT_SHADER ] = FRAGMENT_SHADER_TEXTURED;
-
- // Set the Image URL and the custom shader
- Property::Map imageMap;
- imageMap.Add( ImageVisual::Property::URL, TILE_BACKGROUND_ALPHA );
- imageMap.Add( Visual::Property::SHADER, customShader );
- tileContent.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
-
- tileContent.SetColor( TILE_COLOR );
+ Property::Index propertyIndex = focusableTile.RegisterProperty( "uCustomPosition", value );
// We create a constraint to perform a precalculation on the scroll-view X offset
// and pass it to the shader uniform, along with the tile's position.
- Constraint shaderPosition = Constraint::New < Vector3 > ( tileContent, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) );
+ Constraint shaderPosition = Constraint::New < Vector3 > ( focusableTile, propertyIndex, TileShaderPositionConstraint( mPageWidth, position.x ) );
shaderPosition.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) );
shaderPosition.SetRemoveAction( Constraint::Discard );
shaderPosition.Apply();
- focusableTile.Add( tileContent );
+ //focusableTile.Add( tileContent );
// Create an ImageView for the 9-patch border around the tile.
- ImageView borderImage = ImageView::New( TILE_BACKGROUND );
+ ImageView borderImage = ImageView::New();
+ borderImage.SetStyleName("DemoTileBorder");
borderImage.SetAnchorPoint( AnchorPoint::CENTER );
borderImage.SetParentOrigin( ParentOrigin::CENTER );
borderImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
borderImage.SetOpacity( 0.8f );
- tileContent.Add( borderImage );
+ focusableTile.Add( borderImage );
TextLabel label = TextLabel::New();
label.SetAnchorPoint( AnchorPoint::CENTER );
{
std::string name = mPressedActor.GetName();
- std::stringstream stream;
- stream << DEMO_EXAMPLE_BIN << name.c_str();
- pid_t pid = fork();
- if( pid == 0)
- {
- execlp( stream.str().c_str(), name.c_str(), NULL );
- DALI_ASSERT_ALWAYS(false && "exec failed!");
- }
+ ExecuteProcess( name );
+
mPressedActor.Reset();
}
}
Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
Property::Map imageMap;
imageMap.Add( ImageVisual::Property::URL, SHAPE_IMAGE_TABLE[ shapeType ] );
- imageMap.Add( Visual::Property::SHADER, effect );
+ imageMap.Add( Toolkit::Visual::Property::SHADER, effect );
dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
- dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );
+ dfActor.SetStyleName( BUBBLE_COLOR_STYLE_NAME[ i%NUMBER_OF_BUBBLE_COLORS ] );
layer.Add( dfActor );
}
stream << "DALi Core: " << CORE_MAJOR_VERSION << "." << CORE_MINOR_VERSION << "." << CORE_MICRO_VERSION << std::endl << "(" << CORE_BUILD_DATE << ")\n";
stream << "DALi Adaptor: " << ADAPTOR_MAJOR_VERSION << "." << ADAPTOR_MINOR_VERSION << "." << ADAPTOR_MICRO_VERSION << std::endl << "(" << ADAPTOR_BUILD_DATE << ")\n";
stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")\n";
+ stream << "DALi Demo:" << "\n(" << DEMO_BUILD_DATE << ")\n";
mVersionPopup = Dali::Toolkit::Popup::New();
Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Version information" );
titleActor.SetName( "titleActor" );
- titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER );
+ titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
Toolkit::TextLabel contentActor = Toolkit::TextLabel::New( stream.str() );
contentActor.SetName( "contentActor" );
contentActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
- contentActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+ contentActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::CENTER );
+ contentActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
contentActor.SetPadding( Padding( 0.0f, 0.0f, 20.0f, 0.0f ) );
mVersionPopup.SetTitle( titleActor );