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 //deprecated - use ImageView instead for nine patch
110 ImageActor::Style ImageActor::GetStyle() const
112 //deprecated - use ImageView instead for nine patch
113 return ImageActor::STYLE_QUAD;
116 void ImageActor::SetNinePatchBorder(const Vector4& border)
118 //deprecated - use ImageView instead for nine patch
121 Vector4 ImageActor::GetNinePatchBorder() const
123 //deprecated - use ImageView instead for nine patch
124 return Vector4::ZERO;
127 void ImageActor::SetSortModifier(float modifier)
129 GetImplementation(*this).SetSortModifier(modifier);
132 float ImageActor::GetSortModifier() const
134 return GetImplementation(*this).GetSortModifier();
137 void ImageActor::SetBlendMode( BlendingMode::Type mode )
139 GetImplementation(*this).SetBlendMode( mode );
142 BlendingMode::Type ImageActor::GetBlendMode() const
144 return GetImplementation(*this).GetBlendMode();
147 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba )
149 GetImplementation(*this).SetBlendFunc( srcFactorRgba, destFactorRgba );
152 void ImageActor::SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
153 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha )
155 GetImplementation(*this).SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
158 void ImageActor::GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
159 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const
161 GetImplementation(*this).GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
164 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgba )
166 GetImplementation(*this).SetBlendEquation( equationRgba );
169 void ImageActor::SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha )
171 GetImplementation(*this).SetBlendEquation( equationRgb, equationAlpha );
174 void ImageActor::GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const
176 GetImplementation(*this).GetBlendEquation( equationRgb, equationAlpha );
179 void ImageActor::SetBlendColor( const Vector4& color )
181 GetImplementation(*this).SetBlendColor( color );
184 const Vector4& ImageActor::GetBlendColor() const
186 return GetImplementation(*this).GetBlendColor();
189 void ImageActor::SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter )
191 GetImplementation(*this).SetFilterMode( minFilter, magFilter );
194 void ImageActor::GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const
196 GetImplementation(*this).GetFilterMode( minFilter, magFilter );
199 void ImageActor::SetShaderEffect(ShaderEffect effect)
201 GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
204 ShaderEffect ImageActor::GetShaderEffect() const
206 Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
208 return ShaderEffect(internal.Get());
211 void ImageActor::RemoveShaderEffect()
213 GetImplementation(*this).RemoveShaderEffect();
217 ImageActor::ImageActor(Internal::ImageActor* internal)
222 void SetShaderEffectRecursively( Actor actor, ShaderEffect effect )
224 // only do something if the actor and effect are valid
225 if( actor && effect )
227 // first remove from this actor
228 ImageActor imageActor = ImageActor::DownCast( actor );
231 imageActor.SetShaderEffect( effect );
233 // then all children recursively
234 const unsigned int count = actor.GetChildCount();
235 for( unsigned int index = 0; index < count; ++index )
237 Actor child( actor.GetChildAt( index ) );
238 SetShaderEffectRecursively( child, effect );
243 void RemoveShaderEffectRecursively( Actor actor )
245 // only do something if the actor is valid
248 // first remove from this actor
249 ImageActor imageActor = ImageActor::DownCast( actor );
252 imageActor.RemoveShaderEffect();
254 // then all children recursively
255 const unsigned int count = actor.GetChildCount();
256 for( unsigned int index = 0; index < count; ++index )
258 Actor child( actor.GetChildAt( index ) );
259 RemoveShaderEffectRecursively( child );