/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
const char * const DEFAULT_TOOLBAR_TEXT( "TOUCH TO LAUNCH EXAMPLE" );
+const Vector4 TILE_COLOR( 0.5f, 0.6f, 0.8f, 0.23f ); ///< Color (including alpha) of tile contents.
const float BUTTON_PRESS_ANIMATION_TIME = 0.25f; ///< Time to perform button scale effect.
const float ROTATE_ANIMATION_TIME = 0.5f; ///< Time to perform rotate effect.
const int MAX_PAGES = 256; ///< Maximum pages (arbitrary safety limit)
const float BOTTOM_PADDING_RATIO = 0.4f / 0.9f;
const Vector3 SCROLLVIEW_RELATIVE_SIZE(0.9f, 1.0f, 0.8f ); ///< ScrollView's relative size to its parent
const Vector3 TABLE_RELATIVE_SIZE(0.95f, 0.9f, 0.8f ); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights.
-const float STENCIL_RELATIVE_SIZE = 1.0f;
-
-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 BUBBLE_COLOR[] =
-{
- Vector4( 0.3255f, 0.3412f, 0.6353f, 0.38f ),
- Vector4( 0.3647f, 0.7569f, 0.8157f, 0.38f ),
- Vector4( 0.3804f, 0.7412f, 0.6510f, 0.38f ),
- Vector4( 1.f, 1.f, 1.f, 0.2f )
-};
-const int NUMBER_OF_BUBBLE_COLOR( sizeof(BUBBLE_COLOR) / sizeof(BUBBLE_COLOR[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;
/**
* Creates the background image
return background;
}
-/**
- * Constraint to return a position for a bubble based on the scroll value and vertical wrapping
- */
-struct AnimateBubbleConstraint
-{
-public:
- AnimateBubbleConstraint( const Vector3& initialPos, float scale )
- : mInitialX( initialPos.x ),
- mScale( scale )
- {
- }
-
- void operator()( Vector3& position, const PropertyInputContainer& inputs )
- {
- const Vector3& parentSize = inputs[1]->GetVector3();
- const Vector3& childSize = inputs[2]->GetVector3();
-
- // Wrap bubbles vertically.
- float range = parentSize.y + childSize.y;
- // This performs a float mod (we don't use fmod as we want the arithmetic modulus as opposed to the remainder).
- position.y -= range * ( floor( position.y / range ) + 0.5f );
-
- // Bubbles X position moves parallax to horizontal
- // panning by a scale factor unique to each bubble.
- position.x = mInitialX + ( inputs[0]->GetVector2().x * mScale );
- }
-
-private:
- float mInitialX;
- float mScale;
-};
-
bool CompareByTitle( const Example& lhs, const Example& rhs )
{
return lhs.title < rhs.title;
mScrollRulerX(),
mScrollRulerY(),
mPressedActor(),
- mAnimationTimer(),
mLogoTapDetector(),
mVersionPopup(),
mPages(),
- mBackgroundAnimations(),
mExampleList(),
mTotalPages(),
mScrolling( false ),
- mSortAlphabetically( false ),
- mBackgroundAnimsPlaying( false )
+ mSortAlphabetically( false )
{
application.InitSignal().Connect( this, &DaliTableView::Initialize );
}
mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER );
mScrollViewLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- // Create solid background colour.
- Control backgroundColourActor = Control::New();
- backgroundColourActor.SetBackgroundColor( BACKGROUND_COLOR );
- backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER );
- backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER );
- backgroundColourActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
- backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) );
-
- mScrollViewLayer.Add( backgroundColourActor );
-
- // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show
- Actor bubbleContainer = Actor::New();
- bubbleContainer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- bubbleContainer.SetAnchorPoint( AnchorPoint::CENTER );
- bubbleContainer.SetParentOrigin( ParentOrigin::CENTER );
- backgroundColourActor.Add( bubbleContainer );
-
- SetupBackground( bubbleContainer );
-
Alignment buttonsAlignment = Alignment::New();
buttonsAlignment.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
buttonsAlignment.Add( mScrollViewLayer );
winHandle.ShowIndicator( Dali::Window::INVISIBLE );
- // Background animation
- mAnimationTimer = Timer::New( BACKGROUND_ANIMATION_DURATION );
- mAnimationTimer.TickSignal().Connect( this, &DaliTableView::PauseBackgroundAnimation );
- mAnimationTimer.Start();
- mBackgroundAnimsPlaying = true;
-
KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &DaliTableView::OnKeyboardPreFocusChange );
KeyboardFocusManager::Get().FocusedActorEnterKeySignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
AccessibilityManager::Get().FocusedActorActivatedSignal().Connect( this, &DaliTableView::OnFocusedActorActivated );
void DaliTableView::OnButtonsPageRelayout( const Dali::Actor& actor )
{
-
}
void DaliTableView::Populate()
{
const Example& example = ( *iter );
- Actor tile = CreateTile( example.name, example.title, Vector3( tileParentMultiplier, tileParentMultiplier, 1.0f ), true );
+ Actor tile = CreateTile( example.name, example.title, Vector3( tileParentMultiplier, tileParentMultiplier, 1.0f ), TILE_COLOR );
AccessibilityManager accessibilityManager = AccessibilityManager::Get();
accessibilityManager.SetFocusOrder( tile, ++exampleCount );
accessibilityManager.SetAccessibilityAttribute( tile, Dali::Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL,
mRotateAnimation.Play();
}
-Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground )
+Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, const Dali::Vector4& color )
{
Actor content = Actor::New();
content.SetName( name );
content.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
content.SetSizeModeFactor( sizeMultiplier );
- // create background image
- if( addBackground )
- {
- ImageView image = ImageView::New( TILE_BACKGROUND );
- image.SetAnchorPoint( AnchorPoint::CENTER );
- image.SetParentOrigin( ParentOrigin::CENTER );
- // make the image 100% of tile
- image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-
- content.Add( image );
-
- // Add stencil
- Toolkit::ImageView stencil = NewStencilImage();
- stencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
- image.Add( stencil );
- }
+ // Create background image.
+ ImageView image = ImageView::New( TILE_BACKGROUND );
+ image.SetAnchorPoint( AnchorPoint::CENTER );
+ image.SetParentOrigin( ParentOrigin::CENTER );
+ // Make the image 100% of tile.
+ image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ content.Add( image );
+
+ // Create the tile background.
+ Actor tileBackground = ImageView::New( TILE_BACKGROUND_ALPHA );
+ tileBackground.SetParentOrigin( ParentOrigin::CENTER );
+ tileBackground.SetAnchorPoint( AnchorPoint::CENTER );
+ tileBackground.SetProperty( Actor::Property::COLOR, color );
+ Property::Map shaderEffect = CreateAlphaDiscardEffect();
+ tileBackground.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderEffect );
+ tileBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ image.Add( tileBackground );
+ // Create the tile label.
TextLabel label = TextLabel::New();
label.SetAnchorPoint( AnchorPoint::TOP_LEFT );
label.SetProperty( Control::Property::STYLE_NAME, "launcherlabel" );
return content;
}
-Toolkit::ImageView DaliTableView::NewStencilImage()
-{
- Toolkit::ImageView stencil = ImageView::New( TILE_BACKGROUND_ALPHA );
- stencil.SetParentOrigin( ParentOrigin::CENTER );
- stencil.SetAnchorPoint( AnchorPoint::CENTER );
- stencil.SetDrawMode( DrawMode::STENCIL );
-
- Property::Map shaderEffect = CreateAlphaDiscardEffect();
- stencil.SetProperty( Toolkit::ImageView::Property::IMAGE, shaderEffect );
-
- return stencil;
-}
-
bool DaliTableView::OnTilePressed( Actor actor, const TouchData& event )
{
return DoTilePress( actor, event.GetState( 0 ) );
void DaliTableView::OnScrollStart( const Dali::Vector2& position )
{
mScrolling = true;
-
- PlayAnimation();
}
void DaliTableView::OnScrollComplete( const Dali::Vector2& position )
}
}
-void DaliTableView::SetupBackground( Actor bubbleContainer )
-{
- // Create distance field shape.
- BufferImage distanceField;
- Size imageSize( 512, 512 );
- CreateShapeImage( CIRCLE, imageSize, distanceField );
-
- // Add bubbles to the bubbleContainer.
- // Note: The bubbleContainer is parented externally to this function.
- AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceField );
-}
-
-void DaliTableView::InitialiseBackgroundActors( Actor actor )
-{
- // Delete current animations
- mBackgroundAnimations.clear();
-
- // Create new animations
- const Vector3 size = actor.GetTargetSize();
-
- for( unsigned int i = 0, childCount = actor.GetChildCount(); i < childCount; ++i )
- {
- Actor child = actor.GetChildAt( i );
-
- // Calculate a random position
- Vector3 childPos( Random::Range( -size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.5f * BACKGROUND_SPREAD_SCALE ),
- Random::Range( -size.y, size.y ),
- Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) );
-
- child.SetPosition( childPos );
-
- // Define bubble horizontal parallax and vertical wrapping
- Constraint animConstraint = Constraint::New < Vector3 > ( child, Actor::Property::POSITION, AnimateBubbleConstraint( childPos, Random::Range( -0.85f, 0.25f ) ) );
- animConstraint.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) );
- animConstraint.AddSource( Dali::ParentSource( Dali::Actor::Property::SIZE ) );
- animConstraint.AddSource( Dali::LocalSource( Dali::Actor::Property::SIZE ) );
- animConstraint.SetRemoveAction( Constraint::Discard );
- animConstraint.Apply();
-
- // Kickoff animation
- Animation animation = Animation::New( Random::Range( 30.0f, 160.0f ) );
- animation.AnimateBy( Property( child, Actor::Property::POSITION ), Vector3( 0.0f, -2000.0f, 0.0f ), AlphaFunction::LINEAR );
- animation.SetLooping( true );
- animation.Play();
- mBackgroundAnimations.push_back( animation );
- }
-}
-
-void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage distanceField )
-{
- for( int i = 0; i < count; ++i )
- {
- float randSize = Random::Range( 10.0f, 400.0f );
- ImageView dfActor = ImageView::New( distanceField );
- dfActor.SetSize( Vector2( randSize, randSize ) );
- dfActor.SetParentOrigin( ParentOrigin::CENTER );
-
- Dali::Property::Map effect = Toolkit::CreateDistanceFieldEffect();
- dfActor.SetProperty( Toolkit::ImageView::Property::IMAGE, effect );
- dfActor.SetColor( BUBBLE_COLOR[ i%NUMBER_OF_BUBBLE_COLOR ] );
-
- layer.Add( dfActor );
- }
-
- // Positioning will occur when the layer is relaid out
- layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors );
-}
-
-void DaliTableView::CreateShapeImage( ShapeType shapeType, const Size& size, BufferImage& distanceFieldOut )
-{
- // this bitmap will hold the alpha map for the distance field shader
- distanceFieldOut = BufferImage::New( size.width, size.height, Pixel::A8 );
-
- // Generate bit pattern
- std::vector< unsigned char > imageDataA8;
- imageDataA8.reserve( size.width * size.height ); // A8
-
- switch( shapeType )
- {
- case CIRCLE:
- GenerateCircle( size, imageDataA8 );
- break;
- case SQUARE:
- GenerateSquare( size, imageDataA8 );
- break;
- default:
- break;
- }
-
- PixelBuffer* buffer = distanceFieldOut.GetBuffer();
- if( buffer )
- {
- GenerateDistanceFieldMap( &imageDataA8[ 0 ], size, buffer, size, 8.0f, size );
- distanceFieldOut.Update();
- }
-}
-
-void DaliTableView::GenerateSquare( const Size& size, std::vector< unsigned char >& distanceFieldOut )
-{
- for( int h = 0; h < size.height; ++h )
- {
- for( int w = 0; w < size.width; ++w )
- {
- distanceFieldOut.push_back( 0xFF );
- }
- }
-}
-
-void DaliTableView::GenerateCircle( const Size& size, std::vector< unsigned char >& distanceFieldOut )
-{
- const float radius = size.width * 0.5f * size.width * 0.5f;
- Vector2 center( size.width / 2, size.height / 2 );
-
- for( int h = 0; h < size.height; ++h )
- {
- for( int w = 0; w < size.width; ++w )
- {
- Vector2 pos( w, h );
- Vector2 dist = pos - center;
-
- if( dist.x * dist.x + dist.y * dist.y > radius )
- {
- distanceFieldOut.push_back( 0x00 );
- }
- else
- {
- distanceFieldOut.push_back( 0xFF );
- }
- }
- }
-}
-
ImageView DaliTableView::CreateLogo( std::string imagePath )
{
ImageView logo = ImageView::New( imagePath );
return logo;
}
-bool DaliTableView::PauseBackgroundAnimation()
-{
- PauseAnimation();
-
- return false;
-}
-
-void DaliTableView::PauseAnimation()
-{
- if( mBackgroundAnimsPlaying )
- {
- for( AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter )
- {
- Animation anim = *animIter;
-
- anim.Stop();
- }
-
- mBackgroundAnimsPlaying = false;
- }
-}
-
-void DaliTableView::PlayAnimation()
-{
- if ( !mBackgroundAnimsPlaying )
- {
- for( AnimationListIter animIter = mBackgroundAnimations.begin(); animIter != mBackgroundAnimations.end(); ++animIter )
- {
- Animation anim = *animIter;
-
- anim.Play();
- }
-
- mBackgroundAnimsPlaying = true;
- }
-
- mAnimationTimer.SetInterval( BACKGROUND_ANIMATION_DURATION );
-}
-
Dali::Actor DaliTableView::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction )
{
Actor nextFocusActor = proposed;
Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Version information" );
titleActor.SetName( "titleActor" );
titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "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::TEXT_COLOR, Color::WHITE );
contentActor.SetPadding( Padding( 0.0f, 0.0f, 20.0f, 0.0f ) );
mVersionPopup.SetTitle( titleActor );
-#ifndef __DALI_DEMO_H__
-#define __DALI_DEMO_H__
+#ifndef DALI_DEMO_H
+#define DALI_DEMO_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
private: // Application callbacks & implementation
- /**
- * Shape enum for create function
- */
- enum ShapeType
- {
- CIRCLE,
- SQUARE
- };
-
/**
* Initialize application.
*
* @param[in] name The unique name for this Tile
* @param[in] title The text caption that appears on the Tile
* @param[in] parentSize Tile's parent size.
- * @param[in] addBackground Whether to add a background graphic to the tile or not
+ * @param[in] color The color (including alpha) of the tiles contents.
*
* @return The Actor for the created tile.
*/
- Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground );
-
- /**
- * Create a stencil image
- *
- * @return The stencil image
- */
- Dali::Toolkit::ImageView NewStencilImage();
+ Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, const Dali::Vector4& color );
// Signal handlers
*/
void OnKeyEvent( const Dali::KeyEvent& event );
- /**
- * Create a depth field background
- *
- * @param[in] bubbleLayer Add the graphics to this layer
- */
- void SetupBackground( Dali::Actor bubbleLayer );
-
- /**
- * Create background actors for the given layer
- *
- * @param[in] layer The layer to add the actors to
- * @param[in] count The number of actors to generate
- * @param[in] distanceField The distance field bitmap to use
- */
- void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField );
-
- /**
- * Create a bitmap with the specified shape and also output a distance field
- *
- * @param[in] shapeType The shape to generate
- * @param[in] size The size of the bitmap to create
- * @param[out] distanceFieldOut The return depth field alpha map
- */
- void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
-
- /**
- * Generate a square bit pattern and depth field
- *
- * @param[in] size The size of the bitmap to create
- * @param[out] imageOut The return bitmap
- * @param[out] distanceFieldOut The return depth field alpha map
- */
- void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
-
- /**
- * Generate a circle bit pattern and depth field
- *
- * @param[in] size The size of the bitmap to create
- * @param[out] imageOut The return bitmap
- * @param[out] distanceFieldOut The return depth field alpha map
- */
- void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
-
/**
* Creates the logo.
*
*/
Dali::Toolkit::ImageView CreateLogo( std::string imagePath );
- /**
- * Timer handler for ending background animation
- *
- * @return Return value for timer handler
- */
- bool PauseBackgroundAnimation();
-
- /**
- * Pause all animations
- */
- void PauseAnimation();
-
- /**
- * Resume all animations
- */
- void PlayAnimation();
-
/**
* Callback when the keyboard focus is going to be changed.
*
*/
void OnButtonsPageRelayout( const Dali::Actor& actor );
- /**
- * @brief Callback called to set up background actors
- *
- * @param[in] actor The actor raising the callback
- */
- void InitialiseBackgroundActors( Dali::Actor actor );
-
private:
Dali::Application& mApplication; ///< Application instance.
Dali::Toolkit::RulerPtr mScrollRulerX; ///< ScrollView X (horizontal) ruler
Dali::Toolkit::RulerPtr mScrollRulerY; ///< ScrollView Y (vertical) ruler
Dali::Actor mPressedActor; ///< The currently pressed actor.
- Dali::Timer mAnimationTimer; ///< Timer used to turn off animation after a specific time period
Dali::TapGestureDetector mLogoTapDetector; ///< To detect taps on the logo
Dali::Toolkit::Popup mVersionPopup; ///< Displays DALi library version information
std::vector< Dali::Actor > mPages; ///< List of pages.
- AnimationList mBackgroundAnimations; ///< List of background bubble animations
ExampleList mExampleList; ///< List of examples.
int mTotalPages; ///< Total pages within scrollview.
bool mScrolling:1; ///< Flag indicating whether view is currently being scrolled
bool mSortAlphabetically:1; ///< Sort examples alphabetically.
- bool mBackgroundAnimsPlaying:1; ///< Are background animations playing
};
-#endif // __DALI_DEMO_H__
+#endif // DALI_DEMO_H