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::SetTitle
161 void SetTitle( Actor text );
164 * @copydoc Demo::Cluster::SetStyle
166 void SetStyle(Demo::ClusterStyle style);
169 * @copydoc Demo::Cluster::GetStyle
171 Demo::ClusterStyle GetStyle() const;
174 * @copydoc Demo::Cluster::GetExpandedCount
176 unsigned int GetExpandedCount() const;
179 * @copydoc Demo::Cluster::GetTotalCount
181 unsigned int GetTotalCount() const;
185 ChildInfo GetChildInfoAt( unsigned int index );
187 void SetDepth( ChildInfo& childInfo, float depth );
190 * Updates the style of the Background
191 * (occurs when either background changes or style changes)
192 * @param[in] duration apply duration for style
194 void UpdateBackground(float duration);
197 * Updates the style of the Title
198 * (occurs when either background changes or style changes)
199 * @param[in] duration apply duration for style
201 void UpdateTitle(float duration);
205 * Expands one or more actors.
207 * @param[in] attributes list of indices of actors to expand.
208 * (if no attributes specifies, then all actors expand)
210 void DoExpandAction(const Property::Map& attributes);
214 * Collapses one or more actors.
216 * @param[in] attributes list of indices of actors to collapse.
217 * (if no attributes specifies, then all actors collapse)
219 void DoCollapseAction(const Property::Map& attributes);
223 * Transforms one actor (index) to a specified position (Vector3),
224 * scale (Vector3), and rotation (Quaternion).
226 * @param[in] attributes index and transform values.
228 void DoTransformAction(const Property::Map& attributes);
230 private: // From Control
232 * From Control; called shortly before a child is removed from the owning actor.
233 * @param[in] child The child being removed.Ptr
235 virtual void OnControlChildRemove(Actor& child);
240 * Performs actions as requested using the action name.
241 * @param[in] object The object on which to perform the action.
242 * @param[in] actionName The action to perform.
243 * @param[in] attributes The attributes with which to perfrom this action.
244 * @return true if action has been accepted by this control
246 static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
248 private: // From Control
251 * @copydoc Control::OnInitialize()
253 virtual void OnInitialize();
257 * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
259 virtual void OnSizeSet( const Vector3& targetSize );
264 * Construct a new Cluster.
265 * @param[in] style of the cluster
267 Cluster(Demo::ClusterStyle& style);
270 * A reference counted object may only be deleted by calling Unreference()
277 Cluster(const Cluster&);
280 Cluster& operator=(const Cluster& rhs);
284 Demo::ClusterStyle mClusterStyle;
285 ChildInfoContainer mChildren;
286 Vector3 mClusterSize;
288 Actor mBackgroundImage; ///< Stores the background image.
289 Actor mTitle; ///< Stores the text title.
290 unsigned int mExpandedCount; ///< A count of how many children have been expanded.
294 } // namespace Internal
296 // Helpers for public-api forwarding methods
298 inline Demo::Internal::Cluster& GetImpl(Demo::Cluster& cluster)
300 DALI_ASSERT_ALWAYS(cluster);
302 Dali::RefObject& handle = cluster.GetImplementation();
304 return static_cast<Demo::Internal::Cluster&>(handle);
307 inline const Demo::Internal::Cluster& GetImpl(const Demo::Cluster& cluster)
309 DALI_ASSERT_ALWAYS(cluster);
311 const Dali::RefObject& handle = cluster.GetImplementation();
313 return static_cast<const Demo::Internal::Cluster&>(handle);
320 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__