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::SetPixelArea()
84 void SetPixelArea( const PixelArea& pixelArea );
87 * @copydoc Dali::ImageActor::GetPixelArea()
89 const PixelArea& GetPixelArea() const;
92 * @copydoc Dali::ImageActor::IsPixelAreaSet()
94 bool IsPixelAreaSet() const;
97 * @copydoc Dali::ImageActor::ClearPixelArea()
99 void ClearPixelArea();
102 * @copydoc Dali::ImageActor::SetStyle()
104 void SetStyle( Style style );
107 * @copydoc Dali::ImageActor::GetStyle()
109 Style GetStyle() const;
112 * @copydoc Dali::ImageActor::SetNinePatchBorder
114 void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
117 * @copydoc Dali::ImageActor::GetNinePatchBorder
119 Vector4 GetNinePatchBorder() const;
122 * Retrieve the attachment which renders the image.
123 * @return The attachment.
125 ImageAttachment& GetImageAttachment();
127 public: // Default property extensions from Object
130 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
132 virtual unsigned int GetDefaultPropertyCount() const;
135 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
137 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
140 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
142 virtual const char* GetDefaultPropertyName(Property::Index index) const;
145 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
147 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
150 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
152 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
155 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
157 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
160 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
162 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
165 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
167 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
170 * @copydoc Dali::Internal::Object::SetDefaultProperty()
172 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
175 * @copydoc Dali::Internal::Object::GetDefaultProperty()
177 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
179 public: // From Actor
182 * @copydoc Dali::Actor::GetNaturalSize()
184 virtual Vector3 GetNaturalSize() const;
186 private: // From RenderableActor
189 * @copydoc RenderableActor::GetRenderableAttachment
191 virtual RenderableAttachment& GetRenderableAttachment() const;
196 * Protected constructor; see also ImageActor::New()
201 * A reference counted object may only be deleted by calling Unreference()
203 virtual ~ImageActor();
208 * Calculate the natural size of this image actor
210 * @return Return the natural size as a Vector2
212 Vector2 CalculateNaturalSize() const;
215 * From Actor; used to trigger fade-in animations.
217 virtual void OnStageConnectionInternal();
220 * From Actor; used to notify Image.
222 virtual void OnStageDisconnectionInternal();
226 ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
230 } // namespace Internal
232 // Helpers for public-api forwarding methods
234 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
236 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
238 BaseObject& handle = image.GetBaseObject();
240 return static_cast<Internal::ImageActor&>(handle);
243 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
245 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
247 const BaseObject& handle = image.GetBaseObject();
249 return static_cast<const Internal::ImageActor&>(handle);
254 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__