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