Commit cfb84ccc1a1f38f8a1acc2f79676c343c66630a1

Authored by Adeel Kazmi
1 parent 6332cbff

Modify focus animation behaviour to ensure we do NOT constantly render

Change-Id: I2c9ce1bbcfaddb4ad993493a735501deb5d05b61
shared/dali-table-view.cpp
... ... @@ -44,13 +44,15 @@ const std::string LOGO_PATH( DEMO_IMAGE_DIR "Logo-for-demo.png" );
44 44  
45 45 // Keyboard focus effect constants.
46 46 const float KEYBOARD_FOCUS_ANIMATION_DURATION = 1.0f; ///< The total duration of the keyboard focus animation
47   -const float KEYBOARD_FOCUS_START_SCALE = 1.05f; ///< The starting scale of the focus highlight
48   -const float KEYBOARD_FOCUS_END_SCALE = 1.18f; ///< The end scale of the focus highlight
49   -const float KEYBOARD_FOCUS_END_ALPHA = 0.7f; ///< The end alpha of the focus highlight
50   -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.
51   -const Vector3 startScale( KEYBOARD_FOCUS_START_SCALE, KEYBOARD_FOCUS_START_SCALE, KEYBOARD_FOCUS_START_SCALE ); ///< @see KEYBOARD_FOCUS_START_SCALE
52   -const Vector3 endScale( KEYBOARD_FOCUS_END_SCALE, KEYBOARD_FOCUS_END_SCALE, KEYBOARD_FOCUS_END_SCALE ); ///< @see KEYBOARD_FOCUS_END_SCALE
53   -const float initialFadeDuration = KEYBOARD_FOCUS_ANIMATION_DURATION * KEYBOARD_FOCUS_INITIAL_FADE_PERCENTAGE; ///< @see KEYBOARD_FOCUS_INITIAL_FADE_PERCENTAGE
  47 +const int32_t KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT = 5; ///< The number of loops for the keyboard focus animation
  48 +const float KEYBOARD_FOCUS_FINAL_SCALE_FLOAT = 1.05f; ///< The final scale of the focus highlight
  49 +const float KEYBOARD_FOCUS_ANIMATED_SCALE_FLOAT = 1.18f; ///< The scale of the focus highlight during the animation
  50 +const float KEYBOARD_FOCUS_FINAL_ALPHA = 0.7f; ///< The final alpha of the focus highlight
  51 +const float KEYBOARD_FOCUS_ANIMATING_ALPHA = 0.0f; ///< The alpha of the focus highlight during the animation
  52 +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
  53 +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
  54 +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
  55 +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
54 56  
55 57 const float TILE_LABEL_PADDING = 8.0f; ///< Border between edge of tile and the example text
56 58 const float BUTTON_PRESS_ANIMATION_TIME = 0.35f; ///< Time to perform button scale effect.
... ... @@ -307,8 +309,9 @@ void DaliTableView::Initialize( Application&amp; application )
307 309 void DaliTableView::CreateFocusEffect()
308 310 {
309 311 // Hook the required signals to manage the focus.
310   - KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
311   - KeyboardFocusManager::Get().FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
  312 + auto keyboardFocusManager = KeyboardFocusManager::Get();
  313 + keyboardFocusManager.PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
  314 + keyboardFocusManager.FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
312 315 AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
313 316  
314 317 // Loop to create both actors for the focus highlight effect.
... ... @@ -321,31 +324,49 @@ void DaliTableView::CreateFocusEffect()
321 324 mFocusEffect[i].actor.SetInheritScale( false );
322 325 mFocusEffect[i].actor.SetColorMode( USE_OWN_COLOR );
323 326  
324   - // Setup initial values pre-animation.
325   - mFocusEffect[i].actor.SetScale( startScale );
326   - mFocusEffect[i].actor.SetOpacity( 0.0f );
  327 + KeyFrames alphaKeyFrames = KeyFrames::New();
  328 + alphaKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_ALPHA );
  329 + alphaKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, KEYBOARD_FOCUS_ANIMATING_ALPHA );
  330 + alphaKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_ALPHA );
327 331  
328   - // Create and setup the animation to do the following:
329   - // 1) Initial fade in over short period of time
330   - // 2) Zoom in (larger) and fade out simultaneously over longer period of time.
331   - mFocusEffect[i].animation = Animation::New( KEYBOARD_FOCUS_ANIMATION_DURATION );
  332 + KeyFrames scaleKeyFrames = KeyFrames::New();
  333 + scaleKeyFrames.Add( 0.0f, KEYBOARD_FOCUS_FINAL_SCALE );
  334 + scaleKeyFrames.Add( KEYBOARD_FOCUS_MID_KEY_FRAME_TIME, FOCUS_INDICATOR_ANIMATING_SCALE );
  335 + scaleKeyFrames.Add( KEYBOARD_FOCUS_ANIMATION_DURATION, KEYBOARD_FOCUS_FINAL_SCALE );
332 336  
333   - mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), KEYBOARD_FOCUS_END_ALPHA, AlphaFunction::LINEAR, TimePeriod( 0.0f, initialFadeDuration ) );
334   - mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::SCALE ), endScale, AlphaFunction::LINEAR, TimePeriod( initialFadeDuration, KEYBOARD_FOCUS_ANIMATION_DURATION - initialFadeDuration ) );
335   - mFocusEffect[i].animation.AnimateTo( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::LINEAR, TimePeriod( initialFadeDuration, KEYBOARD_FOCUS_ANIMATION_DURATION - initialFadeDuration ) );
  337 + mFocusEffect[i].animation = Animation::New( KEYBOARD_FOCUS_ANIMATION_DURATION );
  338 + mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::COLOR_ALPHA ), alphaKeyFrames );
  339 + mFocusEffect[i].animation.AnimateBetween( Property( mFocusEffect[i].actor, Actor::Property::SCALE ), scaleKeyFrames );
336 340  
337   - mFocusEffect[i].animation.SetLooping( true );
  341 + mFocusEffect[i].animation.SetLoopCount( KEYBOARD_FOCUS_ANIMATION_LOOP_COUNT );
338 342 }
339 343  
340 344 // Parent the secondary effect from the primary.
341 345 mFocusEffect[0].actor.Add( mFocusEffect[1].actor );
342 346  
  347 + keyboardFocusManager.SetFocusIndicatorActor( mFocusEffect[0].actor );
  348 +
  349 + // Connect to the on & off stage signals of the indicator which represents when it is enabled & disabled respectively
  350 + mFocusEffect[0].actor.OnStageSignal().Connect( this, &DaliTableView::OnFocusIndicatorEnabled );
  351 + mFocusEffect[0].actor.OffStageSignal().Connect( this, &DaliTableView::OnFocusIndicatorDisabled );
  352 +}
  353 +
  354 +void DaliTableView::OnFocusIndicatorEnabled( Actor /* actor */ )
  355 +{
343 356 // Play the animation on the 1st glow object.
344 357 mFocusEffect[0].animation.Play();
345   - // Stagger the animation on the 2st glow object half way through.
  358 +
  359 + // Stagger the animation on the 2nd glow object half way through.
346 360 mFocusEffect[1].animation.PlayFrom( KEYBOARD_FOCUS_ANIMATION_DURATION / 2.0f );
  361 +}
347 362  
348   - KeyboardFocusManager::Get().SetFocusIndicatorActor( mFocusEffect[0].actor );
  363 +void DaliTableView::OnFocusIndicatorDisabled( Dali::Actor /* actor */ )
  364 +{
  365 + // Stop the focus effect animations
  366 + for( auto i = 0u; i < FOCUS_ANIMATION_ACTOR_NUMBER; ++i )
  367 + {
  368 + mFocusEffect[ i ].animation.Stop();
  369 + }
349 370 }
350 371  
351 372 void DaliTableView::ApplyCubeEffectToPages()
... ...
shared/dali-table-view.h
... ... @@ -298,6 +298,20 @@ private: // Application callbacks &amp; implementation
298 298 void OnFocusedActorActivated( Dali::Actor activatedActor );
299 299  
300 300 /**
  301 + * Callback when the keyboard focus indicator is enabled.
  302 + *
  303 + * @param[in] actor The keyboard focus indicator.
  304 + */
  305 + void OnFocusIndicatorEnabled( Dali::Actor actor );
  306 +
  307 + /**
  308 + * Callback when the keyboard focus indicator is disabled.
  309 + *
  310 + * @param[in] actor The keyboard focus indicator.
  311 + */
  312 + void OnFocusIndicatorDisabled( Dali::Actor actor );
  313 +
  314 + /**
301 315 * Called when the logo is tapped
302 316 *
303 317 * @param[in] actor The tapped actor
... ...