Bug fix which makes applications crash when adding a renderer to an on stage actor
[platform/core/uifw/dali-core.git] / dali / public-api / actors / image-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/image-actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/event/actors/image-actor-impl.h>
23 #include <dali/internal/event/images/image-impl.h>
24 #include <dali/internal/event/effects/shader-effect-impl.h>
25 #include <dali/public-api/common/dali-common.h>
26
27 namespace Dali
28 {
29
30 ImageActor::ImageActor()
31 {
32 }
33
34 ImageActor ImageActor::New()
35 {
36   Internal::ImageActorPtr internal = Internal::ImageActor::New();
37   return ImageActor( internal.Get() );
38 }
39
40 ImageActor ImageActor::New(Image image)
41 {
42   ImageActor actor = ImageActor::New();
43   actor.SetImage( image );
44
45   return actor;
46 }
47
48 ImageActor ImageActor::New(Image image, PixelArea pixelArea)
49 {
50   ImageActor actor = ImageActor::New();
51   actor.SetImage( image );
52   actor.SetPixelArea( pixelArea );
53
54   return actor;
55 }
56
57 ImageActor ImageActor::DownCast( BaseHandle handle )
58 {
59   return ImageActor( dynamic_cast<Dali::Internal::ImageActor*>(handle.GetObjectPtr()) );
60 }
61
62 ImageActor::~ImageActor()
63 {
64 }
65
66 ImageActor::ImageActor(const ImageActor& copy)
67 : RenderableActor(copy)
68 {
69 }
70
71 ImageActor& ImageActor::operator=(const ImageActor& rhs)
72 {
73   BaseHandle::operator=(rhs);
74   return *this;
75 }
76
77 void ImageActor::SetImage(Image image)
78 {
79   Internal::ImagePtr imagePtr;
80   if( image )
81   {
82     imagePtr = &GetImplementation(image);
83   }
84   GetImplementation(*this).SetImage( imagePtr );
85 }
86
87 Image ImageActor::GetImage()
88 {
89   Internal::ImagePtr imagePtr( GetImplementation(*this).GetImage() );
90   return Dali::Image( imagePtr.Get() );
91 }
92
93 void ImageActor::SetPixelArea(const PixelArea& pixelArea)
94 {
95   GetImplementation(*this).SetPixelArea(pixelArea);
96 }
97
98 ImageActor::PixelArea ImageActor::GetPixelArea() const
99 {
100   return GetImplementation(*this).GetPixelArea();
101 }
102
103 void ImageActor::SetStyle(Style style)
104 {
105   GetImplementation(*this).SetStyle(style);
106 }
107
108 ImageActor::Style ImageActor::GetStyle() const
109 {
110   return GetImplementation(*this).GetStyle();
111 }
112
113 void ImageActor::SetNinePatchBorder(const Vector4& border)
114 {
115   GetImplementation(*this).SetNinePatchBorder(border, true/*in pixels*/);
116 }
117
118 Vector4 ImageActor::GetNinePatchBorder() const
119 {
120   return GetImplementation(*this).GetNinePatchBorder();
121 }
122
123 void ImageActor::SetSortModifier(float modifier)
124 {
125   GetImplementation(*this).SetSortModifier(modifier);
126 }
127
128 float ImageActor::GetSortModifier() const
129 {
130   return GetImplementation(*this).GetSortModifier();
131 }
132
133 void ImageActor::SetCullFace(const CullFaceMode mode)
134 {
135   GetImplementation(*this).SetCullFace(mode);
136 }
137
138 CullFaceMode ImageActor::GetCullFace() const
139 {
140   return GetImplementation(*this).GetCullFace();
141 }
142
143 void ImageActor::SetBlendMode( BlendingMode::Type mode )
144 {
145   GetImplementation(*this).SetBlendMode( mode );
146 }
147
148 BlendingMode::Type ImageActor::GetBlendMode() const
149 {
150   return GetImplementation(*this).GetBlendMode();
151 }
152
153 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
154 {
155   GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
156 }
157
158 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
159                                     BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
160 {
161   GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
162 }
163
164 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
165                                     BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
166 {
167   GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
168 }
169
170 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
171 {
172   GetImplementation(*this).SetBlendEquation( equationRgba );
173 }
174
175 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
176 {
177   GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
178 }
179
180 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
181 {
182   GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
183 }
184
185 void ImageActor::SetBlendColor( const Vector4& color )
186 {
187   GetImplementation(*this).SetBlendColor( color );
188 }
189
190 const Vector4& ImageActor::GetBlendColor() const
191 {
192   return GetImplementation(*this).GetBlendColor();
193 }
194
195 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
196 {
197   GetImplementation(*this).SetFilterMode( minFilter, magFilter );
198 }
199
200 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
201 {
202   GetImplementation(*this).GetFilterMode( minFilter, magFilter );
203 }
204
205 void ImageActor::SetShaderEffect(ShaderEffect effect)
206 {
207   GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
208 }
209
210 ShaderEffect ImageActor::GetShaderEffect() const
211 {
212   Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
213
214   return ShaderEffect(internal.Get());
215 }
216
217 void ImageActor::RemoveShaderEffect()
218 {
219   GetImplementation(*this).RemoveShaderEffect();
220 }
221
222
223 ImageActor::ImageActor(Internal::ImageActor* internal)
224 : RenderableActor(internal)
225 {
226 }
227
228 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
229 {
230   // only do something if the actor and effect are valid
231   if( actor && effect )
232   {
233     // first remove from this actor
234     ImageActor imageActor = ImageActor::DownCast( actor );
235     if( imageActor )
236     {
237       imageActor.SetShaderEffect( effect );
238     }
239     // then all children recursively
240     const unsigned int count = actor.GetChildCount();
241     for( unsigned int index = 0; index < count; ++index )
242     {
243       Actor child( actor.GetChildAt( index ) );
244       SetShaderEffectRecursively( child, effect );
245     }
246   }
247 }
248
249 void RemoveShaderEffectRecursively( Actor actor )
250 {
251   // only do something if the actor is valid
252   if( actor )
253   {
254     // first remove from this actor
255     ImageActor imageActor = ImageActor::DownCast( actor );
256     if( imageActor )
257     {
258       imageActor.RemoveShaderEffect();
259     }
260     // then all children recursively
261     const unsigned int count = actor.GetChildCount();
262     for( unsigned int index = 0; index < count; ++index )
263     {
264       Actor child( actor.GetChildAt( index ) );
265       RemoveShaderEffectRecursively( child );
266     }
267   }
268 }
269
270 } // namespace Dali