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 const BlendingMode::Type ImageActor::DEFAULT_BLENDING_MODE = BlendingMode::AUTO;
32 ImageActor::ImageActor()
36 ImageActor ImageActor::New()
38 Internal::ImageActorPtr internal = Internal::ImageActor::New();
39 return ImageActor( internal.Get() );
42 ImageActor ImageActor::New(Image image)
44 ImageActor actor = ImageActor::New();
45 actor.SetImage( image );
50 ImageActor ImageActor::New(Image image, PixelArea pixelArea)
52 ImageActor actor = ImageActor::New();
53 actor.SetImage( image );
54 actor.SetPixelArea( pixelArea );
59 ImageActor ImageActor::DownCast( BaseHandle handle )
61 return ImageActor( dynamic_cast<Dali::Internal::ImageActor*>(handle.GetObjectPtr()) );
64 ImageActor::~ImageActor()
68 ImageActor::ImageActor(const ImageActor& copy)
73 ImageActor& ImageActor::operator=(const ImageActor& rhs)
75 BaseHandle::operator=(rhs);
79 void ImageActor::SetImage(Image image)
81 Internal::ImagePtr imagePtr;
84 imagePtr = &GetImplementation(image);
86 GetImplementation(*this).SetImage( imagePtr );
89 Image ImageActor::GetImage()
91 Internal::ImagePtr imagePtr( GetImplementation(*this).GetImage() );
92 return Dali::Image( imagePtr.Get() );
95 void ImageActor::SetPixelArea(const PixelArea& pixelArea)
97 GetImplementation(*this).SetPixelArea(pixelArea);
100 ImageActor::PixelArea ImageActor::GetPixelArea() const
102 return GetImplementation(*this).GetPixelArea();
105 void ImageActor::SetStyle(Style style)
107 GetImplementation(*this).SetStyle( style );
110 ImageActor::Style ImageActor::GetStyle() const
112 return GetImplementation(*this).GetStyle();
115 void ImageActor::SetNinePatchBorder(const Vector4& border)
117 GetImplementation(*this).SetNinePatchBorder( border );
120 Vector4 ImageActor::GetNinePatchBorder() const
122 return GetImplementation(*this).GetNinePatchBorder();
125 void ImageActor::SetSortModifier(float modifier)
127 GetImplementation(*this).SetSortModifier(modifier);
130 float ImageActor::GetSortModifier() const
132 return GetImplementation(*this).GetSortModifier();
135 void ImageActor::SetBlendMode( BlendingMode::Type mode )
137 GetImplementation(*this).SetBlendMode( mode );
140 BlendingMode::Type ImageActor::GetBlendMode() const
142 return GetImplementation(*this).GetBlendMode();
145 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
147 GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
150 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
151 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
153 GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
156 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
157 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
159 GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
162 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
164 GetImplementation(*this).SetBlendEquation( equationRgba );
167 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
169 GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
172 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
174 GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
177 void ImageActor::SetBlendColor( const Vector4& color )
179 GetImplementation(*this).SetBlendColor( color );
182 const Vector4& ImageActor::GetBlendColor() const
184 return GetImplementation(*this).GetBlendColor();
187 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
189 GetImplementation(*this).SetFilterMode( minFilter, magFilter );
192 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
194 GetImplementation(*this).GetFilterMode( minFilter, magFilter );
197 void ImageActor::SetShaderEffect(ShaderEffect effect)
199 GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
202 ShaderEffect ImageActor::GetShaderEffect() const
204 Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
206 return ShaderEffect(internal.Get());
209 void ImageActor::RemoveShaderEffect()
211 GetImplementation(*this).RemoveShaderEffect();
215 ImageActor::ImageActor(Internal::ImageActor* internal)
220 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
222 // only do something if the actor and effect are valid
223 if( actor && effect )
225 // first remove from this actor
226 ImageActor imageActor = ImageActor::DownCast( actor );
229 imageActor.SetShaderEffect( effect );
231 // then all children recursively
232 const unsigned int count = actor.GetChildCount();
233 for( unsigned int index = 0; index < count; ++index )
235 Actor child( actor.GetChildAt( index ) );
236 SetShaderEffectRecursively( child, effect );
241 void RemoveShaderEffectRecursively( Actor actor )
243 // only do something if the actor is valid
246 // first remove from this actor
247 ImageActor imageActor = ImageActor::DownCast( actor );
250 imageActor.RemoveShaderEffect();
252 // then all children recursively
253 const unsigned int count = actor.GetChildCount();
254 for( unsigned int index = 0; index < count; ++index )
256 Actor child( actor.GetChildAt( index ) );
257 RemoveShaderEffectRecursively( child );