Make internal actors size match TextLabel size 76/44076/3
authorPaul Wisbey <p.wisbey@samsung.com>
Thu, 16 Jul 2015 12:22:58 +0000 (13:22 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Thu, 16 Jul 2015 15:02:30 +0000 (16:02 +0100)
Change-Id: I9a874e714d482553da446bdea112f3155cc3e84e

dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp
dali-toolkit/internal/text/decorator/text-decorator.h
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-view-interface.h
dali-toolkit/internal/text/text-view.cpp
dali-toolkit/internal/text/text-view.h
dali-toolkit/internal/text/visual-model-impl.h

index dfdff15..71d0ae0 100644 (file)
@@ -50,13 +50,11 @@ namespace
   attribute mediump vec2    aPosition;
   attribute mediump vec2    aTexCoord;
   uniform   mediump mat4    uMvpMatrix;
-  uniform   mediump vec3    uSize;
   varying   mediump vec2    vTexCoord;
 
   void main()
   {
     mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
-    position.xyz *= uSize;
     gl_Position = uMvpMatrix * position;
     vTexCoord = aTexCoord;
   }
index 4a1fc5f..c77ec94 100644 (file)
@@ -126,9 +126,9 @@ public:
     virtual ~ControllerInterface() {};
 
     /**
-     * @brief An input event from one of the handles.
+     * @brief Query the target size of the UI control.
      *
-     * @param[out] targetSize The Size of the UI control the decorator is adding it's decorations to.
+     * @param[out] targetSize The size of the UI control the decorator is adding it's decorations to.
      */
     virtual void GetTargetSize( Vector2& targetSize ) = 0;
 
index fe8da41..a141166 100644 (file)
@@ -35,13 +35,11 @@ const char* VERTEX_SHADER = MAKE_SHADER(
 attribute mediump vec2    aPosition;
 attribute mediump vec2    aTexCoord;
 uniform   mediump mat4    uMvpMatrix;
-uniform   mediump vec3    uSize;
 varying   mediump vec2    vTexCoord;
 
 void main()
 {
   mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
-  position.xyz *= uSize;
   gl_Position = uMvpMatrix * position;
   vTexCoord = aTexCoord;
 }
@@ -60,13 +58,11 @@ void main()
 const char* VERTEX_SHADER_SHADOW = MAKE_SHADER(
 attribute mediump vec2    aPosition;
 attribute mediump vec2    aTexCoord;
-uniform   mediump vec3    uSize;
 varying   mediump vec2    vTexCoord;
 
 void main()
 {
   mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
-  position.xyz *= uSize;
   gl_Position = position;
   vTexCoord = aTexCoord;
 }
index d0cedf4..e6d548f 100644 (file)
@@ -107,14 +107,9 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     mQuadIndexFormat[ "indices" ] = Property::INTEGER;
   }
 
-  void AddGlyphs( const std::vector<Vector2>& positions,
+  void AddGlyphs( Text::ViewInterface& view,
+                  const std::vector<Vector2>& positions,
                   const Vector<GlyphInfo>& glyphs,
-                  const Vector4& textColor,
-                  const Vector2& shadowOffset,
-                  const Vector4& shadowColor,
-                  bool underlineEnabled,
-                  const Vector4& underlineColor,
-                  float underlineHeight,
                   int depth )
   {
     AtlasManager::AtlasSlot slot;
@@ -123,6 +118,15 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     TextCacheEntry textCacheEntry;
     mDepth = depth;
 
+    const Vector2& actorSize( view.GetControlSize() );
+    Vector2 halfActorSize( actorSize * 0.5f );
+    const Vector4& textColor( view.GetTextColor() );
+    const Vector2& shadowOffset( view.GetShadowOffset() );
+    const Vector4& shadowColor( view.GetShadowColor() );
+    bool underlineEnabled( view.IsUnderlineEnabled() );
+    const Vector4& underlineColor( view.GetUnderlineColor() );
+    float underlineHeight( view.GetUnderlineHeight() );
+
     float currentUnderlinePosition = ZERO;
     float currentUnderlineThickness = underlineHeight;
     uint32_t currentBlockSize = 0;
@@ -182,9 +186,6 @@ struct AtlasRenderer::Impl : public ConnectionTracker
           }
         }
 
-        const Vector2& position = positions[ i ];
-        AtlasManager::Mesh2D newMesh;
-
         if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) )
         {
           // Select correct size for new atlas if needed....?
@@ -238,7 +239,11 @@ struct AtlasRenderer::Impl : public ConnectionTracker
           mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ );
         }
 
+        // Move the origin (0,0) of the mesh to the center of the actor
+        Vector2 position = positions[ i ] - halfActorSize;
+
         // Generate mesh data for this quad, plugging in our supplied position
+        AtlasManager::Mesh2D newMesh;
         mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
         textCacheEntry.mFontId = glyph.fontId;
         textCacheEntry.mImageId = slot.mImageId;
@@ -273,17 +278,16 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     {
       for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt )
       {
-        Actor actor = CreateMeshActor( *mIt );
+        Actor actor = CreateMeshActor( *mIt, actorSize );
 
         // Create an effect if necessary
         if ( style == STYLE_DROP_SHADOW )
         {
-          actor.Add( GenerateShadow( *mIt, shadowOffset, shadowColor ) );
+          actor.Add( GenerateShadow( *mIt, actorSize, shadowOffset, shadowColor ) );
         }
 
         if( mActor )
         {
-          actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
           mActor.Add( actor );
         }
         else
@@ -325,7 +329,7 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     mTextCache.Resize( 0 );
   }
 
-  Actor CreateMeshActor( const MeshRecord& meshRecord )
+  Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize )
   {
     PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() );
     PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
@@ -344,7 +348,8 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     actor.SetName( "Text renderable actor" );
 #endif
     actor.AddRenderer( renderer );
-    actor.SetSize( 1.0f, 1.0f );
+    actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
+    actor.SetSize( actorSize );
     actor.SetColor( meshRecord.mColor );
 
     if ( meshRecord.mIsUnderline )
@@ -555,6 +560,7 @@ struct AtlasRenderer::Impl : public ConnectionTracker
   }
 
   Actor GenerateShadow( MeshRecord& meshRecord,
+                        const Vector2& actorSize,
                         const Vector2& shadowOffset,
                         const Vector4& shadowColor )
   {
@@ -621,7 +627,8 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth - 1 );
     Actor actor = Actor::New();
     actor.AddRenderer( renderer );
-    actor.SetSize( 1.0f, 1.0f );
+    actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
+    actor.SetSize( actorSize );
 
     // Create a sub actor to render the source with normalized vertex positions
     Vector< AtlasManager::Vertex2D > normVertexList;
@@ -648,7 +655,8 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     Dali::Renderer normRenderer = Dali::Renderer::New( normGeometry, normMaterial );
     Actor subActor = Actor::New();
     subActor.AddRenderer( normRenderer );
-    subActor.SetSize( 1.0f, 1.0f );
+    subActor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
+    subActor.SetSize( actorSize );
     subActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
     subActor.SetColor( shadowColor );
 
@@ -723,14 +731,9 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
     glyphs.Resize( numberOfGlyphs );
     positions.resize( numberOfGlyphs );
 
-    mImpl->AddGlyphs( positions,
+    mImpl->AddGlyphs( view,
+                      positions,
                       glyphs,
-                      view.GetTextColor(),
-                      view.GetShadowOffset(),
-                      view.GetShadowColor(),
-                      view.IsUnderlineEnabled(),
-                      view.GetUnderlineColor(),
-                      view.GetUnderlineHeight(),
                       depth );
   }
 
index 12fbb2f..fb448ce 100644 (file)
@@ -726,7 +726,7 @@ void Controller::Impl::OnHandleEvent( const Event& event )
       Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE );
 
       // Position the grag handle close to either the left or right edge.
-      position.x = scrollRightDirection ? 0.f : mControlSize.width;
+      position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
 
       // Get the new handle position.
       // The grab handle's position is in decorator coords. Need to transforms to text coords.
@@ -747,7 +747,7 @@ void Controller::Impl::OnHandleEvent( const Event& event )
       Vector2 position = mEventData->mDecorator->GetPosition( leftSelectionHandleEvent ? Text::LEFT_SELECTION_HANDLE : Text::RIGHT_SELECTION_HANDLE );
 
       // Position the selection handle close to either the left or right edge.
-      position.x = scrollRightDirection ? 0.f : mControlSize.width;
+      position.x = scrollRightDirection ? 0.f : mVisualModel->mControlSize.width;
 
       // Get the new handle position.
       // The selection handle's position is in decorator coords. Need to transforms to text coords.
@@ -1619,12 +1619,12 @@ void Controller::Impl::UpdateCursorPosition()
       }
       case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
       {
-        cursorPosition.x = floor( 0.5f * mControlSize.width );
+        cursorPosition.x = floor( 0.5f * mVisualModel->mControlSize.width );
         break;
       }
       case LayoutEngine::HORIZONTAL_ALIGN_END:
       {
-        cursorPosition.x = mControlSize.width;
+        cursorPosition.x = mVisualModel->mControlSize.width;
         break;
       }
     }
@@ -1638,12 +1638,12 @@ void Controller::Impl::UpdateCursorPosition()
       }
       case LayoutEngine::VERTICAL_ALIGN_CENTER:
       {
-        cursorPosition.y = floorf( 0.5f * ( mControlSize.height - lineHeight ) );
+        cursorPosition.y = floorf( 0.5f * ( mVisualModel->mControlSize.height - lineHeight ) );
         break;
       }
       case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
       {
-        cursorPosition.y = mControlSize.height - lineHeight;
+        cursorPosition.y = mVisualModel->mControlSize.height - lineHeight;
         break;
       }
     }
@@ -1728,9 +1728,9 @@ void Controller::Impl::UpdateSelectionHandle( HandleType handleType )
 void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
 {
   // Clamp between -space & 0 (and the text alignment).
-  if( actualSize.width > mControlSize.width )
+  if( actualSize.width > mVisualModel->mControlSize.width )
   {
-    const float space = ( actualSize.width - mControlSize.width ) + mAlignmentOffset.x;
+    const float space = ( actualSize.width - mVisualModel->mControlSize.width ) + mAlignmentOffset.x;
     mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x < -space ) ? -space : mEventData->mScrollPosition.x;
     mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x > -mAlignmentOffset.x ) ? -mAlignmentOffset.x : mEventData->mScrollPosition.x;
 
@@ -1745,9 +1745,9 @@ void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
 void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
 {
   // Clamp between -space & 0 (and the text alignment).
-  if( actualSize.height > mControlSize.height )
+  if( actualSize.height > mVisualModel->mControlSize.height )
   {
-    const float space = ( actualSize.height - mControlSize.height ) + mAlignmentOffset.y;
+    const float space = ( actualSize.height - mVisualModel->mControlSize.height ) + mAlignmentOffset.y;
     mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y < -space ) ? -space : mEventData->mScrollPosition.y;
     mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y > -mAlignmentOffset.y ) ? -mAlignmentOffset.y : mEventData->mScrollPosition.y;
 
@@ -1769,9 +1769,9 @@ void Controller::Impl::ScrollToMakePositionVisible( const Vector2& position )
     mEventData->mScrollPosition.x += offset.x;
     updateDecorator = true;
   }
-  else if( position.x > mControlSize.width )
+  else if( position.x > mVisualModel->mControlSize.width )
   {
-    offset.x = mControlSize.width - position.x;
+    offset.x = mVisualModel->mControlSize.width - position.x;
     mEventData->mScrollPosition.x += offset.x;
     updateDecorator = true;
   }
index 79f56d3..83aafe4 100644 (file)
@@ -209,7 +209,6 @@ struct Controller::Impl
     mView(),
     mLayoutEngine(),
     mModifyEvents(),
-    mControlSize(),
     mTextColor( Color::BLACK ),
     mAlignmentOffset(),
     mOperationsPending( NO_OPERATION ),
@@ -466,7 +465,6 @@ struct Controller::Impl
   View mView;                              ///< The view interface to the rendering back-end.
   LayoutEngine mLayoutEngine;              ///< The layout engine.
   std::vector<ModifyEvent> mModifyEvents;  ///< Temporary stores the text set until the next relayout.
-  Size mControlSize;                       ///< The size of the control.
   Vector4 mTextColor;                      ///< The regular text color
   Vector2 mAlignmentOffset;                ///< Vertical and horizontal offset of the whole text inside the control due to alignment.
   OperationsMask mOperationsPending;       ///< Operations pending to be done to layout the text.
index 8425f56..8b2b476 100644 (file)
@@ -564,7 +564,7 @@ float Controller::GetHeightForWidth( float width )
   ProcessModifyEvents();
 
   Size layoutSize;
-  if( width != mImpl->mControlSize.width )
+  if( width != mImpl->mVisualModel->mControlSize.width )
   {
     // Operations that can be done only once until the text changes.
     const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32  |
@@ -621,9 +621,9 @@ bool Controller::Relayout( const Size& size )
     return glyphsRemoved;
   }
 
-  if( size != mImpl->mControlSize )
+  if( size != mImpl->mVisualModel->mControlSize )
   {
-    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mControlSize.width, mImpl->mControlSize.height );
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mVisualModel->mControlSize.width, mImpl->mVisualModel->mControlSize.height );
 
     // Operations that need to be done if the size changes.
     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
@@ -632,7 +632,7 @@ bool Controller::Relayout( const Size& size )
                                                              UPDATE_ACTUAL_SIZE        |
                                                              REORDER );
 
-    mImpl->mControlSize = size;
+    mImpl->mVisualModel->mControlSize = size;
   }
 
   // Make sure the model is up-to-date before layouting
@@ -640,7 +640,7 @@ bool Controller::Relayout( const Size& size )
   mImpl->UpdateModel( mImpl->mOperationsPending );
 
   Size layoutSize;
-  bool updated = DoRelayout( mImpl->mControlSize,
+  bool updated = DoRelayout( mImpl->mVisualModel->mControlSize,
                              mImpl->mOperationsPending,
                              layoutSize );
 
@@ -1460,7 +1460,7 @@ void Controller::SelectEvent( float x, float y, bool selectAll )
 
 void Controller::GetTargetSize( Vector2& targetSize )
 {
-  targetSize = mImpl->mControlSize;
+  targetSize = mImpl->mVisualModel->mControlSize;
 }
 
 void Controller::AddDecoration( Actor& actor, bool needsClipping )
index d8e2ae6..55e4aca 100644 (file)
@@ -60,6 +60,13 @@ public:
   virtual ~ViewInterface();
 
   /**
+   * @brief Retrieves the target size of the UI control.
+   *
+   * @return The text's size.
+   */
+  virtual const Vector2& GetControlSize() const = 0;
+
+  /**
    * Retrieves the number of glyphs.
    *
    * @return The number of glyphs.
index 34c3f32..621f26d 100644 (file)
@@ -55,6 +55,16 @@ void View::SetVisualModel( VisualModelPtr visualModel )
   mImpl->mVisualModel = visualModel;
 }
 
+const Vector2& View::GetControlSize() const
+{
+  if ( mImpl->mVisualModel )
+  {
+    return mImpl->mVisualModel->mControlSize;
+  }
+
+  return Vector2::ZERO;
+}
+
 Length View::GetGlyphs( GlyphInfo* glyphs,
                         Vector2* glyphPositions,
                         GlyphIndex glyphIndex,
index 43506a5..b724faa 100644 (file)
@@ -58,6 +58,11 @@ public:
   void SetVisualModel( VisualModelPtr visualModel );
 
   /**
+   * @copydoc Dali::Toolkit::Text::ViewInterface::GetControlSize()
+   */
+  virtual const Vector2& GetControlSize() const;
+
+  /**
    * @copydoc Dali::Toolkit::Text::ViewInterface::GetNumberOfGlyphs()
    */
   virtual Length GetNumberOfGlyphs() const;
index f290ba5..57eaffd 100644 (file)
@@ -303,14 +303,13 @@ public:
   Vector<Vector2>        mGlyphPositions;       ///< For each glyph, the position.
   Vector<LineRun>        mLines;                ///< The laid out lines.
 
+  Vector2                mControlSize;           ///< The size of the UI control the decorator is adding it's decorations to.
   Vector4                mTextColor;            ///< The text color
   Vector4                mShadowColor;          ///< Color of drop shadow
   Vector4                mUnderlineColor;       ///< Color of underline
   Vector2                mShadowOffset;         ///< Offset for drop shadow, 0 indicates no shadow
   float                  mUnderlineHeight;      ///< Fixed height for underline to override font metrics.
 
-
-
 private:
 
   Size                   mNaturalSize;        ///< Size of the text with no line wrapping.