f0079f88a8c5a8a7741e6fd669f9211ab34a292c
[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  * | startPosition           | VECTOR2          |
46  * | endPosition             | VECTOR2          |
47  * | stopColor               | ARRAY of VECTOR4 |
48  *
49  * The following properties are essential for create a RADIAL GradientRender
50  *
51  * | %Property Name          | Type             |
52  * |-------------------------|------------------|
53  * | center                  | VECTOR2          |
54  * | radius                  | FLOAT            |
55  * | stopColor               | ARRAY of VECTOR4 |
56  *
57  * The following properties are optional for both LINEAR and RADIAL GradientRender.
58  *
59  * | %Property Name          | Type             |
60  * |-------------------------|------------------|
61  * | units                   | STRING           |
62  * | spreadMethod            | STRING           |
63  *
64  * Valid values for units are 'userSpace' and 'objectBoundingBox'.
65  * Valid values for spreadMethod are 'pad', 'repeat' and 'reflect.'
66  * If not provided, 'objectBoundingBox' is used as default gradient units, and 'pad' is used as default spread method.
67  */
68 class GradientRenderer: public ControlRenderer
69 {
70 public:
71
72   /**
73    * Types of the gradient
74    */
75   enum Type
76   {
77     LINEAR,
78     RADIAL
79   };
80
81   /**
82    * @brief Constructor.
83    *
84    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
85    */
86   GradientRenderer( RendererFactoryCache& factoryCache );
87
88   /**
89    * @brief A reference counted object may only be deleted by calling Unreference().
90    */
91   ~GradientRenderer();
92
93 public:  // from ControlRenderer
94
95   /**
96    * @copydoc ControlRenderer::SetSize
97    */
98   virtual void SetSize( const Vector2& size );
99
100   /**
101    * @copydoc ControlRenderer::SetClipRect
102    */
103   virtual void SetClipRect( const Rect<int>& clipRect );
104
105   /**
106    * @copydoc ControlRenderer::SetOffset
107    */
108   virtual void SetOffset( const Vector2& offset );
109
110   /**
111    * @copydoc ControlRenderer::CreatePropertyMap
112    */
113   virtual void DoCreatePropertyMap( Property::Map& map ) const;
114
115 protected:
116   /**
117    * @copydoc ControlRenderer::DoInitialize
118    */
119   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
120
121   /**
122    * @copydoc ControlRenderer::DoSetOnStage
123    */
124   virtual void DoSetOnStage( Actor& actor );
125
126 private:
127
128   /**
129    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
130    */
131   void InitializeRenderer();
132
133   /**
134    * New a gradient object with the given property map.
135    *
136    * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
137    */
138   bool NewGradient(Type gradientType, const Property::Map& propertyMap);
139
140   /**
141    * Get the stop-offsets from the property.
142    * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
143    *
144    * @param[in] value The property value of stop-offsets
145    * @param[out] stopOffsets The vector contains the stop offset values.
146    */
147   static void GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
148
149   // Undefined
150   GradientRenderer( const GradientRenderer& gradientRenderer );
151
152   // Undefined
153   GradientRenderer& operator=( const GradientRenderer& gradientRenderer );
154
155 private:
156
157   Matrix3 mGradientTransform;
158   IntrusivePtr<Gradient> mGradient;
159   Type mGradientType;
160 };
161
162 } // namespace Internal
163
164 } // namespace Toolkit
165
166 } // namespace Dali
167
168 #endif /* __DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H__ */