Merge changes I0cbfe8d4,I63b556cb into devel/master
[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   //deprecated - use ImageView instead for nine patch
108 }
109
110 ImageActor::Style ImageActor::GetStyle() const
111 {
112   //deprecated - use ImageView instead for nine patch
113   return ImageActor::STYLE_QUAD;
114 }
115
116 void ImageActor::SetNinePatchBorder(const Vector4& border)
117 {
118   //deprecated - use ImageView instead for nine patch
119 }
120
121 Vector4 ImageActor::GetNinePatchBorder() const
122 {
123   //deprecated - use ImageView instead for nine patch
124   return Vector4::ZERO;
125 }
126
127 void ImageActor::SetSortModifier(float modifier)
128 {
129   GetImplementation(*this).SetSortModifier(modifier);
130 }
131
132 float ImageActor::GetSortModifier() const
133 {
134   return GetImplementation(*this).GetSortModifier();
135 }
136
137 void ImageActor::SetBlendMode( BlendingMode::Type mode )
138 {
139   GetImplementation(*this).SetBlendMode( mode );
140 }
141
142 BlendingMode::Type ImageActor::GetBlendMode() const
143 {
144   return GetImplementation(*this).GetBlendMode();
145 }
146
147 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
148 {
149   GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
150 }
151
152 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
153                                     BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
154 {
155   GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
156 }
157
158 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
159                                     BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
160 {
161   GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
162 }
163
164 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
165 {
166   GetImplementation(*this).SetBlendEquation( equationRgba );
167 }
168
169 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
170 {
171   GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
172 }
173
174 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
175 {
176   GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
177 }
178
179 void ImageActor::SetBlendColor( const Vector4& color )
180 {
181   GetImplementation(*this).SetBlendColor( color );
182 }
183
184 const Vector4& ImageActor::GetBlendColor() const
185 {
186   return GetImplementation(*this).GetBlendColor();
187 }
188
189 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
190 {
191   GetImplementation(*this).SetFilterMode( minFilter, magFilter );
192 }
193
194 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
195 {
196   GetImplementation(*this).GetFilterMode( minFilter, magFilter );
197 }
198
199 void ImageActor::SetShaderEffect(ShaderEffect effect)
200 {
201   GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
202 }
203
204 ShaderEffect ImageActor::GetShaderEffect() const
205 {
206   Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
207
208   return ShaderEffect(internal.Get());
209 }
210
211 void ImageActor::RemoveShaderEffect()
212 {
213   GetImplementation(*this).RemoveShaderEffect();
214 }
215
216
217 ImageActor::ImageActor(Internal::ImageActor* internal)
218 : Actor(internal)
219 {
220 }
221
222 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
223 {
224   // only do something if the actor and effect are valid
225   if( actor && effect )
226   {
227     // first remove from this actor
228     ImageActor imageActor = ImageActor::DownCast( actor );
229     if( imageActor )
230     {
231       imageActor.SetShaderEffect( effect );
232     }
233     // then all children recursively
234     const unsigned int count = actor.GetChildCount();
235     for( unsigned int index = 0; index < count; ++index )
236     {
237       Actor child( actor.GetChildAt( index ) );
238       SetShaderEffectRecursively( child, effect );
239     }
240   }
241 }
242
243 void RemoveShaderEffectRecursively( Actor actor )
244 {
245   // only do something if the actor is valid
246   if( actor )
247   {
248     // first remove from this actor
249     ImageActor imageActor = ImageActor::DownCast( actor );
250     if( imageActor )
251     {
252       imageActor.RemoveShaderEffect();
253     }
254     // then all children recursively
255     const unsigned int count = actor.GetChildCount();
256     for( unsigned int index = 0; index < count; ++index )
257     {
258       Actor child( actor.GetChildAt( index ) );
259       RemoveShaderEffectRecursively( child );
260     }
261   }
262 }
263
264 } // namespace Dali