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>
37 * An actor which displays an Image object.
39 * This handles image fade-in if required, waiting for the image to load.
41 * If a new image is set on the actor, then this ensures that the old image
42 * is displayed until the new image is ready to render to prevent flashing
43 * to the actor color. This will also happen if the image is reloaded.
45 * This is achieved by using two connector objects to Image: mImageNext and
46 * mImageAttachment's member object. The first one points to the Image object that is going to
47 * be displayed next, the second one to the Image that is currently being displayed.
49 class ImageActor : public RenderableActor
53 typedef Dali::ImageActor::Style Style;
54 typedef Dali::ImageActor::PixelArea PixelArea;
57 * Create an initialised image actor.
58 * When the image is loaded the actors size will reset to the image size,
59 * unless a custom size chosen via Actor:SetSize().
60 * @param [in] image A pointer to the image object to display or NULL not to display anything.
61 * @return A smart-pointer to a newly allocated image actor.
63 static ImageActorPtr New( Image* image );
66 * Create an initialised image actor
67 * When the image is loaded the actors size will reset to the image size,
68 * unless a custom size chosen via Actor:SetSize().
69 * @param [in] image A pointer to the image object to display or NULL not to display anything.
70 * @param [in] pixelArea The area of the image to display.
71 * This in pixels, relative to the top-left (0,0) of the image.
72 * @return A smart-pointer to a newly allocated image actor.
74 static ImageActorPtr New( Image* image, const PixelArea& pixelArea );
77 * @copydoc Dali::Internal::Actor::OnInitialize
82 * Set the image rendered by the actor's attachment.
83 * When the image is loaded the actors size will be reset to the image size,
84 * unless a custom size chosen via Actor:SetSize().
85 * The old image will continue to be displayed until the new image has loaded
86 * @param [in] image A pointer to the image to display or NULL not to display anything.
88 void SetImage( Image* image );
91 * Retrieve the image rendered by the actor's attachment.
92 * @return The image (uninitialized Image object in case the ImageActor does not display anything).
94 Dali::Image GetImage();
97 * Set a region of the image to display, in pixels.
98 * @param [in] pixelArea The area of the image to display.
99 * This in pixels, relative to the top-left (0,0) of the image.
101 void SetPixelArea( const PixelArea& pixelArea );
104 * Retrieve the region of the image to display, in pixels.
105 * @return The pixel area, or a default-constructed area if none was set.
107 const PixelArea& GetPixelArea() const;
110 * Query whether a pixel area has been set.
111 * @return True if a pixel area has been set.
113 bool IsPixelAreaSet() const;
116 * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
118 void ClearPixelArea();
121 * Set how the image is rendered; the default is STYLE_QUAD.
122 * @param [in] style The new style.
124 void SetStyle( Style style );
127 * Query how the image is rendered.
128 * @return The rendering style.
130 Style GetStyle() const;
133 * @copydoc Dali::ImageActor::SetNinePatchBorder
135 void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
138 * @copydoc Dali::ImageActor::GetNinePatchBorder
140 Vector4 GetNinePatchBorder() const;
143 * Set whether the image should gradually fade in when first rendered.
144 * @param [in] enableFade True if the image should fade in.
146 void SetFadeIn(bool enableFade);
149 * Query whether the image will gradually fade in when first rendered.
150 * @return True if the image will fade in.
152 bool GetFadeIn() const;
155 * Set the duration of the fade-in effect; the default is 1 second.
156 * @param [in] durationSeconds The duration in seconds.
158 void SetFadeInDuration( float durationSeconds );
161 * Retrieve the duration of the fade-in effect.
162 * @return The duration in seconds.
164 float GetFadeInDuration() const;
167 * Retrieve the attachment which renders the image.
168 * @return The attachment.
170 ImageAttachment& GetImageAttachment();
173 * @copydoc Dali::ImageActor::GetCurrentImageSize
175 Vector2 GetCurrentImageSize() const;
177 public: // Default property extensions from ProxyObject
180 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
182 virtual unsigned int GetDefaultPropertyCount() const;
185 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
187 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
190 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
192 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
195 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
197 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
200 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
202 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
205 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
207 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
210 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
212 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
215 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
217 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
219 private: // From RenderableActor
222 * @copydoc RenderableActor::GetRenderableAttachment
224 virtual RenderableAttachment& GetRenderableAttachment() const;
229 * Protected constructor; see also ImageActor::New()
234 * A reference counted object may only be deleted by calling Unreference()
236 virtual ~ImageActor();
240 // Helper for overloads of SetImage().
241 void OnImageSet( Image& image );
245 * This is called after SizeSet() has been called.
247 virtual void OnSizeSet( const Vector3& targetSize );
250 * From Actor; used to trigger fade-in animations.
252 virtual void OnStageConnectionInternal();
255 * From Actor; used to notify Image.
257 virtual void OnStageDisconnectionInternal();
260 * Helper for when the image loads.
261 * @param[in] image The newly (re)loaded image.
263 void ImageLoaded( Dali::Image image );
266 * Helper to start fade-in animations.
272 ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
273 ImageConnector mImageNext; ///< Manages the Image this ImageActor will show (used when changing displayed image)
275 // flags, compressed to bitfield (uses only 4 bytes)
276 bool mCustomSizeSet:1; ///< True if SizeSet() has ever been called
277 bool mFadeIn:1; ///< True if fade in animation is enabled
278 bool mFadeInitial:1; ///< True if fading in for the first time
280 SlotDelegate<ImageActor> mLoadedConnection; ///< Tracks the connection to the "loading finished" signal
282 // For fade-in animations
283 float mFadeInDuration; ///< Length of animation
285 static bool mFirstInstance ;
286 static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
290 } // namespace Internal
292 // Helpers for public-api forwarding methods
294 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
296 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
298 BaseObject& handle = image.GetBaseObject();
300 return static_cast<Internal::ImageActor&>(handle);
303 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
305 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
307 const BaseObject& handle = image.GetBaseObject();
309 return static_cast<const Internal::ImageActor&>(handle);
314 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__