Add GetNaturalSize to Actor and deriving classes.
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / model-actor-factory-impl.h
1 #ifndef __DALI_INTERNAL_MODEL_ACTOR_FACTORY_H__
2 #define __DALI_INTERNAL_MODEL_ACTOR_FACTORY_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/modeling/model.h>
23 #include <dali/internal/event/modeling/model-data-impl.h>
24 #include <dali/internal/event/actors/actor-declarations.h>
25 #include <dali/internal/event/animation/animation-impl.h>
26
27 namespace Dali
28 {
29
30 class Model;
31 class Entity;
32
33 namespace Internal
34 {
35
36 /**
37  * This factory class is used to generate a tree of actors and mesh actors.
38  */
39 class ModelActorFactory
40 {
41 public:
42
43   /**
44    * @copydoc Dali::ModelActorFactory::BuildActorTree
45    */
46   static ActorPtr BuildActorTree(Dali::Model& model, const std::string& name);
47
48
49   /**
50    * Create an animation on the actor and child actors using the named animation map.
51    * If the animation map does not exist in the model, then this returns an uninitialised
52    * handle.
53    * @param[in] model A model resource handle
54    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
55    * @param[in] animationName The name of the animation to build
56    * @return A pointer to an animation.
57    */
58   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, const std::string& animationName);
59
60   /**
61    * Create an animation on the actor and child actors using the named animation map.
62    * If the animation map does not exist in the model, then this returns an uninitialised
63    * handle.
64    * @param[in] model A model resource handle
65    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
66    * @param[in] animationName The name of the animation to build
67    * @param[in] durationSeconds The duration over which to run the animation
68    * @return A pointer to an animation.
69    */
70   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, const std::string& animationName, float durationSeconds);
71
72   /**
73    * Create an animation on the actor and child actors using the named animation map.
74    * If the animation map does not exist in the model, then this returns an uninitialised
75    * handle.
76    * @param[in] model A model resource handle
77    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
78    * @param[in] animationName The name of the animation to build
79    * @param[in] alpha The alpha function to apply to the overall progress
80    * @return A pointer to an animation.
81    */
82   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, const std::string& animationName, AlphaFunction alpha);
83
84   /**
85    * Create an animation on the actor and child actors using the named animation map.
86    * If the animation map does not exist in the model, then this returns an uninitialised
87    * handle.
88    * @param[in] model A model resource handle
89    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
90    * @param[in] animationName The name of the animation to build
91    * @param[in] alpha The alpha function to apply to the overall progress
92    * @param[in] durationSeconds The duration over which to run the animation
93    * @return A pointer to an animation.
94    */
95   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, const std::string& animationName, AlphaFunction alpha, float durationSeconds);
96
97   /**
98    * Create an animation on the actor and child actors using the indexed animation map.
99    * If the animation map does not exist in the model, then this returns an uninitialised
100    * handle.
101    * @param[in] model A model resource handle
102    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
103    * @param[in] index The index of the animation
104    * @return A handle to an animation, or uninitialised.
105    */
106   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, size_t index);
107
108   /**
109    * Create an animation on the actor and child actors using the indexed animation map.
110    * If the animation map does not exist in the model, then this returns an uninitialised
111    * handle.
112    * @param[in] model A model resource handle
113    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
114    * @param[in] index The index of the animation
115    * @param[in] durationSeconds The duration over which to run the animation
116    * @return A handle to an animation, or uninitialised.
117    */
118   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, size_t index, float durationSeconds);
119
120   /**
121    * Create an animation on the actor and child actors using the indexed animation map.
122    * If the animation map does not exist in the model, then this returns an uninitialised
123    * handle.
124    * @param[in] model A model resource handle
125    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
126    * @param[in] index The index of the animation
127    * @param[in] alpha The alpha function to apply to the overall progress
128    * @return A handle to an animation, or uninitialised.
129    */
130   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, size_t index, AlphaFunction alpha);
131
132   /**
133    * Create an animation on the actor and child actors using the indexed animation map.
134    * If the animation map does not exist in the model, then this returns an uninitialised
135    * handle.
136    * @param[in] model A model resource handle
137    * @param[in] rootActor An actor tree (generated by BuildActorTree) to animate
138    * @param[in] index The index of the animation
139    * @param[in] alpha The alpha function to apply to the overall progress
140    * @param[in] durationSeconds The duration over which to run the animation
141    * @return A handle to an animation, or uninitialised.
142    */
143   static AnimationPtr BuildAnimation(Model& model, Actor& rootActor, size_t index, AlphaFunction alpha, float durationSeconds);
144
145
146
147 private:
148   /**
149    * Recursively descend entity tree, creating either actors or meshActors.
150    * @param[in] modelData The model data source.
151    * @param[in] entity The entity to create and descend
152    * @return an Actor representing the entity (May be a handle to a MeshActor)
153    */
154   static ActorPtr RecurseNew(ModelDataPtr modelData, Dali::Entity entity);
155
156   /**
157    * Recursive method which descends the actor tree from actor. For
158    * any mesh actor found, bind it's bones, searching from the
159    * rootActor. (If a mesh is affected by bones, there is no
160    * requirement that they are below it's entity in the model's entity
161    * tree and corresponding actor tree)
162    *
163    * @param[in] rootActor - the actor to search for bones
164    * @param[in] actor     - the current actor to check for meshes.
165    */
166   static void BindBonesToMeshActors(ActorPtr rootActor, ActorPtr actor);
167
168   /**
169    * Create animation and connect each animator in the animation map to the
170    * relevant actor matching entity. This uses the root actor as a point to
171    * search for entity names, so it's advised to use the topmost actor generated
172    * by BuildActorTree.
173    *
174    * @param[in] rootActor The root actor created from the model,
175    * @param[in] animationData The animation map containing entity animator data.
176    * @param[in] alpha The alpha function to apply to the overall progress
177    * @param[in] durationSeconds The duration over which the animation will occur.
178    * @return animation The generated animation
179    */
180   static AnimationPtr CreateAnimation(Actor& rootActor, const ModelAnimationMap* animationData, AlphaFunction alpha, float durationSeconds);
181
182 };
183
184 } // Internal
185 } // namespace Dali
186
187 #endif /* _DALI_INTERNAL_MODEL_ACTOR_FACTORY_H_ */