1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_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/animation/animation.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/rendering/renderer.h>
27 #include <dali/public-api/rendering/shader.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
32 #include <dali-toolkit/internal/visuals/transition-data-impl.h>
33 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
48 * Base class for all Control rendering logic. A control may have multiple visuals.
50 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
52 * The following properties are optional
54 * | %Property Name | Type |
55 * |-------------------------|------------------|
56 * | customShader | MAP |
58 * where custom-shader is a map with the following properties:
59 * | %Property Name | Type |
60 * |-------------------------|------------------|
61 * | vertexShader | STRING |
62 * | fragmentShader | STRING |
63 * | subdivideGridX | INT |
64 * | subdivideGridY | INT |
65 * | shaderHints | INT |
67 class Base : public BaseObject
72 * Setting the properties of the visual, this API should only called by the VisualFactory
73 * @param[in] propertyMap The properties for the requested Visual object.
75 void SetProperties( const Property::Map& propertyMap );
78 * @copydoc Toolkit::Visual::Base::SetName
80 void SetName( const std::string& name );
83 * @copydoc Toolkit::Visual::Base::GetName
85 const std::string& GetName();
88 * @copydoc Toolkit::Visual::Base::SetSize
90 void SetTransformAndSize( const Property::Map& transform, Size controlSize );
93 * @copydoc Toolkit::Visual::Base::GetHeightForWidth
95 virtual float GetHeightForWidth( float width );
98 * @copydoc Toolkit::Visual::Base::GetWidthForHeight
100 virtual float GetWidthForHeight( float height );
103 * @copydoc Toolkit::Visual::Base::GetNaturalSize
105 virtual void GetNaturalSize( Vector2& naturalSize );
108 * @copydoc Toolkit::Visual::Base::SetDepthIndex
110 void SetDepthIndex( float index );
113 * @copydoc Toolkit::Visual::Base::GetDepthIndex
115 float GetDepthIndex() const;
118 * @copydoc Toolkit::Visual::Base::SetOnStage
119 * @pre Impl->mGeometry must be created before this method is called
121 void SetOnStage( Actor& actor );
124 * @copydoc Toolkit::Visual::Base::SetOffStage
126 void SetOffStage( Actor& actor );
129 * @copydoc Toolkit::Visual::Base::CreatePropertyMap
131 void CreatePropertyMap( Property::Map& map ) const;
134 * @brief Set whether the Pre-multiplied Alpha Blending is required
136 * @param[in] preMultipled whether alpha is pre-multiplied.
138 void EnablePreMultipliedAlpha( bool preMultipled );
141 * @brief Query whether alpha is pre-multiplied.
143 * @return True is alpha is pre-multiplied, false otherwise.
145 bool IsPreMultipliedAlphaEnabled() const;
148 * @brief Sets properties of custom shader
149 * @param[in] propertyMap Property map containing the custom shader data
151 void SetCustomShader( const Property::Map& propertyMap );
154 * @copydoc Toolkit::Visual::Base::SetProperty
156 void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
159 * @copydoc Toolkit::Visual::Base::GetProperty
161 Dali::Property::Value GetProperty( Dali::Property::Index index );
164 * Gets currently staged renderer, or an empty handle if not staged
166 Renderer GetRenderer();
169 * Sets the mix color of the visual.
170 * @param[in] mixColor The new mix color
172 void SetMixColor( const Vector4& color );
175 * Gets the mix color of the visual.
176 * @return The mix color
178 const Vector4& GetMixColor() const;
181 * Animate the property if it exists in the visual or renderer.
183 * If it's a visual property such as mix color or a transform property,
184 * saves the target value to the local data.
186 * If the visual isn't staged (i.e. it doesn't have a renderer),
187 * then this will not add an animation.
189 * @param[in] transition The animation to create or attach to
190 * @param[in] animator The animation parameters of the property.
192 void AnimateProperty( Dali::Animation& transition,
193 Internal::TransitionData::Animator& animator );
198 * @brief Constructor.
200 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
202 Base( VisualFactoryCache& factoryCache );
205 * @brief A reference counted object may only be deleted by calling Unreference().
212 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
214 * @param[out] map The visual property map.
216 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
219 * @brief Called by SetProperties() allowing sub classes to set their properties
221 * @param[in] propertyMap The properties for the requested Visual object.
223 virtual void DoSetProperties( const Property::Map& propertyMap ) = 0;
226 * @brief Called when transform or control size changes
227 * ( Of use to SVG and Text visuals )
229 virtual void OnSetTransform() = 0;
232 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
234 * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
236 * @param[in] actor The actor applying this visual.
238 virtual void DoSetOnStage( Actor& actor )=0;
241 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
243 * @param[in] actor The actor applying this visual.
245 virtual void DoSetOffStage( Actor& actor );
250 * @brief Gets the on stage state for this Visual
252 * @return Returns true if this Visual is on stage, false if it is off the stage
254 bool IsOnStage() const;
257 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
259 * @return Returns true if the renderer is from shared cache, false otherwise
261 bool IsFromCache() const;
266 * Register the mix color uniform on the Renderer and store the property index.
267 * Note, this is not used by Color or Primitive Visuals, which will use their
268 * own property index.
270 void RegisterMixColor();
273 * Find the matching property on the renderer or shader. If it's a shader
274 * property, register it on the renderer in order to animate it for this
275 * visual independently.
276 * @param[in] key The key to match.
277 * @return the matching index, or INVALID_INDEX if it's not found
279 Property::Index GetPropertyIndex( Property::Key key );
282 * Set up the transition. If no animation is required, then
283 * transition will be untouched.
285 * @param[in] transition The transition to use or set up.
286 * @param[in] animator The animation data to use
287 * @param[in] index The property index on the renderer to animate
289 void SetupTransition( Dali::Animation& transition,
290 Internal::TransitionData::Animator& animator,
291 Property::Index index );
294 * When a mix color animation has finished, ensure the blend mode is set back
295 * to the right value for the target opacity.
297 void OnMixColorFinished( Animation& animation );
300 Base( const Visual::Base& visual );
303 Base& operator=( const Visual::Base& visual );
308 VisualFactoryCache& mFactoryCache;
311 typedef IntrusivePtr<Base> BasePtr;
315 } // namespace Internal
317 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
319 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
321 const BaseObject& handle = visualBase.GetBaseObject();
323 return static_cast<const Internal::Visual::Base&>(handle);
326 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
328 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
330 BaseObject& handle = visualBase.GetBaseObject();
332 return static_cast<Internal::Visual::Base&>(handle);
335 } // namespace Toolkit
339 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H