Merge "Add Text input style changed signal." into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / gradient / gradient-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_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/visuals/visual-base-impl.h>
23 #include <dali-toolkit/internal/visuals/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 visual 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  * | stopOffset              | ARRAY of FLOAT   |
62  * | units                   | STRING           |
63  * | spreadMethod            | STRING           |
64  *
65  * Valid values for units are 'userSpace' and 'objectBoundingBox'.
66  * Valid values for spreadMethod are 'pad', 'repeat' and 'reflect.'
67  * If not provided, 'objectBoundingBox' is used as default gradient units, and 'pad' is used as default spread method.
68  */
69 class GradientVisual: public Visual::Base
70 {
71 public:
72
73   /**
74    * Types of the gradient
75    */
76   enum Type
77   {
78     LINEAR,
79     RADIAL
80   };
81
82   /**
83    * @brief Constructor.
84    *
85    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
86    */
87   GradientVisual( VisualFactoryCache& factoryCache );
88
89   /**
90    * @brief A reference counted object may only be deleted by calling Unreference().
91    */
92   ~GradientVisual();
93
94 public:  // from Visual
95
96   /**
97    * @copydoc Visual::SetSize
98    */
99   virtual void SetSize( const Vector2& size );
100
101   /**
102    * @copydoc Visual::CreatePropertyMap
103    */
104   virtual void DoCreatePropertyMap( Property::Map& map ) const;
105
106 protected:
107   /**
108    * @copydoc Visual::DoInitialize
109    */
110   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
111
112   /**
113    * @copydoc Visual::DoSetOnStage
114    */
115   virtual void DoSetOnStage( Actor& actor );
116
117 private:
118
119   /**
120    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
121    */
122   void InitializeRenderer();
123
124   /**
125    * New a gradient object with the given property map.
126    *
127    * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
128    */
129   bool NewGradient(Type gradientType, const Property::Map& propertyMap);
130
131   /**
132    * Get the stop-offsets from the property.
133    * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
134    *
135    * @param[in] value The property value of stop-offsets
136    * @param[out] stopOffsets The vector contains the stop offset values.
137    */
138   static void GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
139
140   // Undefined
141   GradientVisual( const GradientVisual& gradientVisual );
142
143   // Undefined
144   GradientVisual& operator=( const GradientVisual& gradientVisual );
145
146 private:
147
148   Matrix3 mGradientTransform;
149   IntrusivePtr<Gradient> mGradient;
150   Type mGradientType;
151 };
152
153 } // namespace Internal
154
155 } // namespace Toolkit
156
157 } // namespace Dali
158
159 #endif /* DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H */