X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fnpatch%2Fnpatch-visual.h;h=0a0465fe5101fc6b7645273c87d6fb71a7cbddc7;hp=a9933036c2845bc3f78ba132cdb8523218863e38;hb=675f5551ef3c7ca20ec45c36b865a5092883af43;hpb=b81c20064def5a5017e77876effd01ddc5bb39d6 diff --git a/dali-toolkit/internal/visuals/npatch/npatch-visual.h b/dali-toolkit/internal/visuals/npatch/npatch-visual.h index a993303..0a0465f 100644 --- a/dali-toolkit/internal/visuals/npatch/npatch-visual.h +++ b/dali-toolkit/internal/visuals/npatch/npatch-visual.h @@ -18,17 +18,18 @@ * */ -// INTERNAL INCLUDES -#include - // EXTERNAL INCLUDES +#include #include #include -#include +#include #include #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,23 +58,42 @@ class NPatchVisual: public Visual::Base public: /** - * @brief Constructor. + * @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 * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] imageUrl The URL to 9 patch image resource to use + * @param[in] properties A Property::Map containing settings for this visual + * @return A smart-pointer to the newly allocated visual. */ - NPatchVisual( VisualFactoryCache& factoryCache ); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties ); /** - * @brief A reference counted object may only be deleted by calling Unreference(). + * @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 + * + * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object + * @param[in] imageUrl The URL to 9 patch image resource to use + * @return A smart-pointer to the newly allocated visual. */ - ~NPatchVisual(); + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl ); + + /** + * @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 + */ + static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image ); public: // from Visual /** * @copydoc Visual::Base::GetNaturalSize */ - virtual void GetNaturalSize( Vector2& naturalSize ) const; + virtual void GetNaturalSize( Vector2& naturalSize ); /** * @copydoc Visual::Base::CreatePropertyMap @@ -80,45 +103,38 @@ public: // from Visual protected: /** - * @copydoc Visual::Base::DoInitialize + * @brief Constructor. + * + * @param[in] factoryCache Reference to the VisualFactoryCache object */ - virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ); + NPatchVisual( VisualFactoryCache& factoryCache ); /** - * @copydoc Visual::Base::DoSetOnStage + * @brief A reference counted object may only be deleted by calling Unreference(). */ - virtual void DoSetOnStage( Actor& actor ); + virtual ~NPatchVisual(); /** - * @copydoc Visual::Base::DoSetOffStage + * @copydoc Visual::Base::DoSetProperties */ - virtual void DoSetOffStage( Actor& actor ); - -public: + virtual void DoSetProperties( const Property::Map& propertyMap ); /** - * @brief Sets the 9 patch image of this visual to the resource at imageUrl - * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage - * - * @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 + * @copydoc Visual::Base::DoSetOnStage */ - void SetImage( const std::string& imageUrl, bool borderOnly = false ); + virtual void DoSetOnStage( Actor& actor ); /** - * @brief Sets the 9 patch image of this viusal to the 9 patch image - * - * @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 + * @copydoc Visual::Base::DoSetOffStage */ - void SetImage( NinePatchImage image, bool borderOnly = false ); - -private: + virtual void DoSetOffStage( Actor& actor ); /** - * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing. + * @copydoc Visual::Base::OnSetTransform */ - void InitializeRenderer(); + virtual void OnSetTransform(); + +private: /** * @brief Creates a geometry for this renderer's grid size @@ -135,12 +151,24 @@ private: Shader CreateShader(); /** + * @brief Applies texture and related uniforms + */ + void ApplyTextureAndUniforms(); + + /** + * Helper method to get the default Nine patch geometry from cache or create and store it there + * @param subType to use + * @return the geometry + */ + Geometry GetNinePatchGeometry( VisualFactoryCache::GeometryType subType ); + + /** * @brief Creates a geometry for the grid size to be used by this visuals' shaders * * @param[in] gridSize The grid size of the solid geometry to create * @return Returns the created geometry for the grid size */ - Geometry CreateGeometry( Uint16Pair gridSize ); + Geometry CreateGridGeometry( Uint16Pair gridSize ); /** * @brief Creates a geometry with the border only for the grid size to be used by this visuals' shaders @@ -163,45 +191,15 @@ private: * @param[in] gridSize The grid size of the solid geometry to create * @return Returns the created geometry for the grid size */ - Geometry CreateGeometryBorder( Uint16Pair gridSize ); - - /** - * @brief Creates Image from the image url and parses the image for the stretch borders. Will create a error image if the n patch image is invalid - * - * @param[in] nPatchImage The NinePatchImage to base our cropped images and stretch borders from - */ - void InitializeFromImage( NinePatchImage nPatchImage ); - - /** - * @brief Creates an error Image to indicate that there was an error in either the image url or the parsing of the image - * - */ - void InitializeFromBrokenImage(); - - /** - * @brief Applies this renderer's image to the sampler to the texture set used for this renderer - */ - void ApplyImageToSampler(); - - /** - * @brief Changes the current renderer if the n-patch meta data has changed - * - * @param[in] oldBorderOnly The old flag indicating if the image should omit the centre of the n-patch and only render the border - * @param[in] oldGridX The old horizontal grid size of the solid geometry - * @param[in] oldGridY The old vertical grid size of the solid geometry - */ - void ChangeRenderer( bool oldBorderOnly, size_t oldGridX, size_t oldGridY ); + Geometry CreateBorderGeometry( Uint16Pair gridSize ); private: - NinePatchImage mImage; ///< The image to render if the visual was set from an NinePatchImage, empty otherwise - Image mCroppedImage; + NPatchLoader& mLoader; ///< reference to N patch loader for fast access + std::string mImageUrl; ///< The url to the N patch to load + std::size_t mId; ///< id of the N patch (from loader/cache) + bool mBorderOnly; ///< if only border is desired - std::string mImageUrl; ///< The url to the image resource to render if the visual was set from an image resource url, empty otherwise - NinePatchImage::StretchRanges mStretchPixelsX; - NinePatchImage::StretchRanges mStretchPixelsY; - ImageDimensions mImageSize; - bool mBorderOnly; }; } // namespace Internal