Add GetNaturalSize to Actor and deriving classes. 04/27704/5
authorKingsley Stephens <k.stephens@partner.samsung.com>
Wed, 17 Sep 2014 09:58:13 +0000 (10:58 +0100)
committerKingsley Stephens <k.stephens@partner.samsung.com>
Mon, 22 Sep 2014 15:17:14 +0000 (16:17 +0100)
Change-Id: I5562282646fb6d17b12cb0558854bffcc18cd4bb

16 files changed:
automated-tests/src/dali-unmanaged/utc-Dali-CustomActor.cpp
automated-tests/src/dali-unmanaged/utc-Dali-TypeRegistry.cpp
automated-tests/src/dali/utc-Dali-Actor.cpp
automated-tests/src/dali/utc-Dali-CustomActor.cpp
automated-tests/src/dali/utc-Dali-ImageActor.cpp
automated-tests/src/dali/utc-Dali-TextActor.cpp
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h
dali/internal/event/actors/custom-actor-internal.h
dali/internal/event/actors/image-actor-impl.cpp
dali/internal/event/actors/image-actor-impl.h
dali/internal/event/actors/text-actor-impl.cpp
dali/internal/event/actors/text-actor-impl.h
dali/public-api/actors/actor.cpp
dali/public-api/actors/actor.h
dali/public-api/actors/custom-actor-impl.h

index 93ca794..8bb6ede 100644 (file)
@@ -164,6 +164,11 @@ struct TestCustomActor : public CustomActorImpl
     }
   }
 
+  virtual Vector3 GetNaturalSize()
+  {
+    return Vector3( 0.0f, 0.0f, 0.0f );
+  }
+
   void SetDaliProperty(std::string s)
   {
     Self().SetProperty(mDaliProperty, s) ;
index 6e80cc8..53eb88c 100644 (file)
@@ -242,6 +242,11 @@ struct MyTestCustomActor : public CustomActorImpl
     return Actor::New();
   }
 
+  virtual Vector3 GetNaturalSize()
+  {
+    return Vector3( 0.0f, 0.0f, 0.0f );
+  }
+
 public:
 
   SignalType mSignal;
index 94f37c2..38dddff 100644 (file)
@@ -806,6 +806,18 @@ int UtcDaliActorGetCurrentSize(void)
   END_TEST;
 }
 
+int UtcDaliActorGetNaturalSize(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  Vector3 vector( 0.0f, 0.0f, 0.0f );
+
+  DALI_TEST_CHECK( actor.GetNaturalSize() == vector );
+
+  END_TEST;
+}
+
 // SetPosition(float x, float y)
 int UtcDaliActorSetPosition01(void)
 {
index 3feb248..2e54d07 100644 (file)
@@ -176,6 +176,11 @@ struct TestCustomActor : public CustomActorImpl
     }
   }
 
+  virtual Vector3 GetNaturalSize()
+  {
+    return Vector3( 0.0f, 0.0f, 0.0f );
+  }
+
   void SetDaliProperty(std::string s)
   {
     Self().SetProperty(mDaliProperty, s) ;
@@ -470,6 +475,11 @@ public:
   {
     return Actor();
   }
+
+  virtual Vector3 GetNaturalSize()
+  {
+    return Vector3( 0.0f, 0.0f, 0.0f );
+  }
 };
 
 } ; // namespace Impl
@@ -609,6 +619,11 @@ public:
     return GetImpl().mTargetSize;
   }
 
+  virtual Vector3 GetNaturalSize()
+  {
+    return Vector3( 0.0f, 0.0f, 0.0f );
+  }
+
 private:
 
   TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
index 51a428c..42c4846 100644 (file)
@@ -1091,3 +1091,22 @@ int UtcDaliImageActorNinePatch04(void)
 
   END_TEST;
 }
+
+int UtcDaliImageActorGetNaturalSize(void)
+{
+  TestApplication application;
+
+  // Standard image
+  BitmapImage img = BitmapImage::New( 10, 10 );
+  ImageActor actor = ImageActor::New( img );
+
+  DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
+
+  // Pixel area set
+  ImageActor::PixelArea area( 1, 2, 3, 4 );
+  actor.SetPixelArea( area );
+
+  DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );
+
+  END_TEST;
+}
index 892e210..a57b2aa 100644 (file)
@@ -1061,3 +1061,19 @@ int UtcDaliTextActorPropertyIndices(void)
   DALI_TEST_EQUALS( indices.size(), textActor.GetPropertyCount(), TEST_LOCATION );
   END_TEST;
 }
+
+int UtcDaliTextActorGetNaturalSize(void)
+{
+  TestApplication application;
+
+  TextActor actor = TextActor::New();
+  std::string text( "something else" );
+  actor.SetText( text );
+
+  Font defaultFont = Font::New();
+  Vector3 naturalSize = defaultFont.MeasureText( text );
+
+  DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == naturalSize.GetVectorXY() );
+
+  END_TEST;
+}
index 9675844..52c903a 100644 (file)
@@ -1091,9 +1091,12 @@ void Actor::SetSize(float width, float height, float depth)
 
 void Actor::SetSize(const Vector2& size)
 {
-  Vector3 volume( size );
-  volume.z = std::min( size.width, size.height );
-  SetSize( volume );
+  SetSize( Vector3( size.width, size.height, CalculateSizeZ( size ) ) );
+}
+
+float Actor::CalculateSizeZ( const Vector2& size ) const
+{
+  return std::min( size.width, size.height );
 }
 
 void Actor::SetSize(const Vector3& size)
@@ -1154,6 +1157,13 @@ const Vector3& Actor::GetCurrentSize() const
   return Vector3::ZERO;
 }
 
+Vector3 Actor::GetNaturalSize() const
+{
+  // It is up to deriving classes to return the appropriate natural size
+  return Vector3( 0.0f, 0.0f, 0.0f );
+}
+
+
 #ifdef DYNAMICS_SUPPORT
 
 //--------------- Dynamics ---------------
index 0b60100..7bee28b 100644 (file)
@@ -301,6 +301,13 @@ public:
   const Vector3& GetCurrentSize() const;
 
   /**
+   * Return the natural size of the actor
+   *
+   * @return The actor's natural size
+   */
+  virtual Vector3 GetNaturalSize() const;
+
+  /**
    * Set the origin of an actor, within its parent's area.
    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
    * and (1.0, 1.0, 0.5) is the bottom-right corner.
@@ -1088,6 +1095,15 @@ protected:
    */
   bool IsNodeConnected() const;
 
+  /**
+   * Calculate the size of the z dimension for a 2D size
+   *
+   * @param[in] size The 2D size (X, Y) to calculate Z from
+   *
+   * @return Return the Z dimension for this size
+   */
+  float CalculateSizeZ( const Vector2& size ) const;
+
 public: // Default property extensions from ProxyObject
 
   /**
index f8515f3..44b3418 100644 (file)
@@ -158,6 +158,14 @@ private:
   }
 
   /**
+   * @copydoc Internal::Actor::GetNaturalSize
+   */
+  virtual Vector3 GetNaturalSize() const
+  {
+    return mImpl->GetNaturalSize();
+  }
+
+  /**
    * Private constructor; see also CustomActor::New()
    */
   CustomActor(CustomActorImpl& extension);
index 7a981f2..60fcfb8 100644 (file)
@@ -237,28 +237,41 @@ void ImageActor::SetNaturalSize()
 {
   if( mUsingNaturalSize )
   {
-    // if no image then natural size is 0
-    Vector2 size;
-    ImagePtr image = mImageAttachment->GetImage();
-    if( image )
-    {
-      if( IsPixelAreaSet() )
-      {
-        PixelArea area(GetPixelArea());
-        size.width = area.width;
-        size.height = area.height;
-      }
-      else
-      {
-        size = image->GetNaturalSize();
-      }
-    }
     mInternalSetSize = true;
-    SetSize( size );
+    SetSize( CalculateNaturalSize() );
     mInternalSetSize = false;
   }
 }
 
+Vector3 ImageActor::GetNaturalSize() const
+{
+  Vector2 naturalSize( CalculateNaturalSize() );
+  return Vector3( naturalSize.width, naturalSize.height, CalculateSizeZ( naturalSize ) );
+}
+
+Vector2 ImageActor::CalculateNaturalSize() const
+{
+  // if no image then natural size is 0
+  Vector2 size( 0.0f, 0.0f );
+
+  ImagePtr image = mImageAttachment->GetImage();
+  if( image )
+  {
+    if( IsPixelAreaSet() )
+    {
+      PixelArea area(GetPixelArea());
+      size.width = area.width;
+      size.height = area.height;
+    }
+    else
+    {
+      size = image->GetNaturalSize();
+    }
+  }
+
+  return size;
+}
+
 void ImageActor::OnSizeSet( const Vector3& targetSize )
 {
   if( !mInternalSetSize )
index fb6aaca..d89970c 100644 (file)
@@ -181,6 +181,13 @@ public: // Default property extensions from ProxyObject
    */
   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
 
+public: // From Actor
+
+  /**
+   * @copydoc Dali::Actor::GetNaturalSize()
+   */
+  virtual Vector3 GetNaturalSize() const;
+
 private: // From RenderableActor
 
   /**
@@ -208,6 +215,13 @@ private:
   void SetNaturalSize();
 
   /**
+   * Calculate the natural size of this image actor
+   *
+   * @return Return the natural size as a Vector2
+   */
+  Vector2 CalculateNaturalSize() const;
+
+  /**
    * From Actor.
    * This is called after SizeSet() has been called.
    */
index 5ae1921..42dd751 100644 (file)
@@ -288,6 +288,12 @@ void TextActor::SetFont(Font& font, TextRequestMode mode )
   }
 }
 
+Vector3 TextActor::GetNaturalSize() const
+{
+  Vector2 naturalSize( mTextAttachment->GetNaturalTextSize() );
+  return Vector3( naturalSize.width, naturalSize.height, CalculateSizeZ( naturalSize ) );
+}
+
 void TextActor::OnSizeSet(const Vector3& targetSize)
 {
   if( !mInternalSetSize )
index 08494cd..7d7192b 100644 (file)
@@ -225,6 +225,13 @@ public:
    */
   bool IsFontDetectionAutomatic() const;
 
+public: // From Actor
+
+  /**
+   * @copydoc Dali::Actor::GetNaturalSize()
+   */
+  virtual Vector3 GetNaturalSize() const;
+
 private: // from Actor
 
   /**
index 6469997..284e45b 100644 (file)
@@ -230,6 +230,11 @@ Vector3 Actor::GetCurrentSize() const
   return GetImplementation(*this).GetCurrentSize();
 }
 
+Vector3 Actor::GetNaturalSize() const
+{
+  return GetImplementation(*this).GetNaturalSize();
+}
+
 void Actor::SetPosition(float x, float y)
 {
   GetImplementation(*this).SetPosition(x, y);
index da29650..631b591 100644 (file)
@@ -621,6 +621,15 @@ public:
   Vector3 GetCurrentSize() const;
 
   /**
+   * Return the natural size of the actor.
+   *
+   * Deriving classes stipulate the natural size and by default an actor has a ZERO natural size.
+   *
+   * @return The actor's natural size
+   */
+  Vector3 GetNaturalSize() const;
+
+  /**
    * @brief Sets the position of the actor.
    *
    * The Actor's z position will be set to 0.0f.
index df7ad32..071cb8f 100644 (file)
@@ -189,6 +189,13 @@ public:
    */
   virtual Dali::Actor GetChildByAlias(const std::string& actorAlias) = 0;
 
+  /**
+   * Return the natural size of the actor
+   *
+   * @return The actor's natural size
+   */
+  virtual Vector3 GetNaturalSize() = 0;
+
 protected: // For derived classes
 
   /**