Merge "Fix prevent issue - Unsigned compared against 0" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / actors / renderable-actor.cpp
1 /*
2  * Copyright (c) 2015 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/renderable-actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/renderable-actor-impl.h>
23 #include <dali/internal/event/effects/shader-effect-impl.h>
24
25 namespace Dali
26 {
27
28 const BlendingMode::Type RenderableActor::DEFAULT_BLENDING_MODE = BlendingMode::AUTO;
29
30 RenderableActor::RenderableActor()
31 {
32 }
33
34 RenderableActor RenderableActor::DownCast( BaseHandle handle )
35 {
36   return RenderableActor( dynamic_cast<Dali::Internal::RenderableActor*>(handle.GetObjectPtr()) );
37 }
38
39 RenderableActor::~RenderableActor()
40 {
41 }
42
43 RenderableActor::RenderableActor(const RenderableActor& copy)
44 : Actor(copy)
45 {
46 }
47
48 RenderableActor& RenderableActor::operator=(const RenderableActor& rhs)
49 {
50   BaseHandle::operator=(rhs);
51   return *this;
52 }
53
54 void RenderableActor::SetSortModifier(float modifier)
55 {
56   GetImplementation(*this).SetSortModifier(modifier);
57 }
58
59 float RenderableActor::GetSortModifier() const
60 {
61   return GetImplementation(*this).GetSortModifier();
62 }
63
64 void RenderableActor::SetCullFace(const CullFaceMode mode)
65 {
66   GetImplementation(*this).SetCullFace(mode);
67 }
68
69 CullFaceMode RenderableActor::GetCullFace() const
70 {
71   return GetImplementation(*this).GetCullFace();
72 }
73
74 void RenderableActor::SetBlendMode( BlendingMode::Type mode )
75 {
76   GetImplementation(*this).SetBlendMode( mode );
77 }
78
79 BlendingMode::Type RenderableActor::GetBlendMode() const
80 {
81   return GetImplementation(*this).GetBlendMode();
82 }
83
84 void RenderableActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
85                                     BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
86 {
87   GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
88 }
89
90 void RenderableActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
91                                     BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
92 {
93   GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
94 }
95
96 void RenderableActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
97 {
98   GetImplementation(*this).SetFilterMode( minFilter, magFilter );
99 }
100
101 void RenderableActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
102 {
103   GetImplementation(*this).GetFilterMode( minFilter, magFilter );
104 }
105
106 void RenderableActor::SetShaderEffect(ShaderEffect effect)
107 {
108   GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
109 }
110
111 ShaderEffect RenderableActor::GetShaderEffect() const
112 {
113   Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
114
115   return ShaderEffect(internal.Get());
116 }
117
118 void RenderableActor::RemoveShaderEffect()
119 {
120   GetImplementation(*this).RemoveShaderEffect();
121 }
122
123 RenderableActor::RenderableActor(Internal::RenderableActor* internal)
124 : Actor(internal)
125 {
126 }
127
128 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
129 {
130   // only do something if the actor and effect are valid
131   if( actor && effect )
132   {
133     // first remove from this actor
134     RenderableActor renderable = RenderableActor::DownCast( actor );
135     if( renderable )
136     {
137       renderable.SetShaderEffect( effect );
138     }
139     // then all children recursively
140     const unsigned int count = actor.GetChildCount();
141     for( unsigned int index = 0; index < count; ++index )
142     {
143       Actor child( actor.GetChildAt( index ) );
144       SetShaderEffectRecursively( child, effect );
145     }
146   }
147 }
148
149 void RemoveShaderEffectRecursively( Actor actor )
150 {
151   // only do something if the actor is valid
152   if( actor )
153   {
154     // first remove from this actor
155     RenderableActor renderable = RenderableActor::DownCast( actor );
156     if( renderable )
157     {
158       renderable.RemoveShaderEffect();
159     }
160     // then all children recursively
161     const unsigned int count = actor.GetChildCount();
162     for( unsigned int index = 0; index < count; ++index )
163     {
164       Actor child( actor.GetChildAt( index ) );
165       RemoveShaderEffectRecursively( child );
166     }
167   }
168 }
169
170 } // namespace Dali