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/images/image-operations.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/rendering/shader.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
28 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
43 class ResourceObserver;
46 * Base class for all Control rendering logic. A control may have multiple visuals.
48 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
50 * The following properties are optional
52 * | %Property Name | Type |
53 * |-------------------------|------------------|
54 * | customShader | MAP |
56 * where custom-shader is a map with the following properties:
57 * | %Property Name | Type |
58 * |-------------------------|------------------|
59 * | vertexShader | STRING |
60 * | fragmentShader | STRING |
61 * | subdivideGridX | INT |
62 * | subdivideGridY | INT |
63 * | shaderHints | INT |
65 class Base : public BaseObject
70 * Initialisation of the visual, this API should only called by the VisualFactory:
71 * request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
72 * record the property values.
74 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
75 * @param[in] propertyMap The properties for the requested Visual object.
77 void Initialize( Actor& actor, const Property::Map& propertyMap );
80 * @copydoc Toolkit::Visual::Base::SetSize
82 virtual void SetSize( const Vector2& size );
85 * @copydoc Toolkit::Visual::Base::GetSize
87 const Vector2& GetSize() const;
90 * @copydoc Toolkit::Visual::Base::SetName
92 void SetName( const std::string& name );
95 * @copydoc Toolkit::Visual::Base::GetName
97 const std::string& GetName() const;
100 * @copydoc Toolkit::Visual::Base::GetNaturalSize
102 virtual void GetNaturalSize( Vector2& naturalSize ) const;
105 * ToDo: Add this function to Toolkit::Visual when it is fully implemented.
107 * Set the clip rectangular of this visual.
108 * The contents of the visual will not be visible outside this rectangular.
110 * @param [in] clipRect The clipping rectangular.
112 virtual void SetClipRect( const Rect<int>& clipRect );
115 *ToDo: Add this function to Toolkit::Visual when it is fully implemented.
117 * Reposition this visual with a 2D offset.
119 * @param[in] offset The offset to reposition the visual.
121 virtual void SetOffset( const Vector2& offset );
124 * @copydoc Toolkit::Visual::Base::SetDepthIndex
126 void SetDepthIndex( float index );
129 * @copydoc Toolkit::Visual::Base::GetDepthIndex
131 float GetDepthIndex() const;
134 * @copydoc Toolkit::Visual::Base::SetOnStage
135 * @pre Impl->mGeometry must be created before this method is called
137 void SetOnStage( Actor& actor );
140 * @copydoc Toolkit::Visual::Base::SetOffStage
142 void SetOffStage( Actor& actor );
145 * @copydoc Toolkit::Visual::Base::CreatePropertyMap
147 void CreatePropertyMap( Property::Map& map ) const;
150 * @brief Set whether the Pre-multiplied Alpha Blending is required
152 * @param[in] preMultipled whether alpha is pre-multiplied.
154 void EnablePreMultipliedAlpha( bool preMultipled );
157 * @brief Query whether alpha is pre-multiplied.
159 * @return True is alpha is pre-multiplied, false otherwise.
161 bool IsPreMultipliedAlphaEnabled() const;
164 * @brief Sets properties of custom shader
165 * @param[in] propertyMap Property map containing the custom shader data
167 void SetCustomShader( const Property::Map& propertyMap );
170 * @brief Add an observer to watch for when the Visuals resources are loaded.
171 * Currently only supports a single observer
174 void AddResourceObserver( Visual::ResourceObserver& observer );
177 * @brief Remove an observer
179 void RemoveResourceObserver( Visual::ResourceObserver& observer );
182 * @brief Called when the visuals resources are loaded / ready
184 void ResourceReady();
187 * @brief Called when the visuals resources are loaded / ready
188 * @return true if ready, false otherwise
190 bool IsResourceReady() const;
195 * @brief Constructor.
197 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
199 Base( VisualFactoryCache& factoryCache );
202 * @brief A reference counted object may only be deleted by calling Unreference().
208 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
210 * @param[out] map The visual property map.
212 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
215 * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
217 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
218 * @param[in] propertyMap The properties for the requested Visual object.
220 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
225 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
227 * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
228 * @param[in] actor The actor applying this visual.
230 virtual void DoSetOnStage( Actor& actor ) = 0;
233 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
235 * @param[in] actor The actor applying this visual.
237 virtual void DoSetOffStage( Actor& actor );
241 * @brief Gets the on stage state for this Visual
243 * @return Returns true if this Visual is on stage, false if it is off the stage
245 bool GetIsOnStage() const;
248 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
250 * @return Returns true if the renderer is from shared cache, false otherwise
252 bool GetIsFromCache() const;
257 Base( const Visual::Base& visual );
260 Base& operator=( const Visual::Base& visual );
265 VisualFactoryCache& mFactoryCache;
270 } // namespace Internal
272 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
274 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
276 const BaseObject& handle = visualBase.GetBaseObject();
278 return static_cast<const Internal::Visual::Base&>(handle);
281 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
283 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
285 BaseObject& handle = visualBase.GetBaseObject();
287 return static_cast<Internal::Visual::Base&>(handle);
290 } // namespace Toolkit
294 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H