Commit 4757ec2b1ea48584267741666c2c228995341b93

Authored by Tom Robinson
Committed by Adeel Kazmi
1 parent fcd958eb

Removed some constraints from dali-table-view

Change-Id: Ia404e970624dd932da002b11365fa1c9b099091b
Showing 1 changed file with 42 additions and 134 deletions
demo/dali-table-view.cpp
... ... @@ -63,7 +63,7 @@ const float EFFECT_SNAP_DURATION = 0.66f; ///< Scroll Snap
63 63 const float EFFECT_FLICK_DURATION = 0.5f; ///< Scroll Flick Duration for Effects
64 64 const Vector3 ANGLE_CUBE_PAGE_ROTATE(Math::PI * 0.5f, Math::PI * 0.5f, 0.0f);
65 65  
66   -const int NUM_BACKGROUND_IMAGES = 20;
  66 +const int NUM_BACKGROUND_IMAGES = 18;
67 67 const float BACKGROUND_SWIPE_SCALE = 0.025f;
68 68 const float BACKGROUND_SPREAD_SCALE = 1.5f;
69 69 const float SCALE_MOD = 1000.0f * Math::PI * 2.0f;
... ... @@ -137,90 +137,40 @@ const float IMAGE_BORDER_TOP = IMAGE_BORDER_LEFT;
137 137 const float IMAGE_BORDER_BOTTOM = IMAGE_BORDER_LEFT;
138 138  
139 139 /**
140   - * TableViewVisibilityConstraint
  140 + * Constraint to return a position for a bubble based on the scroll value and vertical wrapping.
141 141 */
142   -struct TableViewVisibilityConstraint
143   -{
144   - bool operator()( const bool& current,
145   - const PropertyInput& pagePositionProperty,
146   - const PropertyInput& pageSizeProperty )
147   - {
148   - // Only the tableview in the current page should be visible.
149   - const Vector3& pagePosition = pagePositionProperty.GetVector3();
150   - const Vector3& pageSize = pageSizeProperty.GetVector3();
151   - return fabsf( pagePosition.x ) < pageSize.x;
152   - }
153   -};
154   -
155   -/**
156   - * Constraint to wrap an actor in y that is moving vertically
157   - */
158   -Vector3 ShapeMovementConstraint( const Vector3& current,
159   - const PropertyInput& shapeSizeProperty,
160   - const PropertyInput& parentSizeProperty )
161   -{
162   - const Vector3& shapeSize = shapeSizeProperty.GetVector3();
163   - const Vector3& parentSize = parentSizeProperty.GetVector3();
164   -
165   - Vector3 pos( current );
166   - if( pos.y + shapeSize.y * 0.5f < -parentSize.y * 0.5f )
167   - {
168   - pos.y += parentSize.y + shapeSize.y;
169   - }
170   -
171   - return pos;
172   -}
173   -
174   -/**
175   - * Constraint to return a position for the background based on the scroll value
176   - */
177   -struct AnimScrollConstraint
  142 +struct AnimateBubbleConstraint
178 143 {
179 144 public:
180   -
181   - AnimScrollConstraint( const Vector3& initialPos, float scale )
182   - : mInitialPos( initialPos ),
183   - mScale( scale )
184   - {
185   -
186   - }
187   -
188   - Vector3 operator()( const Vector3& current, const PropertyInput& scrollProperty )
  145 + AnimateBubbleConstraint( const Vector3& initialPos, float scale, float size )
  146 + : mInitialX( initialPos.x ),
  147 + mScale( scale ),
  148 + mShapeSize( size )
189 149 {
190   - float scrollPos = scrollProperty.GetVector3().x;
191   -
192   - return mInitialPos + Vector3( -scrollPos * mScale, 0.0f, 0.0f );
193 150 }
194 151  
195   -private:
196   - Vector3 mInitialPos;
197   - float mScale;
198   -};
199   -
200   -/**
201   - * Constraint to return a tracked world position added to the constant local position
202   - */
203   -struct TranslateLocalConstraint
204   -{
205   -public:
206   -
207   - TranslateLocalConstraint( const Vector3& localPos )
208   - : mLocalPos( localPos )
  152 + Vector3 operator()( const Vector3& current, const PropertyInput& scrollProperty, const PropertyInput& parentSize )
209 153 {
210   - }
  154 + Vector3 pos( current );
211 155  
212   - Vector3 operator()( const Vector3& current, const PropertyInput& pagePosProperty )
213   - {
214   - Vector3 worldPos = pagePosProperty.GetVector3();
  156 + // Wrap bubbles verically.
  157 + if( pos.y + mShapeSize * 0.5f < -parentSize.GetVector3().y * 0.5f )
  158 + {
  159 + pos.y += parentSize.GetVector3().y + mShapeSize;
  160 + }
215 161  
216   - return ( worldPos + mLocalPos );
  162 + // Bubbles X position moves parallax to horizontal
  163 + // panning by a scale factor unique to each bubble.
  164 + pos.x = mInitialX + ( scrollProperty.GetVector3().x * mScale );
  165 + return pos;
217 166 }
218 167  
219 168 private:
220   - Vector3 mLocalPos;
  169 + float mInitialX;
  170 + float mScale;
  171 + float mShapeSize;
221 172 };
222 173  
223   -
224 174 bool CompareByTitle( const Example& lhs, const Example& rhs )
225 175 {
226 176 return lhs.title < rhs.title;
... ... @@ -507,12 +457,6 @@ Actor DaliTableView::CreateTile( const std::string&amp; name, const std::string&amp; tit
507 457 tile.SetAnchorPoint( AnchorPoint::CENTER );
508 458 tile.SetParentOrigin( ParentOrigin::CENTER );
509 459  
510   - Actor content = Actor::New();
511   - content.SetAnchorPoint( AnchorPoint::CENTER );
512   - content.SetParentOrigin( ParentOrigin::CENTER );
513   - content.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) );
514   - tile.Add(content);
515   -
516 460 // create background image
517 461 if( addBackground )
518 462 {
... ... @@ -526,8 +470,7 @@ Actor DaliTableView::CreateTile( const std::string&amp; name, const std::string&amp; tit
526 470 image.SetZ( -1 );
527 471 image.SetStyle( ImageActor::STYLE_NINE_PATCH );
528 472 image.SetNinePatchBorder( Vector4( IMAGE_BORDER_LEFT, IMAGE_BORDER_TOP, IMAGE_BORDER_RIGHT, IMAGE_BORDER_BOTTOM ) );
529   -
530   - content.Add( image );
  473 + tile.Add( image );
531 474  
532 475 // Add stencil
533 476 ImageActor stencil = NewStencilImage();
... ... @@ -548,7 +491,7 @@ Actor DaliTableView::CreateTile( const std::string&amp; name, const std::string&amp; tit
548 491 text.SetSize( 0.9f * parentSize.width, 0.9f * parentSize.height );
549 492 text.SetStyleToCurrentText( GetTableTextStyle() );
550 493 text.SetSnapshotModeEnabled( false );
551   - content.Add( text );
  494 + tile.Add( text );
552 495  
553 496 // Set the tile to be keyboard focusable
554 497 tile.SetKeyboardFocusable(true);
... ... @@ -738,61 +681,25 @@ void DaliTableView::OnKeyEvent( const KeyEvent&amp; event )
738 681 }
739 682 }
740 683  
741   -Actor CreateBackgroundActor( const Vector2& size )
742   -{
743   - Actor layer = Actor::New();
744   - layer.SetAnchorPoint( AnchorPoint::CENTER );
745   - layer.SetParentOrigin( ParentOrigin::CENTER );
746   - layer.SetSize( size );
747   - return layer;
748   -}
749   -
750   -void DaliTableView::SetupBackground( Actor bubbleLayer, Actor backgroundLayer, const Vector2& size )
  684 +void DaliTableView::SetupBackground( Actor bubbleContainer, Actor backgroundLayer, const Vector2& size )
751 685 {
752   - // Create distance field shape
  686 + // Create distance field shape.
753 687 BitmapImage distanceField;
754 688 Size imageSize( 512, 512 );
755 689 CreateShapeImage( CIRCLE, imageSize, distanceField );
756 690  
757   - // Create layers
758   - Actor backgroundAnimLayer0 = CreateBackgroundActor( size );
759   - Actor backgroundAnimLayer1 = CreateBackgroundActor( size );
760   - Actor backgroundAnimLayer2 = CreateBackgroundActor( size );
761   -
762   - // Add constraints
763   - Constraint animConstraint0 = Constraint::New < Vector3 > ( Actor::POSITION,
764   - Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
765   - AnimScrollConstraint( backgroundAnimLayer0.GetCurrentPosition(), 0.75f ) );
766   - backgroundAnimLayer0.ApplyConstraint( animConstraint0 );
767   -
768   - Constraint animConstraint1 = Constraint::New < Vector3 > ( Actor::POSITION,
769   - Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
770   - AnimScrollConstraint( backgroundAnimLayer1.GetCurrentPosition(), 0.5f ) );
771   - backgroundAnimLayer1.ApplyConstraint( animConstraint1 );
772   -
773   - Constraint animConstraint2 = Constraint::New < Vector3 > ( Actor::POSITION,
774   - Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
775   - AnimScrollConstraint( backgroundAnimLayer2.GetCurrentPosition(), 0.25f ) );
776   - backgroundAnimLayer2.ApplyConstraint( animConstraint2 );
  691 + // Create solid background colour.
  692 + ImageActor backgroundColourActor = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR );
  693 + backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER );
  694 + backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER );
  695 + backgroundColourActor.SetSize( size * BACKGROUND_SIZE_SCALE );
  696 + backgroundColourActor.SetZ( BACKGROUND_Z );
  697 + backgroundColourActor.SetPositionInheritanceMode( DONT_INHERIT_POSITION );
  698 + backgroundLayer.Add( backgroundColourActor );
777 699  
778   - // Background
779   - ImageActor layer = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR );
780   - layer.SetAnchorPoint( AnchorPoint::CENTER );
781   - layer.SetParentOrigin( ParentOrigin::CENTER );
782   - layer.SetSize( size * BACKGROUND_SIZE_SCALE );
783   - layer.SetZ( BACKGROUND_Z );
784   - layer.SetPositionInheritanceMode( DONT_INHERIT_POSITION );
785   - backgroundLayer.Add( layer );
786   -
787   - // Parent the layers
788   - bubbleLayer.Add( backgroundAnimLayer0 );
789   - bubbleLayer.Add( backgroundAnimLayer1 );
790   - bubbleLayer.Add( backgroundAnimLayer2 );
791   -
792   - // Add all the children
793   - AddBackgroundActors( backgroundAnimLayer0, NUM_BACKGROUND_IMAGES / 3, distanceField, size );
794   - AddBackgroundActors( backgroundAnimLayer1, NUM_BACKGROUND_IMAGES / 3, distanceField, size );
795   - AddBackgroundActors( backgroundAnimLayer2, NUM_BACKGROUND_IMAGES / 3, distanceField, size );
  700 + // Add bubbles to the bubbleContainer.
  701 + // Note: The bubbleContainer is parented externally to this function.
  702 + AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceField, size );
796 703 }
797 704  
798 705 void DaliTableView::AddBackgroundActors( Actor layer, int count, BitmapImage distanceField, const Dali::Vector2& size )
... ... @@ -822,11 +729,12 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BitmapImage dis
822 729 Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) );
823 730 dfActor.SetPosition( actorPos );
824 731  
825   - Constraint movementConstraint = Constraint::New < Vector3 > ( Actor::POSITION,
826   - LocalSource( Actor::SIZE ),
827   - ParentSource( Actor::SIZE ),
828   - ShapeMovementConstraint );
829   - dfActor.ApplyConstraint( movementConstraint );
  732 + // Define bubble horizontal parallax and vertical wrapping
  733 + Constraint animConstraint = Constraint::New < Vector3 > ( Actor::POSITION,
  734 + Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ),
  735 + Dali::ParentSource( Dali::Actor::SIZE ),
  736 + AnimateBubbleConstraint( actorPos, Random::Range( -0.85f, 0.35f ), randSize ) );
  737 + dfActor.ApplyConstraint( animConstraint );
830 738  
831 739 // Kickoff animation
832 740 Animation animation = Animation::New( Random::Range( 40.0f, 200.0f ) );
... ...