- mApplication.Quit();
- }
- }
-}
-
-void DaliTableView::SetupBackground( Actor bubbleContainer, Actor backgroundLayer, const Vector2& size )
-{
- // Create distance field shape.
- BitmapImage distanceField;
- Size imageSize( 512, 512 );
- CreateShapeImage( CIRCLE, imageSize, distanceField );
-
- // Create solid background colour.
- ImageActor backgroundColourActor = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR );
- backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER );
- backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER );
- backgroundColourActor.SetSize( size * BACKGROUND_SIZE_SCALE );
- backgroundColourActor.SetZ( BACKGROUND_Z );
- backgroundColourActor.SetPositionInheritanceMode( DONT_INHERIT_POSITION );
- backgroundLayer.Add( backgroundColourActor );
-
- // Add bubbles to the bubbleContainer.
- // Note: The bubbleContainer is parented externally to this function.
- AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceField, size );
-}
-
-void DaliTableView::AddBackgroundActors( Actor layer, int count, BitmapImage distanceField, const Dali::Vector2& size )
-{
- for( int i = 0; i < count; ++i )
- {
- float randSize = Random::Range( 10.0f, 400.0f );
- float hue = Random::Range( 0.3f, 1.0f );
- Vector4 randColour( hue, hue*0.5, 0.0f, Random::Range( 0.3f, 0.6f ));
-
- ImageActor dfActor = ImageActor::New( distanceField );
- mBackgroundActors.push_back( dfActor );
- dfActor.SetSize( Vector2( randSize, randSize ) );
- dfActor.SetParentOrigin( ParentOrigin::CENTER );
-
- Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
- dfActor.SetShaderEffect( effect );
- dfActor.SetColor( randColour );
- effect.SetOutlineParams( Vector2( 0.55f, 0.00f ) );
- effect.SetSmoothingEdge( 0.5f );
- layer.Add( dfActor );
-
- // Setup animation
- Vector3 actorPos(
- Random::Range( -size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.5f * BACKGROUND_SPREAD_SCALE ),
- Random::Range( -size.y * 0.5f - randSize, size.y * 0.5f + randSize ),
- Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) );
- dfActor.SetPosition( actorPos );
-
- // Define bubble horizontal parallax and vertical wrapping
- Constraint animConstraint = Constraint::New < Vector3 > ( Actor::POSITION,
- Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
- Dali::ParentSource( Dali::Actor::SIZE ),
- AnimateBubbleConstraint( actorPos, Random::Range( -0.85f, 0.25f ), randSize ) );
- dfActor.ApplyConstraint( animConstraint );
-
- // Kickoff animation
- Animation animation = Animation::New( Random::Range( 40.0f, 200.0f ) );
- KeyFrames keyframes = KeyFrames::New();
- keyframes.Add( 0.0f, actorPos );
- Vector3 toPos( actorPos );
- toPos.y -= ( size.y + randSize );
- keyframes.Add( 1.0f, toPos );
- animation.AnimateBetween( Property( dfActor, Actor::POSITION ), keyframes );
- animation.SetLooping( true );
- animation.Play();
- mBackgroundAnimations.push_back( animation );
- }
-}
-
-void DaliTableView::CreateShapeImage( ShapeType shapeType, const Size& size, BitmapImage& distanceFieldOut )
-{
- // this bitmap will hold the alpha map for the distance field shader
- distanceFieldOut = BitmapImage::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 )