1 #ifndef __DALI_DEMO_INTERNAL_CLUSTER_H__
2 #define __DALI_DEMO_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>
26 #include "cluster-style.h"
27 #include <dali-toolkit/public-api/controls/control-impl.h>
40 typedef IntrusivePtr<Cluster> ClusterPtr;
52 ChildInfo(Actor actor, unsigned int positionIndex)
55 mPositionIndex(positionIndex)
61 unsigned int mPositionIndex;
64 typedef std::vector<ChildInfo> ChildInfoContainer;
65 typedef ChildInfoContainer::iterator ChildInfoIter;
66 typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
69 * Cluster is a container of grouped actors positioned in different cluster styles.
70 * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
71 * of the child actors in the cluster.
73 class Cluster : public Toolkit::Internal::Control
78 * Create a new Cluster.
79 * @param[in] style of the cluster
80 * @return A public handle to the newly allocated Cluster.
82 static Dali::Demo::Cluster New(Demo::ClusterStyle& style);
85 * @copydoc Demo::Cluster::AddChild( Actor child )
87 void AddChild( Actor child );
90 * @copydoc Demo::Cluster::AddChild( Actor child, unsigned int positionIndex )
92 void AddChild( Actor child, unsigned int positionIndex );
95 * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int index );
97 void AddChildAt( Actor child, unsigned int index );
100 * @copydoc Demo::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
102 void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
105 * Adds a ChildInfo struct to the end of the children list.
106 * @param[in] childInfo the child info to that to children list.
108 void AddChildInfo( ChildInfo childInfo );
111 * Adds a ChildInfo struct before the specified index.
112 * @param[in] childInfo the child info to that to children list.
113 * @param[in] index the index within the children list to insert
116 void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
119 * @copydoc Demo::Cluster::GetChildAt
121 Actor GetChildAt( unsigned int index );
124 * @copydoc Demo::Cluster::RemoveChildAt
126 Actor RemoveChildAt( unsigned int index );
129 * @copydoc Demo::Cluster::ExpandChild
131 void ExpandChild( unsigned int index );
134 * @copydoc Demo::Cluster::ExpandAllChildren
136 void ExpandAllChildren();
139 * @copydoc Demo::Cluster::CollapseChild
141 void CollapseChild( unsigned int index, bool front );
144 * @copydoc Demo::Cluster::CollapseAllChildren
146 void CollapseAllChildren( bool front );
149 * @copydoc Demo::Cluster::TransformChild
151 void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
154 * @copydoc Demo::Cluster::RestoreChild
156 void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
159 * @copydoc Demo::Cluster::SetBackgroundImage
161 void SetBackgroundImage( Actor image );
164 * @copydoc Demo::Cluster::SetTitle
166 void SetTitle( Actor text );
169 * @copydoc Demo::Cluster::SetStyle
171 void SetStyle(Demo::ClusterStyle style);
174 * @copydoc Demo::Cluster::GetStyle
176 Demo::ClusterStyle GetStyle() const;
179 * @copydoc Demo::Cluster::GetExpandedCount
181 unsigned int GetExpandedCount() const;
184 * @copydoc Demo::Cluster::GetTotalCount
186 unsigned int GetTotalCount() const;
190 ChildInfo GetChildInfoAt( unsigned int index );
192 void SetDepth( ChildInfo& childInfo, float depth );
195 * Updates the style of the Background
196 * (occurs when either background changes or style changes)
197 * @param[in] duration apply duration for style
199 void UpdateBackground(float duration);
202 * Updates the style of the Title
203 * (occurs when either background changes or style changes)
204 * @param[in] duration apply duration for style
206 void UpdateTitle(float duration);
210 * Expands one or more actors.
212 * @param[in] attributes list of indices of actors to expand.
213 * (if no attributes specifies, then all actors expand)
215 void DoExpandAction(const PropertyValueContainer& attributes);
219 * Collapses one or more actors.
221 * @param[in] attributes list of indices of actors to collapse.
222 * (if no attributes specifies, then all actors collapse)
224 void DoCollapseAction(const PropertyValueContainer& attributes);
228 * Transforms one actor (index) to a specified position (Vector3),
229 * scale (Vector3), and rotation (Quaternion).
231 * @param[in] attributes index and transform values.
233 void DoTransformAction(const PropertyValueContainer& attributes);
235 private: // From Control
237 * From Control; called shortly before a child is removed from the owning actor.
238 * @param[in] child The child being removed.Ptr
240 virtual void OnControlChildRemove(Actor& child);
245 * Performs actions as requested using the action name.
246 * @param[in] object The object on which to perform the action.
247 * @param[in] actionName The action to perform.
248 * @param[in] attributes The attributes with which to perfrom this action.
249 * @return true if action has been accepted by this control
251 static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
253 private: // From Control
256 * @copydoc Control::OnInitialize()
258 virtual void OnInitialize();
262 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
264 virtual void OnSizeSet( const Vector3& targetSize );
269 * Construct a new Cluster.
270 * @param[in] style of the cluster
272 Cluster(Demo::ClusterStyle& style);
275 * A reference counted object may only be deleted by calling Unreference()
282 Cluster(const Cluster&);
285 Cluster& operator=(const Cluster& rhs);
289 Demo::ClusterStyle mClusterStyle;
290 ChildInfoContainer mChildren;
291 Vector3 mClusterSize;
293 Actor mBackgroundImage; ///< Stores the background image.
294 Actor mTitle; ///< Stores the text title.
295 unsigned int mExpandedCount; ///< A count of how many children have been expanded.
299 } // namespace Internal
301 // Helpers for public-api forwarding methods
303 inline Demo::Internal::Cluster& GetImpl(Demo::Cluster& cluster)
305 DALI_ASSERT_ALWAYS(cluster);
307 Dali::RefObject& handle = cluster.GetImplementation();
309 return static_cast<Demo::Internal::Cluster&>(handle);
312 inline const Demo::Internal::Cluster& GetImpl(const Demo::Cluster& cluster)
314 DALI_ASSERT_ALWAYS(cluster);
316 const Dali::RefObject& handle = cluster.GetImplementation();
318 return static_cast<const Demo::Internal::Cluster&>(handle);
325 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__