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