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/internal/event/actors/actor-declarations.h>
25 #include <dali/internal/event/actors/renderable-actor-impl.h>
26 #include <dali/internal/event/actor-attachments/image-attachment-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/images/nine-patch-image-impl.h>
39 * An actor which displays an Image object.
41 * This handles image fade-in if required, waiting for the image to load.
43 * If a new image is set on the actor, then this ensures that the old image
44 * is displayed until the new image is ready to render to prevent flashing
45 * to the actor color. This will also happen if the image is reloaded.
47 * This is achieved by using two connector objects to Image: mImageNext and
48 * mImageAttachment's member object. The first one points to the Image object that is going to
49 * be displayed next, the second one to the Image that is currently being displayed.
51 class ImageActor : public RenderableActor
55 typedef Dali::ImageActor::Style Style;
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
82 * @copydoc Dali::ImageActor::SetToNaturalSize()
84 void SetToNaturalSize();
87 * @copydoc Dali::ImageActor::SetPixelArea()
89 void SetPixelArea( const PixelArea& pixelArea );
92 * @copydoc Dali::ImageActor::GetPixelArea()
94 const PixelArea& GetPixelArea() const;
97 * @copydoc Dali::ImageActor::IsPixelAreaSet()
99 bool IsPixelAreaSet() const;
102 * @copydoc Dali::ImageActor::ClearPixelArea()
104 void ClearPixelArea();
107 * @copydoc Dali::ImageActor::SetStyle()
109 void SetStyle( Style style );
112 * @copydoc Dali::ImageActor::GetStyle()
114 Style GetStyle() const;
117 * @copydoc Dali::ImageActor::SetNinePatchBorder
119 void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
122 * @copydoc Dali::ImageActor::GetNinePatchBorder
124 Vector4 GetNinePatchBorder() const;
127 * Retrieve the attachment which renders the image.
128 * @return The attachment.
130 ImageAttachment& GetImageAttachment();
134 * @copydoc Dali::RenderableActor::SetSortModifier()
136 void SetSortModifier(float modifier);
139 * @copydoc Dali::RenderableActor::GetSortModifier()
141 float GetSortModifier() const;
144 * @copydoc Dali::RenderableActor::SetCullFace()
146 void SetCullFace(CullFaceMode mode);
149 * @copydoc Dali::RenderableActor::GetCullFace()
151 CullFaceMode GetCullFace() const;
154 * @copydoc Dali::RenderableActor::SetBlendMode()
156 void SetBlendMode( BlendingMode::Type mode );
159 * @copydoc Dali::RenderableActor::GetBlendMode()
161 BlendingMode::Type GetBlendMode() const;
164 * @copydoc Dali::RenderableActor::SetBlendFunc()
166 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
169 * @copydoc Dali::RenderableActor::SetBlendFunc()
171 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
172 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
175 * @copydoc Dali::RenderableActor::GetBlendFunc()
177 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
178 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
181 * @copydoc Dali::RenderableActor::SetBlendEquation()
183 void SetBlendEquation( BlendingEquation::Type equationRgba );
186 * @copydoc Dali::RenderableActor::SetBlendEquation()
188 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
191 * @copydoc Dali::RenderableActor::GetBlendEquation()
193 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
196 * @copydoc Dali::RenderableActor::SetBlendColor()
198 void SetBlendColor( const Vector4& color );
201 * @copydoc Dali::RenderableActor::GetBlendColor()
203 const Vector4& GetBlendColor() const;
206 * @copydoc Dali::RenderableActor::SetFilterMode()
208 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
211 * @copydoc Dali::RenderableActor::GetFilterMode()
213 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
217 * @copydoc Actor::SetShaderEffect
219 virtual void SetShaderEffect(ShaderEffect& effect);
222 * @copydoc Actor::GetShaderEffect
224 virtual ShaderEffectPtr GetShaderEffect() const;
227 * @copydoc Actor::RemoveShaderEffect
229 virtual void RemoveShaderEffect();
231 public: // Default property extensions from Object
234 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
236 virtual unsigned int GetDefaultPropertyCount() const;
239 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
241 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
244 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
246 virtual const char* GetDefaultPropertyName(Property::Index index) const;
249 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
251 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
254 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
256 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
259 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
261 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
264 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
266 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
269 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
271 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
274 * @copydoc Dali::Internal::Object::SetDefaultProperty()
276 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
279 * @copydoc Dali::Internal::Object::GetDefaultProperty()
281 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
283 public: // From Actor
286 * @copydoc Dali::Actor::GetNaturalSize()
288 virtual Vector3 GetNaturalSize() const;
290 private: // From RenderableActor
293 * @copydoc RenderableActor::GetRenderableAttachment
295 virtual RenderableAttachment& GetRenderableAttachment() const;
300 * Protected constructor; see also ImageActor::New()
305 * A reference counted object may only be deleted by calling Unreference()
307 virtual ~ImageActor();
312 * Helper to set the actor to the image's natural size
314 void SetNaturalSize();
317 * Calculate the natural size of this image actor
319 * @return Return the natural size as a Vector2
321 Vector2 CalculateNaturalSize() const;
325 * This is called after SizeSet() has been called.
327 virtual void OnSizeSet( const Vector3& targetSize );
330 * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
332 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
335 * From Actor; used to trigger fade-in animations.
337 virtual void OnStageConnectionInternal();
340 * From Actor; used to notify Image.
342 virtual void OnStageDisconnectionInternal();
346 ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
348 // flags, compressed to bitfield (uses only 1 byte)
349 bool mUsingNaturalSize:1; ///< True only when the actor is using
350 bool mInternalSetSize:1; ///< True whilst setting size internally, false at all other times
354 } // namespace Internal
356 // Helpers for public-api forwarding methods
358 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
360 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
362 BaseObject& handle = image.GetBaseObject();
364 return static_cast<Internal::ImageActor&>(handle);
367 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
369 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
371 const BaseObject& handle = image.GetBaseObject();
373 return static_cast<const Internal::ImageActor&>(handle);
378 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__