/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <dali/integration-api/debug.h>
+#include <dali/devel-api/object/handle-devel.h>
//INTERNAL INCLUDES
+#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
#include <dali-toolkit/internal/visuals/visual-factory-impl.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
namespace
{
-const char * const COLOR_NAME("mixColor");
const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
attribute mediump vec2 aPosition;\n
uniform mediump mat4 uMvpMatrix;\n
uniform mediump vec3 uSize;\n
\n
+
+ //Visual size and offset
+ uniform mediump vec2 offset;\n
+ uniform mediump vec2 size;\n
+ uniform mediump vec4 offsetSizeMode;\n
+ uniform mediump vec2 origin;\n
+ uniform mediump vec2 anchorPoint;\n
+
+ vec4 ComputeVertexPosition()\n
+ {\n
+ vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );\n
+ vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n
+ return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n
+ }\n
+
void main()\n
{\n
- mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
- vertexPosition.xyz *= uSize;\n
- gl_Position = uMvpMatrix * vertexPosition;\n
+ gl_Position = uMvpMatrix * ComputeVertexPosition();\n
}\n
);
const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
uniform lowp vec4 uColor;\n
- uniform lowp vec4 mixColor;\n
+ uniform lowp vec3 mixColor;\n
+ uniform lowp float opacity;\n
\n
void main()\n
{\n
- gl_FragColor = mixColor*uColor;\n
+ gl_FragColor = vec4(mixColor, opacity)*uColor;\n
}\n
);
}
+ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
+{
+ ColorVisualPtr colorVisualPtr( new ColorVisual( factoryCache ) );
+ colorVisualPtr->SetProperties( properties );
+ return colorVisualPtr;
+}
+
ColorVisual::ColorVisual( VisualFactoryCache& factoryCache )
-: Visual::Base( factoryCache ),
- mMixColorIndex( Property::INVALID_INDEX )
+: Visual::Base( factoryCache, Visual::FittingMode::FILL ),
+ mRenderIfTransparent( false )
{
}
{
}
-void ColorVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
+void ColorVisual::DoSetProperties( const Property::Map& propertyMap )
{
- Property::Value* color = propertyMap.Find( COLOR_NAME );
- if( !( color && color->Get(mMixColor) ) )
+ // By virtue of DoSetProperties being called last, this will override
+ // anything set by Toolkit::Visual::Property::MIX_COLOR
+ Property::Value* colorValue = propertyMap.Find( Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR );
+ if( colorValue )
{
- DALI_LOG_ERROR( "Fail to provide a color to the ColorVisual object" );
+ Vector4 color;
+ if( colorValue->Get( color ) )
+ {
+ Property::Type type = colorValue->GetType();
+ if( type == Property::VECTOR4 )
+ {
+ SetMixColor( color );
+ }
+ else if( type == Property::VECTOR3 )
+ {
+ Vector3 color3(color);
+ SetMixColor( color3 );
+ }
+ }
+ else
+ {
+ DALI_LOG_ERROR("ColorVisual: mixColor property has incorrect type\n");
+ }
}
-}
-
-void ColorVisual::SetSize( const Vector2& size )
-{
- Visual::Base::SetSize( size );
- // ToDo: renderer responds to the size change
+ Property::Value* renderIfTransparentValue = propertyMap.Find( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, RENDER_IF_TRANSPARENT_NAME );
+ if( renderIfTransparentValue )
+ {
+ if( ! renderIfTransparentValue->Get( mRenderIfTransparent ) )
+ {
+ DALI_LOG_ERROR( "ColorVisual: renderIfTransparent property has incorrect type: %d\n", renderIfTransparentValue->GetType() );
+ }
+ }
}
-void ColorVisual::SetClipRect( const Rect<int>& clipRect )
+void ColorVisual::DoSetOnStage( Actor& actor )
{
- Visual::Base::SetClipRect( clipRect );
+ InitializeRenderer();
- //ToDo: renderer responds to the clipRect change
+ // Only add the renderer if it's not fully transparent
+ // We cannot avoid creating a renderer as it's used in the base class
+ if( mRenderIfTransparent || mImpl->mMixColor.a > 0.0f )
+ {
+ actor.AddRenderer( mImpl->mRenderer );
+ }
+
+ // Color Visual generated and ready to display
+ ResourceReady( Toolkit::Visual::ResourceStatus::READY );
}
-void ColorVisual::SetOffset( const Vector2& offset )
+void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const
{
- //ToDo: renderer applies the offset
+ map.Clear();
+ map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR );
+ map.Insert( Toolkit::ColorVisual::Property::MIX_COLOR, mImpl->mMixColor );
+ map.Insert( Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT, mRenderIfTransparent );
}
-void ColorVisual::DoSetOnStage( Actor& actor )
+void ColorVisual::DoCreateInstancePropertyMap( Property::Map& map ) const
{
- InitializeRenderer();
+ // Do nothing
}
-void ColorVisual::DoCreatePropertyMap( Property::Map& map ) const
+
+void ColorVisual::OnSetTransform()
{
- map.Clear();
- map.Insert( RENDERER_TYPE, COLOR_RENDERER );
- map.Insert( COLOR_NAME, mMixColor );
+ if( mImpl->mRenderer )
+ {
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+ }
}
void ColorVisual::InitializeRenderer()
{
Geometry geometry = mFactoryCache.GetGeometry( VisualFactoryCache::QUAD_GEOMETRY );
- if( !geometry )
- {
- geometry = VisualFactoryCache::CreateQuadGeometry();
- mFactoryCache.SaveGeometry( VisualFactoryCache::QUAD_GEOMETRY, geometry );
- }
Shader shader = mFactoryCache.GetShader( VisualFactoryCache::COLOR_SHADER );
if( !shader )
mImpl->mRenderer = Renderer::New( geometry, shader );
- mMixColorIndex = mImpl->mRenderer.RegisterProperty( COLOR_NAME, mMixColor );
- if( mMixColor.a < 1.f )
+ // ColorVisual has it's own index key for mix color - use this instead
+ // of using the new base index to avoid changing existing applications
+ // String keys will get to this property.
+ mImpl->mMixColorIndex = DevelHandle::RegisterProperty( mImpl->mRenderer, Toolkit::ColorVisual::Property::MIX_COLOR, MIX_COLOR, Vector3(mImpl->mMixColor) );
+
+ if( mImpl->mMixColor.a < 1.f )
{
mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
}
-}
-
-void ColorVisual::SetColor(const Vector4& color)
-{
- mMixColor = color;
- if( mImpl->mRenderer )
- {
- (mImpl->mRenderer).SetProperty( mMixColorIndex, color );
- if( color.a < 1.f )
- {
- mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
- }
- }
+ // Register transform properties
+ mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
}
} // namespace Internal