31d9d4b37378cfdb932ad1aac642c69097f0086f
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / internal / controls / cluster / cluster-style-impl.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // INTERNAL INCLUDES
19 #include <dali/public-api/object/ref-object.h>
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/math/vector3.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali-toolkit/public-api/controls/cluster/cluster-style.h>
24
25 namespace Dali
26 {
27
28 struct Vector3;
29
30 namespace Toolkit
31 {
32
33 namespace Internal
34 {
35
36 class ClusterStyle;
37
38 typedef IntrusivePtr<ClusterStyle>       ClusterStylePtr;
39
40 /**
41  * ClusterStyle internal implementation
42  */
43 class ClusterStyle : public Dali::BaseObject
44 {
45 public:
46
47   /**
48    * @copydoc Toolkit::ClusterStyle::GetMaximumNumberOfChildren
49    */
50   unsigned int GetMaximumNumberOfChildren() const;
51
52   /**
53    * @copydoc Toolkit::ClusterStyle::ApplyStyle
54    */
55   virtual void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds) = 0;
56
57   /**
58    * @copydoc Toolkit::ClusterStyle::ApplyStyleToBackground
59    */
60   virtual void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds) = 0;
61
62   /**
63    * @copydoc Toolkit::ClusterStyle::ApplyStyleToTitle
64    */
65   virtual void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds) = 0;
66
67 protected:
68
69   /**
70    * Set the maximum number of children this Style can handle.
71    * @param[in] The maximum number of children.
72    */
73   void SetMaximumNumberOfChildren(unsigned int children);
74
75   /**
76    * Set the title properties
77    * @param[in] relativePosition Relative position of the title
78    * @param[in] offsetPosition Offset position of the title
79    * @param[in] size The size of the title
80    */
81   void SetTitleProperties(const Vector3& relativePosition,
82                           const Vector3& offsetPosition,
83                           const Vector3& size);
84
85   /**
86    * Set the background properties
87    * @param[in] relativePosition Relative position of the background
88    * @param[in] offsetPosition Offset position of the background
89    * @param[in] size The size of the title
90    */
91   void SetBackgroundProperties(const Vector3& relativePosition,
92                                const Vector3& offsetPosition,
93                                const Vector3& size);
94
95 protected:
96
97   /**
98    * Protected constructor see ClusterStyle::New().
99    */
100   ClusterStyle();
101
102   /**
103    * A reference counted object may only be deleted by calling Unreference()
104    */
105   virtual ~ClusterStyle();
106
107 protected:
108
109   unsigned int mMaxChildren;                      ///< Maximum number of children that this style supports
110   Vector3 mTitlePositionRelative;                 ///< Title's position relative to size of cluster
111   Vector3 mTitlePositionOffset;                   ///< Title's position offset
112   Vector3 mTitleSize;                             ///< Title's size relative to size of cluster
113   Vector3 mBackgroundPositionRelative;            ///< Background's position relative to size of cluster
114   Vector3 mBackgroundPositionOffset;              ///< Background's position offset
115   Vector3 mBackgroundSize;                        ///< Background's size relative to size of cluster
116
117 };
118
119 /**
120  * ClusterStyleStandard internal implementation
121  */
122 class ClusterStyleStandard : public ClusterStyle
123 {
124 public:
125
126   typedef Toolkit::ClusterStyleStandard::StyleType StyleType;
127
128 public:
129
130   /**
131    * Create a new cluster style.
132    * @param[in] style The style type to create.
133    * @return A smart-pointer to the newly allocated ClusterStyle.
134    */
135   static ClusterStylePtr New(StyleType style);
136
137 public:
138
139   /**
140    * @copydoc Toolkit::ClusterStyle::ApplyStyle
141    */
142   void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds);
143
144   /**
145    * @copydoc Toolkit::ClusterStyle::ApplyStyleToBackground
146    */
147   void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds);
148
149   /**
150    * @copydoc Toolkit::ClusterStyle::ApplyStyleToTitle
151    */
152   void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds);
153
154 private:
155
156   /**
157    * Set the relative sizes of the children
158    * @param[in] size The list of sizes for the children
159    */
160   void SetSizes(const float *sizes);
161
162   /**
163    * Set the relative positions of the children
164    * @param[in] positions The list of positions for the children
165    */
166   void SetPositions(const Vector3 *positions);
167
168 protected:
169
170   /**
171    * Protected constructor see ClusterStyleRandom::New().
172    */
173   ClusterStyleStandard(StyleType style);
174
175 private:
176
177   const float *mSizes;                            ///< List of sizes
178   const Vector3 *mPositions;                      ///< List of positions
179
180 };
181
182 /**
183  * ClusterStyleRandom internal implementation
184  */
185 class ClusterStyleRandom : public ClusterStyle
186 {
187 public:
188
189   /**
190    * Create a new cluster style.
191    * @return A smart-pointer to the newly allocated ClusterStyle.
192    */
193   static ClusterStylePtr New();
194
195 public:
196
197   /**
198    * @copydoc Toolkit::ClusterStyle::ApplyStyle
199    */
200   void ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds);
201
202   /**
203    * @copydoc Toolkit::ClusterStyle::ApplyStyleToBackground
204    */
205   void ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds);
206
207   /**
208    * @copydoc Toolkit::ClusterStyle::ApplyStyleToTitle
209    */
210   void ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds);
211
212 protected:
213
214   /**
215    * Protected constructor see ClusterStyleRandom::New().
216    */
217   ClusterStyleRandom();
218
219 private:
220
221 };
222
223 } // namespace Internal
224
225 // Helpers for public-api forwarding methods
226
227 inline Internal::ClusterStyle& GetImpl(Toolkit::ClusterStyle& pub)
228 {
229   DALI_ASSERT_ALWAYS(pub);
230
231   Dali::RefObject& handle = pub.GetBaseObject();
232
233   return static_cast<Internal::ClusterStyle&>(handle);
234 }
235
236 inline const Internal::ClusterStyle& GetImpl(const Toolkit::ClusterStyle& pub)
237 {
238   DALI_ASSERT_ALWAYS(pub);
239
240   const Dali::RefObject& handle = pub.GetBaseObject();
241
242   return static_cast<const Internal::ClusterStyle&>(handle);
243 }
244
245 } // namespace Toolkit
246
247 } // namespace Dali