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