1 #ifndef __DALI_TOOLKIT_INTERNAL_N_PATCH_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_N_PATCH_RENDERER_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/images/nine-patch-image.h>
27 #include <dali/public-api/images/image-operations.h>
28 #include <dali/devel-api/rendering/geometry.h>
29 #include <dali/devel-api/rendering/shader.h>
30 #include <dali/devel-api/rendering/sampler.h>
31 #include <dali/integration-api/image-integ.h>
43 * The renderer which renders an 9 patch image to the control's quad
45 * The following properties are optional
47 * | %Property Name | Type |
48 * |---------------------------|------------------|
49 * | image-url | STRING |
50 * | border-only | BOOLEAN
53 class NPatchRenderer: public ControlRenderer
60 * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
62 NPatchRenderer( RendererFactoryCache& factoryCache );
65 * @brief A reference counted object may only be deleted by calling Unreference().
69 public: // from ControlRenderer
72 * @copydoc ControlRenderer::GetNaturalSize
74 virtual void GetNaturalSize( Vector2& naturalSize ) const;
77 * @copydoc ControlRenderer::SetClipRect
79 virtual void SetClipRect( const Rect<int>& clipRect );
82 * @copydoc ControlRenderer::SetOffset
84 virtual void SetOffset( const Vector2& offset );
87 * @copydoc ControlRenderer::CreatePropertyMap
89 virtual void DoCreatePropertyMap( Property::Map& map ) const;
94 * @copydoc ControlRenderer::DoInitialize
96 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
99 * @copydoc ControlRenderer::DoSetOnStage
101 virtual void DoSetOnStage( Actor& actor );
104 * @copydoc ControlRenderer::DoSetOffStage
106 virtual void DoSetOffStage( Actor& actor );
111 * @brief Sets the 9 patch image of this renderer to the resource at imageUrl
112 * The renderer will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
114 * @param[in] imageUrl The URL to 9 patch image resource to use
115 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
117 void SetImage( const std::string& imageUrl, bool borderOnly = false );
120 * @brief Sets the 9 patch image of this renderer to the 9 patch image
122 * @param[in] image The NinePatchImage to use
123 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
125 void SetImage( NinePatchImage image, bool borderOnly = false );
130 * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
132 void InitializeRenderer();
135 * @brief Creates a geometry for this renderer's grid size
137 * @return Returns the created geometry for this renderer's grid size
139 Geometry CreateGeometry();
142 * @brief Creates a shader for this renderer's grid size
144 * @return Returns the created shader for this renderer's grid size
146 Shader CreateShader();
149 * @brief Creates a geometry for the grid size to be used by this renderers' shaders
151 * @param[in] gridSize The grid size of the solid geometry to create
152 * @return Returns the created geometry for the grid size
154 Geometry CreateGeometry( Uint16Pair gridSize );
157 * @brief Creates a geometry with the border only for the grid size to be used by this renderers' shaders
158 * e.g. a 5x4 grid would create a geometry that would look like:
160 * ---------------------
163 * ---------------------
169 * ---------------------
172 * ---------------------
174 * @param[in] gridSize The grid size of the solid geometry to create
175 * @return Returns the created geometry for the grid size
177 Geometry CreateGeometryBorder( Uint16Pair gridSize );
180 * @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
182 * @param[in] nPatchImage The NinePatchImage to base our cropped images and stretch borders from
184 void InitializeFromImage( NinePatchImage nPatchImage );
187 * @brief Creates an error Image to indicate that there was an error in either the image url or the parsing of the image
190 void InitializeFromBrokenImage();
193 * @brief Applies this renderer's image to the sampler to the material used for this renderer
195 void ApplyImageToSampler();
198 * @brief Changes the current renderer if the n-patch meta data has changed
200 * @param[in] oldBorderOnly The old flag indicating if the image should omit the centre of the n-patch and only render the border
201 * @param[in] oldGridX The old horizontal grid size of the solid geometry
202 * @param[in] oldGridY The old vertical grid size of the solid geometry
204 void ChangeRenderer( bool oldBorderOnly, size_t oldGridX, size_t oldGridY );
208 NinePatchImage mImage; ///< The image to render if the renderer was set from an NinePatchImage, empty otherwise
211 std::string mImageUrl; ///< The url to the image resource to render if the renderer was set from an image resource url, empty otherwise
212 Integration::StretchRanges mStretchPixelsX;
213 Integration::StretchRanges mStretchPixelsY;
214 ImageDimensions mImageSize;
218 } // namespace Internal
220 } // namespace Toolkit
224 #endif /* __DALI_TOOLKIT_INTERNAL_N_PATCH_RENDERER_H__ */