1 #ifndef DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_H
5 * Copyright (c) 2016 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/visuals/visual-base-impl.h>
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/images/nine-patch-image.h>
28 #include <dali/public-api/rendering/geometry.h>
29 #include <dali/public-api/rendering/sampler.h>
30 #include <dali/public-api/rendering/shader.h>
42 * The visual which renders an 9 patch image to the control's quad
44 * The following properties are optional
46 * | %Property Name | Type |
47 * |--------------------------|------------------|
49 * | borderOnly | BOOLEAN
52 class NPatchVisual: public Visual::Base
59 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
61 NPatchVisual( VisualFactoryCache& factoryCache );
64 * @brief A reference counted object may only be deleted by calling Unreference().
68 public: // from Visual
71 * @copydoc Visual::GetNaturalSize
73 virtual void GetNaturalSize( Vector2& naturalSize ) const;
76 * @copydoc Visual::SetClipRect
78 virtual void SetClipRect( const Rect<int>& clipRect );
81 * @copydoc Visual::SetOffset
83 virtual void SetOffset( const Vector2& offset );
86 * @copydoc Visual::CreatePropertyMap
88 virtual void DoCreatePropertyMap( Property::Map& map ) const;
93 * @copydoc Visual::DoInitialize
95 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
98 * @copydoc Visual::DoSetOnStage
100 virtual void DoSetOnStage( Actor& actor );
103 * @copydoc Visual::DoSetOffStage
105 virtual void DoSetOffStage( Actor& actor );
110 * @brief Sets the 9 patch image of this visual to the resource at imageUrl
111 * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
113 * @param[in] imageUrl The URL to 9 patch image resource to use
114 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
116 void SetImage( const std::string& imageUrl, bool borderOnly = false );
119 * @brief Sets the 9 patch image of this viusal to the 9 patch image
121 * @param[in] image The NinePatchImage to use
122 * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
124 void SetImage( NinePatchImage image, bool borderOnly = false );
129 * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
131 void InitializeRenderer();
134 * @brief Creates a geometry for this renderer's grid size
136 * @return Returns the created geometry for this renderer's grid size
138 Geometry CreateGeometry();
141 * @brief Creates a shader for this renderer's grid size
143 * @return Returns the created shader for this renderer's grid size
145 Shader CreateShader();
148 * @brief Creates a geometry for the grid size to be used by this visuals' shaders
150 * @param[in] gridSize The grid size of the solid geometry to create
151 * @return Returns the created geometry for the grid size
153 Geometry CreateGeometry( Uint16Pair gridSize );
156 * @brief Creates a geometry with the border only for the grid size to be used by this visuals' shaders
157 * e.g. a 5x4 grid would create a geometry that would look like:
159 * ---------------------
162 * ---------------------
168 * ---------------------
171 * ---------------------
173 * @param[in] gridSize The grid size of the solid geometry to create
174 * @return Returns the created geometry for the grid size
176 Geometry CreateGeometryBorder( Uint16Pair gridSize );
179 * @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
181 * @param[in] nPatchImage The NinePatchImage to base our cropped images and stretch borders from
183 void InitializeFromImage( NinePatchImage nPatchImage );
186 * @brief Creates an error Image to indicate that there was an error in either the image url or the parsing of the image
189 void InitializeFromBrokenImage();
192 * @brief Applies this renderer's image to the sampler to the texture set used for this renderer
194 void ApplyImageToSampler();
197 * @brief Changes the current renderer if the n-patch meta data has changed
199 * @param[in] oldBorderOnly The old flag indicating if the image should omit the centre of the n-patch and only render the border
200 * @param[in] oldGridX The old horizontal grid size of the solid geometry
201 * @param[in] oldGridY The old vertical grid size of the solid geometry
203 void ChangeRenderer( bool oldBorderOnly, size_t oldGridX, size_t oldGridY );
207 NinePatchImage mImage; ///< The image to render if the visual was set from an NinePatchImage, empty otherwise
210 std::string mImageUrl; ///< The url to the image resource to render if the visual was set from an image resource url, empty otherwise
211 NinePatchImage::StretchRanges mStretchPixelsX;
212 NinePatchImage::StretchRanges mStretchPixelsY;
213 ImageDimensions mImageSize;
217 } // namespace Internal
219 } // namespace Toolkit
223 #endif // DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_H