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