using namespace Dali;
using namespace Dali::Toolkit;
+namespace
+{
+const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
+const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.jpg";
+}
+
void dali_control_renderer_startup(void)
{
test_return_value = TET_UNDEF;
END_TEST;
}
-int UtcDaliControlRendererSetOnStage(void)
+int UtcDaliControlRendererSetOnOffStage(void)
{
ToolkitTestApplication application;
tet_infoline( "UtcDaliControlRendererSetDepthIndex" );
DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
controlRenderer.SetOnStage( actor );
-
application.SendNotification();
application.Render(0);
DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+ controlRenderer.SetOffStage( actor );
+ application.SendNotification();
+ application.Render(0);
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap1(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap1: ColorRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert("renderer-type", "color-renderer");
+ propertyMap.Insert("blend-color", Color::BLUE);
+ ControlRenderer colorRenderer = factory.GetControlRenderer( propertyMap );
+
+ Property::Map resultMap;
+ colorRenderer.CreatePropertyMap( resultMap );
+
+ Property::Value* typeValue = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( typeValue );
+ DALI_TEST_CHECK( typeValue->Get<std::string>() == "color-renderer" );
+
+ Property::Value* colorValue = resultMap.Find( "blend-color", Property::VECTOR4 );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
+
+ // change the blend color
+ factory.ResetRenderer( colorRenderer, Color::CYAN );
+ colorRenderer.CreatePropertyMap( resultMap );
+
+ colorValue = resultMap.Find( "blend-color", Property::VECTOR4 );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap2(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap2: BorderRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert("renderer-type", "border-renderer");
+ propertyMap.Insert("border-color", Color::BLUE);
+ propertyMap.Insert("border-size", 5.f);
+ ControlRenderer borderRenderer = factory.GetControlRenderer( propertyMap );
+
+ Property::Map resultMap;
+ borderRenderer.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from control renderer
+ Property::Value* typeValue = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( typeValue );
+ DALI_TEST_CHECK( typeValue->Get<std::string>() == "border-renderer" );
+
+ Property::Value* colorValue = resultMap.Find( "border-color", Property::VECTOR4 );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::BLUE );
+
+ Property::Value* sizeValue = resultMap.Find( "border-size", Property::FLOAT );
+ DALI_TEST_CHECK( sizeValue );
+ DALI_TEST_CHECK( sizeValue->Get<float>() == 5.f );
+
+ borderRenderer = factory.GetControlRenderer( 10.f, Color::CYAN );
+ borderRenderer.CreatePropertyMap( resultMap );
+
+ typeValue = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( typeValue );
+ DALI_TEST_CHECK( typeValue->Get<std::string>() == "border-renderer" );
+
+ colorValue = resultMap.Find( "border-color", Property::VECTOR4 );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_CHECK( colorValue->Get<Vector4>() == Color::CYAN );
+
+ colorValue = resultMap.Find( "border-size", Property::FLOAT );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_CHECK( colorValue->Get<float>() == 10.f );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap3(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap3: linear GradientRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ DALI_TEST_CHECK( factory );
+
+ Property::Map propertyMap;
+ propertyMap.Insert("renderer-type", "gradient-renderer");
+
+ Vector2 start(-1.f, -1.f);
+ Vector2 end(1.f, 1.f);
+ propertyMap.Insert("gradient-start-position", start);
+ propertyMap.Insert("gradient-end-position", end);
+ propertyMap.Insert("gradient-spread-method", "repeat");
+
+ propertyMap.Insert("gradient-stop-offset", Vector2(0.2f, 0.8f));
+
+ Property::Array stopColors;
+ stopColors.PushBack( Color::RED );
+ stopColors.PushBack( Color::GREEN );
+ propertyMap.Insert("gradient-stop-color", stopColors);
+
+ ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);
+
+ Property::Map resultMap;
+ gradientRenderer.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from control renderer
+ Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );
+
+ value = resultMap.Find( "gradient-units", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "object-bounding-box" );
+
+ value = resultMap.Find( "gradient-spread-method", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "repeat" );
+
+ value = resultMap.Find( "gradient-start-position", Property::VECTOR2 );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<Vector2>(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-end-position", Property::VECTOR2 );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<Vector2>(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
+ DALI_TEST_CHECK( value );
+ Property::Array* offsetArray = value->GetArray();
+ DALI_TEST_CHECK( offsetArray->Count() == 2 );
+ DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
+ DALI_TEST_CHECK( value );
+ Property::Array* colorArray = value->GetArray();
+ DALI_TEST_CHECK( colorArray->Count() == 2 );
+ DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap4(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap4: radial GradientRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ DALI_TEST_CHECK( factory );
+
+ Property::Map propertyMap;
+ propertyMap.Insert("renderer-type", "gradient-renderer");
+
+ Vector2 center(100.f, 100.f);
+ float radius = 100.f;
+ propertyMap.Insert("gradient-units", "user-space");
+ propertyMap.Insert("gradient-center", center);
+ propertyMap.Insert("gradient-radius", radius);
+ propertyMap.Insert("gradient-stop-offset", Vector3(0.1f, 0.3f, 1.1f));
+
+ Property::Array stopColors;
+ stopColors.PushBack( Color::RED );
+ stopColors.PushBack( Color::BLACK );
+ stopColors.PushBack( Color::GREEN );
+ propertyMap.Insert("gradient-stop-color", stopColors);
+
+ ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);
+ DALI_TEST_CHECK( gradientRenderer );
+
+ Property::Map resultMap;
+ gradientRenderer.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from control renderer
+ Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );
+
+ value = resultMap.Find( "gradient-units", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "user-space" );
+
+ value = resultMap.Find( "gradient-spread-method", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "pad" );
+
+ value = resultMap.Find( "gradient-center", Property::VECTOR2 );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<Vector2>(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-radius", Property::FLOAT );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get<float>(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
+ DALI_TEST_CHECK( value );
+ Property::Array* offsetArray = value->GetArray();
+ DALI_TEST_CHECK( offsetArray->Count() == 3 );
+ DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ // any stop value will be clamped to [0.0, 1.0];
+ DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get<float>(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
+ DALI_TEST_CHECK( value );
+ Property::Array* colorArray = value->GetArray();
+ DALI_TEST_CHECK( colorArray->Count() == 3 );
+ DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap5(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap5: ImageRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert( "renderer-type", "image-renderer" );
+ propertyMap.Insert( "image-url", TEST_IMAGE_FILE_NAME );
+ propertyMap.Insert( "image-desired-width", 20 );
+ propertyMap.Insert( "image-desired-height", 30 );
+ propertyMap.Insert( "image-fitting-mode", "fit-height" );
+ propertyMap.Insert( "image-sampling-mode", "box-then-nearest" );
+
+ ControlRenderer imageRenderer = factory.GetControlRenderer(propertyMap);
+ DALI_TEST_CHECK( imageRenderer );
+
+ Property::Map resultMap;
+ imageRenderer.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from control renderer
+ Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "image-renderer" );
+
+ value = resultMap.Find( "image-url", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
+
+ value = resultMap.Find( "image-fitting-mode", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "fit-height" );
+
+ value = resultMap.Find( "image-sampling-mode", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "box-then-nearest" );
+
+ value = resultMap.Find( "image-desired-width", Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == 20 );
+
+ value = resultMap.Find( "image-desired-height", Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == 30 );
+
+ // Get an image renderer with an image handle, and test the default property values
+ Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME, ImageDimensions(100, 200));
+ imageRenderer = factory.GetControlRenderer(image);
+ imageRenderer.CreatePropertyMap( resultMap );
+
+ value = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "image-renderer" );
+
+ value = resultMap.Find( "image-url", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == TEST_IMAGE_FILE_NAME );
+
+ value = resultMap.Find( "image-fitting-mode", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "shrink-to-fit" );
+
+ value = resultMap.Find( "image-sampling-mode", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "box" );
+
+ value = resultMap.Find( "image-desired-width", Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == 100 );
+
+ value = resultMap.Find( "image-desired-height", Property::INTEGER );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<int>() == 200 );
+
+ END_TEST;
+}
+
+int UtcDaliControlRendererGetPropertyMap6(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliControlRendererGetPropertyMap6: NPatchRenderer" );
+
+ RendererFactory factory = RendererFactory::Get();
+ Property::Map propertyMap;
+ propertyMap.Insert( "renderer-type", "n-patch-renderer" );
+ propertyMap.Insert( "image-url", TEST_NPATCH_FILE_NAME );
+ propertyMap.Insert( "border-only", true );
+ ControlRenderer nPatchRenderer = factory.GetControlRenderer( propertyMap );
+
+ Property::Map resultMap;
+ nPatchRenderer.CreatePropertyMap( resultMap );
+
+ // check the property values from the returned map from control renderer
+ Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == "n-patch-renderer" );
+
+ value = resultMap.Find( "image-url", Property::STRING );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<std::string>() == TEST_NPATCH_FILE_NAME );
+
+ value = resultMap.Find( "border-only", Property::BOOLEAN );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get<bool>() );
+
END_TEST;
}
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uBlendColor", actualValue ) );
DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
+ controlRenderer.SetOffStage( actor );
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
END_TEST;
}
DALI_TEST_CHECK( gl.GetUniformValue<float>( "uBorderSize", actualSize ) );
DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
+ controlRenderer.SetOffStage( actor );
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
END_TEST;
}
application.SendNotification();
application.Render(0);
+ controlRenderer.SetOffStage( actor );
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
END_TEST;
}
DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+ controlRenderer.SetOffStage( actor );
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
END_TEST;
}
DALI_TEST_CHECK( gl.GetUniformValue< int >( "sTexture", textureUnit ) );
DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+ controlRenderer.SetOffStage( actor );
+ DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+
END_TEST;
}
GetImplementation( *this ).SetOnStage(actor);
}
+void ControlRenderer::SetOffStage( Actor& actor )
+{
+ GetImplementation( *this ).SetOffStage(actor);
+}
+
+void ControlRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ GetImplementation( *this ).CreatePropertyMap( map );
+}
+
} // namespace Toolkit
} // namespace Dali
}
/**
- * ControlRenderer provides renderer for rendering the controls. A control may have multiple ControlRenders.
+ * @brief ControlRenderer provides renderer for rendering the controls. A control may have multiple ControlRenders.
+ *
* ControlRenderers reuses geometry, shader etc. across controls and manages the renderer and material to exist only when control is on-stage.
* It also responds to actor size and color change, and provides the clipping at the renderer level.
* Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
ControlRenderer& operator=( const ControlRenderer& handle );
/**
- * Set the size of the painting area.
+ * @brief Set the size of the painting area.
*
* @param[in] size The size of the painting area.
*/
void SetSize( const Vector2& size );
/**
- * Set the depth index of this renderer.
+ * @brief Set the depth index of this renderer.
+ *
* Depth-index controls draw-order for overlapping renderers.
* Renderer with higher depth indices are rendered in front of other renderer with smaller values
*
void SetDepthIndex( float index );
/**
- * Renderer only exists when control is on stage.
+ * @brief Renderer only exists when control is on stage.
+ *
* This function should be called when the control put on stage.
*
* @param[in] actor The actor applying this renderer.
*/
void SetOnStage( Actor& actor );
+ /**
+ * @brief Renderer is destroyed when control is off stage.
+ *
+ * This function should be called when the control removes from stage
+ *
+ * @param[in] actor The actor applying this renderer.
+ */
+ void SetOffStage( Actor& actor );
+
+ /**
+ * @brief Create the property map representing this renderer.
+ *
+ * @param[out] map The renderer property map.
+ */
+ void CreatePropertyMap( Property::Map& map ) const;
+
public: // Not intended for application developers
explicit DALI_INTERNAL ControlRenderer(Internal::ControlRenderer *impl);
}
/**
- * RendererFactory is a singleton object that provides and shares renderers for controls
+ * @brief RendererFactory is a singleton object that provides and shares renderers for controls
*
* The renderer type is required in the property map for requesting a control renderer.
*
namespace
{
+const char * const RENDERER_TYPE("renderer-type");
+const char * const RENDERER_TYPE_VALUE("border-renderer");
+
const char * const COLOR_NAME("border-color");
const char * const COLOR_UNIFORM_NAME("uBorderColor");
const char * const SIZE_NAME("border-size");
mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_UNIFORM_NAME, mBorderSize );
}
+void BorderRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ map.Clear();
+ map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
+ map.Insert( COLOR_NAME, mBorderColor );
+ map.Insert( SIZE_NAME, mBorderSize );
+}
+
void BorderRenderer::Initialize( RendererFactoryCache& factoryCache)
{
mImpl->mGeometry = factoryCache.GetGeometry( RendererFactoryCache::BORDER_GEOMETRY );
*/
virtual void DoSetOnStage( Actor& actor );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const;
+
public:
/**
namespace
{
+const char * const RENDERER_TYPE("renderer-type");
+const char * const RENDERER_TYPE_VALUE("color-renderer");
const char * const COLOR_NAME("blend-color");
const char * const COLOR_UNIFORM_NAME("uBlendColor");
//ToDo: renderer applies the offset
}
+void ColorRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ map.Clear();
+ map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
+ map.Insert( COLOR_NAME, mBlendColor );
+}
+
void ColorRenderer::DoSetOnStage( Actor& actor )
{
mBlendColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_UNIFORM_NAME, mBlendColor );
*/
virtual void SetOffset( const Vector2& offset );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const;
+
protected:
/**
* @copydoc ControlRenderer::DoSetOnStage
void SetOnStage( Actor& actor );
/**
- * ToDo: Add this function to Toolkit::ControlRenderer when the Renderer can be removed from actor properly.
- *
- * Renderer is destroyed when control is off stage.
- * This function should be called when the control removes from stage
- *
- * @param[in] actor The actor applying this renderer.
+ * @copydoc Toolkit::ControlRenderer::SetOffStage
*/
void SetOffStage( Actor& actor );
+ /**
+ * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const = 0;
+
protected:
/**
#include "gradient-renderer.h"
// EXTERNAL INCLUDES
+#include <typeinfo>
#include <dali/integration-api/debug.h>
#include <dali/public-api/common/dali-vector.h>
#include <dali/public-api/images/buffer-image.h>
namespace
{
+const char * const RENDERER_TYPE("renderer-type");
+const char * const RENDERER_TYPE_VALUE("gradient-renderer");
+
// properties: linear gradient
const char * const GRADIENT_START_POSITION_NAME("gradient-start-position"); // Property::VECTOR2
const char * const GRADIENT_END_POSITION_NAME("gradient-end-position"); // Property::VECTOR2
// string values
const char * const UNIT_USER_SPACE("user-space");
+const char * const UNIT_BOUNDING_BOX("object-bounding-box");
+const char * const SPREAD_PAD("pad");
const char * const SPREAD_REFLECT("reflect");
const char * const SPREAD_REPEAT("repeat");
//ToDo: renderer applies the offset
}
+void GradientRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ map.Clear();
+ map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
+
+ Gradient::GradientUnits units = mGradient->GetGradientUnits();
+ if( units == Gradient::USER_SPACE_ON_USE )
+ {
+ map.Insert( GRADIENT_UNITS_NAME, UNIT_USER_SPACE );
+ }
+ else // if( units == Gradient::OBJECT_BOUNDING_BOX )
+ {
+ map.Insert( GRADIENT_UNITS_NAME, UNIT_BOUNDING_BOX );
+ }
+
+ Gradient::SpreadMethod spread = mGradient->GetSpreadMethod();
+ if( spread == Gradient::PAD )
+ {
+ map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_PAD );
+ }
+ else if( spread == Gradient::REFLECT )
+ {
+ map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REFLECT );
+ }
+ else // if( units == Gradient::REPEAT )
+ {
+ map.Insert( GRADIENT_SPREAD_METHOD_NAME, SPREAD_REPEAT );
+ }
+
+ const Vector<Gradient::GradientStop>& stops( mGradient->GetStops() );
+ Property::Array offsets;
+ Property::Array colors;
+ for( unsigned int i=0; i<stops.Count(); i++ )
+ {
+ offsets.PushBack( stops[i].mOffset );
+ colors.PushBack( stops[i].mStopColor );
+ }
+
+ map.Insert( GRADIENT_STOP_OFFSET_NAME, offsets );
+ map.Insert( GRADIENT_STOP_COLOR_NAME, colors );
+
+ if( &typeid( *mGradient ) == &typeid(LinearGradient) )
+ {
+ LinearGradient* gradient = static_cast<LinearGradient*>( mGradient.Get() );
+ map.Insert( GRADIENT_START_POSITION_NAME, gradient->GetStartPosition() );
+ map.Insert( GRADIENT_END_POSITION_NAME, gradient->GetEndPosition() );
+ }
+ else // if( &typeid( *mGradient ) == &typeid(RadialGradient) )
+ {
+ RadialGradient* gradient = static_cast<RadialGradient*>( mGradient.Get() );
+ map.Insert( GRADIENT_CENTER_NAME, gradient->GetCenter() );
+ map.Insert( GRADIENT_RADIUS_NAME, gradient->GetRadius() );
+ }
+}
+
void GradientRenderer::DoSetOnStage( Actor& actor )
{
mGradientTransformIndex = (mImpl->mRenderer).RegisterProperty( UNIFORM_ALIGNMENT_MATRIX_NAME, mGradientTransform );
Property::Value* stopColorValue = propertyMap.Find( GRADIENT_STOP_COLOR_NAME );
if( stopOffsetValue && stopColorValue )
{
- Property::Array* offsetArray = stopOffsetValue->GetArray();
+ Vector<float> offsetArray;
Property::Array* colorArray = stopColorValue->GetArray();
- if( offsetArray && colorArray )
+ if( colorArray && GetStopOffsets( stopOffsetValue, offsetArray ))
{
- unsigned int numStop = offsetArray->Count() < colorArray->Count() ?
- offsetArray->Count() : colorArray->Count();
- float offset;
+ unsigned int numStop = offsetArray.Count() < colorArray->Count() ?
+ offsetArray.Count() : colorArray->Count();
Vector4 color;
for( unsigned int i=0; i<numStop; i++ )
{
- if( (offsetArray->GetElementAt(i)).Get(offset)
- && (colorArray->GetElementAt(i)).Get(color) )
+ if( (colorArray->GetElementAt(i)).Get(color) )
{
- mGradient->AddStop( offset, color);
+ mGradient->AddStop( offsetArray[i], color);
numValidStop++;
}
}
}
}
+
if( numValidStop < 1u ) // no valid stop
{
return false;
return true;
}
+bool GradientRenderer::GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets)
+{
+ Vector2 offset2;
+ if( value->Get( offset2 ) )
+ {
+ stopOffsets.PushBack( offset2.x );
+ stopOffsets.PushBack( offset2.y );
+ return true;
+ }
+
+ Vector3 offset3;
+ if( value->Get( offset3 ) )
+ {
+ stopOffsets.PushBack( offset3.x );
+ stopOffsets.PushBack( offset3.y );
+ stopOffsets.PushBack( offset3.z );
+ return true;
+ }
+
+ Vector4 offset4;
+ if( value->Get( offset4 ) )
+ {
+ stopOffsets.PushBack( offset4.x );
+ stopOffsets.PushBack( offset4.y );
+ stopOffsets.PushBack( offset4.z );
+ stopOffsets.PushBack( offset4.w );
+ return true;
+ }
+
+ Property::Array* offsetArray = value->GetArray();
+ if( offsetArray )
+ {
+ unsigned int numStop = offsetArray->Count();
+ float offset;
+ for( unsigned int i=0; i<numStop; i++ )
+ {
+ if( offsetArray->GetElementAt(i).Get(offset) )
+ {
+ stopOffsets.PushBack( offset );
+ }
+ }
+ return true;
+ }
+
+ return false;
+}
+
} // namespace Internal
} // namespace Toolkit
*/
virtual void SetOffset( const Vector2& offset );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const;
+
protected:
/**
* @copydoc ControlRenderer::DoSetOnStage
*/
bool NewGradient(Type gradientType, const Property::Map& propertyMap);
+ /**
+ * Get the stop-offsets from the property.
+ * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
+ *
+ * @param[in] value The property value of stop-offsets
+ * @param[out] stopOffsets The vector contains the stop offset values.
+ */
+ static bool GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
+
// Undefined
GradientRenderer( const GradientRenderer& gradientRenderer );
mGradientStops.PushBack( GradientStop( Clamp( offset, 0.f, 1.f ), color) );
}
+const Vector<Gradient::GradientStop>& Gradient::GetStops()
+{
+ return mGradientStops;
+}
+
void Gradient::SetGradientUnits( GradientUnits gradientUnits )
{
mGradientUnits = gradientUnits;
void AddStop(float offset, const Vector4& color);
/**
+ * Get the gradient stops.
+ * @return The vector of gradient stops.
+ */
+ const Vector<GradientStop>& GetStops();
+
+ /**
* Set the coordinate system used by the gradient attributes.
* @param[in] gradientUnits The the attributes are defined using the current user coordinate system or the bounding box of the shape.
*/
namespace
{
+const char * const RENDERER_TYPE("renderer-type");
+const char * const RENDERER_TYPE_VALUE("image-renderer");
+// property names
const char * const IMAGE_URL_NAME("image-url");
const char * const IMAGE_FITTING_MODE("image-fitting-mode");
const char * const IMAGE_SAMPLING_MODE("image-sampling-mode");
const char * const IMAGE_DESIRED_WIDTH("image-desired-width");
const char * const IMAGE_DESIRED_HEIGHT("image-desired-height");
+// fitting modes
+const char * const SHRINK_TO_FIT("shrink-to-fit");
+const char * const SCALE_TO_FILL("scale-to-fill");
+const char * const FIT_WIDTH("fit-width");
+const char * const FIT_HEIGHT("fit-height");
+const char * const DEFAULT("default");
+
+// sampling modes
+const char * const BOX("box");
+const char * const NEAREST("nearest");
+const char * const LINEAR("linear");
+const char * const BOX_THEN_NEAREST("box-then-nearest");
+const char * const BOX_THEN_LINEAR("box-then-linear");
+const char * const NO_FILTER("no-filter");
+const char * const DONT_CARE("dont-care");
+
std::string TEXTURE_UNIFORM_NAME = "sTexture";
const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
fittingValue->Get( fitting );
mFittingMode = FittingMode::DEFAULT;
- if( fitting == "shrink-to-fit" )
+ if( fitting == SHRINK_TO_FIT )
{
mFittingMode = FittingMode::SHRINK_TO_FIT;
}
- else if( fitting == "scale-to-fill" )
+ else if( fitting == SCALE_TO_FILL )
{
mFittingMode = FittingMode::SCALE_TO_FILL;
}
- else if( fitting == "fit-width" )
+ else if( fitting == FIT_WIDTH )
{
mFittingMode = FittingMode::FIT_WIDTH;
}
- else if( fitting == "fit-height" )
+ else if( fitting == FIT_HEIGHT )
{
mFittingMode = FittingMode::FIT_HEIGHT;
}
- else if( fitting == "default" )
+ else if( fitting == DEFAULT )
{
mFittingMode = FittingMode::DEFAULT;
}
samplingValue->Get( sampling );
mSamplingMode = SamplingMode::DEFAULT;
- if( sampling == "box" )
+ if( sampling == BOX )
{
mSamplingMode = SamplingMode::BOX;
}
- else if( sampling == "nearest" )
+ else if( sampling == NEAREST )
{
mSamplingMode = SamplingMode::NEAREST;
}
- else if( sampling == "linear" )
+ else if( sampling == LINEAR )
{
mSamplingMode = SamplingMode::LINEAR;
}
- else if( sampling == "box-then-nearest" )
+ else if( sampling == BOX_THEN_NEAREST )
{
mSamplingMode = SamplingMode::BOX_THEN_NEAREST;
}
- else if( sampling == "box-then-linear" )
+ else if( sampling == BOX_THEN_LINEAR )
{
mSamplingMode = SamplingMode::BOX_THEN_LINEAR;
}
- else if( sampling == "no-filter" )
+ else if( sampling == NO_FILTER )
{
mSamplingMode = SamplingMode::NO_FILTER;
}
- else if( sampling == "dont-care" )
+ else if( sampling == DONT_CARE )
{
mSamplingMode = SamplingMode::DONT_CARE;
}
- else if( sampling == "default" )
+ else if( sampling == DEFAULT )
{
mSamplingMode = SamplingMode::DEFAULT;
}
}
}
+void ImageRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ map.Clear();
+ map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
+ if( !mImageUrl.empty() )
+ {
+ map.Insert( IMAGE_URL_NAME, mImageUrl );
+ map.Insert( IMAGE_DESIRED_WIDTH, mDesiredSize.GetWidth() );
+ map.Insert( IMAGE_DESIRED_HEIGHT, mDesiredSize.GetHeight() );
+ }
+ else if( mImage )
+ {
+ map.Insert( IMAGE_DESIRED_WIDTH, static_cast<int>(mImage.GetWidth()) );
+ map.Insert( IMAGE_DESIRED_HEIGHT, static_cast<int>(mImage.GetHeight()) );
+
+ ResourceImage resourceImage = ResourceImage::DownCast(mImage);
+ if( resourceImage )
+ {
+ map.Insert( IMAGE_URL_NAME, resourceImage.GetUrl() );
+ }
+ }
+
+ switch( mFittingMode )
+ {
+ case Dali::FittingMode::FIT_HEIGHT:
+ {
+ map.Insert( IMAGE_FITTING_MODE, FIT_HEIGHT );
+ break;
+ }
+ case Dali::FittingMode::FIT_WIDTH:
+ {
+ map.Insert( IMAGE_FITTING_MODE, FIT_WIDTH );
+ break;
+ }
+ case Dali::FittingMode::SCALE_TO_FILL:
+ {
+ map.Insert( IMAGE_FITTING_MODE, SCALE_TO_FILL );
+ break;
+ }
+ case Dali::FittingMode::SHRINK_TO_FIT:
+ {
+ map.Insert( IMAGE_FITTING_MODE, SHRINK_TO_FIT );
+ break;
+ }
+ default:
+ {
+ map.Insert( IMAGE_FITTING_MODE, DEFAULT );
+ break;
+ }
+ }
+
+ switch( mSamplingMode )
+ {
+ case Dali::SamplingMode::BOX:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, BOX );
+ break;
+ }
+ case Dali::SamplingMode::NEAREST:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, NEAREST );
+ break;
+ }
+ case Dali::SamplingMode::LINEAR:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, LINEAR );
+ break;
+ }
+ case Dali::SamplingMode::BOX_THEN_LINEAR:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, BOX_THEN_LINEAR );
+ break;
+ }
+ case Dali::SamplingMode::BOX_THEN_NEAREST:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, BOX_THEN_NEAREST );
+ break;
+ }
+ case Dali::SamplingMode::NO_FILTER:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, NO_FILTER );
+ break;
+ }
+ case Dali::SamplingMode::DONT_CARE:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, DONT_CARE );
+ break;
+ }
+ default:
+ {
+ map.Insert( IMAGE_SAMPLING_MODE, DEFAULT );
+ break;
+ }
+ }
+}
+
void ImageRenderer::Initialize( RendererFactoryCache& factoryCache )
{
mImpl->mGeometry = factoryCache.GetGeometry( RendererFactoryCache::QUAD_GEOMETRY );
*/
virtual void SetOffset( const Vector2& offset );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const;
+
protected:
/**
* @copydoc ControlRenderer::DoSetOnStage
namespace
{
+const char * const RENDERER_TYPE("renderer-type");
+const char * const RENDERER_TYPE_VALUE("n-patch-renderer");
const char * const IMAGE_URL_NAME("image-url");
const char * const BORDER_ONLY("border-only");
mCroppedImage.Reset();
}
+void NPatchRenderer::CreatePropertyMap( Property::Map& map ) const
+{
+ map.Clear();
+ map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
+ if( !mImageUrl.empty() )
+ {
+ map.Insert( IMAGE_URL_NAME, mImageUrl );
+ }
+ else if( mImage )
+ {
+ map.Insert( IMAGE_URL_NAME, mImage.GetUrl() );
+ }
+ map.Insert( BORDER_ONLY, mBorderOnly );
+}
+
void NPatchRenderer::Initialize( RendererFactoryCache& factoryCache )
{
mNinePatchGeometry = factoryCache.GetGeometry( RendererFactoryCache::NINE_PATCH_GEOMETRY );
* | %Property Name | Type |
* |---------------------------|------------------|
* | image-url | STRING |
+ * | border-only | BOOLEAN
*
*/
class NPatchRenderer: public ControlRenderer
*/
virtual void SetOffset( const Vector2& offset );
+ /**
+ * @copydoc ControlRenderer::CreatePropertyMap
+ */
+ virtual void CreatePropertyMap( Property::Map& map ) const;
+
protected:
/**
* @copydoc ControlRenderer::DoSetOnStage