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>
44 * Base class for all Control rendering logic. A control may have multiple visuals.
46 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
48 * The following properties are optional
50 * | %Property Name | Type |
51 * |-------------------------|------------------|
52 * | customShader | MAP |
54 * where custom-shader is a map with the following properties:
55 * | %Property Name | Type |
56 * |-------------------------|------------------|
57 * | vertexShader | STRING |
58 * | fragmentShader | STRING |
59 * | subdivideGridX | INT |
60 * | subdivideGridY | INT |
61 * | shaderHints | INT |
63 class Base : public BaseObject
68 * Initialisation of the visual, this API should only called by the VisualFactory:
69 * request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
70 * record the property values.
72 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
73 * @param[in] propertyMap The properties for the requested Visual object.
75 void Initialize( Actor& actor, const Property::Map& propertyMap );
78 * @copydoc Toolkit::Visual::Base::SetSize
80 virtual void SetSize( const Vector2& size );
83 * @copydoc Toolkit::Visual::Base::GetSize
85 const Vector2& GetSize() const;
88 * @copydoc Toolkit::Visual::Base::GetNaturalSize
90 virtual void GetNaturalSize( Vector2& naturalSize ) const;
93 * ToDo: Add this function to Toolkit::Visual when it is fully implemented.
95 * Set the clip rectangular of this visual.
96 * The contents of the visual will not be visible outside this rectangular.
98 * @param [in] clipRect The clipping rectangular.
100 virtual void SetClipRect( const Rect<int>& clipRect );
103 *ToDo: Add this function to Toolkit::Visual when it is fully implemented.
105 * Reposition this visual with a 2D offset.
107 * @param[in] offset The offset to reposition the visual.
109 virtual void SetOffset( const Vector2& offset );
112 * @copydoc Toolkit::Visual::Base::SetDepthIndex
114 void SetDepthIndex( float index );
117 * @copydoc Toolkit::Visual::Base::GetDepthIndex
119 float GetDepthIndex() const;
122 * @copydoc Toolkit::Visual::Base::SetOnStage
123 * @pre Impl->mGeometry must be created before this method is called
125 void SetOnStage( Actor& actor );
128 * @copydoc Toolkit::Visual::Base::SetOffStage
130 void SetOffStage( Actor& actor );
133 * @copydoc Toolkit::Visual::Base::CreatePropertyMap
135 void CreatePropertyMap( Property::Map& map ) const;
138 * @brief Set whether the Pre-multiplied Alpha Blending is required
140 * @param[in] preMultipled whether alpha is pre-multiplied.
142 void EnablePreMultipliedAlpha( bool preMultipled );
145 * @brief Query whether alpha is pre-multiplied.
147 * @return True is alpha is pre-multiplied, false otherwise.
149 bool IsPreMultipliedAlphaEnabled() const;
152 * @brief Sets properties of custom shader
153 * @param[in] propertyMap Property map containing the custom shader data
155 void SetCustomShader( const Property::Map& propertyMap );
160 * @brief Constructor.
162 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
164 Base( VisualFactoryCache& factoryCache );
167 * @brief A reference counted object may only be deleted by calling Unreference().
173 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
175 * @param[out] map The visual property map.
177 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
180 * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
182 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
183 * @param[in] propertyMap The properties for the requested Visual object.
185 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {}
190 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
192 * @param[in] actor The actor applying this visual.
194 virtual void DoSetOnStage( Actor& actor );
197 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
199 * @param[in] actor The actor applying this visual.
201 virtual void DoSetOffStage( Actor& actor );
205 * @brief Gets the on stage state for this Visual
207 * @return Returns true if this Visual is on stage, false if it is off the stage
209 bool GetIsOnStage() const;
212 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
214 * @return Returns true if the renderer is from shared cache, false otherwise
216 bool GetIsFromCache() const;
221 Base( const Visual::Base& visual );
224 Base& operator=( const Visual::Base& visual );
229 VisualFactoryCache& mFactoryCache;
234 } // namespace Internal
236 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
238 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
240 const BaseObject& handle = visualBase.GetBaseObject();
242 return static_cast<const Internal::Visual::Base&>(handle);
245 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
247 DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
249 BaseObject& handle = visualBase.GetBaseObject();
251 return static_cast<Internal::Visual::Base&>(handle);
254 } // namespace Toolkit
258 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H