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