0747a1c3099ec7c1ff0838d38f9d913e5d154b4b
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / gradient / gradient-renderer.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
23 #include <dali-toolkit/internal/controls/renderers/gradient/gradient.h>
24
25 namespace Dali
26 {
27 class Vector2;
28
29 namespace Toolkit
30 {
31
32 namespace Internal
33 {
34
35 class Gradient;
36
37 /**
38  * The renderer which renders smooth transition of colors to the control's quad.
39  * It supports two types of gradients: linear and radial.
40  *
41  * The following properties are essential for create a LINEAR GradientRender
42  *
43  * | %Property Name            | Type             |
44  * |---------------------------|------------------|
45  * | gradient-start-position   | VECTOR2          |
46  * | gradient-end-position     | VECTOR2          |
47  * | gradient-stop-offset      | ARRAY of FLOAT   |
48  * | gradient-stop-color       | ARRAY of VECTOR4 |
49  *
50  * The following properties are essential for create a RADIAL GradientRender
51  *
52  * | %Property Name            | Type             |
53  * |---------------------------|------------------|
54  * | gradient-center           | VECTOR2          |
55  * | gradient-radius           | FLOAT            |
56  * | gradient-stop-offset      | ARRAY of FLOAT   |
57  * | gradient-stop-color       | ARRAY of VECTOR4 |
58  *
59  * The following properties are optional for both LINEAR and RADIAL GradientRender.
60  *
61  * | %Property Name            | Type             |
62  * |---------------------------|------------------|
63  * | gradient-units            | STRING           |
64  * | gradient-spread-method    | STRING           |
65  *
66  * Valid values for gradient-units are 'user-space' and 'object-bounding-box'.
67  * Valid values for gradient-spread-method are 'pad', 'repeat' and 'reflect.'
68  * If not provided, 'objectBoundingBox' is used as default gradient units, and 'pad' is used as default spread method.
69  */
70 class GradientRenderer: public ControlRenderer
71 {
72 public:
73
74   /**
75    * Types of the gradient
76    */
77   enum Type
78   {
79     LINEAR,
80     RADIAL
81   };
82
83   /**
84    * @brief Constructor.
85    *
86    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
87    */
88   GradientRenderer( RendererFactoryCache& factoryCache );
89
90   /**
91    * @brief A reference counted object may only be deleted by calling Unreference().
92    */
93   ~GradientRenderer();
94
95 public:  // from ControlRenderer
96
97   /**
98    * @copydoc ControlRenderer::SetSize
99    */
100   virtual void SetSize( const Vector2& size );
101
102   /**
103    * @copydoc ControlRenderer::SetClipRect
104    */
105   virtual void SetClipRect( const Rect<int>& clipRect );
106
107   /**
108    * @copydoc ControlRenderer::SetOffset
109    */
110   virtual void SetOffset( const Vector2& offset );
111
112   /**
113    * @copydoc ControlRenderer::CreatePropertyMap
114    */
115   virtual void DoCreatePropertyMap( Property::Map& map ) const;
116
117 protected:
118   /**
119    * @copydoc ControlRenderer::DoInitialize
120    */
121   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
122
123   /**
124    * @copydoc ControlRenderer::DoSetOnStage
125    */
126   virtual void DoSetOnStage( Actor& actor );
127
128 private:
129
130   /**
131    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
132    */
133   void InitializeRenderer();
134
135   /**
136    * New a gradient object with the given property map.
137    *
138    * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
139    */
140   bool NewGradient(Type gradientType, const Property::Map& propertyMap);
141
142   /**
143    * Get the stop-offsets from the property.
144    * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
145    *
146    * @param[in] value The property value of stop-offsets
147    * @param[out] stopOffsets The vector contains the stop offset values.
148    */
149   static bool GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
150
151   // Undefined
152   GradientRenderer( const GradientRenderer& gradientRenderer );
153
154   // Undefined
155   GradientRenderer& operator=( const GradientRenderer& gradientRenderer );
156
157 private:
158
159   Matrix3 mGradientTransform;
160   IntrusivePtr<Gradient> mGradient;
161   Type mGradientType;
162 };
163
164 } // namespace Internal
165
166 } // namespace Toolkit
167
168 } // namespace Dali
169
170 #endif /* __DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H__ */