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 Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/internal/event/actors/renderable-actor-impl.h>
25 #include <dali/internal/event/actor-attachments/image-attachment-impl.h>
26 #include <dali/internal/event/animation/animation-impl.h>
27 #include <dali/internal/event/images/nine-patch-image-impl.h>
38 * An actor which displays an Image object.
40 * This handles image fade-in if required, waiting for the image to load.
42 * If a new image is set on the actor, then this ensures that the old image
43 * is displayed until the new image is ready to render to prevent flashing
44 * to the actor color. This will also happen if the image is reloaded.
46 * This is achieved by using two connector objects to Image: mImageNext and
47 * mImageAttachment's member object. The first one points to the Image object that is going to
48 * be displayed next, the second one to the Image that is currently being displayed.
50 class ImageActor : public RenderableActor
54 typedef Dali::ImageActor::Style Style;
55 typedef Dali::ImageActor::PixelArea PixelArea;
58 * @brief Create an initialised image actor.
59 * When the image is loaded the actors size will reset to the image size,
60 * unless a custom size chosen via Actor:SetSize().
61 * @param[in] image A pointer to the image object to display or NULL not to display anything.
62 * @return A smart-pointer to a newly allocated image actor.
64 static ImageActorPtr New( Image* image );
67 * @brief Create an initialised image actor.
68 * When the image is loaded the actors size will reset to the image size,
69 * unless a custom size chosen via Actor:SetSize().
70 * @param [in] image A pointer to the image object to display or NULL not to display anything.
71 * @param [in] pixelArea The area of the image to display.
72 * This in pixels, relative to the top-left (0,0) of the image.
73 * @return A smart-pointer to a newly allocated image actor.
75 static ImageActorPtr New( Image* image, const PixelArea& pixelArea );
78 * @copydoc Dali::Internal::Actor::OnInitialize
83 * Set the image rendered by the actor's attachment.
84 * When the image is loaded the actors size will be reset to the image size,
85 * unless a custom size is chosen via Actor:SetSize().
86 * The old image will continue to be displayed until the new image has loaded
87 * @param [in] image A pointer to the image to display or NULL not to display anything.
89 void SetImage( Image* image );
92 * Retrieve the image rendered by the actor's attachment.
93 * @return The image (uninitialized Image object in case the ImageActor does not display anything).
95 Dali::Image GetImage();
98 * @copydoc Dali::ImageActor::SetToNaturalSize()
100 void SetToNaturalSize();
103 * Set a region of the image to display, in pixels.
104 * @param [in] pixelArea The area of the image to display.
105 * This in pixels, relative to the top-left (0,0) of the image.
107 void SetPixelArea( const PixelArea& pixelArea );
110 * Retrieve the region of the image to display, in pixels.
111 * @return The pixel area, or a default-constructed area if none was set.
113 const PixelArea& GetPixelArea() const;
116 * Query whether a pixel area has been set.
117 * @return True if a pixel area has been set.
119 bool IsPixelAreaSet() const;
122 * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
124 void ClearPixelArea();
127 * Set how the image is rendered; the default is STYLE_QUAD.
128 * @param [in] style The new style.
130 void SetStyle( Style style );
133 * Query how the image is rendered.
134 * @return The rendering style.
136 Style GetStyle() const;
139 * @copydoc Dali::ImageActor::SetNinePatchBorder
141 void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
144 * @copydoc Dali::ImageActor::GetNinePatchBorder
146 Vector4 GetNinePatchBorder() const;
149 * Set whether the image should gradually fade in when first rendered.
150 * @param [in] enableFade True if the image should fade in.
152 void SetFadeIn(bool enableFade);
155 * Query whether the image will gradually fade in when first rendered.
156 * @return True if the image will fade in.
158 bool GetFadeIn() const;
161 * Set the duration of the fade-in effect; the default is 1 second.
162 * @param [in] durationSeconds The duration in seconds.
164 void SetFadeInDuration( float durationSeconds );
167 * Retrieve the duration of the fade-in effect.
168 * @return The duration in seconds.
170 float GetFadeInDuration() const;
173 * Retrieve the attachment which renders the image.
174 * @return The attachment.
176 ImageAttachment& GetImageAttachment();
179 * @copydoc Dali::ImageActor::GetCurrentImageSize
181 Vector2 GetCurrentImageSize() const;
183 public: // Default property extensions from ProxyObject
186 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
188 virtual unsigned int GetDefaultPropertyCount() const;
191 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
193 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
196 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
198 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
201 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
203 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
206 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
208 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
211 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
213 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
216 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
218 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
221 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
223 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
226 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
228 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
231 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
233 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
235 private: // From RenderableActor
238 * @copydoc RenderableActor::GetRenderableAttachment
240 virtual RenderableAttachment& GetRenderableAttachment() const;
245 * Protected constructor; see also ImageActor::New()
250 * A reference counted object may only be deleted by calling Unreference()
252 virtual ~ImageActor();
256 // Helper for overloads of SetImage().
257 void OnImageSet( Image& image );
259 // Helper to set the actor to the image's natural size
260 void SetNaturalSize( Image& image );
265 * This is called after SizeSet() has been called.
267 virtual void OnSizeSet( const Vector3& targetSize );
270 * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
272 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
275 * From Actor; used to trigger fade-in animations.
277 virtual void OnStageConnectionInternal();
280 * From Actor; used to notify Image.
282 virtual void OnStageDisconnectionInternal();
285 * Helper for when the image loads.
286 * @param[in] image The newly (re)loaded image.
288 void ImageLoaded( Dali::Image image );
291 * Helper to start fade-in animations.
297 ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
298 ImageConnector mImageNext; ///< Manages the Image this ImageActor will show (used when changing displayed image)
300 // flags, compressed to bitfield (uses only 4 bytes)
301 bool mUsingNaturalSize:1; ///< True only when the actor is using
302 bool mInternalSetSize:1; ///< True whilst setting size internally, false at all other times
303 bool mFadeIn:1; ///< True if fade in animation is enabled
304 bool mFadeInitial:1; ///< True if fading in for the first time
306 SlotDelegate<ImageActor> mLoadedConnection; ///< Tracks the connection to the "loading finished" signal
308 // For fade-in animations
309 float mFadeInDuration; ///< Length of animation
311 static bool mFirstInstance ;
312 static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
316 } // namespace Internal
318 // Helpers for public-api forwarding methods
320 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
322 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
324 BaseObject& handle = image.GetBaseObject();
326 return static_cast<Internal::ImageActor&>(handle);
329 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
331 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
333 const BaseObject& handle = image.GetBaseObject();
335 return static_cast<const Internal::ImageActor&>(handle);
340 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__