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::RenderableActor::SetSortModifier()
105 void SetSortModifier(float modifier);
108 * @copydoc Dali::RenderableActor::GetSortModifier()
110 float GetSortModifier() const;
113 * @copydoc Dali::RenderableActor::SetCullFace()
115 void SetCullFace(CullFaceMode mode);
118 * @copydoc Dali::RenderableActor::GetCullFace()
120 CullFaceMode GetCullFace() const;
123 * @copydoc Dali::RenderableActor::SetBlendMode()
125 void SetBlendMode( BlendingMode::Type mode );
128 * @copydoc Dali::RenderableActor::GetBlendMode()
130 BlendingMode::Type GetBlendMode() const;
133 * @copydoc Dali::RenderableActor::SetBlendFunc()
135 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
138 * @copydoc Dali::RenderableActor::SetBlendFunc()
140 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
141 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
144 * @copydoc Dali::RenderableActor::GetBlendFunc()
146 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
147 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
150 * @copydoc Dali::RenderableActor::SetBlendEquation()
152 void SetBlendEquation( BlendingEquation::Type equationRgba );
155 * @copydoc Dali::RenderableActor::SetBlendEquation()
157 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
160 * @copydoc Dali::RenderableActor::GetBlendEquation()
162 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
165 * @copydoc Dali::RenderableActor::SetBlendColor()
167 void SetBlendColor( const Vector4& color );
170 * @copydoc Dali::RenderableActor::GetBlendColor()
172 const Vector4& GetBlendColor() const;
175 * @copydoc Dali::RenderableActor::SetFilterMode()
177 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
180 * @copydoc Dali::RenderableActor::GetFilterMode()
182 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
185 * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
187 void EffectImageUpdated();
191 * @copydoc Actor::SetShaderEffect
193 virtual void SetShaderEffect(ShaderEffect& effect);
196 * @copydoc Actor::GetShaderEffect
198 virtual ShaderEffectPtr GetShaderEffect() const;
201 * @copydoc Actor::RemoveShaderEffect
203 virtual void RemoveShaderEffect();
205 public: // Default property extensions from Object
208 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
210 virtual unsigned int GetDefaultPropertyCount() const;
213 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
215 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
218 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
220 virtual const char* GetDefaultPropertyName(Property::Index index) const;
223 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
225 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
228 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
230 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
233 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
235 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
238 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
240 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
243 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
245 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
248 * @copydoc Dali::Internal::Object::SetDefaultProperty()
250 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
253 * @copydoc Dali::Internal::Object::GetDefaultProperty()
255 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
257 public: // From Actor
260 * @copydoc Dali::Actor::GetNaturalSize()
262 virtual Vector3 GetNaturalSize() const;
267 * Protected constructor; see also ImageActor::New()
272 * A reference counted object may only be deleted by calling Unreference()
274 virtual ~ImageActor();
279 * Calculate the natural size of this image actor
281 * @return Return the natural size as a Vector2
283 Vector2 CalculateNaturalSize() const;
286 * Update the grid geometry.
288 void UpdateGeometry();
291 * Update the texture rect uniform
293 void UpdateTexureRect();
297 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
298 RendererPtr mRenderer; ///< The renderer used to render the image
299 PixelArea mPixelArea; ///< The pixel area of the image to render
300 Vector4 mBlendColor; ///< The blend color for this ImageActor
301 Uint16Pair mGridSize; ///< The geometry grid size
302 int mRendererIndex; ///< The index location of mRenderer
303 size_t mTextureIndex; ///< The texture index for this ImageActor's texture
304 size_t mEffectTextureIndex; ///< The texture index for this ImageActor's effect texture
305 FilterMode::Type mMinFilter; ///< The minification filter currently set
306 FilterMode::Type mMagFilter; ///< The magnification filter currently set
307 bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set
310 } // namespace Internal
312 // Helpers for public-api forwarding methods
314 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
316 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
318 BaseObject& handle = image.GetBaseObject();
320 return static_cast<Internal::ImageActor&>(handle);
323 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
325 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
327 const BaseObject& handle = image.GetBaseObject();
329 return static_cast<const Internal::ImageActor&>(handle);
334 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__