END_TEST;
}
+int UtcDaliRendererFactoryGetBorderRenderer1(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer1: Request border renderer with a Property::Map" );
+
+ RendererFactory factory = RendererFactory::Get();
+ DALI_TEST_CHECK( factory );
+
+ Property::Map propertyMap;
+ Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
+ float testSize = 5.f;
+ propertyMap.Insert("renderer-type", "border-renderer");
+ propertyMap.Insert("border-color", testColor);
+ propertyMap.Insert("border-size", testSize);
+
+ ControlRenderer controlRenderer = factory.GetControlRenderer(propertyMap);
+ DALI_TEST_CHECK( controlRenderer );
+
+ Actor actor = Actor::New();
+ actor.SetSize(200.f, 200.f);
+ Stage::GetCurrent().Add( actor );
+ controlRenderer.SetSize(Vector2(200.f, 200.f));
+ controlRenderer.SetOnStage( actor );
+
+ DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+
+ application.SendNotification();
+ application.Render(0);
+
+ Vector4 actualColor(Vector4::ZERO);
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uBorderColor", actualColor ) );
+ DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
+
+ float actualSize = 0.f;
+ DALI_TEST_CHECK( gl.GetUniformValue<float>( "uBorderSize", actualSize ) );
+ DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererFactoryGetBorderRenderer2(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "UtcDaliRendererFactoryGetBorderRenderer2: Request border renderer with a borderSize and a borderColor" );
+
+ RendererFactory factory = RendererFactory::Get();
+ DALI_TEST_CHECK( factory );
+
+ Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
+ float testSize = 5.f;
+
+ ControlRenderer controlRenderer = factory.GetControlRenderer(testSize, testColor);
+ DALI_TEST_CHECK( controlRenderer );
+
+ Actor actor = Actor::New();
+ actor.SetSize(200.f, 200.f);
+ Stage::GetCurrent().Add( actor );
+ controlRenderer.SetSize(Vector2(200.f, 200.f));
+ controlRenderer.SetOnStage( actor );
+
+ DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+
+ application.SendNotification();
+ application.Render(0);
+
+ Vector4 actualColor(Vector4::ZERO);
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uBorderColor", actualColor ) );
+ DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
+
+ float actualSize = 0.f;
+ DALI_TEST_CHECK( gl.GetUniformValue<float>( "uBorderSize", actualSize ) );
+ DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
+
+ END_TEST;
+}
+
+
int UtcDaliRendererFactoryGetLinearGradientRenderer(void)
{
ToolkitTestApplication application;
return GetImplementation( *this ).ResetRenderer( renderer, color );
}
+ControlRenderer RendererFactory::GetControlRenderer( float borderSize, const Vector4& borderColor )
+{
+ return GetImplementation( *this ).GetControlRenderer( borderSize, borderColor );
+}
+
ControlRenderer RendererFactory::GetControlRenderer( const Image& image )
{
return GetImplementation( *this ).GetControlRenderer( image );
bool ResetRenderer( ControlRenderer& renderer, const Vector4& color );
/**
+ * @brief Request the control renderer to renderer the border with the given size and color.
+ *
+ * @param[in] borderSize The size of the border. Border size is the same along all edges.
+ * @param[in] borderColor The color of the border.
+ * @return The pointer pointing to the control renderer
+ */
+ ControlRenderer GetControlRenderer( float borderSize, const Vector4& borderColor );
+
+ /**
* @brief Request the control renderer to render the image.
*
* @param[in] image The image to be rendered.
#include <dali/public-api/object/type-registry.h>
#include <dali/devel-api/object/type-registry-helper.h>
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
+
namespace Dali
{
DALI_TYPE_REGISTRATION_END()
-const char* DEFAULT_FRAME_IMAGE_PATH = DALI_IMAGE_DIR "magnifier-image-frame.png";
-
-const float IMAGE_BORDER_INDENT = 14.0f; ///< Indent of border in pixels.
+const float IMAGE_BORDER_INDENT = 5.0f; ///< Indent of border in pixels.
struct CameraActorPositionConstraint
{
{
Actor self(Self());
- Image image = ResourceImage::New( DEFAULT_FRAME_IMAGE_PATH );
- mFrame = ImageActor::New( image );
- mFrame.SetStyle( ImageActor::STYLE_NINE_PATCH );
+ mFrame = Actor::New( );
mFrame.SetPositionInheritanceMode(DONT_INHERIT_POSITION);
mFrame.SetInheritScale(true);
mFrame.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
Vector3 sizeOffset(IMAGE_BORDER_INDENT*2.f - 2.f, IMAGE_BORDER_INDENT*2.f - 2.f, 0.0f);
mFrame.SetSizeModeFactor( sizeOffset );
+ //TODO Set the renderer onto the control self when Actor::RemoveRenderer is supported
+ Toolkit::RendererFactory rendererFactory = Toolkit::RendererFactory::Get();
+ Toolkit::ControlRenderer borderRenderer = rendererFactory.GetControlRenderer(IMAGE_BORDER_INDENT, Color::WHITE);
+ borderRenderer.SetOnStage( mFrame );
+
Constraint constraint = Constraint::New<Vector3>( mFrame, Actor::Property::POSITION, EqualToConstraint() );
constraint.AddSource( ParentSource( Actor::Property::WORLD_POSITION ) );
constraint.Apply();
- mFrame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT );
self.Add(mFrame);
}
else if(!visible && mFrame)
RenderTask mTask; ///< Render Task to render the source actor contents.
CameraActor mCameraActor; ///< CameraActor attached to RenderTask
- ImageActor mFrame; ///< The Magnifier Frame
+ Actor mFrame; ///< The Magnifier Frame
Actor mSourceActor; ///< Source Delegate Actor represents the source position to read.
float mDefaultCameraDistance; ///< Default RenderTask's camera distance from target.
Vector3 mActorSize; ///< The Actor size
--- /dev/null
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "border-renderer.h"
+
+// EXTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+
+//INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/renderers/renderer-factory-impl.h>
+#include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
+#include <dali-toolkit/internal/controls/renderers/control-renderer-data-impl.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+namespace
+{
+const char * const COLOR_NAME("border-color");
+const char * const COLOR_UNIFORM_NAME("uBorderColor");
+const char * const SIZE_NAME("border-size");
+const char * const SIZE_UNIFORM_NAME("uBorderSize");
+
+const char * const POSITION_ATTRIBUTE_NAME("aPosition");
+const char * const DRIFT_ATTRIBUTE_NAME("aDrift");
+const char * const INDEX_NAME("indices");
+
+
+const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
+ attribute mediump vec2 aPosition;\n
+ attribute mediump vec2 aDrift;\n
+ uniform mediump mat4 uMvpMatrix;\n
+ uniform mediump vec3 uSize;\n
+ uniform mediump float uBorderSize;\n
+ \n
+ void main()\n
+ {\n
+ vec2 position = aPosition*uSize.xy + aDrift*uBorderSize;\n
+ gl_Position = uMvpMatrix * vec4(position, 0.0, 1.0);\n
+ }\n
+);
+
+const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
+ uniform lowp vec4 uColor;\n
+ uniform lowp vec4 uBorderColor;\n
+ \n
+ void main()\n
+ {\n
+ gl_FragColor = uBorderColor*uColor;\n
+ }\n
+);
+}
+
+BorderRenderer::BorderRenderer()
+: ControlRenderer(),
+ mBorderColor( Color::TRANSPARENT ),
+ mBorderSize( 0.f ),
+ mBorderColorIndex( Property::INVALID_INDEX ),
+ mBorderSizeIndex( Property::INVALID_INDEX )
+{
+}
+
+BorderRenderer::~BorderRenderer()
+{
+}
+
+void BorderRenderer::Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap )
+{
+ Initialize( factoryCache );
+
+ Property::Value* color = propertyMap.Find( COLOR_NAME );
+ if( !( color && color->Get(mBorderColor) ) )
+ {
+ DALI_LOG_ERROR( "Fail to provide a border color to the BorderRenderer object" );
+ }
+
+ Property::Value* size = propertyMap.Find( SIZE_NAME );
+ if( !( size && size->Get(mBorderSize) ) )
+ {
+ DALI_LOG_ERROR( "Fail to provide a border size to the BorderRenderer object" );
+ }
+}
+
+void BorderRenderer::SetClipRect( const Rect<int>& clipRect )
+{
+ ControlRenderer::SetClipRect( clipRect );
+
+ //ToDo: renderer responds to the clipRect change
+}
+
+void BorderRenderer::DoSetOnStage( Actor& actor )
+{
+ mBorderColorIndex = (mImpl->mRenderer).RegisterProperty( COLOR_UNIFORM_NAME, mBorderColor );
+ if( mBorderColor.a < 1.f )
+ {
+ (mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON );
+ }
+ mBorderSizeIndex = (mImpl->mRenderer).RegisterProperty( SIZE_UNIFORM_NAME, mBorderSize );
+}
+
+void BorderRenderer::Initialize( RendererFactoryCache& factoryCache)
+{
+ mImpl->mGeometry = factoryCache.GetGeometry( RendererFactoryCache::BORDER_GEOMETRY );
+ if( !(mImpl->mGeometry) )
+ {
+ mImpl->mGeometry = CreateBorderGeometry();
+ factoryCache.SaveGeometry( RendererFactoryCache::QUAD_GEOMETRY, mImpl->mGeometry );
+ }
+
+ mImpl->mShader = factoryCache.GetShader( RendererFactoryCache::BORDER_SHADER );
+ if( !(mImpl->mShader) )
+ {
+ mImpl->mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
+ factoryCache.SaveShader( RendererFactoryCache::COLOR_SHADER, mImpl->mShader );
+ }
+}
+
+void BorderRenderer::SetBorderColor(const Vector4& color)
+{
+ mBorderColor = color;
+
+ if( mImpl->mIsOnStage )
+ {
+ (mImpl->mRenderer).SetProperty( mBorderColorIndex, color );
+ if( color.a < 1.f && (mImpl->mRenderer).GetMaterial().GetBlendMode() != BlendingMode::ON)
+ {
+ (mImpl->mRenderer).GetMaterial().SetBlendMode( BlendingMode::ON );
+ }
+ }
+}
+
+void BorderRenderer::SetBorderSize( float size )
+{
+ mBorderSize = size;
+
+ if( mImpl->mIsOnStage )
+ {
+ (mImpl->mRenderer).SetProperty( mBorderSizeIndex, size );
+ }
+}
+
+/**
+ * Vertices and triangles of the border geometry:
+ *
+ * vertex position = aPosition*uSize.xy + aDrift*uBorderSize;
+ *
+ * 0--1--2--3
+ * | /| /| /|
+ * |/ |/ |/ |
+ * 4--5--6--7
+ * | /| | /|
+ * |/ | |/ |
+ * 8--9--10-11
+ * | /| /| /|
+ * |/ |/ |/ |
+ * 12-13-14-15
+ */
+Geometry BorderRenderer::CreateBorderGeometry()
+{
+ const float halfWidth = 0.5f;
+ const float halfHeight = 0.5f;
+ struct BorderVertex { Vector2 position; Vector2 drift;};
+ BorderVertex borderVertexData[16] =
+ {
+ { Vector2(-halfWidth, -halfHeight), Vector2(0.f, 0.f) },
+ { Vector2(-halfWidth, -halfHeight), Vector2(1.f, 0.f) },
+ { Vector2(halfWidth, -halfHeight), Vector2(-1.f, 0.f) },
+ { Vector2(halfWidth, -halfHeight), Vector2(0.f, 0.f) },
+
+ { Vector2(-halfWidth, -halfHeight), Vector2(0.f, 1.f) },
+ { Vector2(-halfWidth, -halfHeight), Vector2(1.f, 1.f) },
+ { Vector2(halfWidth, -halfHeight), Vector2(-1.f, 1.f) },
+ { Vector2(halfWidth, -halfHeight), Vector2(0.f, 1.f) },
+
+ { Vector2(-halfWidth, halfHeight), Vector2(0.f, -1.f) },
+ { Vector2(-halfWidth, halfHeight), Vector2(1.f, -1.f) },
+ { Vector2(halfWidth, halfHeight), Vector2(-1.f, -1.f) },
+ { Vector2(halfWidth, halfHeight), Vector2(0.f, -1.f) },
+
+ { Vector2(-halfWidth, halfHeight), Vector2(0.f, 0.f) },
+ { Vector2(-halfWidth, halfHeight), Vector2(1.f, 0.f) },
+ { Vector2(halfWidth, halfHeight), Vector2(-1.f, 0.f) },
+ { Vector2(halfWidth, halfHeight), Vector2(0.f, 0.f) },
+ };
+
+ Property::Map borderVertexFormat;
+ borderVertexFormat[POSITION_ATTRIBUTE_NAME] = Property::VECTOR2;
+ borderVertexFormat[DRIFT_ATTRIBUTE_NAME] = Property::VECTOR2;
+ PropertyBuffer borderVertices = PropertyBuffer::New( borderVertexFormat, 16 );
+ borderVertices.SetData(borderVertexData);
+
+ // Create indices
+ unsigned int indexData[48] = { 0, 4, 1, 1, 4, 5, 1, 5, 2, 2, 5, 6, 2, 6,3, 3, 6, 7,
+ 4, 8, 5, 5, 8, 9, 6, 10, 7, 7, 10, 11,
+ 8, 12, 9, 9, 12, 13, 9, 13, 10, 10, 13, 14, 10, 11, 14, 11, 14, 15};
+
+ Property::Map indexFormat;
+ indexFormat[INDEX_NAME] = Property::INTEGER;
+ PropertyBuffer indices = PropertyBuffer::New( indexFormat, 48 );
+ indices.SetData(indexData);
+
+ // Create the geometry object
+ Geometry geometry = Geometry::New();
+ geometry.AddVertexBuffer( borderVertices );
+ geometry.SetIndexBuffer( indices );
+
+ return geometry;
+}
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_TOOLKIT_INTERNAL_BORDER_RENDERER_H__
+#define __DALI_TOOLKIT_INTERNAL_BORDER_RENDERER_H__
+
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+// EXTERNAL INCLUDES
+#include <dali/devel-api/rendering/geometry.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Internal
+{
+
+/**
+ * The renderer which renders a solid color to the control's quad border fixed to a specified size.
+ *
+ * The following properties are required for create a BorderRender
+ *
+ * | %Property Name | Type |
+ * |------------------|-------------|
+ * | border-color | VECTOR4 |
+ * | border-size | FLOAT |
+ */
+
+class BorderRenderer : public ControlRenderer
+{
+public:
+
+ /**
+ * @brief Constructor.
+ */
+ BorderRenderer();
+
+ /**
+ * @brief A reference counted object may only be deleted by calling Unreference().
+ */
+ virtual ~BorderRenderer();
+
+public: // from ControlRenderer
+
+ /**
+ * @copydoc ControlRenderer::Initialize
+ */
+ virtual void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap );
+
+ /**
+ * @copydoc ControlRenderer::SetClipRect
+ */
+ virtual void SetClipRect( const Rect<int>& clipRect );
+
+protected:
+ /**
+ * @copydoc ControlRenderer::DoSetOnStage
+ */
+ virtual void DoSetOnStage( Actor& actor );
+
+public:
+
+ /**
+ * Request the geometry and shader from the cache, if not available, create and save to the cache for sharing.
+ *
+ * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
+ */
+ void Initialize( RendererFactoryCache& factoryCache );
+
+ /**
+ * Set the color of the border.
+ * @param[in] color The border color.
+ */
+ void SetBorderColor( const Vector4& color);
+
+ /**
+ * Set the size of the border.
+ * @param[in] size The border size.
+ */
+ void SetBorderSize( float size );
+
+private:
+
+ /**
+ * Create the geometry which presents the border.
+ * @return The border geometry
+ */
+ Geometry CreateBorderGeometry();
+
+ // Undefined
+ BorderRenderer( const BorderRenderer& borderRenderer );
+
+ // Undefined
+ BorderRenderer& operator=( const BorderRenderer& borderRenderer );
+
+private:
+
+ Vector4 mBorderColor;
+ float mBorderSize;
+
+ Property::Index mBorderColorIndex;
+ Property::Index mBorderSizeIndex;
+};
+
+} // namespace Internal
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif /* __DALI_TOOLKIT_INTERNAL_BORDER_RENDERER_H__ */
enum GeometryType
{
QUAD_GEOMETRY,
+ BORDER_GEOMETRY,
NINE_PATCH_GEOMETRY,
NINE_PATCH_BORDER_GEOMETRY,
GEOMETRY_TYPE_MAX = NINE_PATCH_BORDER_GEOMETRY
#include <dali/devel-api/object/type-registry-helper.h>
// Internal HEADER
+#include <dali-toolkit/internal/controls/renderers/border/border-renderer.h>
#include <dali-toolkit/internal/controls/renderers/color/color-renderer.h>
#include <dali-toolkit/internal/controls/renderers/gradient/gradient-renderer.h>
#include <dali-toolkit/internal/controls/renderers/npatch/npatch-renderer.h>
namespace
{
const char * const RENDERER_TYPE_NAME( "renderer-type" );
+
const char * const COLOR_RENDERER("color-renderer");
+const char * const BORDER_RENDERER("border-renderer");
const char * const GRADIENT_RENDERER("gradient-renderer");
const char * const IMAGE_RENDERER("image-renderer");
const char * const N_PATCH_RENDERER("n-patch-renderer");
{
rendererPtr = new NPatchRenderer();
}
+ else if( typeValue == BORDER_RENDERER )
+ {
+ rendererPtr = new BorderRenderer();
+ }
}
if( rendererPtr )
}
}
+Toolkit::ControlRenderer RendererFactory::GetControlRenderer( float borderSize, const Vector4& borderColor )
+{
+ BorderRenderer* rendererPtr = new BorderRenderer();
+
+ if( !mFactoryCache )
+ {
+ mFactoryCache = new RendererFactoryCache();
+ }
+ rendererPtr->Initialize( *( mFactoryCache.Get() ) );
+
+ rendererPtr->SetBorderSize( borderSize );
+ rendererPtr->SetBorderColor( borderColor );
+
+ return Toolkit::ControlRenderer( rendererPtr );
+}
+
Toolkit::ControlRenderer RendererFactory::GetControlRenderer( const Image& image )
{
if( !mFactoryCache )
bool ResetRenderer( Toolkit::ControlRenderer& renderer, const Vector4& color );
/**
+ * @copydoc Toolkit::RenderFactory::GetControlRenderer( float, const Vector4& )
+ */
+ Toolkit::ControlRenderer GetControlRenderer( float borderSize, const Vector4& borderColor );
+
+ /**
* @copydoc Toolkit::RenderFactory::GetControlRenderer( const Image& )
*/
Toolkit::ControlRenderer GetControlRenderer( const Image& image );
$(toolkit_src_dir)/controls/renderers/control-renderer-impl.cpp \
$(toolkit_src_dir)/controls/renderers/renderer-factory-cache.cpp \
$(toolkit_src_dir)/controls/renderers/renderer-factory-impl.cpp \
+ $(toolkit_src_dir)/controls/renderers/border/border-renderer.cpp \
$(toolkit_src_dir)/controls/renderers/color/color-renderer.cpp \
$(toolkit_src_dir)/controls/renderers/image/image-renderer.cpp \
$(toolkit_src_dir)/controls/renderers/npatch/npatch-renderer.cpp \