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