#include <dali/devel-api/text-abstraction/font-client.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
#include <dali-toolkit/internal/text/glyph-run.h>
#include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
#include <dali-toolkit/internal/text/rendering/atlas/atlas-mesh-factory.h>
struct MeshRecord
{
MeshRecord()
- : mColor( Color::BLACK ),
- mAtlasId( 0 )
+ : mAtlasId( 0u )
{
}
- Vector4 mColor;
uint32_t mAtlasId;
AtlasManager::Mesh2D mMesh;
FrameBufferImage mBuffer;
mRight( 0.0f ),
mUnderlinePosition( 0.0f ),
mUnderlineThickness( 0.0f ),
- mMeshRecordIndex( 0 )
+ mMeshRecordIndex( 0u )
{
}
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
+ mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
void AddGlyphs( Text::ViewInterface& view,
const Vector<Vector2>& positions,
const Vector<GlyphInfo>& glyphs,
+ const Vector<Vector4>& colors,
int depth )
{
AtlasManager::AtlasSlot slot;
const Vector2& actorSize( view.GetControlSize() );
const Vector2 halfActorSize( actorSize * 0.5f );
- const Vector4& textColor( view.GetTextColor() );
const Vector2& shadowOffset( view.GetShadowOffset() );
const Vector4& shadowColor( view.GetShadowColor() );
const bool underlineEnabled( view.IsUnderlineEnabled() );
Vector< TextCacheEntry > newTextCache;
const GlyphInfo* const glyphsBuffer = glyphs.Begin();
const Vector2* const positionsBuffer = positions.Begin();
+ const Vector4* const colorsBuffer = colors.Begin();
for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
{
}
}
+ // Get the color of the character.
+ const Vector4& color = *( colorsBuffer + i );
+
+ for( unsigned int index = 0u, size = newMesh.mVertices.Count();
+ index < size;
+ ++index )
+ {
+ AtlasManager::Vertex2D& vertex = *( verticesBuffer + index );
+
+ // Set the color of the vertex.
+ vertex.mColor = color;
+ }
+
// Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
StitchTextMesh( meshContainer,
newMesh,
extents,
- textColor,
position.y + glyph.yBearing,
underlineGlyph,
currentUnderlinePosition,
if( thereAreUnderlinedGlyphs )
{
// Check to see if any of the text needs an underline
- GenerateUnderlines( meshContainer, extents, underlineColor, textColor );
+ GenerateUnderlines( meshContainer, extents, underlineColor );
}
// For each MeshData object, create a mesh actor and add to the renderable actor
// Create an effect if necessary
if( style == STYLE_DROP_SHADOW )
{
+ // Change the color of the vertices.
+ for( Vector<AtlasManager::Vertex2D>::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
+ vEndIt = meshRecord.mMesh.mVertices.End();
+ vIt != vEndIt;
+ ++vIt )
+ {
+ AtlasManager::Vertex2D& vertex = *vIt;
+
+ vertex.mColor = shadowColor;
+ }
+
// Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
Actor containerActor = Actor::New();
containerActor.SetParentOrigin( ParentOrigin::CENTER );
containerActor.SetSize( actorSize );
- Actor shadowActor = Actor::New();
+ Actor shadowActor = CreateMeshActor( meshRecord, actorSize );
#if defined(DEBUG_ENABLED)
shadowActor.SetName( "Text Shadow renderable actor" );
#endif
shadowActor.RegisterProperty("uOffset", shadowOffset );
if( actor.GetRendererCount() )
{
- Dali::Renderer renderer( actor.GetRendererAt( 0 ) );
- Geometry geometry = renderer.GetGeometry();
- Material material = renderer.GetMaterial();
-
- Dali::Renderer shadowRenderer = Dali::Renderer::New( geometry, material );
- shadowRenderer.SetDepthIndex( renderer.GetDepthIndex() - 1 );
- shadowActor.AddRenderer( shadowRenderer );
+ Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
+ renderer.SetDepthIndex( renderer.GetDepthIndex() - 1 );
shadowActor.SetParentOrigin( ParentOrigin::CENTER );
shadowActor.SetSize( actorSize );
- shadowActor.SetColor( shadowColor );
containerActor.Add( shadowActor );
containerActor.Add( actor );
actor = containerActor;
Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
- renderer.SetDepthIndex( CONTENT_DEPTH_INDEX + mDepth );
+ renderer.SetDepthIndex( DepthIndex::CONTENT + mDepth );
Actor actor = Actor::New();
#if defined(DEBUG_ENABLED)
actor.SetName( "Text renderable actor" );
actor.AddRenderer( renderer );
actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
actor.SetSize( actorSize );
- actor.SetColor( meshRecord.mColor );
actor.RegisterProperty("uOffset", Vector2::ZERO );
return actor;
}
void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
AtlasManager::Mesh2D& newMesh,
Vector< Extent >& extents,
- const Vector4& color,
float baseLine,
bool underlineGlyph,
float underlinePosition,
mIt != mEndIt;
++mIt, ++index )
{
- if( slot.mAtlasId == mIt->mAtlasId && color == mIt->mColor )
+ if( slot.mAtlasId == mIt->mAtlasId )
{
// Append the mesh to the existing mesh and adjust any extents
Toolkit::Internal::AtlasMeshFactory::AppendMesh( mIt->mMesh, newMesh );
MeshRecord meshRecord;
meshRecord.mAtlasId = slot.mAtlasId;
meshRecord.mMesh = newMesh;
- meshRecord.mColor = color;
meshContainer.push_back( meshRecord );
if( underlineGlyph )
void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
Vector< Extent >& extents,
- const Vector4& underlineColor,
- const Vector4& textColor )
+ const Vector4& underlineColor )
{
AtlasManager::Mesh2D newMesh;
unsigned short faceIndex = 0;
newMesh.mIndices.PushBack( faceIndex + 1u );
faceIndex += 4;
- if( underlineColor == textColor )
- {
- Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
- }
- else
- {
- MeshRecord record;
- record.mMesh = newMesh;
- record.mAtlasId = meshRecords[ index ].mAtlasId;
- record.mColor = underlineColor;
- meshRecords.push_back( record );
- }
+ vert.mColor = underlineColor;
+
+ Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
}
}
Vector<Vector2> positions;
positions.Resize( numberOfGlyphs );
+ Vector<Vector4> colors;
+ colors.Resize( numberOfGlyphs, view.GetTextColor() );
+
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
+ colors.Begin(),
0u,
numberOfGlyphs );
+
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
+ colors.Resize( numberOfGlyphs );
mImpl->AddGlyphs( view,
positions,
glyphs,
+ colors,
depth );
/* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */