Revert "License conversion from Flora to Apache 2.0"
[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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/actors/image-actor.h>
22 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
23 #include <dali/internal/event/actor-attachments/renderable-attachment-impl.h>
24 #include <dali/internal/event/images/image-impl.h>
25 #include <dali/internal/event/images/image-connector.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35 class ImageAttachment;
36 class Node;
37 }
38
39 /**
40  * An attachment for rendering images in various ways.
41  * The default geometry scaling mode is ScaleToFill.
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] parentNode The node to attach a scene-object to.
53    * @param[in] image A pointer to the image to display or NULL to not render anything.
54    * @return A smart-pointer to the newly allocated ImageAttachment.
55    */
56   static ImageAttachmentPtr New( const SceneGraph::Node& parentNode, Image* image );
57
58   /**
59    * Sets image rendered by the attachment.
60    * @param [in] image A pointer to the image to display or NULL to clear.
61    */
62   void SetImage(Image* 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   Dali::Image 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    * @param[in] image A pointer to the image to display or NULL to not render anything.
139    */
140   ImageAttachment(Stage& stage, Image* image);
141
142   /**
143    * Creates the corresponding scene-graph ImageAttachment.
144    * @return A newly allocated scene object.
145    */
146   static SceneGraph::ImageAttachment* CreateSceneObject( const Image* current );
147
148   /**
149    * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
150    */
151   virtual void OnStageConnection2();
152
153   /**
154    * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
155    */
156   virtual void OnStageDisconnection2();
157
158   /**
159    * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
160    */
161   virtual const SceneGraph::RenderableAttachment& GetSceneObject() const;
162
163 protected:
164
165   /**
166    * A reference counted object may only be deleted by calling Unreference()
167    */
168   virtual ~ImageAttachment();
169
170 private:
171
172   const SceneGraph::ImageAttachment* mSceneObject; ///< Not owned
173
174   ImageConnector mImageConnectable; ///< Manages the image displayed by the attachment
175
176   // Cached for public getters
177
178   PixelArea mPixelArea;
179
180   Style mStyle;
181   Vector4 mBorder;
182
183   bool mIsPixelAreaSet : 1;
184   bool mBorderInPixels : 1;
185 };
186
187 } // namespace Internal
188
189 } // namespace Dali
190
191 #endif // __DALI_INTERNAL_IMAGE_ATTACHMENT_H__