1 #ifndef DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_GRADIENT_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>
25 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
26 #include <dali-toolkit/internal/visuals/gradient/gradient.h>
40 typedef IntrusivePtr< GradientVisual > GradientVisualPtr;
43 * The visual which renders smooth transition of colors to the control's quad.
44 * It supports two types of gradients: linear and radial.
46 * The following properties are essential for create a LINEAR GradientRender
48 * | %Property Name | Type |
49 * |-------------------------|------------------|
50 * | startPosition | VECTOR2 |
51 * | endPosition | VECTOR2 |
52 * | stopColor | ARRAY of VECTOR4 |
54 * The following properties are essential for create a RADIAL GradientRender
56 * | %Property Name | Type |
57 * |-------------------------|------------------|
58 * | center | VECTOR2 |
60 * | stopColor | ARRAY of VECTOR4 |
62 * The following properties are optional for both LINEAR and RADIAL GradientRender.
64 * | %Property Name | Type |
65 * |-------------------------|------------------|
66 * | stopOffset | ARRAY of FLOAT |
68 * | spreadMethod | STRING |
70 * Valid values for units are 'userSpace' and 'objectBoundingBox'.
71 * Valid values for spreadMethod are 'pad', 'repeat' and 'reflect.'
72 * If not provided, 'objectBoundingBox' is used as default gradient units, and 'pad' is used as default spread method.
74 class GradientVisual: public Visual::Base
79 * Types of the gradient
88 * @brief Create a new gradient visual.
90 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
91 * @return A smart-pointer to the newly allocated visual.
93 static GradientVisualPtr New( VisualFactoryCache& factoryCache );
95 public: // from Visual
98 * @copydoc Visual::Base::CreatePropertyMap
100 virtual void DoCreatePropertyMap( Property::Map& map ) const;
103 * @copydoc Visual::Base::DoSetProperty
105 virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
108 * @copydoc Visual::Base::DoGetProperty
110 virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
115 * @brief Constructor.
117 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
119 GradientVisual( VisualFactoryCache& factoryCache );
122 * @brief A reference counted object may only be deleted by calling Unreference().
124 virtual ~GradientVisual();
127 * @copydoc Visual::Base::DoSetProperties
129 virtual void DoSetProperties( const Property::Map& propertyMap );
132 * @copydoc Visual::Base::OnSetTransform
134 virtual void OnSetTransform();
137 * @copydoc Visual::Base::DoSetOnStage
139 virtual void DoSetOnStage( Actor& actor );
144 * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
146 void InitializeRenderer();
149 * New a gradient object with the given property map.
151 * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
153 bool NewGradient(Type gradientType, const Property::Map& propertyMap);
156 * Get the stop-offsets from the property.
157 * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
159 * @param[in] value The property value of stop-offsets
160 * @param[out] stopOffsets The vector contains the stop offset values.
162 static void GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
165 GradientVisual( const GradientVisual& gradientVisual );
168 GradientVisual& operator=( const GradientVisual& gradientVisual );
172 Matrix3 mGradientTransform;
173 IntrusivePtr<Gradient> mGradient;
175 bool mIsOpaque; ///< Set to false if any of the stop colors are not opaque
178 } // namespace Internal
180 } // namespace Toolkit
184 #endif /* DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H */