Commit 804a3e6108cf706b7fcaa60c1652e9c5b972bb10

Authored by Kimmo Hoikka
Committed by Gerrit Code Review
2 parents 1676ce8b ad4f36a1

Merge "Replaced buffer image generation in dali-demo with simple images" into devel/master

demo/dali-table-view.cpp
1 1 /*
2   - * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  2 + * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
... ... @@ -82,6 +82,13 @@ const Vector4 BUBBLE_COLOR[] =
82 82 };
83 83 const int NUMBER_OF_BUBBLE_COLOR( sizeof(BUBBLE_COLOR) / sizeof(BUBBLE_COLOR[0]) );
84 84  
  85 +const char * const SHAPE_IMAGE_TABLE[] =
  86 +{
  87 + DEMO_IMAGE_DIR "shape-circle.png",
  88 + DEMO_IMAGE_DIR "shape-bubble.png"
  89 +};
  90 +const int NUMBER_OF_SHAPE_IMAGES( sizeof( SHAPE_IMAGE_TABLE ) / sizeof( SHAPE_IMAGE_TABLE[0] ) );
  91 +
85 92 const int NUM_BACKGROUND_IMAGES = 18;
86 93 const float BACKGROUND_SWIPE_SCALE = 0.025f;
87 94 const float BACKGROUND_SPREAD_SCALE = 1.5f;
... ... @@ -732,16 +739,9 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event )
732 739  
733 740 void DaliTableView::SetupBackground( Actor bubbleContainer )
734 741 {
735   - // Create distance field shapes.
736   - BufferImage distanceFields[2];
737   - Size imageSize( 512, 512 );
738   -
739   - CreateShapeImage( CIRCLE, imageSize, distanceFields[0] );
740   - CreateShapeImage( BUBBLE, imageSize, distanceFields[1] );
741   -
742 742 // Add bubbles to the bubbleContainer.
743 743 // Note: The bubbleContainer is parented externally to this function.
744   - AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceFields );
  744 + AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES );
745 745 }
746 746  
747 747 void DaliTableView::InitialiseBackgroundActors( Actor actor )
... ... @@ -780,13 +780,13 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor )
780 780 }
781 781 }
782 782  
783   -void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage* distanceField )
  783 +void DaliTableView::AddBackgroundActors( Actor layer, int count )
784 784 {
785 785 for( int i = 0; i < count; ++i )
786 786 {
787 787 float randSize = Random::Range( 10.0f, 400.0f );
788   - int distanceFieldType = static_cast<int>( Random::Range( 0.0f, 1.0f ) + 0.5f );
789   - ImageView dfActor = ImageView::New( distanceField[ distanceFieldType ] );
  788 + int shapeType = static_cast<int>( Random::Range( 0.0f, NUMBER_OF_SHAPE_IMAGES - 1 ) + 0.5f );
  789 + ImageView dfActor = ImageView::New( SHAPE_IMAGE_TABLE[ shapeType ] );
790 790 dfActor.SetSize( Vector2( randSize, randSize ) );
791 791 dfActor.SetParentOrigin( ParentOrigin::CENTER );
792 792  
... ... @@ -801,57 +801,6 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage* di
801 801 layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors );
802 802 }
803 803  
804   -void DaliTableView::CreateShapeImage( ShapeType shapeType, const Size& size, BufferImage& distanceFieldOut )
805   -{
806   - // this bitmap will hold the alpha map for the distance field shader
807   - distanceFieldOut = BufferImage::New( size.width, size.height, Pixel::A8 );
808   -
809   - // Generate bit pattern
810   - std::vector< unsigned char > imageDataA8;
811   - imageDataA8.reserve( size.width * size.height ); // A8
812   -
813   - switch( shapeType )
814   - {
815   - case CIRCLE:
816   - GenerateCircle( size, imageDataA8 );
817   - break;
818   - case BUBBLE:
819   - GenerateCircle( size, imageDataA8, true );
820   - break;
821   - default:
822   - break;
823   - }
824   -
825   - PixelBuffer* buffer = distanceFieldOut.GetBuffer();
826   - if( buffer )
827   - {
828   - GenerateDistanceFieldMap( &imageDataA8[ 0 ], size, buffer, size, 8.0f, size );
829   - distanceFieldOut.Update();
830   - }
831   -}
832   -
833   -void DaliTableView::GenerateCircle( const Size& size, std::vector< unsigned char >& distanceFieldOut, bool hollow )
834   -{
835   - const float radius = size.width * 0.5f * size.width * 0.5f;
836   - Vector2 center( size.width / 2, size.height / 2 );
837   -
838   - for( int h = 0; h < size.height; ++h )
839   - {
840   - for( int w = 0; w < size.width; ++w )
841   - {
842   - Vector2 pos( w, h );
843   - Vector2 dist = pos - center;
844   -
845   - float distance = ( dist.x * dist.x ) + ( dist.y * dist.y );
846   -
847   - // If hollow, check the distance against a min & max value, otherwise just use the max value.
848   - unsigned char fillByte = ( hollow ? ( ( distance <= radius ) && ( distance > ( radius * 0.7f ) ) ) : ( distance <= radius ) ) ? 0xFF : 0x00;
849   -
850   - distanceFieldOut.push_back( fillByte );
851   - }
852   - }
853   -}
854   -
855 804 ImageView DaliTableView::CreateLogo( std::string imagePath )
856 805 {
857 806 ImageView logo = ImageView::New( imagePath );
... ...
demo/dali-table-view.h
... ... @@ -2,7 +2,7 @@
2 2 #define DALI_DEMO_H
3 3  
4 4 /*
5   - * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  5 + * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 6 *
7 7 * Licensed under the Apache License, Version 2.0 (the "License");
8 8 * you may not use this file except in compliance with the License.
... ... @@ -262,37 +262,8 @@ private: // Application callbacks &amp; implementation
262 262 *
263 263 * @param[in] layer The layer to add the actors to
264 264 * @param[in] count The number of actors to generate
265   - * @param[in] distanceField A array (pointer) to 2 distance field types to use
266 265 */
267   - void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage* distanceField );
268   -
269   - /**
270   - * Create a bitmap with the specified shape and also output a distance field
271   - *
272   - * @param[in] shapeType The shape to generate
273   - * @param[in] size The size of the bitmap to create
274   - * @param[out] distanceFieldOut The return depth field alpha map
275   - */
276   - void CreateShapeImage( ShapeType shapeType, const Dali::Size& size, Dali::BufferImage& distanceFieldOut );
277   -
278   - /**
279   - * Generate a square bit pattern and depth field
280   - *
281   - * @param[in] size The size of the bitmap to create
282   - * @param[out] imageOut The return bitmap
283   - * @param[out] distanceFieldOut The return depth field alpha map
284   - */
285   - void GenerateSquare( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut );
286   -
287   - /**
288   - * Generate a circle bit pattern and depth field
289   - *
290   - * @param[in] size The size of the bitmap to create
291   - * @param[out] imageOut The return bitmap
292   - * @param[out] distanceFieldOut The return depth field alpha map
293   - * @param[in] hollow Optional - Set to true for a thick circle outline without fill
294   - */
295   - void GenerateCircle( const Dali::Size& size, std::vector<unsigned char>& distanceFieldOut, bool hollow = false );
  266 + void AddBackgroundActors( Dali::Actor layer, int count );
296 267  
297 268 /**
298 269 * Creates the logo.
... ...
resources/images/shape-bubble.png 0 → 100644

37.9 KB

resources/images/shape-circle.png 0 → 100644

22.8 KB