1 #ifndef __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
21 #include <dali/public-api/object/ref-object.h>
23 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
24 #include <dali-toolkit/public-api/controls/cluster/cluster-style.h>
25 #include <dali-toolkit/public-api/controls/control-impl.h>
38 typedef IntrusivePtr<Cluster> ClusterPtr;
50 ChildInfo(Actor actor, unsigned int positionIndex)
53 mPositionIndex(positionIndex)
59 unsigned int mPositionIndex;
62 typedef std::vector<ChildInfo> ChildInfoContainer;
63 typedef ChildInfoContainer::iterator ChildInfoIter;
64 typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
67 * Cluster is a container of grouped actors positioned in different cluster styles.
68 * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
69 * of the child actors in the cluster.
71 class Cluster : public ControlImpl
76 * Create a new Cluster.
77 * @param[in] style of the cluster
78 * @return A public handle to the newly allocated Cluster.
80 static Dali::Toolkit::Cluster New(Toolkit::ClusterStyle& style);
83 * @copydoc Toolkit::Cluster::AddChild( Actor child )
85 void AddChild( Actor child );
88 * @copydoc Toolkit::Cluster::AddChild( Actor child, unsigned int positionIndex )
90 void AddChild( Actor child, unsigned int positionIndex );
93 * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int index );
95 void AddChildAt( Actor child, unsigned int index );
98 * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
100 void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
103 * Adds a ChildInfo struct to the end of the children list.
104 * @param[in] childInfo the child info to that to children list.
106 void AddChildInfo( ChildInfo childInfo );
109 * Adds a ChildInfo struct before the specified index.
110 * @param[in] childInfo the child info to that to children list.
111 * @param[in] index the index within the children list to insert
114 void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
117 * @copydoc Toolkit::Cluster::GetChildAt
119 Actor GetChildAt( unsigned int index );
122 * @copydoc Toolkit::Cluster::RemoveChildAt
124 Actor RemoveChildAt( unsigned int index );
127 * @copydoc Toolkit::Cluster::ExpandChild
129 void ExpandChild( unsigned int index );
132 * @copydoc Toolkit::Cluster::ExpandAllChildren
134 void ExpandAllChildren();
137 * @copydoc Toolkit::Cluster::CollapseChild
139 void CollapseChild( unsigned int index, bool front );
142 * @copydoc Toolkit::Cluster::CollapseAllChildren
144 void CollapseAllChildren( bool front );
147 * @copydoc Toolkit::Cluster::TransformChild
149 void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
152 * @copydoc Toolkit::Cluster::RestoreChild
154 void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
157 * @copydoc Toolkit::Cluster::SetBackgroundImage
159 void SetBackgroundImage( Actor image );
162 * @copydoc Toolkit::Cluster::SetTitle
164 void SetTitle( Actor text );
167 * @copydoc Toolkit::Cluster::SetStyle
169 void SetStyle(Toolkit::ClusterStyle style);
172 * @copydoc Toolkit::Cluster::GetStyle
174 Toolkit::ClusterStyle GetStyle() const;
177 * @copydoc Toolkit::Cluster::GetExpandedCount
179 unsigned int GetExpandedCount() const;
182 * @copydoc Toolkit::Cluster::GetTotalCount
184 unsigned int GetTotalCount() const;
188 ChildInfo GetChildInfoAt( unsigned int index );
190 void SetDepth( ChildInfo& childInfo, float depth );
193 * Updates the style of the Background
194 * (occurs when either background changes or style changes)
195 * @param[in] duration apply duration for style
197 void UpdateBackground(float duration);
200 * Updates the style of the Title
201 * (occurs when either background changes or style changes)
202 * @param[in] duration apply duration for style
204 void UpdateTitle(float duration);
208 * Expands one or more actors.
210 * @param[in] attributes list of indices of actors to expand.
211 * (if no attributes specifies, then all actors expand)
213 void DoExpandAction(const PropertyValueContainer& attributes);
217 * Collapses one or more actors.
219 * @param[in] attributes list of indices of actors to collapse.
220 * (if no attributes specifies, then all actors collapse)
222 void DoCollapseAction(const PropertyValueContainer& attributes);
226 * Transforms one actor (index) to a specified position (Vector3),
227 * scale (Vector3), and rotation (Quaternion).
229 * @param[in] attributes index and transform values.
231 void DoTransformAction(const PropertyValueContainer& attributes);
233 private: // From ControlImpl
235 * From Toolkit::ControlImpl; called shortly before a child is removed from the owning actor.
236 * @param[in] child The child being removed.Ptr
238 virtual void OnControlChildRemove(Actor& child);
243 * Performs actions as requested using the action name.
244 * @param[in] object The object on which to perform the action.
245 * @param[in] actionName The action to perform.
246 * @param[in] attributes The attributes with which to perfrom this action.
247 * @return true if action has been accepted by this control
249 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
251 private: // From ControlImpl
254 * @copydoc Toolkit::Control::OnInitialize()
256 virtual void OnInitialize();
261 * Construct a new Cluster.
262 * @param[in] style of the cluster
264 Cluster(Toolkit::ClusterStyle& style);
267 * A reference counted object may only be deleted by calling Unreference()
274 Cluster(const Cluster&);
277 Cluster& operator=(const Cluster& rhs);
281 Toolkit::ClusterStyle mClusterStyle;
282 ChildInfoContainer mChildren;
284 Actor mBackgroundImage; ///< Stores the background image.
285 Actor mTitle; ///< Stores the text title.
286 unsigned int mExpandedCount; ///< A count of how many children have been expanded.
290 } // namespace Internal
292 // Helpers for public-api forwarding methods
294 inline Toolkit::Internal::Cluster& GetImpl(Toolkit::Cluster& cluster)
296 DALI_ASSERT_ALWAYS(cluster);
298 Dali::RefObject& handle = cluster.GetImplementation();
300 return static_cast<Toolkit::Internal::Cluster&>(handle);
303 inline const Toolkit::Internal::Cluster& GetImpl(const Toolkit::Cluster& cluster)
305 DALI_ASSERT_ALWAYS(cluster);
307 const Dali::RefObject& handle = cluster.GetImplementation();
309 return static_cast<const Toolkit::Internal::Cluster&>(handle);
312 } // namespace Toolkit
316 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__