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/internal/event/actors/actor-declarations.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27 #include <dali/internal/event/animation/animation-impl.h>
28 #include <dali/internal/event/effects/shader-effect-impl.h>
29 #include <dali/internal/event/images/nine-patch-image-impl.h>
30 #include <dali/internal/event/rendering/texture-set-impl.h>
41 * An actor which displays an Image.
43 class ImageActor : public Actor
47 typedef Dali::ImageActor::PixelArea PixelArea;
50 * @brief Create an image actor instance.
51 * @return A smart-pointer to a newly allocated image actor.
53 static ImageActorPtr New();
56 * @copydoc Dali::Internal::Actor::OnInitialize
61 * @see Dali::ImageActor::SetImage()
62 * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
64 void SetImage( ImagePtr& image );
67 * Retrieve the image rendered by the actor.
68 * @return smart pointer to the image or an empty one if no image is assigned
70 ImagePtr GetImage() const;
73 * @copydoc Dali::ImageActor::SetPixelArea()
75 void SetPixelArea( const PixelArea& pixelArea );
78 * @copydoc Dali::ImageActor::GetPixelArea()
80 const PixelArea& GetPixelArea() const;
83 * @copydoc Dali::ImageActor::IsPixelAreaSet()
85 bool IsPixelAreaSet() const;
88 * @copydoc Dali::ImageActor::ClearPixelArea()
90 void ClearPixelArea();
93 * @copydoc Dali::ImageActor::SetStyle()
95 void SetStyle( Dali::ImageActor::Style style );
98 * @copydoc Dali::ImageActor::GetStyle()
100 Dali::ImageActor::Style GetStyle() const;
103 * @copydoc Dali::ImageActor::SetNinePatchBorder()
105 void SetNinePatchBorder( const Vector4& border );
108 * @copydoc Dali::ImageActor::GetNinePatchBorder()
110 Vector4 GetNinePatchBorder() const;
113 * @copydoc Dali::RenderableActor::SetSortModifier()
115 void SetSortModifier(float modifier);
118 * @copydoc Dali::RenderableActor::GetSortModifier()
120 float GetSortModifier() 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();
208 * @copydoc Actor::OnRelayout
210 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
213 * @copydoc Actor::OnSizeSet
215 virtual void OnSizeSet( const Vector3& targetSize );
217 public: // Default property extensions from Object
220 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
222 virtual unsigned int GetDefaultPropertyCount() const;
225 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
227 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
230 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
232 virtual const char* GetDefaultPropertyName(Property::Index index) const;
235 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
237 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
240 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
242 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
245 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
247 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
250 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
252 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
255 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
257 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
260 * @copydoc Dali::Internal::Object::SetDefaultProperty()
262 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
265 * @copydoc Dali::Internal::Object::GetDefaultProperty()
267 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
269 public: // From Actor
272 * @copydoc Dali::Actor::GetNaturalSize()
274 virtual Vector3 GetNaturalSize() const;
279 * Protected constructor; see also ImageActor::New()
284 * A reference counted object may only be deleted by calling Unreference()
286 virtual ~ImageActor();
291 * Calculate the natural size of this image actor
293 * @return Return the natural size as a Vector2
295 Vector2 CalculateNaturalSize() const;
298 * Update the grid geometry.
300 void UpdateGeometry();
303 * Update the texture rect uniform
305 void UpdateTexureRect();
309 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
310 RendererPtr mRenderer; ///< The renderer used to render the image
311 PixelArea mPixelArea; ///< The pixel area of the image to render
312 Vector4 mBlendColor; ///< The blend color for this ImageActor
313 Vector4 mNinePatchBorder; ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
314 Vector2 mActorSize; ///< The actor size
315 Uint16Pair mGridSize; ///< The geometry grid size
316 int mRendererIndex; ///< The index location of mRenderer
317 FilterMode::Type mMinFilter; ///< The minification filter currently set
318 FilterMode::Type mMagFilter; ///< The magnification filter currently set
319 Dali::ImageActor::Style mStyle; ///< The style set by SetStyle. Not used internally, only used to store what is set so it can be returned for backwards compatibility.
320 bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set
323 } // namespace Internal
325 // Helpers for public-api forwarding methods
327 inline Internal::ImageActor& GetImplementation(Dali::ImageActor& image)
329 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
331 BaseObject& handle = image.GetBaseObject();
333 return static_cast<Internal::ImageActor&>(handle);
336 inline const Internal::ImageActor& GetImplementation(const Dali::ImageActor& image)
338 DALI_ASSERT_ALWAYS(image && "Image handle is empty");
340 const BaseObject& handle = image.GetBaseObject();
342 return static_cast<const Internal::ImageActor&>(handle);
347 #endif // __DALI_INTERNAL_IMAGE_ACTOR_H__