[dali_1.0.10] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / public-api / actors / actor.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/actors/actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/math/degree.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector2.h>
28
29 #include <dali/internal/event/actors/actor-impl.h>
30 #include <dali/internal/event/actors/layer-impl.h>
31 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
32 #include <dali/internal/event/animation/constraint-impl.h>
33
34 #include <dali/public-api/dynamics/dynamics-body.h>
35 #include <dali/public-api/dynamics/dynamics-joint.h>
36 #include <dali/public-api/dynamics/dynamics-body-config.h>
37
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
40 #include <dali/internal/event/dynamics/dynamics-body-config-impl.h>
41 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
42 #include <dali/internal/event/dynamics/dynamics-joint-impl.h>
43 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
44 #endif
45
46 using namespace std;
47
48 namespace Dali
49 {
50
51 const char* const Actor::SIGNAL_TOUCHED = "touched";
52 const char* const Actor::SIGNAL_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
53 const char* const Actor::SIGNAL_SET_SIZE = "set-size";
54 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
55 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
56
57 const char* const Actor::ACTION_SHOW = "show";
58 const char* const Actor::ACTION_HIDE = "hide";
59
60 Actor::Actor()
61 {
62 }
63
64 Actor Actor::New()
65 {
66   Internal::ActorPtr internal = Internal::Actor::New();
67
68   return Actor(internal.Get());
69 }
70
71 Actor Actor::DownCast( BaseHandle handle )
72 {
73   return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
74 }
75
76 Actor::~Actor()
77 {
78 }
79
80 Actor::Actor(const Actor& copy)
81 : Constrainable(copy)
82 {
83 }
84
85 Actor& Actor::operator=(const Actor& rhs)
86 {
87   BaseHandle::operator=(rhs);
88   return *this;
89 }
90
91 Actor& Actor::operator=(BaseHandle::NullType* rhs)
92 {
93   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
94   Reset();
95   return *this;
96 }
97
98 const std::string& Actor::GetName() const
99 {
100   return GetImplementation(*this).GetName();
101 }
102
103 void Actor::SetName(const std::string& name)
104 {
105   GetImplementation(*this).SetName(name);
106 }
107
108 unsigned int Actor::GetId() const
109 {
110   return GetImplementation(*this).GetId();
111 }
112
113 bool Actor::IsRoot() const
114 {
115   return GetImplementation(*this).IsRoot();
116 }
117
118 bool Actor::OnStage() const
119 {
120   return GetImplementation(*this).OnStage();
121 }
122
123 bool Actor::IsLayer() const
124 {
125   return GetImplementation(*this).IsLayer();
126 }
127
128 Layer Actor::GetLayer()
129 {
130   return GetImplementation(*this).GetLayer();
131 }
132
133 void Actor::Add(Actor actor)
134 {
135   GetImplementation(*this).Add(GetImplementation(actor));
136 }
137
138 void Actor::Insert(unsigned int index, Actor actor)
139 {
140   GetImplementation(*this).Insert(index, GetImplementation(actor));
141 }
142
143 void Actor::Remove(Actor actor)
144 {
145   GetImplementation(*this).Remove(GetImplementation(actor));
146 }
147
148 void Actor::Unparent()
149 {
150   GetImplementation(*this).Unparent();
151 }
152
153 unsigned int Actor::GetChildCount() const
154 {
155   return GetImplementation(*this).GetChildCount();
156 }
157
158 Actor Actor::GetChildAt(unsigned int index) const
159 {
160   return GetImplementation(*this).GetChildAt(index);
161 }
162
163 Actor Actor::FindChildByName(const std::string& actorName)
164 {
165   Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
166   return Actor(child.Get());
167 }
168
169 Actor Actor::FindChildByAlias(const std::string& actorAlias)
170 {
171   Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
172   return child;
173 }
174
175 Actor Actor::FindChildById(const unsigned int id)
176 {
177   Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
178   return Actor(child.Get());
179 }
180
181 Actor Actor::GetParent() const
182 {
183   Internal::Actor* parent = GetImplementation(*this).GetParent();
184
185   return Actor(parent);
186 }
187
188 void Actor::SetParentOrigin(const Vector3& origin)
189 {
190   GetImplementation(*this).SetParentOrigin(origin);
191 }
192
193 Vector3 Actor::GetCurrentParentOrigin() const
194 {
195   return GetImplementation(*this).GetCurrentParentOrigin();
196 }
197
198 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
199 {
200   GetImplementation(*this).SetAnchorPoint(anchorPoint);
201 }
202
203 Vector3 Actor::GetCurrentAnchorPoint() const
204 {
205   return GetImplementation(*this).GetCurrentAnchorPoint();
206 }
207
208 void Actor::SetSize(float width, float height)
209 {
210   GetImplementation(*this).SetSize(width, height);
211 }
212
213 void Actor::SetSize(float width, float height, float depth)
214 {
215   GetImplementation(*this).SetSize(width, height, depth);
216 }
217
218 void Actor::SetSize(const Vector2& size)
219 {
220   GetImplementation(*this).SetSize(size);
221 }
222
223 void Actor::SetSize(const Vector3& size)
224 {
225   GetImplementation(*this).SetSize(size);
226 }
227
228 Vector3 Actor::GetSize() const
229 {
230   return GetImplementation(*this).GetSize();
231 }
232
233 Vector3 Actor::GetCurrentSize() const
234 {
235   return GetImplementation(*this).GetCurrentSize();
236 }
237
238 Vector3 Actor::GetNaturalSize() const
239 {
240   return GetImplementation(*this).GetNaturalSize();
241 }
242
243 void Actor::SetPosition(float x, float y)
244 {
245   GetImplementation(*this).SetPosition(x, y);
246 }
247
248 void Actor::SetPosition(float x, float y, float z)
249 {
250   GetImplementation(*this).SetPosition(x, y, z);
251 }
252
253 void Actor::SetPosition(const Vector3& position)
254 {
255   GetImplementation(*this).SetPosition(position);
256 }
257
258 void Actor::SetX(float x)
259 {
260   GetImplementation(*this).SetX(x);
261 }
262
263 void Actor::SetY(float y)
264 {
265   GetImplementation(*this).SetY(y);
266 }
267
268 void Actor::SetZ(float z)
269 {
270   GetImplementation(*this).SetZ(z);
271 }
272
273 void Actor::MoveBy(const Vector3& distance)
274 {
275   GetImplementation(*this).MoveBy(distance);
276 }
277
278 Vector3 Actor::GetCurrentPosition() const
279 {
280   return GetImplementation(*this).GetCurrentPosition();
281 }
282
283 Vector3 Actor::GetCurrentWorldPosition() const
284 {
285   return GetImplementation(*this).GetCurrentWorldPosition();
286 }
287
288 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
289 {
290   GetImplementation(*this).SetPositionInheritanceMode( mode );
291 }
292
293 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
294 {
295   return GetImplementation(*this).GetPositionInheritanceMode();
296 }
297
298 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
299 {
300   GetImplementation(*this).SetRotation(Radian(angle), axis);
301 }
302
303 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
304 {
305   GetImplementation(*this).SetRotation(angle, axis);
306 }
307
308 void Actor::SetRotation(const Quaternion& rotation)
309 {
310   GetImplementation(*this).SetRotation(rotation);
311 }
312
313 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
314 {
315   GetImplementation(*this).RotateBy(Radian(angle), axis);
316 }
317
318 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
319 {
320   GetImplementation(*this).RotateBy(angle, axis);
321 }
322
323 void Actor::RotateBy(const Quaternion& relativeRotation)
324 {
325   GetImplementation(*this).RotateBy(relativeRotation);
326 }
327
328 Quaternion Actor::GetCurrentRotation() const
329 {
330   return GetImplementation(*this).GetCurrentRotation();
331 }
332
333 void Actor::SetInheritRotation(bool inherit)
334 {
335   GetImplementation(*this).SetInheritRotation(inherit);
336 }
337
338 bool Actor::IsRotationInherited() const
339 {
340   return GetImplementation(*this).IsRotationInherited();
341 }
342
343 Quaternion Actor::GetCurrentWorldRotation() const
344 {
345   return GetImplementation(*this).GetCurrentWorldRotation();
346 }
347
348 void Actor::SetScale(float scale)
349 {
350   GetImplementation(*this).SetScale(scale);
351 }
352
353 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
354 {
355   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
356 }
357
358 void Actor::SetScale(const Vector3& scale)
359 {
360   GetImplementation(*this).SetScale(scale);
361 }
362
363 void Actor::ScaleBy(const Vector3& relativeScale)
364 {
365   GetImplementation(*this).ScaleBy(relativeScale);
366 }
367
368 Vector3 Actor::GetCurrentScale() const
369 {
370   return GetImplementation(*this).GetCurrentScale();
371 }
372
373 Vector3 Actor::GetCurrentWorldScale() const
374 {
375   return GetImplementation(*this).GetCurrentWorldScale();
376 }
377
378 void Actor::SetInheritScale( bool inherit )
379 {
380   GetImplementation(*this).SetInheritScale( inherit );
381 }
382
383 bool Actor::IsScaleInherited() const
384 {
385   return GetImplementation(*this).IsScaleInherited();
386 }
387
388 Matrix Actor::GetCurrentWorldMatrix() const
389 {
390   return GetImplementation(*this).GetCurrentWorldMatrix();
391 }
392
393 void Actor::SetVisible(bool visible)
394 {
395   GetImplementation(*this).SetVisible(visible);
396 }
397
398 bool Actor::IsVisible() const
399 {
400   return GetImplementation(*this).IsVisible();
401 }
402
403 void Actor::SetOpacity(float opacity)
404 {
405   GetImplementation(*this).SetOpacity(opacity);
406 }
407
408 void Actor::OpacityBy(float relativeOpacity)
409 {
410   GetImplementation(*this).OpacityBy(relativeOpacity);
411 }
412
413 float Actor::GetCurrentOpacity() const
414 {
415   return GetImplementation(*this).GetCurrentOpacity();
416 }
417
418 void Actor::SetColor(const Vector4& color)
419 {
420   GetImplementation(*this).SetColor(color);
421 }
422
423 void Actor::ColorBy(const Vector4& relativeColor)
424 {
425   GetImplementation(*this).ColorBy(relativeColor);
426 }
427
428 Vector4 Actor::GetCurrentColor() const
429 {
430   return GetImplementation(*this).GetCurrentColor();
431 }
432
433 void Actor::SetColorMode( ColorMode colorMode )
434 {
435   GetImplementation(*this).SetColorMode(colorMode);
436 }
437
438 ColorMode Actor::GetColorMode() const
439 {
440   return GetImplementation(*this).GetColorMode();
441 }
442
443 Vector4 Actor::GetCurrentWorldColor() const
444 {
445   return GetImplementation(*this).GetCurrentWorldColor();
446 }
447
448 void Actor::SetDrawMode( DrawMode::Type drawMode )
449 {
450   GetImplementation(*this).SetDrawMode( drawMode );
451 }
452
453 DrawMode::Type Actor::GetDrawMode() const
454 {
455   return GetImplementation(*this).GetDrawMode();
456 }
457
458 void Actor::SetSensitive(bool sensitive)
459 {
460   GetImplementation(*this).SetSensitive(sensitive);
461 }
462
463 bool Actor::IsSensitive() const
464 {
465   return GetImplementation(*this).IsSensitive();
466 }
467
468 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
469 {
470   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
471 }
472
473 void Actor::SetLeaveRequired(bool required)
474 {
475   GetImplementation(*this).SetLeaveRequired(required);
476 }
477
478 bool Actor::GetLeaveRequired() const
479 {
480   return GetImplementation(*this).GetLeaveRequired();
481 }
482
483 void Actor::SetKeyboardFocusable( bool focusable )
484 {
485   GetImplementation(*this).SetKeyboardFocusable(focusable);
486 }
487
488 bool Actor::IsKeyboardFocusable() const
489 {
490   return GetImplementation(*this).IsKeyboardFocusable();
491 }
492
493 Actor::TouchSignalV2& Actor::TouchedSignal()
494 {
495   return GetImplementation(*this).TouchedSignal();
496 }
497
498 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
499 {
500   return GetImplementation(*this).MouseWheelEventSignal();
501 }
502
503 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
504 {
505   return GetImplementation(*this).SetSizeSignal();
506 }
507
508 Actor::OnStageSignalV2& Actor::OnStageSignal()
509 {
510   return GetImplementation(*this).OnStageSignal();
511 }
512
513 Actor::OffStageSignalV2& Actor::OffStageSignal()
514 {
515   return GetImplementation(*this).OffStageSignal();
516 }
517
518 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
519 {
520 #ifdef DYNAMICS_SUPPORT
521   Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
522
523   Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
524
525   return DynamicsBody( body.Get() );
526 #else
527   return DynamicsBody();
528 #endif
529 }
530
531 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
532 {
533 #ifdef DYNAMICS_SUPPORT
534   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
535   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
536
537   return DynamicsJoint( joint.Get() );
538 #else
539   return DynamicsJoint();
540 #endif
541 }
542
543 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
544 {
545 #ifdef DYNAMICS_SUPPORT
546   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
547   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
548
549   return DynamicsJoint( joint.Get() );
550 #else
551   return DynamicsJoint();
552 #endif
553 }
554
555 const int Actor::GetNumberOfJoints() const
556 {
557 #ifdef DYNAMICS_SUPPORT
558   return GetImplementation(*this).GetNumberOfJoints();
559 #else
560   return int();
561 #endif
562 }
563
564 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
565 {
566 #ifdef DYNAMICS_SUPPORT
567   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
568
569   return DynamicsJoint( joint.Get() );
570 #else
571   return DynamicsJoint();
572 #endif
573 }
574
575 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
576 {
577 #ifdef DYNAMICS_SUPPORT
578   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
579
580   return DynamicsJoint( joint.Get() );
581 #else
582   return DynamicsJoint();
583 #endif
584 }
585
586 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
587 {
588 #ifdef DYNAMICS_SUPPORT
589   GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
590 #endif
591 }
592
593 void Actor::DisableDynamics()
594 {
595 #ifdef DYNAMICS_SUPPORT
596   GetImplementation(*this).DisableDynamics();
597 #endif
598 }
599
600 DynamicsBody Actor::GetDynamicsBody()
601 {
602 #ifdef DYNAMICS_SUPPORT
603   Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
604   return DynamicsBody( internal.Get() );
605 #else
606   return DynamicsBody();
607 #endif
608 }
609
610 Actor::Actor(Internal::Actor* internal)
611 : Constrainable(internal)
612 {
613 }
614
615 void UnparentAndReset( Actor& actor )
616 {
617   if( actor )
618   {
619     actor.Unparent();
620     actor.Reset();
621   }
622 }
623
624 } // namespace Dali