Change-Id: I9a874e714d482553da446bdea112f3155cc3e84e
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
uniform mediump mat4 uMvpMatrix;
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 );
varying mediump vec2 vTexCoord;
void main()
{
mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
}
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
}
virtual ~ControllerInterface() {};
/**
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;
*/
virtual void GetTargetSize( Vector2& targetSize ) = 0;
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
uniform mediump mat4 uMvpMatrix;
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 );
varying mediump vec2 vTexCoord;
void main()
{
mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
}
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
}
const char* VERTEX_SHADER_SHADOW = MAKE_SHADER(
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
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 );
varying mediump vec2 vTexCoord;
void main()
{
mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
gl_Position = position;
vTexCoord = aTexCoord;
}
gl_Position = position;
vTexCoord = aTexCoord;
}
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
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 Vector<GlyphInfo>& glyphs,
- const Vector4& textColor,
- const Vector2& shadowOffset,
- const Vector4& shadowColor,
- bool underlineEnabled,
- const Vector4& underlineColor,
- float underlineHeight,
int depth )
{
AtlasManager::AtlasSlot slot;
int depth )
{
AtlasManager::AtlasSlot slot;
TextCacheEntry textCacheEntry;
mDepth = depth;
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;
float currentUnderlinePosition = ZERO;
float currentUnderlineThickness = underlineHeight;
uint32_t currentBlockSize = 0;
- const Vector2& position = positions[ i ];
- AtlasManager::Mesh2D newMesh;
-
if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) )
{
// Select correct size for new atlas if needed....?
if ( !mGlyphManager.Cached( glyph.fontId, glyph.index, slot ) )
{
// Select correct size for new atlas if needed....?
mGlyphManager.AdjustReferenceCount( glyph.fontId, glyph.index, 1/*increment*/ );
}
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
// 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;
mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
textCacheEntry.mFontId = glyph.fontId;
textCacheEntry.mImageId = slot.mImageId;
{
for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt )
{
{
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 )
{
// Create an effect if necessary
if ( style == STYLE_DROP_SHADOW )
{
- actor.Add( GenerateShadow( *mIt, shadowOffset, shadowColor ) );
+ actor.Add( GenerateShadow( *mIt, actorSize, shadowOffset, shadowColor ) );
- actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
mActor.Add( actor );
}
else
mActor.Add( actor );
}
else
mTextCache.Resize( 0 );
}
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() );
{
PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() );
PropertyBuffer quadIndices = PropertyBuffer::New( mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
actor.SetName( "Text renderable actor" );
#endif
actor.AddRenderer( renderer );
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 )
actor.SetColor( meshRecord.mColor );
if ( meshRecord.mIsUnderline )
}
Actor GenerateShadow( MeshRecord& meshRecord,
}
Actor GenerateShadow( MeshRecord& meshRecord,
+ const Vector2& actorSize,
const Vector2& shadowOffset,
const Vector4& shadowColor )
{
const Vector2& shadowOffset,
const Vector4& shadowColor )
{
renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth - 1 );
Actor actor = Actor::New();
actor.AddRenderer( renderer );
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;
// Create a sub actor to render the source with normalized vertex positions
Vector< AtlasManager::Vertex2D > normVertexList;
Dali::Renderer normRenderer = Dali::Renderer::New( normGeometry, normMaterial );
Actor subActor = Actor::New();
subActor.AddRenderer( normRenderer );
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 );
subActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
subActor.SetColor( shadowColor );
glyphs.Resize( numberOfGlyphs );
positions.resize( numberOfGlyphs );
glyphs.Resize( numberOfGlyphs );
positions.resize( numberOfGlyphs );
- mImpl->AddGlyphs( positions,
+ mImpl->AddGlyphs( view,
+ positions,
- view.GetTextColor(),
- view.GetShadowOffset(),
- view.GetShadowColor(),
- view.IsUnderlineEnabled(),
- view.GetUnderlineColor(),
- view.GetUnderlineHeight(),
Vector2 position = mEventData->mDecorator->GetPosition( GRAB_HANDLE );
// Position the grag handle close to either the left or right edge.
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.
// Get the new handle position.
// The grab handle's position is in decorator coords. Need to transforms to text coords.
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.
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.
// Get the new handle position.
// The selection handle's position is in decorator coords. Need to transforms to text coords.
}
case LayoutEngine::HORIZONTAL_ALIGN_CENTER:
{
}
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:
{
break;
}
case LayoutEngine::HORIZONTAL_ALIGN_END:
{
- cursorPosition.x = mControlSize.width;
+ cursorPosition.x = mVisualModel->mControlSize.width;
}
case LayoutEngine::VERTICAL_ALIGN_CENTER:
{
}
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:
{
break;
}
case LayoutEngine::VERTICAL_ALIGN_BOTTOM:
{
- cursorPosition.y = mControlSize.height - lineHeight;
+ cursorPosition.y = mVisualModel->mControlSize.height - lineHeight;
void Controller::Impl::ClampHorizontalScroll( const Vector2& actualSize )
{
// Clamp between -space & 0 (and the text alignment).
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;
mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x < -space ) ? -space : mEventData->mScrollPosition.x;
mEventData->mScrollPosition.x = ( mEventData->mScrollPosition.x > -mAlignmentOffset.x ) ? -mAlignmentOffset.x : mEventData->mScrollPosition.x;
void Controller::Impl::ClampVerticalScroll( const Vector2& actualSize )
{
// Clamp between -space & 0 (and the text alignment).
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;
mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y < -space ) ? -space : mEventData->mScrollPosition.y;
mEventData->mScrollPosition.y = ( mEventData->mScrollPosition.y > -mAlignmentOffset.y ) ? -mAlignmentOffset.y : mEventData->mScrollPosition.y;
mEventData->mScrollPosition.x += offset.x;
updateDecorator = true;
}
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;
}
mEventData->mScrollPosition.x += offset.x;
updateDecorator = true;
}
mView(),
mLayoutEngine(),
mModifyEvents(),
mView(),
mLayoutEngine(),
mModifyEvents(),
mTextColor( Color::BLACK ),
mAlignmentOffset(),
mOperationsPending( NO_OPERATION ),
mTextColor( Color::BLACK ),
mAlignmentOffset(),
mOperationsPending( NO_OPERATION ),
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.
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.
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.
ProcessModifyEvents();
Size layoutSize;
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 |
{
// Operations that can be done only once until the text changes.
const OperationsMask onlyOnceOperations = static_cast<OperationsMask>( CONVERT_TO_UTF32 |
- 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 |
// Operations that need to be done if the size changes.
mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
UPDATE_ACTUAL_SIZE |
REORDER );
UPDATE_ACTUAL_SIZE |
REORDER );
- mImpl->mControlSize = size;
+ mImpl->mVisualModel->mControlSize = size;
}
// Make sure the model is up-to-date before layouting
}
// Make sure the model is up-to-date before layouting
mImpl->UpdateModel( mImpl->mOperationsPending );
Size layoutSize;
mImpl->UpdateModel( mImpl->mOperationsPending );
Size layoutSize;
- bool updated = DoRelayout( mImpl->mControlSize,
+ bool updated = DoRelayout( mImpl->mVisualModel->mControlSize,
mImpl->mOperationsPending,
layoutSize );
mImpl->mOperationsPending,
layoutSize );
void Controller::GetTargetSize( Vector2& targetSize )
{
void Controller::GetTargetSize( Vector2& targetSize )
{
- targetSize = mImpl->mControlSize;
+ targetSize = mImpl->mVisualModel->mControlSize;
}
void Controller::AddDecoration( Actor& actor, bool needsClipping )
}
void Controller::AddDecoration( Actor& actor, bool needsClipping )
virtual ~ViewInterface();
/**
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.
* Retrieves the number of glyphs.
*
* @return The number of glyphs.
mImpl->mVisualModel = 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,
Length View::GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
GlyphIndex glyphIndex,
void SetVisualModel( VisualModelPtr visualModel );
/**
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;
* @copydoc Dali::Toolkit::Text::ViewInterface::GetNumberOfGlyphs()
*/
virtual Length GetNumberOfGlyphs() const;
Vector<Vector2> mGlyphPositions; ///< For each glyph, the position.
Vector<LineRun> mLines; ///< The laid out lines.
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.
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.
private:
Size mNaturalSize; ///< Size of the text with no line wrapping.