From c211a7d84885dca19c90b4656055002865e6fce2 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Wed, 19 Oct 2016 17:21:06 +0100 Subject: [PATCH] Added New methods to cater for second step initialization Change-Id: Ib487d11e1fdb114eaa3fdf0b3ab438da523c46f6 --- .../internal/visuals/border/border-visual.cpp | 5 ++ .../internal/visuals/border/border-visual.h | 17 ++++- .../internal/visuals/color/color-visual.cpp | 5 ++ dali-toolkit/internal/visuals/color/color-visual.h | 30 ++++++--- .../internal/visuals/gradient/gradient-visual.cpp | 4 ++ .../internal/visuals/gradient/gradient-visual.h | 30 ++++++--- .../internal/visuals/image/batch-image-visual.cpp | 11 +++- .../internal/visuals/image/batch-image-visual.h | 33 ++++++---- .../internal/visuals/image/image-visual.cpp | 21 +++++- dali-toolkit/internal/visuals/image/image-visual.h | 75 ++++++++++++++++------ dali-toolkit/internal/visuals/mesh/mesh-visual.cpp | 7 +- dali-toolkit/internal/visuals/mesh/mesh-visual.h | 26 ++++++-- .../internal/visuals/npatch/npatch-visual.cpp | 45 +++++++------ .../internal/visuals/npatch/npatch-visual.h | 41 ++++++++---- .../visuals/primitive/primitive-visual.cpp | 7 +- .../internal/visuals/primitive/primitive-visual.h | 27 ++++++-- dali-toolkit/internal/visuals/svg/svg-visual.cpp | 21 +++--- dali-toolkit/internal/visuals/svg/svg-visual.h | 33 +++++++--- dali-toolkit/internal/visuals/text/text-visual.cpp | 25 +++++--- dali-toolkit/internal/visuals/text/text-visual.h | 35 +++++++--- dali-toolkit/internal/visuals/visual-base-impl.h | 3 + .../internal/visuals/visual-factory-impl.cpp | 56 ++++++++-------- .../visuals/wireframe/wireframe-visual.cpp | 7 +- .../internal/visuals/wireframe/wireframe-visual.h | 21 ++++-- 24 files changed, 405 insertions(+), 180 deletions(-) diff --git a/dali-toolkit/internal/visuals/border/border-visual.cpp b/dali-toolkit/internal/visuals/border/border-visual.cpp index 0c27103..ba326d0 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.cpp +++ b/dali-toolkit/internal/visuals/border/border-visual.cpp @@ -102,6 +102,11 @@ const char* FRAGMENT_SHADER_ANTI_ALIASING = DALI_COMPOSE_SHADER( ); } +BorderVisualPtr BorderVisual::New( VisualFactoryCache& factoryCache ) +{ + return new BorderVisual( factoryCache ); +} + BorderVisual::BorderVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mBorderColor( Color::TRANSPARENT ), diff --git a/dali-toolkit/internal/visuals/border/border-visual.h b/dali-toolkit/internal/visuals/border/border-visual.h index c1e30d8..3fce5d6 100644 --- a/dali-toolkit/internal/visuals/border/border-visual.h +++ b/dali-toolkit/internal/visuals/border/border-visual.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include @@ -33,6 +34,9 @@ namespace Toolkit namespace Internal { +class BorderVisual; +typedef IntrusivePtr< BorderVisual > BorderVisualPtr; + /** * The visual which renders a solid color to the control's quad border fixed to a specified size. * @@ -44,12 +48,21 @@ namespace Internal * | borderSize | FLOAT | * | antiAliasing | BOOLEAN | */ - class BorderVisual : public Visual::Base { public: /** + * @brief Create a new border visual. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. + */ + static BorderVisualPtr New( VisualFactoryCache& factoryCache ); + +protected: + + /** * @brief Constructor. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object @@ -61,8 +74,6 @@ public: */ virtual ~BorderVisual(); -protected: - /** * @copydoc Visual::Base::DoInitialize */ diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index a1ef6d2..8736d54 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -65,6 +65,11 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( ); } +ColorVisualPtr ColorVisual::New( VisualFactoryCache& factoryCache ) +{ + return new ColorVisual( factoryCache ); +} + ColorVisual::ColorVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mMixColorIndex( Property::INVALID_INDEX ) diff --git a/dali-toolkit/internal/visuals/color/color-visual.h b/dali-toolkit/internal/visuals/color/color-visual.h index 88fb152..6552ac6 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.h +++ b/dali-toolkit/internal/visuals/color/color-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_COLOR_VISUAL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include @@ -30,6 +33,9 @@ namespace Toolkit namespace Internal { +class ColorVisual; +typedef IntrusivePtr< ColorVisual > ColorVisualPtr; + /** * The visual which renders a solid color to the control's quad * @@ -44,16 +50,12 @@ class ColorVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new color visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ColorVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~ColorVisual(); + static ColorVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -80,6 +82,18 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + ColorVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~ColorVisual(); + + /** * @copydoc Visual::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index f30ff03..b662821 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -185,6 +185,10 @@ Dali::WrapMode::Type GetWrapMode( Toolkit::GradientVisual::SpreadMethod::Type sp } // unnamed namespace +GradientVisualPtr GradientVisual::New( VisualFactoryCache& factoryCache ) +{ + return new GradientVisual( factoryCache ); +} GradientVisual::GradientVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.h b/dali-toolkit/internal/visuals/gradient/gradient-visual.h index 1726c51..5171b12 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.h +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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. @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -33,6 +36,8 @@ namespace Internal { class Gradient; +class GradientVisual; +typedef IntrusivePtr< GradientVisual > GradientVisualPtr; /** * The visual which renders smooth transition of colors to the control's quad. @@ -80,16 +85,12 @@ public: }; /** - * @brief Constructor. + * @brief Create a new gradient visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - GradientVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~GradientVisual(); + static GradientVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -114,6 +115,19 @@ public: // from Visual virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ); protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + GradientVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~GradientVisual(); + /** * @copydoc Visual::Base::DoInitialize */ diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp index 46244aa..973355a 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.cpp @@ -85,11 +85,16 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} //unnamed namespace +} // unnamed namespace + +BatchImageVisualPtr BatchImageVisual::New( VisualFactoryCache& factoryCache ) +{ + return new BatchImageVisual( factoryCache ); +} BatchImageVisual::BatchImageVisual( VisualFactoryCache& factoryCache ) - : Visual::Base( factoryCache ), - mDesiredSize() +: Visual::Base( factoryCache ), + mDesiredSize() { } diff --git a/dali-toolkit/internal/visuals/image/batch-image-visual.h b/dali-toolkit/internal/visuals/image/batch-image-visual.h index e5536e9..7151100 100644 --- a/dali-toolkit/internal/visuals/image/batch-image-visual.h +++ b/dali-toolkit/internal/visuals/image/batch-image-visual.h @@ -18,13 +18,13 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL HEADER #include #include -// EXTERNAL INCLUDES -#include - namespace Dali { namespace Toolkit @@ -32,21 +32,20 @@ namespace Toolkit namespace Internal { +class BatchImageVisual; +typedef IntrusivePtr< BatchImageVisual > BatchImageVisualPtr; + class BatchImageVisual: public Visual::Base, public ConnectionTracker { public: /** - * @brief Constructor. + * @brief Create a new batch-image visual. * - * @param[in] factoryCache The VisualFactoryCache object - */ - BatchImageVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ~BatchImageVisual(); + static BatchImageVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -78,6 +77,18 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + BatchImageVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + ~BatchImageVisual(); + + /** * @copydoc Visua::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/image/image-visual.cpp b/dali-toolkit/internal/visuals/image/image-visual.cpp index d9cb845..e25b6b6 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.cpp +++ b/dali-toolkit/internal/visuals/image/image-visual.cpp @@ -186,7 +186,26 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS return geometry; } -} //unnamed namespace +} // unnamed namespace + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache ) +{ + return new ImageVisual( factoryCache ); +} + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size, + FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ) +{ + return new ImageVisual( factoryCache, imageUrl, size, fittingMode, samplingMode ); +} + +ImageVisualPtr ImageVisual::New( VisualFactoryCache& factoryCache, const Image& image ) +{ + return new ImageVisual( factoryCache, image ); +} ImageVisual::ImageVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), diff --git a/dali-toolkit/internal/visuals/image/image-visual.h b/dali-toolkit/internal/visuals/image/image-visual.h index 56b1ae1..cd22ebc 100644 --- a/dali-toolkit/internal/visuals/image/image-visual.h +++ b/dali-toolkit/internal/visuals/image/image-visual.h @@ -18,16 +18,17 @@ * */ -// INTERNAL INCLUDES -#include -#include - // EXTERNAL INCLUDES +#include #include #include #include #include +// INTERNAL INCLUDES +#include +#include + namespace Dali { @@ -79,14 +80,15 @@ class ImageVisual: public Visual::Base, public ConnectionTracker, public AtlasUp public: /** - * @brief Constructor. + * @brief Create a new image visual. * - * @param[in] factoryCache The VisualFactoryCache object + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - ImageVisual( VisualFactoryCache& factoryCache ); + static ImageVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor with a URL. + * @brief Create a new image visual with a URL. * * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage * @@ -96,24 +98,19 @@ public: * @param[in] fittingMode The FittingMode of the resource to load * @param[in] samplingMode The SamplingMode of the resource to load */ - ImageVisual( VisualFactoryCache& factoryCache, - const std::string& imageUrl, - ImageDimensions size=ImageDimensions(), - FittingMode::Type fittingMode = FittingMode::DEFAULT, - Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); + static ImageVisualPtr New( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size = ImageDimensions(), + FittingMode::Type fittingMode = FittingMode::DEFAULT, + Dali::SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ); /** - * @brief Constructor with an Image type. + * @brief Create a new image visual with an Image type. * * @param[in] factoryCache The VisualFactoryCache object * @param[in] image The image to use */ - ImageVisual( VisualFactoryCache& factoryCache, const Image& image ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~ImageVisual(); + static ImageVisualPtr New( VisualFactoryCache& factoryCache, const Image& image ); public: // from Visual @@ -138,6 +135,44 @@ public: // from Visual virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ); protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + ImageVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief Constructor with a URL. + * + * The visual will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] imageUrl The URL of the image resource to use + * @param[in] size The width and height to fit the loaded image to. + * @param[in] fittingMode The FittingMode of the resource to load + * @param[in] samplingMode The SamplingMode of the resource to load + */ + ImageVisual( VisualFactoryCache& factoryCache, + const std::string& imageUrl, + ImageDimensions size, + FittingMode::Type fittingMode, + Dali::SamplingMode::Type samplingMode ); + + /** + * @brief Constructor with an Image type. + * + * @param[in] factoryCache The VisualFactoryCache object + * @param[in] image The image to use + */ + ImageVisual( VisualFactoryCache& factoryCache, const Image& image ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~ImageVisual(); + /** * @copydoc Visual::Base::DoInitialize */ diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp index 5f8d4e0..28ff3d1 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.cpp @@ -288,7 +288,12 @@ const char* NORMAL_MAP_FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} // namespace +} // unnamed namespace + +MeshVisualPtr MeshVisual::New( VisualFactoryCache& factoryCache ) +{ + return new MeshVisual( factoryCache ); +} MeshVisual::MeshVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), diff --git a/dali-toolkit/internal/visuals/mesh/mesh-visual.h b/dali-toolkit/internal/visuals/mesh/mesh-visual.h index a05f848..1762f46 100644 --- a/dali-toolkit/internal/visuals/mesh/mesh-visual.h +++ b/dali-toolkit/internal/visuals/mesh/mesh-visual.h @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // INTERNAL INCLUDES #include @@ -36,6 +37,9 @@ namespace Toolkit namespace Internal { +class MeshVisual; +typedef IntrusivePtr< MeshVisual > MeshVisualPtr; + /** * The visual which renders a 3D object to the control's quad * @@ -56,16 +60,12 @@ class MeshVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new mesh visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - MeshVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~MeshVisual(); + static MeshVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -92,6 +92,18 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + MeshVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~MeshVisual(); + + /** * @copydoc Visual::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp index 1a3f640..036f978 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.cpp @@ -200,35 +200,35 @@ void RegisterStretchProperties( Renderer& renderer, const char * uniformName, co /////////////////NPatchVisual//////////////// -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mImage(), - mCroppedImage(), - mImageUrl(), - mStretchPixelsX(), - mStretchPixelsY(), - mImageSize(), - mBorderOnly( false ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache ) { + return new NPatchVisual( factoryCache ); } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) -: Visual::Base( factoryCache ), - mImage(), - mCroppedImage(), - mImageUrl( imageUrl ), - mStretchPixelsX(), - mStretchPixelsY(), - mImageSize(), - mBorderOnly( borderOnly ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly ) { - NinePatchImage nPatch = NinePatchImage::New( mImageUrl ); - InitializeFromImage( nPatch ); + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + nPatchVisual->mImageUrl = imageUrl; + + NinePatchImage image = NinePatchImage::New( imageUrl ); + nPatchVisual->InitializeFromImage( image ); + + return nPatchVisual; } -NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +NPatchVisualPtr NPatchVisual::New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly ) +{ + NPatchVisual* nPatchVisual = new NPatchVisual( factoryCache, borderOnly ); + nPatchVisual->mImage = image; + + nPatchVisual->InitializeFromImage( image ); + + return nPatchVisual; +} + +NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly ) : Visual::Base( factoryCache ), - mImage( image ), + mImage(), mCroppedImage(), mImageUrl(), mStretchPixelsX(), @@ -236,7 +236,6 @@ NPatchVisual::NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage ima mImageSize(), mBorderOnly( borderOnly ) { - InitializeFromImage( image ); } NPatchVisual::~NPatchVisual() diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index e178eb8..07918ee 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -18,10 +18,8 @@ * */ -// INTERNAL INCLUDES -#include - // EXTERNAL INCLUDES +#include #include #include #include @@ -29,6 +27,9 @@ #include #include +// INTERNAL INCLUDES +#include + namespace Dali { @@ -38,6 +39,9 @@ namespace Toolkit namespace Internal { +class NPatchVisual; +typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr; + /** * The visual which renders an 9 patch image to the control's quad * @@ -54,14 +58,15 @@ class NPatchVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new n-patch visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - NPatchVisual( VisualFactoryCache& factoryCache ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor which creates an N-patch visual using an image URL. + * @brief Create an N-patch visual using an image URL. * * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage * @@ -69,21 +74,16 @@ public: * @param[in] imageUrl The URL to 9 patch image resource to use * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border */ - NPatchVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false ); /** - * @brief Constructor which creates an N-patch viusal with a NinePatchImage resource. + * @brief Create an N-patch visual with a NinePatchImage resource. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] image The NinePatchImage to use * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border */ - NPatchVisual( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~NPatchVisual(); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false ); public: // from Visual @@ -110,6 +110,19 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border + */ + NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly = false ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~NPatchVisual(); + + /** * @copydoc Visual::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp index 956714b..6142ad1 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.cpp @@ -160,7 +160,12 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( }\n ); -} // namespace +} // unnamed namespace + +PrimitiveVisualPtr PrimitiveVisual::New( VisualFactoryCache& factoryCache ) +{ + return new PrimitiveVisual( factoryCache ); +} PrimitiveVisual::PrimitiveVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), diff --git a/dali-toolkit/internal/visuals/primitive/primitive-visual.h b/dali-toolkit/internal/visuals/primitive/primitive-visual.h index 04f1d3d..59979f8 100644 --- a/dali-toolkit/internal/visuals/primitive/primitive-visual.h +++ b/dali-toolkit/internal/visuals/primitive/primitive-visual.h @@ -44,6 +44,8 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +// EXTERNAL INCLUDES +#include // INTERNAL INCLUDES #include @@ -58,6 +60,9 @@ namespace Toolkit namespace Internal { +class PrimitiveVisual; +typedef IntrusivePtr< PrimitiveVisual > PrimitiveVisualPtr; + /** * The visual which renders a simple 3D shape to the control's quad * @@ -97,16 +102,12 @@ class PrimitiveVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new primitive visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - PrimitiveVisual( VisualFactoryCache& factoryCache ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - virtual ~PrimitiveVisual(); + static PrimitiveVisualPtr New( VisualFactoryCache& factoryCache ); public: // from Visual @@ -138,6 +139,18 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + PrimitiveVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~PrimitiveVisual(); + + /** * @copydoc Visual::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 46b6a62..f3ad956 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -53,18 +53,19 @@ namespace Toolkit namespace Internal { -SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mAtlasRect( FULL_TEXTURE_RECT ), - mImageUrl(), - mParsedImage( NULL ), - mPlacementActor() +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache ) { - // the rasterized image is with pre-multiplied alpha format - mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; + return new SvgVisual( factoryCache ); +} + +SvgVisualPtr SvgVisual::New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) +{ + SvgVisual* svgVisual = new SvgVisual( factoryCache ); + svgVisual->ParseFromUrl( imageUrl, size ); + return svgVisual; } -SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size ) +SvgVisual::SvgVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ), mAtlasRect( FULL_TEXTURE_RECT ), mImageUrl(), @@ -73,8 +74,6 @@ SvgVisual::SvgVisual( VisualFactoryCache& factoryCache, const std::string& image { // the rasterized image is with pre-multiplied alpha format mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; - - ParseFromUrl( imageUrl, size ); } SvgVisual::~SvgVisual() diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index 8fd9165..5dbd24e 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -18,7 +18,8 @@ * */ -//EXTERNAL INCLUDES +// EXTERNAL INCLUDES +#include #include // INTERNAL INCLUDES @@ -35,6 +36,9 @@ namespace Toolkit namespace Internal { +class SvgVisual; +typedef IntrusivePtr< SvgVisual > SvgVisualPtr; + /** * The visual which renders a svg image * @@ -50,27 +54,24 @@ class SvgVisual: public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new SVG visual. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - SvgVisual( VisualFactoryCache& factoryCache ); + static SvgVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief Constructor which creates the SVG Visual using the image URL. + * @brief Create the SVG Visual using the image URL. * * The visual will parse the SVG image once it is set. * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object * @param[in] imageUrl The URL to svg resource to use + * @param[in] size The required size for the SVG */ - SvgVisual( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); - - /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~SvgVisual(); + static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, ImageDimensions size = ImageDimensions() ); public: // from Visual @@ -102,6 +103,18 @@ public: // from Visual protected: /** + * @brief Constructor. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + */ + SvgVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~SvgVisual(); + + /** * @copydoc Visual::Base::DoInitialize */ virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index e9278f9..3f9dd1e 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -154,18 +154,11 @@ Geometry CreateGeometry( VisualFactoryCache& factoryCache, ImageDimensions gridS return geometry; } -} // namespace +} // unnamed namespace -TextVisual::TextVisual( VisualFactoryCache& factoryCache ) -: Visual::Base( factoryCache ), - mController( Text::Controller::New() ), - mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ), - mHasBeenStaged( false ) -{ -} - -TextVisual::~TextVisual() +TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache ) { + return new TextVisual( factoryCache ); } void TextVisual::SetTextControlInterface( Text::ControlInterface* controlInterface ) @@ -254,6 +247,18 @@ void TextVisual::DoCreatePropertyMap( Property::Map& map ) const map.Insert( Toolkit::TextVisual::Property::BATCHING_ENABLED, false ); // TODO } +TextVisual::TextVisual( VisualFactoryCache& factoryCache ) +: Visual::Base( factoryCache ), + mController( Text::Controller::New() ), + mRenderingBackend( Toolkit::Text::DEFAULT_RENDERING_BACKEND ), + mHasBeenStaged( false ) +{ +} + +TextVisual::~TextVisual() +{ +} + void TextVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap ) { mSelf = actor; diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 9151ec7..c609990 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include #include @@ -69,19 +72,16 @@ class TextVisual : public Visual::Base public: /** - * @brief Constructor. + * @brief Create a new text visual. * - * @param[in] factoryCache The VisualFactoryCache object + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. */ - TextVisual( VisualFactoryCache& factoryCache ); + static TextVisualPtr New( VisualFactoryCache& factoryCache ); /** - * @brief A reference counted object may only be deleted by calling Unreference(). - */ - ~TextVisual(); - - /** - * + * @brief Sets the text control interface which is needed to communicate with a control. + * @param[in] controlInterface Pointer to the control-interface. */ void SetTextControlInterface( Text::ControlInterface* controlInterface ); @@ -107,7 +107,22 @@ public: // from Visual::Base */ virtual void DoCreatePropertyMap( Property::Map& map ) const; -protected: // from Visual::Base +protected: + + /** + * @brief Constructor. + * + * @param[in] factoryCache The VisualFactoryCache object + */ + TextVisual( VisualFactoryCache& factoryCache ); + + /** + * @brief A reference counted object may only be deleted by calling Unreference(). + */ + virtual ~TextVisual(); + + // from Visual::Base + /** * @copydoc Visual::Base::DoInitialize() */ diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 3334842..23394ad 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -19,6 +19,7 @@ */ // EXTERNAL INCLUDES +#include #include #include #include @@ -246,6 +247,8 @@ protected: VisualFactoryCache& mFactoryCache; }; +typedef IntrusivePtr BasePtr; + } // namspace Visual } // namespace Internal diff --git a/dali-toolkit/internal/visuals/visual-factory-impl.cpp b/dali-toolkit/internal/visuals/visual-factory-impl.cpp index 76d0ba7..c7a9f33 100644 --- a/dali-toolkit/internal/visuals/visual-factory-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-factory-impl.cpp @@ -100,10 +100,10 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property // Return a new WireframeVisual if we have debug enabled if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } - Visual::Base* visualPtr = NULL; + Visual::BasePtr visualPtr; Property::Value* typeValue = propertyMap.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE ); Toolkit::Visual::Type visualType = Toolkit::Visual::IMAGE; // Default to IMAGE type. @@ -116,19 +116,19 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property { case Toolkit::Visual::BORDER: { - visualPtr = new BorderVisual( *( mFactoryCache.Get() ) ); + visualPtr = BorderVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::COLOR: { - visualPtr = new ColorVisual( *( mFactoryCache.Get() ) ); + visualPtr = ColorVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::GRADIENT: { - visualPtr = new GradientVisual( *( mFactoryCache.Get() ) ); + visualPtr = GradientVisual::New( *( mFactoryCache.Get() ) ); break; } @@ -142,11 +142,11 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property UrlType::Type type = ResolveUrlType( imageUrl ); if( UrlType::N_PATCH == type ) { - visualPtr = new NPatchVisual( *( mFactoryCache.Get() ) ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ) ); } else if( UrlType::SVG == type ) { - visualPtr = new SvgVisual( *( mFactoryCache.Get() ) ); + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ) ); } else // Regular image { @@ -159,12 +159,12 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property if( batchingEnabled ) { - visualPtr = new BatchImageVisual( *( mFactoryCache.Get() ) ); + visualPtr = BatchImageVisual::New( *( mFactoryCache.Get() ) ); break; } else { - visualPtr = new ImageVisual( *( mFactoryCache.Get() ) ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ) ); } } } @@ -174,28 +174,27 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property case Toolkit::Visual::MESH: { - visualPtr = new MeshVisual( *( mFactoryCache.Get() ) ); + visualPtr = MeshVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::PRIMITIVE: { - visualPtr = new PrimitiveVisual( *( mFactoryCache.Get() ) ); + visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::WIREFRAME: { - visualPtr = new WireframeVisual( *( mFactoryCache.Get() ) ); + visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ) ); break; } case Toolkit::Visual::TEXT: { - visualPtr = new TextVisual( *( mFactoryCache.Get() ) ); + visualPtr = TextVisual::New( *( mFactoryCache.Get() ) ); break; } - } if( visualPtr ) @@ -208,7 +207,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property DALI_LOG_ERROR( "Renderer type unknown\n" ); } - return Toolkit::Visual::Base( visualPtr ); + return Toolkit::Visual::Base( visualPtr.Get() ); } Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) @@ -220,20 +219,22 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image ) if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } + Visual::BasePtr visualPtr; + NinePatchImage npatchImage = NinePatchImage::DownCast( image ); if( npatchImage ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), npatchImage ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage ); } else { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), image ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image ); } + + return Toolkit::Visual::Base( visualPtr.Get() ); } Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size ) @@ -245,26 +246,27 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image if( mDebugEnabled ) { - return Toolkit::Visual::Base( new WireframeVisual( *( mFactoryCache.Get() ) ) ); + return Toolkit::Visual::Base( WireframeVisual::New( *( mFactoryCache.Get() ) ).Get() ); } + Visual::BasePtr visualPtr; + // first resolve url type to know which visual to create UrlType::Type type = ResolveUrlType( url ); if( UrlType::N_PATCH == type ) { - NPatchVisual* visualPtr = new NPatchVisual( *( mFactoryCache.Get() ), url ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url ); } else if( UrlType::SVG == type ) { - SvgVisual* visualPtr = new SvgVisual( *( mFactoryCache.Get() ), url, size ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url, size ); } else // Regular image { - ImageVisual* visualPtr = new ImageVisual( *( mFactoryCache.Get() ), url, size ); - return Toolkit::Visual::Base( visualPtr ); + visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size ); } + + return Toolkit::Visual::Base( visualPtr.Get() ); } } // namespace Internal diff --git a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp index 551e14f..09a7a8d 100644 --- a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp +++ b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.cpp @@ -64,6 +64,10 @@ void main()\n } +WireframeVisualPtr WireframeVisual::New( VisualFactoryCache& factoryCache ) +{ + return new WireframeVisual( factoryCache ); +} WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache ) : Visual::Base( factoryCache ) @@ -71,7 +75,8 @@ WireframeVisual::WireframeVisual( VisualFactoryCache& factoryCache ) } WireframeVisual::~WireframeVisual() -{} +{ +} void WireframeVisual::DoSetOnStage( Actor& actor ) { diff --git a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h index 805e2c7..c4ff5c4 100644 --- a/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h +++ b/dali-toolkit/internal/visuals/wireframe/wireframe-visual.h @@ -18,6 +18,9 @@ * */ +// EXTERNAL INCLUDES +#include + // INTERNAL INCLUDES #include @@ -30,15 +33,27 @@ namespace Toolkit namespace Internal { +class WireframeVisual; +typedef IntrusivePtr< WireframeVisual > WireframeVisualPtr; + /** - * The visual which renders a wireframe outline to the control's quad. - * + * @brief Renders a wireframe outline to the control's quad. */ class WireframeVisual: public Visual::Base { public: /** + * @brief Create a new wireframe visual. + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @return A smart-pointer to the newly allocated visual. + */ + static WireframeVisualPtr New( VisualFactoryCache& factoryCache ); + +protected: + + /** * @brief Constructor. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object @@ -50,8 +65,6 @@ public: */ virtual ~WireframeVisual(); -protected: - /** * @copydoc Visual::Base::DoSetOnStage */ -- 2.7.4