1 #ifndef __DALI_INTERNAL_IMAGE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_IMAGE_ATTACHMENT_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/actors/image-actor.h>
23 #include <dali/public-api/actors/blending.h>
24 #include <dali/devel-api/rendering/cull-face.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/image-sampler.h>
27 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
28 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
29 #include <dali/internal/event/images/image-impl.h>
30 #include <dali/internal/event/images/image-connector.h>
31 #include <dali/internal/event/effects/shader-declarations.h>
41 class ImageAttachment;
46 * An attachment for rendering images in various ways.
48 class ImageAttachment : public RenderableAttachment
52 typedef Dali::ImageActor::Style Style;
53 typedef Dali::ImageActor::PixelArea PixelArea;
56 * Create a new ImageAttachment.
57 * @param[in] eventThreadServices to use
58 * @param[in] parentNode The node to attach a scene-object to.
59 * @return A smart-pointer to the newly allocated ImageAttachment.
61 static ImageAttachmentPtr New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode );
64 * Sets image rendered by the attachment.
65 * @param [in] image A pointer to the image to display or NULL to clear. Reference to avoid unnecessary increment/decrement reference count.
67 void SetImage( ImagePtr& image );
70 * Retrieve the image rendered by the attachment.
71 * @return The image or an uninitialized image in case the ImageActor was cleared.
76 * Set a region of the image to display, in pixels.
77 * @param [in] pixelArea The area of the image to display.
78 * This in pixels, relative to the top-left (0,0) of the image.
80 void SetPixelArea(const PixelArea& pixelArea);
83 * Retrieve the region of the image to display, in pixels.
84 * @return The pixel area, or a default-constructed area if none was set.
86 const PixelArea& GetPixelArea() const
88 // This is not animatable; the cached value is up-to-date.
93 * Query whether a pixel area has been set.
94 * @return True if a pixel area has been set.
96 bool IsPixelAreaSet() const
98 // This is not animatable; the cached value is up-to-date.
99 return mIsPixelAreaSet;
103 * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
104 * @pre image must be initialized.
106 void ClearPixelArea();
109 * Set how the ImageAttachment is rendered; the default is STYLE_QUAD.
110 * @param [in] style The new style.
112 void SetStyle(Style style);
115 * Query how the image is rendered.
116 * @return The rendering style.
120 // This is not animatable; the cached value is up-to-date.
125 * @copydoc Dali::ImageActor::SetNinePatchBorder
127 void SetNinePatchBorder(const Vector4& border, bool inPixels);
130 * @copydoc Dali::ImageActor::GetNinePatchBorder
132 Vector4 GetNinePatchBorder()
134 // This is not animatable; the cached value is up-to-date.
140 * Set the depth-sort modifier for the renderable.
141 * This modifies the back-to-front distance calculation, when rendering with transparency.
142 * This is useful for ordering transparent objects that are positioned close to each other.
143 * @param[in] modifier The depth-sort modifier.
145 void SetSortModifier(float modifier);
148 * From Renderable; Retrieve the depth-sort modifier for the renderable.
149 * @return The depth-sort modifier.
151 float GetSortModifier() const;
154 * Set the face-culling mode for this attachment.
155 * @param[in] mode The culling mode.
157 void SetCullFace(CullFaceMode mode);
160 * Retrieve the face-culling mode for this attachment.
161 * @return mode The culling mode.
163 CullFaceMode GetCullFace() const;
166 * @copydoc Dali::RenderableActor::SetBlendMode()
168 void SetBlendMode( BlendingMode::Type mode );
171 * @copydoc Dali::RenderableActor::GetBlendMode()
173 BlendingMode::Type GetBlendMode() const;
176 * @copydoc Dali::RenderableActor::SetBlendFunc()
178 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
179 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
182 * @copydoc Dali::RenderableActor::GetBlendFunc()
184 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
185 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
188 * @copydoc Dali::RenderableActor::SetBlendEquation()
190 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
193 * @copydoc Dali::RenderableActor::GetBlendEquation()
195 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
198 * @copydoc Dali::RenderableActor::SetBlendColor()
200 void SetBlendColor( const Vector4& color );
203 * @copydoc Dali::RenderableActor::GetBlendColor()
205 const Vector4& GetBlendColor() const;
208 * @copydoc Dali::RenderableActor::SetFilterMode()
210 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
213 * @copydoc Dali::RenderableActor::GetFilterMode()
215 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter ) const;
218 * @copydoc Dali::RenderableActor::SetShaderEffect
220 void SetShaderEffect(ShaderEffect& effect);
223 * @copydoc Dali::RenderableActor::GetShaderEffect
225 ShaderEffectPtr GetShaderEffect() const;
228 * @copydoc Dali::RenderableActor::RemoveShaderEffect
230 void RemoveShaderEffect();
235 * First stage construction of a ImageAttachment.
236 * @param[in] eventThreadServices Used for messaging to and reading from scene-graph.
238 ImageAttachment( EventThreadServices& eventThreadServices );
241 * Creates the corresponding scene-graph ImageAttachment.
242 * @return A newly allocated scene object.
244 static SceneGraph::ImageAttachment* CreateSceneObject();
247 * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
249 virtual void OnStageConnection2();
252 * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
254 virtual void OnStageDisconnection2();
257 * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
259 const SceneGraph::ImageAttachment& GetSceneObject() const;
264 * A reference counted object may only be deleted by calling Unreference()
266 virtual ~ImageAttachment();
270 const SceneGraph::ImageAttachment* mSceneObject; ///< Not owned
272 ImageConnector mImageConnectable; ///< Manages the image displayed by the attachment
274 // Cached for public getters
276 PixelArea mPixelArea;
281 bool mIsPixelAreaSet : 1;
282 bool mBorderInPixels : 1;
284 BlendingOptions mBlendingOptions;
285 unsigned int mSamplerBitfield;
287 CullFaceMode mCullFaceMode:3; ///< cullface mode, 3 bits enough for 4 values
288 BlendingMode::Type mBlendingMode:2; ///< blending mode, 2 bits enough for 3 values
290 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
293 } // namespace Internal
297 #endif // __DALI_INTERNAL_IMAGE_ATTACHMENT_H__