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.h>
41 * Base class for all Control rendering logic. A control may have multiple visuals.
43 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
45 * The following properties are optional
47 * | %Property Name | Type |
48 * |-------------------------|------------------|
49 * | customShader | MAP |
51 * where custom-shader is a map with the following properties:
52 * | %Property Name | Type |
53 * |-------------------------|------------------|
54 * | vertexShader | STRING |
55 * | fragmentShader | STRING |
56 * | subdivideGridX | INT |
57 * | subdivideGridY | INT |
58 * | shaderHints | INT |
60 class Visual : public BaseObject
65 * Initialisation of the visual, this API should only called by the VisualFactory:
66 * request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
67 * record the property values.
69 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
70 * @param[in] propertyMap The properties for the requested Visual object.
72 void Initialize( Actor& actor, const Property::Map& propertyMap );
75 * @copydoc Toolkit::Visual::SetSize
77 virtual void SetSize( const Vector2& size );
80 * @copydoc Toolkit::Visual::GetSize
82 const Vector2& GetSize() const;
85 * @copydoc Toolkit::Visual::GetNaturalSize
87 virtual void GetNaturalSize( Vector2& naturalSize ) const;
90 * ToDo: Add this function to Toolkit::Visual when it is fully implemented.
92 * Set the clip rectangular of this visual.
93 * The contents of the visual will not be visible outside this rectangular.
95 * @param [in] clipRect The clipping rectangular.
97 virtual void SetClipRect( const Rect<int>& clipRect );
100 *ToDo: Add this function to Toolkit::Visual when it is fully implemented.
102 * Reposition this visual with a 2D offset.
104 * @param[in] offset The offset to reposition the visual.
106 virtual void SetOffset( const Vector2& offset );
109 * @copydoc Toolkit::Visual::SetDepthIndex
111 void SetDepthIndex( float index );
114 * @copydoc Toolkit::Visual::GetDepthIndex
116 float GetDepthIndex() const;
119 * @copydoc Toolkit::Visual::SetOnStage
120 * @pre Impl->mGeometry must be created before this method is called
122 void SetOnStage( Actor& actor );
125 * @copydoc Toolkit::Visual::SetOffStage
127 void SetOffStage( Actor& actor );
130 * @copydoc Toolkit::Visual::CreatePropertyMap
132 void CreatePropertyMap( Property::Map& map ) const;
135 * @brief Set whether the Pre-multiplied Alpha Blending is required
137 * @param[in] preMultipled whether alpha is pre-multiplied.
139 void EnablePreMultipliedAlpha( bool preMultipled );
142 * @brief Query whether alpha is pre-multiplied.
144 * @return True is alpha is pre-multiplied, false otherwise.
146 bool IsPreMultipliedAlphaEnabled() const;
149 * @brief Sets properties of custom shader
150 * @param[in] propertyMap Property map containing the custom shader data
152 void SetCustomShader( const Property::Map& propertyMap );
157 * @brief Constructor.
159 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
161 Visual( VisualFactoryCache& factoryCache );
164 * @brief A reference counted object may only be deleted by calling Unreference().
170 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
172 * @param[out] map The visual property map.
174 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
177 * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
179 * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
180 * @param[in] propertyMap The properties for the requested Visual object.
182 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
187 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
189 * @param[in] actor The actor applying this visual.
191 virtual void DoSetOnStage( Actor& actor );
194 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
196 * @param[in] actor The actor applying this visual.
198 virtual void DoSetOffStage( Actor& actor );
202 * @brief Gets the on stage state for this Visual
204 * @return Returns true if this Visual is on stage, false if it is off the stage
206 bool GetIsOnStage() const;
209 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
211 * @return Returns true if the renderer is from shared cache, false otherwise
213 bool GetIsFromCache() const;
218 Visual( const Visual& visual );
221 Visual& operator=( const Visual& visual );
226 VisualFactoryCache& mFactoryCache;
229 } // namespace Internal
231 inline const Internal::Visual& GetImplementation(const Toolkit::Visual& visual)
233 DALI_ASSERT_ALWAYS( visual && "Visual handle is empty" );
235 const BaseObject& handle = visual.GetBaseObject();
237 return static_cast<const Internal::Visual&>(handle);
240 inline Internal::Visual& GetImplementation(Toolkit::Visual& visual)
242 DALI_ASSERT_ALWAYS( visual && "Visual handle is empty" );
244 BaseObject& handle = visual.GetBaseObject();
246 return static_cast<Internal::Visual&>(handle);
249 } // namespace Toolkit
253 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H