#ifndef __DALI_INTERNAL_IMAGE_ACTOR_H__
#define __DALI_INTERNAL_IMAGE_ACTOR_H__
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// INTERNAL INCLUDES
#include <dali/public-api/object/ref-object.h>
#include <dali/public-api/actors/image-actor.h>
+#include <dali/public-api/math/uint-16-pair.h>
+#include <dali/devel-api/rendering/cull-face.h>
#include <dali/internal/event/actors/actor-declarations.h>
-#include <dali/internal/event/actors/renderable-actor-impl.h>
-#include <dali/internal/event/actor-attachments/image-attachment-impl.h>
+#include <dali/internal/event/actors/actor-impl.h>
#include <dali/internal/event/animation/animation-impl.h>
+#include <dali/internal/event/effects/shader-effect-impl.h>
+#include <dali/internal/event/images/nine-patch-image-impl.h>
namespace Dali
{
* mImageAttachment's member object. The first one points to the Image object that is going to
* be displayed next, the second one to the Image that is currently being displayed.
*/
-class ImageActor : public RenderableActor
+class ImageActor : public Actor
{
public:
- typedef Dali::ImageActor::Style Style;
typedef Dali::ImageActor::PixelArea PixelArea;
/**
- * Create an initialised image actor.
- * When the image is loaded the actors size will reset to the image size,
- * unless a custom size chosen via Actor:SetSize().
- * @param [in] image A pointer to the image object to display or NULL not to display anything.
- * @return A smart-pointer to a newly allocated image actor.
- */
- static ImageActorPtr New( Image* image );
-
- /**
- * Create an initialised image actor
- * When the image is loaded the actors size will reset to the image size,
- * unless a custom size chosen via Actor:SetSize().
- * @param [in] image A pointer to the image object to display or NULL not to display anything.
- * @param [in] pixelArea The area of the image to display.
- * This in pixels, relative to the top-left (0,0) of the image.
+ * @brief Create an image actor instance.
* @return A smart-pointer to a newly allocated image actor.
*/
- static ImageActorPtr New( Image* image, const PixelArea& pixelArea );
+ static ImageActorPtr New();
/**
* @copydoc Dali::Internal::Actor::OnInitialize
void OnInitialize() ;
/**
- * Set the image rendered by the actor's attachment.
- * When the image is loaded the actors size will be reset to the image size,
- * unless a custom size is chosen via Actor:SetSize().
- * The old image will continue to be displayed until the new image has loaded
- * @param [in] image A pointer to the image to display or NULL not to display anything.
+ * @see Dali::ImageActor::SetImage()
+ * @param[in] ImagePtr reference to the image object to display. Reference to avoid unnecessary increment/decrement reference.
*/
- void SetImage( Image* image );
+ void SetImage( ImagePtr& image );
/**
* Retrieve the image rendered by the actor's attachment.
- * @return The image (uninitialized Image object in case the ImageActor does not display anything).
+ * @return smart pointer to the image or an empty one if no image is assigned
*/
- Dali::Image GetImage();
+ ImagePtr GetImage() const;
/**
- * @copydoc Dali::ImageActor::SetToNaturalSize()
- */
- void SetToNaturalSize();
-
- /**
- * Set a region of the image to display, in pixels.
- * @param [in] pixelArea The area of the image to display.
- * This in pixels, relative to the top-left (0,0) of the image.
+ * @copydoc Dali::ImageActor::SetPixelArea()
*/
void SetPixelArea( const PixelArea& pixelArea );
/**
- * Retrieve the region of the image to display, in pixels.
- * @return The pixel area, or a default-constructed area if none was set.
+ * @copydoc Dali::ImageActor::GetPixelArea()
*/
const PixelArea& GetPixelArea() const;
/**
- * Query whether a pixel area has been set.
- * @return True if a pixel area has been set.
+ * @copydoc Dali::ImageActor::IsPixelAreaSet()
*/
bool IsPixelAreaSet() const;
/**
- * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
+ * @copydoc Dali::ImageActor::ClearPixelArea()
*/
void ClearPixelArea();
/**
- * Set how the image is rendered; the default is STYLE_QUAD.
- * @param [in] style The new style.
+ * @copydoc Dali::ImageActor::SetStyle()
*/
- void SetStyle( Style style );
+ void SetStyle( Dali::ImageActor::Style style );
/**
- * Query how the image is rendered.
- * @return The rendering style.
+ * @copydoc Dali::ImageActor::GetStyle()
*/
- Style GetStyle() const;
+ Dali::ImageActor::Style GetStyle() const;
/**
- * @copydoc Dali::ImageActor::SetNinePatchBorder
+ * @copydoc Dali::ImageActor::SetNinePatchBorder()
*/
- void SetNinePatchBorder( const Vector4& border, bool inPixels = false );
+ void SetNinePatchBorder( const Vector4& border );
/**
- * @copydoc Dali::ImageActor::GetNinePatchBorder
+ * @copydoc Dali::ImageActor::GetNinePatchBorder()
*/
Vector4 GetNinePatchBorder() const;
/**
- * Set whether the image should gradually fade in when first rendered.
- * @param [in] enableFade True if the image should fade in.
+ * @copydoc Dali::RenderableActor::SetSortModifier()
*/
- void SetFadeIn(bool enableFade);
+ void SetSortModifier(float modifier);
/**
- * Query whether the image will gradually fade in when first rendered.
- * @return True if the image will fade in.
+ * @copydoc Dali::RenderableActor::GetSortModifier()
*/
- bool GetFadeIn() const;
+ float GetSortModifier() const;
/**
- * Set the duration of the fade-in effect; the default is 1 second.
- * @param [in] durationSeconds The duration in seconds.
+ * @copydoc Dali::RenderableActor::SetCullFace()
*/
- void SetFadeInDuration( float durationSeconds );
+ void SetCullFace(CullFaceMode mode);
/**
- * Retrieve the duration of the fade-in effect.
- * @return The duration in seconds.
+ * @copydoc Dali::RenderableActor::GetCullFace()
*/
- float GetFadeInDuration() const;
+ CullFaceMode GetCullFace() const;
/**
- * Retrieve the attachment which renders the image.
- * @return The attachment.
+ * @copydoc Dali::RenderableActor::SetBlendMode()
*/
- ImageAttachment& GetImageAttachment();
+ void SetBlendMode( BlendingMode::Type mode );
/**
- * @copydoc Dali::ImageActor::GetCurrentImageSize
+ * @copydoc Dali::RenderableActor::GetBlendMode()
*/
- Vector2 GetCurrentImageSize() const;
+ BlendingMode::Type GetBlendMode() const;
-public: // Default property extensions from ProxyObject
+ /**
+ * @copydoc Dali::RenderableActor::SetBlendFunc()
+ */
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
+ * @copydoc Dali::RenderableActor::SetBlendFunc()
*/
- virtual unsigned int GetDefaultPropertyCount() const;
+ void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
+ BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
+ * @copydoc Dali::RenderableActor::GetBlendFunc()
*/
- virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
+ void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
+ BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
+ * @copydoc Dali::RenderableActor::SetBlendEquation()
*/
- virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
+ void SetBlendEquation( BlendingEquation::Type equationRgba );
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
+ * @copydoc Dali::RenderableActor::SetBlendEquation()
*/
- virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
+ void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
/**
- * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
+ * @copydoc Dali::RenderableActor::GetBlendEquation()
*/
- virtual bool IsDefaultPropertyWritable(Property::Index index) const;
+ void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
/**
- * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
+ * @copydoc Dali::RenderableActor::SetBlendColor()
*/
- virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
+ void SetBlendColor( const Vector4& color );
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
+ * @copydoc Dali::RenderableActor::GetBlendColor()
*/
- virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
+ const Vector4& GetBlendColor() const;
/**
- * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
+ * @copydoc Dali::RenderableActor::SetFilterMode()
*/
- virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
+ void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
/**
- * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
+ * @copydoc Dali::RenderableActor::GetFilterMode()
*/
- virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+ void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
-private: // From RenderableActor
+ /**
+ * @brief Allows this ImageActor to respond to the eventa that the shader effect's effect texture has been changed
+ */
+ void EffectImageUpdated();
+public:
/**
- * @copydoc RenderableActor::GetRenderableAttachment
+ * @copydoc Actor::SetShaderEffect
*/
- virtual RenderableAttachment& GetRenderableAttachment() const;
+ virtual void SetShaderEffect(ShaderEffect& effect);
-protected:
+ /**
+ * @copydoc Actor::GetShaderEffect
+ */
+ virtual ShaderEffectPtr GetShaderEffect() const;
/**
- * Protected constructor; see also ImageActor::New()
+ * @copydoc Actor::RemoveShaderEffect
*/
- ImageActor();
+ virtual void RemoveShaderEffect();
+
+public: // Default property extensions from Object
/**
- * A reference counted object may only be deleted by calling Unreference()
+ * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
*/
- virtual ~ImageActor();
+ virtual unsigned int GetDefaultPropertyCount() const;
-private:
+ /**
+ * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
+ */
+ virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
- // Helper for overloads of SetImage().
- void OnImageSet( Image& image );
+ /**
+ * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
+ */
+ virtual const char* GetDefaultPropertyName(Property::Index index) const;
- // Helper to set the actor to the image's natural size
- void SetNaturalSize( Image& image );
+ /**
+ * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
+ */
+ virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
+ /**
+ * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
+ */
+ virtual bool IsDefaultPropertyWritable(Property::Index index) const;
/**
- * From Actor.
- * This is called after SizeSet() has been called.
+ * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
*/
- virtual void OnSizeSet( const Vector3& targetSize );
+ virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
/**
- * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
+ * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
*/
- virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
+ virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
/**
- * From Actor; used to trigger fade-in animations.
+ * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
*/
- virtual void OnStageConnectionInternal();
+ virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
/**
- * From Actor; used to notify Image.
+ * @copydoc Dali::Internal::Object::SetDefaultProperty()
*/
- virtual void OnStageDisconnectionInternal();
+ virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
/**
- * Helper for when the image loads.
- * @param[in] image The newly (re)loaded image.
+ * @copydoc Dali::Internal::Object::GetDefaultProperty()
*/
- void ImageLoaded( Dali::Image image );
+ virtual Property::Value GetDefaultProperty( Property::Index index ) const;
+
+public: // From Actor
/**
- * Helper to start fade-in animations.
+ * @copydoc Dali::Actor::GetNaturalSize()
*/
- void FadeIn();
+ virtual Vector3 GetNaturalSize() const;
-private:
+protected:
- ImageAttachmentPtr mImageAttachment; ///< Used to display the image (holds a pointer to currently showed Image)
- ImageConnector mImageNext; ///< Manages the Image this ImageActor will show (used when changing displayed image)
+ /**
+ * Protected constructor; see also ImageActor::New()
+ */
+ ImageActor();
- // flags, compressed to bitfield (uses only 4 bytes)
- bool mUsingNaturalSize:1; ///< True only when the actor is using
- bool mInternalSetSize:1; ///< True whilst setting size internally, false at all other times
- bool mFadeIn:1; ///< True if fade in animation is enabled
- bool mFadeInitial:1; ///< True if fading in for the first time
+ /**
+ * A reference counted object may only be deleted by calling Unreference()
+ */
+ virtual ~ImageActor();
- SlotDelegate<ImageActor> mLoadedConnection; ///< Tracks the connection to the "loading finished" signal
+private:
- // For fade-in animations
- float mFadeInDuration; ///< Length of animation
+ /**
+ * Calculate the natural size of this image actor
+ *
+ * @return Return the natural size as a Vector2
+ */
+ Vector2 CalculateNaturalSize() const;
+
+ /**
+ * Update the grid geometry.
+ */
+ void UpdateGeometry();
- static bool mFirstInstance ;
- static DefaultPropertyLookup* mDefaultImageActorPropertyLookup; ///< Default properties
+ /**
+ * Update the texture rect uniform
+ */
+ void UpdateTexureRect();
+
+private:
+ ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
+ RendererPtr mRenderer; ///< The renderer used to render the image
+ PixelArea mPixelArea; ///< The pixel area of the image to render
+ Vector4 mBlendColor; ///< The blend color for this ImageActor
+ Vector4 mNinePatchBorder; ///< Nine-patch not supported, but this is used to store what is set so it can be returned for backwards compatibility.
+ Uint16Pair mGridSize; ///< The geometry grid size
+ int mRendererIndex; ///< The index location of mRenderer
+ size_t mTextureIndex; ///< The texture index for this ImageActor's texture
+ size_t mEffectTextureIndex; ///< The texture index for this ImageActor's effect texture
+ FilterMode::Type mMinFilter; ///< The minification filter currently set
+ FilterMode::Type mMagFilter; ///< The magnification filter currently set
+ 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.
+ bool mIsPixelAreaSet; ///< Flag indicating if the pixel area has been set
};
} // namespace Internal