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