Implement default height for width and width for height for visuals and remove obsole... 66/103566/2
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 8 Dec 2016 19:12:32 +0000 (19:12 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 9 Dec 2016 12:44:33 +0000 (12:44 +0000)
Change-Id: I7066e6c1456de146b80265c259e6f7f411268a3b

dali-toolkit/devel-api/visual-factory/visual-base.cpp
dali-toolkit/devel-api/visual-factory/visual-base.h
dali-toolkit/internal/controls/image-view/image-view-impl.cpp
dali-toolkit/internal/controls/image-view/image-view-impl.h
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h
dali-toolkit/internal/visuals/visual-base-impl.cpp
dali-toolkit/internal/visuals/visual-base-impl.h

index 4454e98..eea2b44 100644 (file)
@@ -66,11 +66,16 @@ void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size con
   GetImplementation( *this ).SetTransformAndSize( transform, controlSize );
 }
 
   GetImplementation( *this ).SetTransformAndSize( transform, controlSize );
 }
 
-float Visual::Base::GetHeightForWidth( float width ) const
+float Visual::Base::GetHeightForWidth( float width )
 {
   return GetImplementation( *this ).GetHeightForWidth( width );
 }
 
 {
   return GetImplementation( *this ).GetHeightForWidth( width );
 }
 
+float Visual::Base::GetWidthForHeight( float height )
+{
+  return GetImplementation( *this ).GetWidthForHeight( height );
+}
+
 void Visual::Base::GetNaturalSize(Vector2& naturalSize )
 {
   GetImplementation( *this ).GetNaturalSize( naturalSize );
 void Visual::Base::GetNaturalSize(Vector2& naturalSize )
 {
   GetImplementation( *this ).GetNaturalSize( naturalSize );
index 9e9fc64..f7ffb51 100644 (file)
@@ -142,7 +142,16 @@ public:
    *
    * @return The height based on the width.
    */
    *
    * @return The height based on the width.
    */
-  float GetHeightForWidth( float width ) const;
+  float GetHeightForWidth( float width );
+
+  /**
+   * @brief Returns the width for a given height.
+   *
+   * @param[in] height Height to use.
+   *
+   * @return The width based on the height.
+   */
+  float GetWidthForHeight( float height );
 
   /**
    * @brief Return the natural size of the visual.
 
   /**
    * @brief Return the natural size of the visual.
index ec0e177..80f1ee4 100644 (file)
@@ -73,76 +73,41 @@ Toolkit::ImageView ImageView::New()
 
 void ImageView::SetImage( Image image )
 {
 
 void ImageView::SetImage( Image image )
 {
-  if( ( mImage != image ) ||
-      ! mUrl.empty()      ||   // If we're changing from a URL type to an Image type
-      ! mPropertyMap.Empty() ) // If we're changing from a property map type to an Image type
-  {
-    mUrl.clear();
-    mPropertyMap.Clear();
-
-    mImage = image;
+  // Don't bother comparing if we had a visual previously, just drop old visual and create new one
+  mImage = image;
+  mUrl.clear();
+  mPropertyMap.Clear();
 
 
-    mVisual =  Toolkit::VisualFactory::Get().CreateVisual( image );
-    RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
-    mImageSize = image ? ImageDimensions( image.GetWidth(), image.GetHeight() ) : ImageDimensions( 0, 0 );
+  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( image );
+  RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
 
 
-    RelayoutRequest();
-  }
+  RelayoutRequest();
 }
 
 void ImageView::SetImage( const Property::Map& map )
 {
 }
 
 void ImageView::SetImage( const Property::Map& map )
 {
+  // Comparing a property map is too expensive so just creating a new visual
+  mPropertyMap = map;
   mUrl.clear();
   mImage.Reset();
   mUrl.clear();
   mImage.Reset();
-  mPropertyMap = map;
 
   mVisual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
   RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
 
 
   mVisual =  Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
   RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual  );
 
-  Property::Value* widthValue = mPropertyMap.Find( "width" );
-  if( widthValue )
-  {
-    int width;
-    if( widthValue->Get( width ) )
-    {
-      mImageSize = ImageDimensions( width, mImageSize.GetHeight() );
-    }
-  }
-
-  Property::Value* heightValue = mPropertyMap.Find( "height" );
-  if( heightValue )
-  {
-    int height;
-    if( heightValue->Get( height ) )
-    {
-      mImageSize = ImageDimensions( mImageSize.GetWidth(), height );
-    }
-  }
-
   RelayoutRequest();
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
 {
   RelayoutRequest();
 }
 
 void ImageView::SetImage( const std::string& url, ImageDimensions size )
 {
-  if( ( mUrl != url ) ||
-        mImage        ||       // If we're changing from an Image type to a URL type
-      ! mPropertyMap.Empty() ) // If we're changing from a property map type to a URL type
-  {
-    mImage.Reset();
-    mPropertyMap.Clear();
-
-    mUrl = url;
-
-    if( size.GetWidth() != 0u && size.GetHeight() != 0u )
-    {
-      mImageSize = size;
-    }
+  // Don't bother comparing if we had a visual previously, just drop old visual and create new one
+  mUrl = url;
+  mImage.Reset();
+  mPropertyMap.Clear();
 
 
-    mVisual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
-    RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
+  mVisual =  Toolkit::VisualFactory::Get().CreateVisual( url, size );
+  RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
 
 
-    RelayoutRequest();
-  }
+  RelayoutRequest();
 }
 
 Image ImageView::GetImage() const
 }
 
 Image ImageView::GetImage() const
@@ -184,27 +149,15 @@ Vector3 ImageView::GetNaturalSize()
     return Vector3( rendererNaturalSize );
   }
 
     return Vector3( rendererNaturalSize );
   }
 
-  Vector3 size;
-  size.x = mImageSize.GetWidth();
-  size.y = mImageSize.GetHeight();
-
-  if( size.x > 0 && size.y > 0 )
-  {
-    size.z = std::min(size.x, size.y);
-    return size;
-  }
-  else
-  {
-    // if no image then use Control's natural size
-    return Control::GetNaturalSize();
-  }
+  // if no visual then use Control's natural size
+  return Control::GetNaturalSize();
 }
 
 float ImageView::GetHeightForWidth( float width )
 {
 }
 
 float ImageView::GetHeightForWidth( float width )
 {
-  if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 )
+  if( mVisual )
   {
   {
-    return GetHeightForWidthBase( width );
+    return mVisual.GetHeightForWidth( width );
   }
   else
   {
   }
   else
   {
@@ -214,9 +167,9 @@ float ImageView::GetHeightForWidth( float width )
 
 float ImageView::GetWidthForHeight( float height )
 {
 
 float ImageView::GetWidthForHeight( float height )
 {
-  if( mImageSize.GetWidth() > 0 && mImageSize.GetHeight() > 0 )
+  if( mVisual )
   {
   {
-    return GetWidthForHeightBase( height );
+    return mVisual.GetWidthForHeight( height );
   }
   else
   {
   }
   else
   {
index 2dec681..ac76e78 100644 (file)
@@ -149,7 +149,6 @@ private:
 
 private:
   Toolkit::Visual::Base  mVisual;
 
 private:
   Toolkit::Visual::Base  mVisual;
-  ImageDimensions        mImageSize;
 
   std::string      mUrl;          ///< the url for the image if the image came from a URL, empty otherwise
   Image            mImage;        ///< the Image if the image came from a Image, null otherwise
 
   std::string      mUrl;          ///< the url for the image if the image came from a URL, empty otherwise
   Image            mImage;        ///< the Image if the image came from a Image, null otherwise
index 930d631..4f2fb6e 100644 (file)
@@ -522,13 +522,11 @@ TextureSet ImageVisual::CreateTextureSet( Vector4& textureRect, const std::strin
 
 void ImageVisual::InitializeRenderer( const std::string& imageUrl )
 {
 
 void ImageVisual::InitializeRenderer( const std::string& imageUrl )
 {
-  DALI_ASSERT_DEBUG( !mImpl->mRenderer && "Renderer should have been removed from stage and already reset before initialization" );
-
   mImageUrl = imageUrl;
   mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
 
   if( !mImpl->mCustomShader &&
   mImageUrl = imageUrl;
   mImpl->mFlags &= ~Impl::IS_ATLASING_APPLIED;
 
   if( !mImpl->mCustomShader &&
-      ( strncasecmp( imageUrl.c_str(), HTTP_URL,  sizeof(HTTP_URL)  -1 ) != 0 ) && // ignore remote images
+      ( strncasecmp( imageUrl.c_str(), HTTP_URL,  sizeof(HTTP_URL)  -1 ) != 0 ) && // dont atlas remote images
       ( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) )
   {
     bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
       ( strncasecmp( imageUrl.c_str(), HTTPS_URL, sizeof(HTTPS_URL) -1 ) != 0 ) )
   {
     bool defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
@@ -586,7 +584,6 @@ void ImageVisual::InitializeRenderer( const std::string& imageUrl )
 
 void ImageVisual::InitializeRenderer( const Image& image )
 {
 
 void ImageVisual::InitializeRenderer( const Image& image )
 {
-  DALI_ASSERT_DEBUG( !mImpl->mRenderer && "Renderer should have been removed from stage and already reset before initialization" );
 
   mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
 
 
   mImpl->mFlags &= ~Impl::IS_FROM_CACHE;
 
index e7b40a8..03bcfae 100644 (file)
@@ -139,7 +139,7 @@ TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache )
   return new TextVisual( factoryCache );
 }
 
   return new TextVisual( factoryCache );
 }
 
-float TextVisual::GetHeightForWidth( float width ) const
+float TextVisual::GetHeightForWidth( float width )
 {
   return mController->GetHeightForWidth( width );
 }
 {
   return mController->GetHeightForWidth( width );
 }
index 7cee7bf..c5b0efd 100644 (file)
@@ -80,7 +80,7 @@ public: // from Visual::Base
   /**
    * @copydoc Visual::Base::GetHeightForWidth()
    */
   /**
    * @copydoc Visual::Base::GetHeightForWidth()
    */
-  virtual float GetHeightForWidth( float width ) const;
+  virtual float GetHeightForWidth( float width );
 
   /**
    * @copydoc Visual::Base::GetNaturalSize()
 
   /**
    * @copydoc Visual::Base::GetNaturalSize()
index 0abe256..a8ae21c 100644 (file)
@@ -120,9 +120,28 @@ const std::string& Visual::Base::GetName()
   return mImpl->mName;
 }
 
   return mImpl->mName;
 }
 
-float Visual::Base::GetHeightForWidth( float width ) const
+float Visual::Base::GetHeightForWidth( float width )
 {
 {
-  return 0.f;
+  float aspectCorrectedHeight = 0.f;
+  Vector2 naturalSize;
+  GetNaturalSize( naturalSize );
+  if( naturalSize.width )
+  {
+    aspectCorrectedHeight = naturalSize.height * width / naturalSize.width;
+  }
+  return aspectCorrectedHeight;
+}
+
+float Visual::Base::GetWidthForHeight( float height )
+{
+  float aspectCorrectedWidth = 0.f;
+  Vector2 naturalSize;
+  GetNaturalSize( naturalSize );
+  if( naturalSize.height > 0.0f )
+  {
+    aspectCorrectedWidth = naturalSize.width * height / naturalSize.height;
+  }
+  return aspectCorrectedWidth;
 }
 
 void Visual::Base::GetNaturalSize( Vector2& naturalSize )
 }
 
 void Visual::Base::GetNaturalSize( Vector2& naturalSize )
index 1c7039b..1a84b2d 100644 (file)
@@ -89,7 +89,12 @@ public:
   /**
    * @copydoc Toolkit::Visual::Base::GetHeightForWidth
    */
   /**
    * @copydoc Toolkit::Visual::Base::GetHeightForWidth
    */
-  virtual float GetHeightForWidth( float width ) const;
+  virtual float GetHeightForWidth( float width );
+
+  /**
+   * @copydoc Toolkit::Visual::Base::GetWidthForHeight
+   */
+  virtual float GetWidthForHeight( float height );
 
   /**
    * @copydoc Toolkit::Visual::Base::GetNaturalSize
 
   /**
    * @copydoc Toolkit::Visual::Base::GetNaturalSize