Change-Id: I96a16ce938ec0a160f9ba3b98a3e7f4a4af16850
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
const char* VERTEX_SHADER = MAKE_SHADER(
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
const char* VERTEX_SHADER = MAKE_SHADER(
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
+attribute mediump vec4 aColor;
uniform mediump vec2 uOffset;
uniform mediump mat4 uMvpMatrix;
varying mediump vec2 vTexCoord;
uniform mediump vec2 uOffset;
uniform mediump mat4 uMvpMatrix;
varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
void main()
{
mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
void main()
{
mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
}
);
const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
}
);
const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
-uniform lowp vec4 uColor;
uniform sampler2D sTexture;
varying mediump vec2 vTexCoord;
uniform sampler2D sTexture;
varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
void main()
{
mediump vec4 color = texture2D( sTexture, vTexCoord );
void main()
{
mediump vec4 color = texture2D( sTexture, vTexCoord );
- gl_FragColor = vec4( uColor.rgb, uColor.a * color.r );
+ gl_FragColor = vec4( vColor.rgb, vColor.a * color.r );
{
Vector2 mPosition; ///< Vertex posiiton
Vector2 mTexCoords; ///< Vertex texture co-ordinates
{
Vector2 mPosition; ///< Vertex posiiton
Vector2 mTexCoords; ///< Vertex texture co-ordinates
+ Vector4 mColor; ///< Vertex color
struct MeshRecord
{
MeshRecord()
struct MeshRecord
{
MeshRecord()
- : mColor( Color::BLACK ),
- mAtlasId( 0 )
uint32_t mAtlasId;
AtlasManager::Mesh2D mMesh;
FrameBufferImage mBuffer;
uint32_t mAtlasId;
AtlasManager::Mesh2D mMesh;
FrameBufferImage mBuffer;
mRight( 0.0f ),
mUnderlinePosition( 0.0f ),
mUnderlineThickness( 0.0f ),
mRight( 0.0f ),
mUnderlinePosition( 0.0f ),
mUnderlineThickness( 0.0f ),
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
+ mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
void AddGlyphs( Text::ViewInterface& view,
const Vector<Vector2>& positions,
const Vector<GlyphInfo>& glyphs,
void AddGlyphs( Text::ViewInterface& view,
const Vector<Vector2>& positions,
const Vector<GlyphInfo>& glyphs,
+ const Vector<Vector4>& colors,
int depth )
{
AtlasManager::AtlasSlot slot;
int depth )
{
AtlasManager::AtlasSlot slot;
const Vector2& actorSize( view.GetControlSize() );
const Vector2 halfActorSize( actorSize * 0.5f );
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() );
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();
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 )
{
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,
// 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,
position.y + glyph.yBearing,
underlineGlyph,
currentUnderlinePosition,
position.y + glyph.yBearing,
underlineGlyph,
currentUnderlinePosition,
if( thereAreUnderlinedGlyphs )
{
// Check to see if any of the text needs an underline
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
}
// For each MeshData object, create a mesh actor and add to the renderable actor
// Create an effect if necessary
if( style == STYLE_DROP_SHADOW )
{
// 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 );
// 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
#if defined(DEBUG_ENABLED)
shadowActor.SetName( "Text Shadow renderable actor" );
#endif
shadowActor.RegisterProperty("uOffset", shadowOffset );
if( actor.GetRendererCount() )
{
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.SetParentOrigin( ParentOrigin::CENTER );
shadowActor.SetSize( actorSize );
- shadowActor.SetColor( shadowColor );
containerActor.Add( shadowActor );
containerActor.Add( actor );
actor = containerActor;
containerActor.Add( shadowActor );
containerActor.Add( actor );
actor = containerActor;
actor.AddRenderer( renderer );
actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
actor.SetSize( actorSize );
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;
}
actor.RegisterProperty("uOffset", Vector2::ZERO );
return actor;
}
void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
AtlasManager::Mesh2D& newMesh,
Vector< Extent >& extents,
void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
AtlasManager::Mesh2D& newMesh,
Vector< Extent >& extents,
float baseLine,
bool underlineGlyph,
float underlinePosition,
float baseLine,
bool underlineGlyph,
float underlinePosition,
mIt != mEndIt;
++mIt, ++index )
{
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 );
{
// 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 meshRecord;
meshRecord.mAtlasId = slot.mAtlasId;
meshRecord.mMesh = newMesh;
- meshRecord.mColor = color;
meshContainer.push_back( meshRecord );
if( underlineGlyph )
meshContainer.push_back( meshRecord );
if( underlineGlyph )
void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
Vector< Extent >& extents,
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;
{
AtlasManager::Mesh2D newMesh;
unsigned short faceIndex = 0;
newMesh.mIndices.PushBack( faceIndex + 1u );
faceIndex += 4;
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<Vector2> positions;
positions.Resize( numberOfGlyphs );
+ Vector<Vector4> colors;
+ colors.Resize( numberOfGlyphs, view.GetTextColor() );
+
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
+ colors.Resize( numberOfGlyphs );
mImpl->AddGlyphs( view,
positions,
glyphs,
mImpl->AddGlyphs( view,
positions,
glyphs,
depth );
/* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
depth );
/* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
* @note The returned number of glyphs may be less than @p numberOfGlyphs if a line has ellipsis.
*
* @param[out] glyphs Pointer to a buffer where the glyphs are copied.
* @note The returned number of glyphs may be less than @p numberOfGlyphs if a line has ellipsis.
*
* @param[out] glyphs Pointer to a buffer where the glyphs are copied.
- * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
+ * @param[out] glyphPositions Pointer to a buffer where the glyph's positions are copied.
+ * @param[out] colors Pointer to a buffer where the glyph's colors are copied.
* @param[in] glyphIndex Index to the first glyph.
* @param[in] numberOfGlyphs Number of glyphs to be copied.
*
* @param[in] glyphIndex Index to the first glyph.
* @param[in] numberOfGlyphs Number of glyphs to be copied.
*
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const = 0;
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const = 0;
Length View::GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
Length View::GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const
{
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const
{
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const;
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const;