965ebbf2e81e74d4dee7f1e5e48c6d1e3a4109b0
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / image-attachment-impl.h
1 #ifndef __DALI_INTERNAL_IMAGE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_IMAGE_ATTACHMENT_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
24 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
25 #include <dali/internal/event/images/image-impl.h>
26 #include <dali/internal/event/images/image-connector.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace SceneGraph
35 {
36 class ImageAttachment;
37 class Node;
38 }
39
40 /**
41  * An attachment for rendering images in various ways.
42  */
43 class ImageAttachment : public RenderableAttachment
44 {
45 public:
46
47   typedef Dali::ImageActor::Style Style;
48   typedef Dali::ImageActor::PixelArea PixelArea;
49
50   /**
51    * Create a new ImageAttachment.
52    * @param[in] stage The stage to use for messaging
53    * @param[in] parentNode The node to attach a scene-object to.
54    * @return A smart-pointer to the newly allocated ImageAttachment.
55    */
56   static ImageAttachmentPtr New( Stage& stage, const SceneGraph::Node& parentNode );
57
58   /**
59    * Sets image rendered by the attachment.
60    * @param [in] image A pointer to the image to display or NULL to clear. Reference to avoid unnecessary increment/decrement reference count.
61    */
62   void SetImage( ImagePtr& image );
63
64   /**
65    * Retrieve the image rendered by the attachment.
66    * @return The image or an uninitialized image in case the ImageActor was cleared.
67    */
68   ImagePtr GetImage();
69
70   /**
71    * Set a region of the image to display, in pixels.
72    * @param [in] pixelArea The area of the image to display.
73    * This in pixels, relative to the top-left (0,0) of the image.
74    */
75   void SetPixelArea(const PixelArea& pixelArea);
76
77   /**
78    * Retrieve the region of the image to display, in pixels.
79    * @return The pixel area, or a default-constructed area if none was set.
80    */
81   const PixelArea& GetPixelArea() const
82   {
83     // This is not animatable; the cached value is up-to-date.
84     return mPixelArea;
85   }
86
87   /**
88    * Query whether a pixel area has been set.
89    * @return True if a pixel area has been set.
90    */
91   bool IsPixelAreaSet() const
92   {
93     // This is not animatable; the cached value is up-to-date.
94     return mIsPixelAreaSet;
95   }
96
97   /**
98    * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
99    * @pre image must be initialized.
100    */
101   void ClearPixelArea();
102
103   /**
104    * Set how the ImageAttachment is rendered; the default is STYLE_QUAD.
105    * @param [in] style The new style.
106    */
107   void SetStyle(Style style);
108
109   /**
110    * Query how the image is rendered.
111    * @return The rendering style.
112    */
113   Style GetStyle()
114   {
115     // This is not animatable; the cached value is up-to-date.
116     return mStyle;
117   }
118
119   /**
120    * @copydoc Dali::ImageActor::SetNinePatchBorder
121    */
122   void SetNinePatchBorder(const Vector4& border, bool inPixels);
123
124   /**
125    * @copydoc Dali::ImageActor::GetNinePatchBorder
126    */
127   Vector4 GetNinePatchBorder()
128   {
129     // This is not animatable; the cached value is up-to-date.
130     return mBorder;
131   }
132
133 private:
134
135   /**
136    * First stage construction of a ImageAttachment.
137    * @param[in] stage Used to send messages to scene-graph.
138    */
139   ImageAttachment(Stage& stage);
140
141   /**
142    * Creates the corresponding scene-graph ImageAttachment.
143    * @return A newly allocated scene object.
144    */
145   static SceneGraph::ImageAttachment* CreateSceneObject();
146
147   /**
148    * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
149    */
150   virtual void OnStageConnection2();
151
152   /**
153    * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
154    */
155   virtual void OnStageDisconnection2();
156
157   /**
158    * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
159    */
160   virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
161
162 protected:
163
164   /**
165    * A reference counted object may only be deleted by calling Unreference()
166    */
167   virtual ~ImageAttachment();
168
169 private:
170
171   const SceneGraph::ImageAttachment* mSceneObject; ///< Not owned
172
173   ImageConnector mImageConnectable; ///< Manages the image displayed by the attachment
174
175   // Cached for public getters
176
177   PixelArea mPixelArea;
178
179   Style mStyle;
180   Vector4 mBorder;
181
182   bool mIsPixelAreaSet : 1;
183   bool mBorderInPixels : 1;
184 };
185
186 } // namespace Internal
187
188 } // namespace Dali
189
190 #endif // __DALI_INTERNAL_IMAGE_ATTACHMENT_H__