1 #ifndef __DALI_INTERNAL_IMAGE_ACTOR_H__
2 #define __DALI_INTERNAL_IMAGE_ACTOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/effects/shader-effect-impl.h>
29 #include <dali/internal/event/images/nine-patch-image-impl.h>
40 * An actor which displays an Image object.
42 * This handles image fade-in if required, waiting for the image to load.
44 * If a new image is set on the actor, then this ensures that the old image
45 * is displayed until the new image is ready to render to prevent flashing
46 * to the actor color. This will also happen if the image is reloaded.
48 * This is achieved by using two connector objects to Image: mImageNext and
49 * mImageAttachment's member object. The first one points to the Image object that is going to
50 * be displayed next, the second one to the Image that is currently being displayed.
52 class ImageActor : public Actor
56 typedef Dali::ImageActor::PixelArea PixelArea;
59 * @brief Create an image actor instance.
60 * @return A smart-pointer to a newly allocated image actor.
62 static ImageActorPtr New();
65 * @copydoc Dali::Internal::Actor::OnInitialize
70 * @see Dali::ImageActor::SetImage()
71 * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
73 void SetImage( ImagePtr& image );
76 * Retrieve the image rendered by the actor's attachment.
77 * @return smart pointer to the image or an empty one if no image is assigned
79 ImagePtr GetImage() const;
82 * @copydoc Dali::ImageActor::SetPixelArea()
84 void SetPixelArea( const PixelArea& pixelArea );
87 * @copydoc Dali::ImageActor::GetPixelArea()
89 const PixelArea& GetPixelArea() const;
92 * @copydoc Dali::ImageActor::IsPixelAreaSet()
94 bool IsPixelAreaSet() const;
97 * @copydoc Dali::ImageActor::ClearPixelArea()
99 void ClearPixelArea();
102 * @copydoc Dali::ImageActor::SetStyle()
104 void SetStyle( Dali::ImageActor::Style style );
107 * @copydoc Dali::ImageActor::GetStyle()
109 Dali::ImageActor::Style GetStyle() const;
112 * @copydoc Dali::ImageActor::SetNinePatchBorder()
114 void SetNinePatchBorder( const Vector4& border );
117 * @copydoc Dali::ImageActor::GetNinePatchBorder()
119 Vector4 GetNinePatchBorder() const;
122 * @copydoc Dali::RenderableActor::SetSortModifier()
124 void SetSortModifier(float modifier);
127 * @copydoc Dali::RenderableActor::GetSortModifier()
129 float GetSortModifier() const;
132 * @copydoc Dali::RenderableActor::SetBlendMode()
134 void SetBlendMode( BlendingMode::Type mode );
137 * @copydoc Dali::RenderableActor::GetBlendMode()
139 BlendingMode::Type GetBlendMode() const;
142 * @copydoc Dali::RenderableActor::SetBlendFunc()
144 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
147 * @copydoc Dali::RenderableActor::SetBlendFunc()
149 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
150 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
153 * @copydoc Dali::RenderableActor::GetBlendFunc()
155 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
156 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
159 * @copydoc Dali::RenderableActor::SetBlendEquation()
161 void SetBlendEquation( BlendingEquation::Type equationRgba );
164 * @copydoc Dali::RenderableActor::SetBlendEquation()
166 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
169 * @copydoc Dali::RenderableActor::GetBlendEquation()
171 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
174 * @copydoc Dali::RenderableActor::SetBlendColor()
176 void SetBlendColor( const Vector4& color );
179 * @copydoc Dali::RenderableActor::GetBlendColor()
181 const Vector4& GetBlendColor() const;
184 * @copydoc Dali::RenderableActor::SetFilterMode()
186 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
189 * @copydoc Dali::RenderableActor::GetFilterMode()
191 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
194 * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
196 void EffectImageUpdated();
200 * @copydoc Actor::SetShaderEffect
202 virtual void SetShaderEffect(ShaderEffect& effect);
205 * @copydoc Actor::GetShaderEffect
207 virtual ShaderEffectPtr GetShaderEffect() const;
210 * @copydoc Actor::RemoveShaderEffect
212 virtual void RemoveShaderEffect();
217 * @copydoc Actor::OnRelayout
219 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
222 * @copydoc Actor::OnSizeSet
224 virtual void OnSizeSet( const Vector3& targetSize );
226 public: // Default property extensions from Object
229 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
231 virtual unsigned int GetDefaultPropertyCount() const;
234 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
236 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
239 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
241 virtual const char* GetDefaultPropertyName(Property::Index index) const;
244 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
246 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
249 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
251 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
254 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
256 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
259 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
261 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
264 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
266 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
269 * @copydoc Dali::Internal::Object::SetDefaultProperty()
271 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
274 * @copydoc Dali::Internal::Object::GetDefaultProperty()
276 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
278 public: // From Actor
281 * @copydoc Dali::Actor::GetNaturalSize()
283 virtual Vector3 GetNaturalSize() const;
288 * Protected constructor; see also ImageActor::New()
293 * A reference counted object may only be deleted by calling Unreference()
295 virtual ~ImageActor();
300 * Calculate the natural size of this image actor
302 * @return Return the natural size as a Vector2
304 Vector2 CalculateNaturalSize() const;
307 * Update the grid geometry.
309 void UpdateGeometry();
312 * Update the texture rect uniform
314 void UpdateTexureRect();
318 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
319 RendererPtr mRenderer; ///< The renderer used to render the image
320 PixelArea mPixelArea; ///< The pixel area of the image to render
321 Vector4 mBlendColor; ///< The blend color for this ImageActor
322 Vector4 mNinePatchBorder; ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
323 Vector2 mActorSize; ///< The actor size
324 Uint16Pair mGridSize; ///< The geometry grid size
325 int mRendererIndex; ///< The index location of mRenderer
326 size_t mTextureIndex; ///< The texture index for this ImageActor's texture
327 size_t mEffectTextureIndex; ///< The texture index for this ImageActor's effect texture
328 FilterMode::Type mMinFilter; ///< The minification filter currently set
329 FilterMode::Type mMagFilter; ///< The magnification filter currently set
330 Dali::ImageActor::Style mStyle; ///< The style set by SetStyle. Not used internally, only used to store what is set so it can be returned for backwards compatibility.
331 bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set
334 } // namespace Internal
336 // Helpers for public-api forwarding methods
338 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
340 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
342 BaseObject& handle = image.GetBaseObject();
344 return static_cast<Internal::ImageActor&>(handle);
347 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
349 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
351 const BaseObject& handle = image.GetBaseObject();
353 return static_cast<const Internal::ImageActor&>(handle);
358 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__