1 #ifndef DALI_TOOLKIT_INTERNAL_GRADIENT_H
2 #define DALI_TOOLKIT_INTERNAL_GRADIENT_H
5 * Copyright (c) 2021 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/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>
28 #include <dali-toolkit/public-api/visuals/gradient-visual-properties.h>
39 * Gradients consist of continuously smooth color transitions along a vector from one color to another,
40 * possibly followed by additional transitions along the same vector to other colors.
42 class Gradient : public RefObject
46 * The stop node tells the gradient what color it should be at certain position.
50 GradientStop(float offset, const Vector4& color)
56 bool operator<(const GradientStop& rhs) const
58 return mOffset < rhs.mOffset;
61 float mOffset; // A value ranging from 0 to 1 to indicate where the gradient stop is placed.
62 Vector4 mStopColor; // The color to use at this gradient stop
67 * Add a gradient stop.
69 * @param[in] offset The position to place the stop.
70 * @param[in] color The color to use at this stop.
72 void AddStop(float offset, const Vector4& color);
75 * Get the gradient stops.
76 * @return The vector of gradient stops.
78 const Vector<GradientStop>& GetStops();
81 * Set the coordinate system used by the gradient attributes.
82 * @param[in] gradientUnits The the attributes are defined using the current user coordinate system or the bounding box of the shape.
84 void SetGradientUnits(Toolkit::GradientVisual::Units::Type gradientUnits);
87 * Get the coordinate system used by the gradient attributes.
88 * @return USER_SPACE_ON_USE or OBJECT_BOUNDING_BOX
90 Toolkit::GradientVisual::Units::Type GetGradientUnits() const;
93 * Indicates what happens if the gradient starts or ends inside the bounds of the target rectangle.
94 * If not specified, the effect is as if a value of 'pad' were specified
96 * @param[in] spread The method to fill the remainder of target region which is outside the gradient bounds
98 void SetSpreadMethod(Toolkit::GradientVisual::SpreadMethod::Type spread);
101 * Get the filling method for the the remainder of target region which is outside the gradient boun.
102 * @return PAD, REFLECT or REPEAT
104 Toolkit::GradientVisual::SpreadMethod::Type GetSpreadMethod() const;
107 * Get the transformation matrix to align the vertices with the gradient line/circle
108 * @ return the aligning transformation matrix
110 const Matrix3& GetAlignmentTransform() const;
113 * Generate the lookup texture with the gradient stops.
114 * @return The lookup texture which transit smoothly between stops.
116 Dali::Texture GenerateLookupTexture();
120 * Estimate the resolution of the lookup texture.
121 * Note: Only call this function after the gradient stops are sorted in order.
123 unsigned int EstimateTextureResolution();
127 * Construct a new Gradient object
128 * Called in the constructor of subclasses
133 * @brief A reference counted object may only be deleted by calling Unreference().
138 Gradient(const Gradient& gradient);
141 Gradient& operator=(const Gradient& handle);
144 Vector<GradientStop> mGradientStops;
145 Matrix3 mAlignmentTransform;
146 Toolkit::GradientVisual::Units::Type mGradientUnits;
147 Toolkit::GradientVisual::SpreadMethod::Type mSpreadMethod;
150 } // namespace Internal
152 } // namespace Toolkit
156 #endif // DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H