2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/actors/image-actor.h>
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>
30 ImageActor::ImageActor()
34 ImageActor ImageActor::New()
36 Internal::ImageActorPtr internal = Internal::ImageActor::New();
37 return ImageActor( internal.Get() );
40 ImageActor ImageActor::New(Image image)
42 ImageActor actor = ImageActor::New();
43 actor.SetImage( image );
48 ImageActor ImageActor::New(Image image, PixelArea pixelArea)
50 ImageActor actor = ImageActor::New();
51 actor.SetImage( image );
52 actor.SetPixelArea( pixelArea );
57 ImageActor ImageActor::DownCast( BaseHandle handle )
59 return ImageActor( dynamic_cast<Dali::Internal::ImageActor*>(handle.GetObjectPtr()) );
62 ImageActor::~ImageActor()
66 ImageActor::ImageActor(const ImageActor& copy)
67 : RenderableActor(copy)
71 ImageActor& ImageActor::operator=(const ImageActor& rhs)
73 BaseHandle::operator=(rhs);
77 void ImageActor::SetImage(Image image)
79 Internal::ImagePtr imagePtr;
82 imagePtr = &GetImplementation(image);
84 GetImplementation(*this).SetImage( imagePtr );
87 Image ImageActor::GetImage()
89 Internal::ImagePtr imagePtr( GetImplementation(*this).GetImage() );
90 return Dali::Image( imagePtr.Get() );
93 void ImageActor::SetPixelArea(const PixelArea& pixelArea)
95 GetImplementation(*this).SetPixelArea(pixelArea);
98 ImageActor::PixelArea ImageActor::GetPixelArea() const
100 return GetImplementation(*this).GetPixelArea();
103 void ImageActor::SetStyle(Style style)
105 GetImplementation(*this).SetStyle(style);
108 ImageActor::Style ImageActor::GetStyle() const
110 return GetImplementation(*this).GetStyle();
113 void ImageActor::SetNinePatchBorder(const Vector4& border)
115 GetImplementation(*this).SetNinePatchBorder(border, true/*in pixels*/);
118 Vector4 ImageActor::GetNinePatchBorder() const
120 return GetImplementation(*this).GetNinePatchBorder();
123 void ImageActor::SetSortModifier(float modifier)
125 GetImplementation(*this).SetSortModifier(modifier);
128 float ImageActor::GetSortModifier() const
130 return GetImplementation(*this).GetSortModifier();
133 void ImageActor::SetCullFace(const CullFaceMode mode)
135 GetImplementation(*this).SetCullFace(mode);
138 CullFaceMode ImageActor::GetCullFace() const
140 return GetImplementation(*this).GetCullFace();
143 void ImageActor::SetBlendMode( BlendingMode::Type mode )
145 GetImplementation(*this).SetBlendMode( mode );
148 BlendingMode::Type ImageActor::GetBlendMode() const
150 return GetImplementation(*this).GetBlendMode();
153 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
155 GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
158 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
159 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
161 GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
164 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
165 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
167 GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
170 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
172 GetImplementation(*this).SetBlendEquation( equationRgba );
175 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
177 GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
180 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
182 GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
185 void ImageActor::SetBlendColor( const Vector4& color )
187 GetImplementation(*this).SetBlendColor( color );
190 const Vector4& ImageActor::GetBlendColor() const
192 return GetImplementation(*this).GetBlendColor();
195 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
197 GetImplementation(*this).SetFilterMode( minFilter, magFilter );
200 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
202 GetImplementation(*this).GetFilterMode( minFilter, magFilter );
205 void ImageActor::SetShaderEffect(ShaderEffect effect)
207 GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
210 ShaderEffect ImageActor::GetShaderEffect() const
212 Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
214 return ShaderEffect(internal.Get());
217 void ImageActor::RemoveShaderEffect()
219 GetImplementation(*this).RemoveShaderEffect();
223 ImageActor::ImageActor(Internal::ImageActor* internal)
224 : RenderableActor(internal)
228 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
230 // only do something if the actor and effect are valid
231 if( actor && effect )
233 // first remove from this actor
234 ImageActor imageActor = ImageActor::DownCast( actor );
237 imageActor.SetShaderEffect( effect );
239 // then all children recursively
240 const unsigned int count = actor.GetChildCount();
241 for( unsigned int index = 0; index < count; ++index )
243 Actor child( actor.GetChildAt( index ) );
244 SetShaderEffectRecursively( child, effect );
249 void RemoveShaderEffectRecursively( Actor actor )
251 // only do something if the actor is valid
254 // first remove from this actor
255 ImageActor imageActor = ImageActor::DownCast( actor );
258 imageActor.RemoveShaderEffect();
260 // then all children recursively
261 const unsigned int count = actor.GetChildCount();
262 for( unsigned int index = 0; index < count; ++index )
264 Actor child( actor.GetChildAt( index ) );
265 RemoveShaderEffectRecursively( child );