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/devel-api/rendering/cull-face.h>
26 #include <dali/internal/event/actors/actor-declarations.h>
27 #include <dali/internal/event/actors/actor-impl.h>
28 #include <dali/internal/event/animation/animation-impl.h>
29 #include <dali/internal/event/effects/shader-effect-impl.h>
30 #include <dali/internal/event/images/nine-patch-image-impl.h>
41 * An actor which displays an Image object.
43 * This handles image fade-in if required, waiting for the image to load.
45 * If a new image is set on the actor, then this ensures that the old image
46 * is displayed until the new image is ready to render to prevent flashing
47 * to the actor color. This will also happen if the image is reloaded.
49 * This is achieved by using two connector objects to Image: mImageNext and
50 * mImageAttachment's member object. The first one points to the Image object that is going to
51 * be displayed next, the second one to the Image that is currently being displayed.
53 class ImageActor : public Actor
57 typedef Dali::ImageActor::PixelArea PixelArea;
60 * @brief Create an image actor instance.
61 * @return A smart-pointer to a newly allocated image actor.
63 static ImageActorPtr New();
66 * @copydoc Dali::Internal::Actor::OnInitialize
71 * @see Dali::ImageActor::SetImage()
72 * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
74 void SetImage( ImagePtr& image );
77 * Retrieve the image rendered by the actor's attachment.
78 * @return smart pointer to the image or an empty one if no image is assigned
80 ImagePtr GetImage() const;
83 * @copydoc Dali::ImageActor::SetPixelArea()
85 void SetPixelArea( const PixelArea& pixelArea );
88 * @copydoc Dali::ImageActor::GetPixelArea()
90 const PixelArea& GetPixelArea() const;
93 * @copydoc Dali::ImageActor::IsPixelAreaSet()
95 bool IsPixelAreaSet() const;
98 * @copydoc Dali::ImageActor::ClearPixelArea()
100 void ClearPixelArea();
103 * @copydoc Dali::ImageActor::SetStyle()
105 void SetStyle( Dali::ImageActor::Style style );
108 * @copydoc Dali::ImageActor::GetStyle()
110 Dali::ImageActor::Style GetStyle() const;
113 * @copydoc Dali::ImageActor::SetNinePatchBorder()
115 void SetNinePatchBorder( const Vector4& border );
118 * @copydoc Dali::ImageActor::GetNinePatchBorder()
120 Vector4 GetNinePatchBorder() const;
123 * @copydoc Dali::RenderableActor::SetSortModifier()
125 void SetSortModifier(float modifier);
128 * @copydoc Dali::RenderableActor::GetSortModifier()
130 float GetSortModifier() const;
133 * @copydoc Dali::RenderableActor::SetCullFace()
135 void SetCullFace(CullFaceMode mode);
138 * @copydoc Dali::RenderableActor::GetCullFace()
140 CullFaceMode GetCullFace() const;
143 * @copydoc Dali::RenderableActor::SetBlendMode()
145 void SetBlendMode( BlendingMode::Type mode );
148 * @copydoc Dali::RenderableActor::GetBlendMode()
150 BlendingMode::Type GetBlendMode() const;
153 * @copydoc Dali::RenderableActor::SetBlendFunc()
155 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
158 * @copydoc Dali::RenderableActor::SetBlendFunc()
160 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
161 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
164 * @copydoc Dali::RenderableActor::GetBlendFunc()
166 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
167 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
170 * @copydoc Dali::RenderableActor::SetBlendEquation()
172 void SetBlendEquation( BlendingEquation::Type equationRgba );
175 * @copydoc Dali::RenderableActor::SetBlendEquation()
177 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
180 * @copydoc Dali::RenderableActor::GetBlendEquation()
182 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
185 * @copydoc Dali::RenderableActor::SetBlendColor()
187 void SetBlendColor( const Vector4& color );
190 * @copydoc Dali::RenderableActor::GetBlendColor()
192 const Vector4& GetBlendColor() const;
195 * @copydoc Dali::RenderableActor::SetFilterMode()
197 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
200 * @copydoc Dali::RenderableActor::GetFilterMode()
202 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
205 * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
207 void EffectImageUpdated();
211 * @copydoc Actor::SetShaderEffect
213 virtual void SetShaderEffect(ShaderEffect& effect);
216 * @copydoc Actor::GetShaderEffect
218 virtual ShaderEffectPtr GetShaderEffect() const;
221 * @copydoc Actor::RemoveShaderEffect
223 virtual void RemoveShaderEffect();
228 * @copydoc Actor::OnRelayout
230 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
233 * @copydoc Actor::OnSizeSet
235 virtual void OnSizeSet( const Vector3& targetSize );
237 public: // Default property extensions from Object
240 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
242 virtual unsigned int GetDefaultPropertyCount() const;
245 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
247 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
250 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
252 virtual const char* GetDefaultPropertyName(Property::Index index) const;
255 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
257 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
260 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
262 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
265 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
267 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
270 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
272 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
275 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
277 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
280 * @copydoc Dali::Internal::Object::SetDefaultProperty()
282 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
285 * @copydoc Dali::Internal::Object::GetDefaultProperty()
287 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
289 public: // From Actor
292 * @copydoc Dali::Actor::GetNaturalSize()
294 virtual Vector3 GetNaturalSize() const;
299 * Protected constructor; see also ImageActor::New()
304 * A reference counted object may only be deleted by calling Unreference()
306 virtual ~ImageActor();
311 * Calculate the natural size of this image actor
313 * @return Return the natural size as a Vector2
315 Vector2 CalculateNaturalSize() const;
318 * Update the grid geometry.
320 void UpdateGeometry();
323 * Update the texture rect uniform
325 void UpdateTexureRect();
329 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
330 RendererPtr mRenderer; ///< The renderer used to render the image
331 PixelArea mPixelArea; ///< The pixel area of the image to render
332 Vector4 mBlendColor; ///< The blend color for this ImageActor
333 Vector4 mNinePatchBorder; ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
334 Vector2 mActorSize; ///< The actor size
335 Uint16Pair mGridSize; ///< The geometry grid size
336 int mRendererIndex; ///< The index location of mRenderer
337 size_t mTextureIndex; ///< The texture index for this ImageActor's texture
338 size_t mEffectTextureIndex; ///< The texture index for this ImageActor's effect texture
339 FilterMode::Type mMinFilter; ///< The minification filter currently set
340 FilterMode::Type mMagFilter; ///< The magnification filter currently set
341 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.
342 bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set
345 } // namespace Internal
347 // Helpers for public-api forwarding methods
349 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
351 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
353 BaseObject& handle = image.GetBaseObject();
355 return static_cast<Internal::ImageActor&>(handle);
358 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
360 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
362 const BaseObject& handle = image.GetBaseObject();
364 return static_cast<const Internal::ImageActor&>(handle);
369 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__