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>
42 * The renderer which renders an 9 patch image to the control's quad
44 * The following properties are optional
46 * | %Property Name | Type |
47 * |---------------------------|------------------|
48 * | image-url | STRING |
49 * | border-only | BOOLEAN
52 class NPatchRenderer: public ControlRenderer
62 * @brief A reference counted object may only be deleted by calling Unreference().
66 public: // from ControlRenderer
69 * @copydoc ControlRenderer::Initialize
71 virtual void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap );
74 * @copydoc ControlRenderer::SetClipRect
76 virtual void SetClipRect( const Rect<int>& clipRect );
79 * @copydoc ControlRenderer::SetOffset
81 virtual void SetOffset( const Vector2& offset );
84 * @copydoc ControlRenderer::CreatePropertyMap
86 virtual void CreatePropertyMap( Property::Map& map ) const;
90 * @copydoc ControlRenderer::DoSetOnStage
92 virtual void DoSetOnStage( Actor& actor );
95 * @copydoc ControlRenderer::DoSetOffStage
97 virtual void DoSetOffStage( Actor& actor );
102 * Request the geometry and shader from the cache, if not available, create and save to the cache for sharing.
104 * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
106 void Initialize( RendererFactoryCache& factoryCache );
109 * @brief Sets the 9 patch image of this renderer to the resource at imageUrl
110 * The renderer will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
112 * @param[in] imageUrl The URL to 9 patch image resource to use
113 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
115 void SetImage( const std::string& imageUrl, bool borderOnly = false );
118 * @brief Sets the 9 patch image of this renderer to the 9 patch image
120 * @param[in] image The NinePatchImage to use
121 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
123 void SetImage( NinePatchImage image, bool borderOnly = false );
128 * @brief Creates a geometry for the grid size to be used by this renderers' shaders
130 * @param gridSize The grid size of the solid geometry to create
131 * @return Returns the created geometry for the grid size
133 Geometry CreateGeometry( Uint16Pair gridSize );
136 * @brief Creates a geometry with the border only for the grid size to be used by this renderers' shaders
137 * e.g. a 5x4 grid would create a geometry that would look like:
139 * ---------------------
142 * ---------------------
148 * ---------------------
151 * ---------------------
153 * @param gridSize The grid size of the solid geometry to create
154 * @return Returns the created geometry for the grid size
156 Geometry CreateGeometryBorder( Uint16Pair gridSize );
159 * @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
161 * @param nPatchImage The NinePatchImage to base our cropped images and stretch borders from
163 void InitialiseFromImage( NinePatchImage nPatchImage );
166 * @brief Creates a black Image to indicate that there was an error in either the image url or the parsing of the image
169 void CreateErrorImage();
172 * @brief Applies this renderer's image to the sampler to the material used for this renderer
174 void ApplyImageToSampler();
178 NinePatchImage mImage; ///< The image to render if the renderer was set from an NinePatchImage, empty otherwise
180 Geometry mNinePatchGeometry;
181 Geometry mNinePatchBorderGeometry;
182 Shader mNinePatchShader;
184 std::string mImageUrl; ///< The url to the image resource to render if the renderer was set from an image resource url, empty otherwise
185 NinePatchImage::StretchRanges mStretchPixelsX;
186 NinePatchImage::StretchRanges mStretchPixelsY;
187 ImageDimensions mImageSize;
191 } // namespace Internal
193 } // namespace Toolkit
197 #endif /* __DALI_TOOLKIT_INTERNAL_N_PATCH_RENDERER_H__ */