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/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/images/image.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/devel-api/images/nine-patch-image.h>
26 #include <dali/public-api/rendering/geometry.h>
27 #include <dali/public-api/rendering/sampler.h>
28 #include <dali/public-api/rendering/shader.h>
31 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
43 typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr;
46 * The visual which renders an 9 patch image to the control's quad
48 * The following properties are optional
50 * | %Property Name | Type |
51 * |--------------------------|------------------|
53 * | borderOnly | BOOLEAN
56 class NPatchVisual: public Visual::Base
61 * @brief Create an N-patch visual using an image URL.
63 * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
65 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
66 * @param[in] imageUrl The URL to 9 patch image resource to use
68 static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
71 * @brief Create an N-patch visual with a NinePatchImage resource.
73 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
74 * @param[in] image The NinePatchImage to use
76 static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image );
78 public: // from Visual
81 * @copydoc Visual::Base::GetNaturalSize
83 virtual void GetNaturalSize( Vector2& naturalSize );
86 * @copydoc Visual::Base::CreatePropertyMap
88 virtual void DoCreatePropertyMap( Property::Map& map ) const;
95 * @param[in] factoryCache Reference to the VisualFactoryCache object
97 NPatchVisual( VisualFactoryCache& factoryCache );
100 * @brief A reference counted object may only be deleted by calling Unreference().
102 virtual ~NPatchVisual();
105 * @copydoc Visual::Base::DoSetProperties
107 virtual void DoSetProperties( const Property::Map& propertyMap );
110 * @copydoc Visual::Base::DoSetOnStage
112 virtual void DoSetOnStage( Actor& actor );
115 * @copydoc Visual::Base::DoSetOffStage
117 virtual void DoSetOffStage( Actor& actor );
120 * @copydoc Visual::Base::OnSetTransform
122 virtual void OnSetTransform();
127 * @brief Creates a geometry for this renderer's grid size
129 * @return Returns the created geometry for this renderer's grid size
131 Geometry CreateGeometry();
134 * @brief Creates a shader for this renderer's grid size
136 * @return Returns the created shader for this renderer's grid size
138 Shader CreateShader();
141 * @brief Applies texture and related uniforms
143 void ApplyTextureAndUniforms();
146 * Helper method to get the default Nine patch geometry from cache or create and store it there
147 * @param subType to use
148 * @return the geometry
150 Geometry GetNinePatchGeometry( VisualFactoryCache::GeometryType subType );
153 * @brief Creates a geometry for the grid size to be used by this visuals' shaders
155 * @param[in] gridSize The grid size of the solid geometry to create
156 * @return Returns the created geometry for the grid size
158 Geometry CreateGridGeometry( Uint16Pair gridSize );
161 * @brief Creates a geometry with the border only for the grid size to be used by this visuals' shaders
162 * e.g. a 5x4 grid would create a geometry that would look like:
164 * ---------------------
167 * ---------------------
173 * ---------------------
176 * ---------------------
178 * @param[in] gridSize The grid size of the solid geometry to create
179 * @return Returns the created geometry for the grid size
181 Geometry CreateBorderGeometry( Uint16Pair gridSize );
185 NPatchLoader& mLoader; ///< reference to N patch loader for fast access
186 std::string mImageUrl; ///< The url to the N patch to load
187 std::size_t mId; ///< id of the N patch (from loader/cache)
188 bool mBorderOnly; ///< if only border is desired
192 } // namespace Internal
194 } // namespace Toolkit
198 #endif // DALI_TOOLKIT_INTERNAL_N_PATCH_VISUAL_H