Merge "Create property map from ControlRenderer and make SetOffStage API public"...
[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    * @brief Constructor.
76    */
77   GradientRenderer();
78
79   /**
80    * @brief A reference counted object may only be deleted by calling Unreference().
81    */
82   ~GradientRenderer();
83
84 public:  // from ControlRenderer
85
86   /**
87    * @copydoc ControlRenderer::Initialize
88    */
89   virtual void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap );
90
91   /**
92    * @copydoc ControlRenderer::SetSize
93    */
94   virtual void SetSize( const Vector2& size );
95
96   /**
97    * @copydoc ControlRenderer::SetClipRect
98    */
99   virtual void SetClipRect( const Rect<int>& clipRect );
100
101   /**
102    * @copydoc ControlRenderer::SetOffset
103    */
104   virtual void SetOffset( const Vector2& offset );
105
106   /**
107    * @copydoc ControlRenderer::CreatePropertyMap
108    */
109   virtual void CreatePropertyMap( Property::Map& map ) const;
110
111 protected:
112   /**
113    * @copydoc ControlRenderer::DoSetOnStage
114    */
115   virtual void DoSetOnStage( Actor& actor );
116
117 private:
118
119   /**
120    * Types of the gradient
121    */
122   enum Type
123   {
124     LINEAR,
125     RADIAL
126   };
127
128   /**
129    * New a gradient object with the given property map.
130    *
131    * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
132    */
133   bool NewGradient(Type gradientType, const Property::Map& propertyMap);
134
135   /**
136    * Get the stop-offsets from the property.
137    * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
138    *
139    * @param[in] value The property value of stop-offsets
140    * @param[out] stopOffsets The vector contains the stop offset values.
141    */
142   static bool GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
143
144   // Undefined
145   GradientRenderer( const GradientRenderer& gradientRenderer );
146
147   // Undefined
148   GradientRenderer& operator=( const GradientRenderer& gradientRenderer );
149
150 private:
151
152   Matrix3 mGradientTransform;
153   Property::Index mGradientTransformIndex;
154   IntrusivePtr<Gradient> mGradient;
155 };
156
157 } // namespace Internal
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif /* __DALI_TOOLKIT_INTERNAL_GRADIENT_RENDERER_H__ */