Add GetVisualProperty to Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / gradient / gradient.h
1 #ifndef DALI_TOOLKIT_INTERNAL_GRADIENT_H
2 #define DALI_TOOLKIT_INTERNAL_GRADIENT_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/matrix3.h>
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/rendering/texture.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/visuals/gradient-visual-properties.h>
29
30 namespace Dali
31 {
32
33 class Vector4;
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42  * Gradients consist of continuously smooth color transitions along a vector from one color to another,
43  * possibly followed by additional transitions along the same vector to other colors.
44  */
45 class Gradient : public RefObject
46 {
47 public:
48
49   /**
50    * The stop node tells the gradient what color it should be at certain position.
51    */
52   struct GradientStop
53   {
54     GradientStop( float offset, const Vector4& color )
55     : mOffset( offset ), mStopColor( color )
56     {}
57
58     bool operator<(const GradientStop& rhs) const
59     {
60       return mOffset < rhs.mOffset;
61     }
62
63     float   mOffset;     // A value ranging from 0 to 1 to indicate where the gradient stop is placed.
64     Vector4 mStopColor;  // The color to use at this gradient stop
65   };
66
67 public:
68
69   /**
70    * Add a gradient stop.
71    *
72    * @param[in] offset The position to place the stop.
73    * @param[in] color  The color to use at this stop.
74    */
75   void AddStop(float offset, const Vector4& color);
76
77   /**
78    * Get the gradient stops.
79    * @return The vector of gradient stops.
80    */
81   const Vector<GradientStop>& GetStops();
82
83   /**
84    * Set the coordinate system used by the gradient attributes.
85    * @param[in] gradientUnits The the attributes are defined using the current user coordinate system or the bounding box of the shape.
86    */
87   void SetGradientUnits( Toolkit::GradientVisual::Units::Type gradientUnits );
88
89   /**
90    * Get the coordinate system used by the gradient attributes.
91    * @return USER_SPACE_ON_USE or OBJECT_BOUNDING_BOX
92    */
93   Toolkit::GradientVisual::Units::Type GetGradientUnits() const;
94
95   /**
96    * Indicates what happens if the gradient starts or ends inside the bounds of the target rectangle.
97    * If not specified, the effect is as if a value of 'pad' were specified
98    *
99    * @param[in] spread The method to fill the remainder of target region which is outside the gradient bounds
100    */
101   void SetSpreadMethod( Toolkit::GradientVisual::SpreadMethod::Type spread );
102
103   /**
104    * Get the filling method for the the remainder of target region which is outside the gradient boun.
105    * @return PAD, REFLECT or REPEAT
106    */
107   Toolkit::GradientVisual::SpreadMethod::Type GetSpreadMethod() const;
108
109   /**
110    * Get the transformation matrix to align the vertices with the gradient line/circle
111    * @ return the aligning transformation matrix
112    */
113   const Matrix3& GetAlignmentTransform() const;
114
115   /**
116    * Generate the lookup texture with the gradient stops.
117    * @return The lookup texture which transit smoothly between stops.
118    */
119   Dali::Texture GenerateLookupTexture();
120
121 private:
122
123   /**
124    * Estimate the resolution of the lookup texture.
125    * Note: Only call this function after the gradient stops are sorted in order.
126    */
127   unsigned int EstimateTextureResolution();
128
129 protected:
130
131   /**
132    * Construct a new Gradient object
133    * Called in the constructor of subclasses
134    */
135   Gradient();
136
137   /**
138    * @brief A reference counted object may only be deleted by calling Unreference().
139    */
140   virtual ~Gradient();
141
142   // Undefined
143   Gradient( const Gradient& gradient );
144
145   // Undefined
146   Gradient& operator=( const Gradient& handle );
147
148 protected:
149
150   Vector<GradientStop>                        mGradientStops;
151   Matrix3                                     mAlignmentTransform;
152   Toolkit::GradientVisual::Units::Type        mGradientUnits;
153   Toolkit::GradientVisual::SpreadMethod::Type mSpreadMethod;
154
155 };
156
157 } // namespace Internal
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif // DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H