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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/ref-object.h>
24 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
25 #include <dali-toolkit/public-api/controls/cluster/cluster-style.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
39 typedef IntrusivePtr<Cluster> ClusterPtr;
51 ChildInfo(Actor actor, unsigned int positionIndex)
54 mPositionIndex(positionIndex)
60 unsigned int mPositionIndex;
63 typedef std::vector<ChildInfo> ChildInfoContainer;
64 typedef ChildInfoContainer::iterator ChildInfoIter;
65 typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
68 * Cluster is a container of grouped actors positioned in different cluster styles.
69 * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
70 * of the child actors in the cluster.
72 class Cluster : public Control
77 * Create a new Cluster.
78 * @param[in] style of the cluster
79 * @return A public handle to the newly allocated Cluster.
81 static Dali::Toolkit::Cluster New(Toolkit::ClusterStyle& style);
84 * @copydoc Toolkit::Cluster::AddChild( Actor child )
86 void AddChild( Actor child );
89 * @copydoc Toolkit::Cluster::AddChild( Actor child, unsigned int positionIndex )
91 void AddChild( Actor child, unsigned int positionIndex );
94 * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int index );
96 void AddChildAt( Actor child, unsigned int index );
99 * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
101 void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
104 * Adds a ChildInfo struct to the end of the children list.
105 * @param[in] childInfo the child info to that to children list.
107 void AddChildInfo( ChildInfo childInfo );
110 * Adds a ChildInfo struct before the specified index.
111 * @param[in] childInfo the child info to that to children list.
112 * @param[in] index the index within the children list to insert
115 void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
118 * @copydoc Toolkit::Cluster::GetChildAt
120 Actor GetChildAt( unsigned int index );
123 * @copydoc Toolkit::Cluster::RemoveChildAt
125 Actor RemoveChildAt( unsigned int index );
128 * @copydoc Toolkit::Cluster::ExpandChild
130 void ExpandChild( unsigned int index );
133 * @copydoc Toolkit::Cluster::ExpandAllChildren
135 void ExpandAllChildren();
138 * @copydoc Toolkit::Cluster::CollapseChild
140 void CollapseChild( unsigned int index, bool front );
143 * @copydoc Toolkit::Cluster::CollapseAllChildren
145 void CollapseAllChildren( bool front );
148 * @copydoc Toolkit::Cluster::TransformChild
150 void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
153 * @copydoc Toolkit::Cluster::RestoreChild
155 void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
158 * @copydoc Toolkit::Cluster::SetBackgroundImage
160 void SetBackgroundImage( Actor image );
163 * @copydoc Toolkit::Cluster::SetTitle
165 void SetTitle( Actor text );
168 * @copydoc Toolkit::Cluster::SetStyle
170 void SetStyle(Toolkit::ClusterStyle style);
173 * @copydoc Toolkit::Cluster::GetStyle
175 Toolkit::ClusterStyle GetStyle() const;
178 * @copydoc Toolkit::Cluster::GetExpandedCount
180 unsigned int GetExpandedCount() const;
183 * @copydoc Toolkit::Cluster::GetTotalCount
185 unsigned int GetTotalCount() const;
189 ChildInfo GetChildInfoAt( unsigned int index );
191 void SetDepth( ChildInfo& childInfo, float depth );
194 * Updates the style of the Background
195 * (occurs when either background changes or style changes)
196 * @param[in] duration apply duration for style
198 void UpdateBackground(float duration);
201 * Updates the style of the Title
202 * (occurs when either background changes or style changes)
203 * @param[in] duration apply duration for style
205 void UpdateTitle(float duration);
209 * Expands one or more actors.
211 * @param[in] attributes list of indices of actors to expand.
212 * (if no attributes specifies, then all actors expand)
214 void DoExpandAction(const PropertyValueContainer& attributes);
218 * Collapses one or more actors.
220 * @param[in] attributes list of indices of actors to collapse.
221 * (if no attributes specifies, then all actors collapse)
223 void DoCollapseAction(const PropertyValueContainer& attributes);
227 * Transforms one actor (index) to a specified position (Vector3),
228 * scale (Vector3), and rotation (Quaternion).
230 * @param[in] attributes index and transform values.
232 void DoTransformAction(const PropertyValueContainer& attributes);
234 private: // From Control
236 * From Control; called shortly before a child is removed from the owning actor.
237 * @param[in] child The child being removed.Ptr
239 virtual void OnControlChildRemove(Actor& child);
244 * Performs actions as requested using the action name.
245 * @param[in] object The object on which to perform the action.
246 * @param[in] actionName The action to perform.
247 * @param[in] attributes The attributes with which to perfrom this action.
248 * @return true if action has been accepted by this control
250 static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
252 private: // From Control
255 * @copydoc Toolkit::Control::OnInitialize()
257 virtual void OnInitialize();
261 * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
263 virtual void OnControlSizeSet( const Vector3& targetSize );
268 * Construct a new Cluster.
269 * @param[in] style of the cluster
271 Cluster(Toolkit::ClusterStyle& style);
274 * A reference counted object may only be deleted by calling Unreference()
281 Cluster(const Cluster&);
284 Cluster& operator=(const Cluster& rhs);
288 Toolkit::ClusterStyle mClusterStyle;
289 ChildInfoContainer mChildren;
290 Vector3 mClusterSize;
292 Actor mBackgroundImage; ///< Stores the background image.
293 Actor mTitle; ///< Stores the text title.
294 unsigned int mExpandedCount; ///< A count of how many children have been expanded.
298 } // namespace Internal
300 // Helpers for public-api forwarding methods
302 inline Toolkit::Internal::Cluster& GetImpl(Toolkit::Cluster& cluster)
304 DALI_ASSERT_ALWAYS(cluster);
306 Dali::RefObject& handle = cluster.GetImplementation();
308 return static_cast<Toolkit::Internal::Cluster&>(handle);
311 inline const Toolkit::Internal::Cluster& GetImpl(const Toolkit::Cluster& cluster)
313 DALI_ASSERT_ALWAYS(cluster);
315 const Dali::RefObject& handle = cluster.GetImplementation();
317 return static_cast<const Toolkit::Internal::Cluster&>(handle);
320 } // namespace Toolkit
324 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__