f1b3059a5c2206492160c272a36fbd5fa4a57a18
[platform/core/uifw/dali-core.git] / dali / integration-api / scene.h
1 #ifndef DALI_SCENE_H
2 #define DALI_SCENE_H
3
4 /*
5  * Copyright (c) 2019 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/object/handle.h>
23 #include <dali/public-api/math/vector2.h>
24
25 namespace Dali
26 {
27
28 class Actor;
29 struct KeyEvent;
30 class Layer;
31 class RenderTaskList;
32 class TouchData;
33 struct WheelEvent;
34
35 namespace Internal DALI_INTERNAL
36 {
37   class Scene;
38 }
39
40 namespace Integration
41 {
42
43 class RenderSurface;
44 struct Event;
45
46 /**
47  * @brief
48  *
49  * Scene creates a "world" that can be bound to a surface for rendering.
50  *
51  */
52 class DALI_CORE_API Scene : public BaseHandle
53 {
54 public:
55   typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type
56   typedef Signal< void (const Dali::KeyEvent&) > KeyEventSignalType; ///< Key event signal type
57   typedef Signal< void (const Dali::TouchData&) > TouchSignalType; ///< Touch signal type
58   typedef Signal< void (const Dali::WheelEvent&) > WheelEventSignalType; ///< Touched signal type
59
60   /**
61    * @brief Create an initialized Scene handle.
62    *
63    * @param[in] size The size of the scene in pixels as a Vector
64    *
65    * @return a handle to a newly allocated Dali resource.
66    */
67   static Scene New( const Size& size );
68
69   /**
70    * @brief Downcast an Object handle to Scene handle.
71    *
72    * If handle points to a Scene object the downcast produces
73    * valid handle. If not the returned handle is left uninitialized.
74    * @param[in] handle to An object
75    * @return handle to a Scene object or an uninitialized handle
76    */
77   static Scene DownCast( BaseHandle handle );
78
79   /**
80    * @brief Create an uninitialized Scene handle.
81    *
82    * This can be initialized with Scene::New(). Calling member
83    * functions with an uninitialized Dali::Object is not allowed.
84    */
85   Scene();
86
87   /**
88    * @brief Destructor
89    *
90    * This is non-virtual since derived Handle types must not contain data or virtual methods.
91    */
92   ~Scene();
93
94   /**
95    * @brief This copy constructor is required for (smart) pointer semantics.
96    *
97    * @param [in] handle A reference to the copied handle
98    */
99   Scene(const Scene& handle);
100
101   /**
102    * @brief This assignment operator is required for (smart) pointer semantics.
103    *
104    * @param [in] rhs  A reference to the copied handle
105    * @return A reference to this
106    */
107   Scene& operator=(const Scene& rhs);
108
109   /**
110    * @brief Adds a child Actor to the Scene.
111    *
112    * The child will be referenced.
113    * @param[in] actor The child
114    * @pre The actor has been initialized.
115    * @pre The actor does not have a parent.
116    */
117   void Add(Actor actor);
118
119   /**
120    * @brief Removes a child Actor from the Scene.
121    *
122    * The child will be unreferenced.
123    * @param[in] actor The child
124    * @pre The actor has been added to the stage.
125    */
126   void Remove(Actor actor);
127
128   /**
129    * @brief Returns the size of the Scene in pixels as a Vector.
130    *
131    * The x component will be the width of the Scene in pixels.
132    * The y component will be the height of the Scene in pixels.
133    *
134    * @return The size of the Scene as a Vector
135    */
136   Size GetSize() const;
137
138   /**
139    * Sets horizontal and vertical pixels per inch value that is used by the display
140    * @param[in] dpi Horizontal and vertical dpi value
141    */
142   void SetDpi( Vector2 dpi );
143
144   /**
145    * @brief Retrieves the DPI of the display device to which the scene is connected.
146    *
147    * @return The horizontal and vertical DPI
148    */
149   Vector2 GetDpi() const;
150
151   /**
152    * @brief Retrieves the list of render-tasks.
153    *
154    * @return A valid handle to a RenderTaskList
155    */
156   Dali::RenderTaskList GetRenderTaskList() const;
157
158   /**
159    * @brief Returns the Scene's Root Layer.
160    *
161    * @return The root layer
162    */
163   Layer GetRootLayer() const;
164
165   /**
166    * @brief Queries the number of on-stage layers.
167    *
168    * Note that a default layer is always provided (count >= 1).
169    * @return The number of layers
170    */
171   uint32_t GetLayerCount() const;
172
173   /**
174    * @brief Retrieves the layer at a specified depth.
175    *
176    * @param[in] depth The depth
177    * @return The layer found at the given depth
178    * @pre Depth is less than layer count; see GetLayerCount().
179    */
180   Layer GetLayer( uint32_t depth ) const;
181
182   /**
183    * @brief Binds the rendering surface to the scene
184    *
185    * @return The root layer
186    */
187   void SetSurface( Integration::RenderSurface& surface );
188
189   /**
190    * @brief Gets the rendering surface bound to the scene
191    *
192    * @return The render surface
193    */
194   Integration::RenderSurface* GetSurface() const;
195
196   /**
197    * @brief Retrieve the Scene that the given actor belongs to.
198    * @return The Scene.
199    */
200   static Integration::Scene Get( Actor actor );
201
202   /**
203    * This function is called when an event is queued.
204    * @param[in] event A event to queue.
205    */
206   void QueueEvent( const Integration::Event& event );
207
208   /**
209    * This function is called by Core when events are processed.
210    */
211   void ProcessEvents();
212
213   /**
214    * @brief This signal is emitted just after the event processing is finished.
215    *
216    * @return The signal to connect to
217    */
218   EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
219
220   /**
221    * @brief This signal is emitted when key event is received.
222    *
223    * A callback of the following type may be connected:
224    * @code
225    *   void YourCallbackName(const KeyEvent& event);
226    * @endcode
227    * @return The signal to connect to
228    */
229   KeyEventSignalType& KeyEventSignal();
230
231   /**
232    * @brief This signal is emitted when the screen is touched and when the touch ends
233    * (i.e. the down & up touch events only).
234    *
235    * If there are multiple touch points, then this will be emitted when the first touch occurs and
236    * then when the last finger is lifted.
237    * An interrupted event will also be emitted (if it occurs).
238    * A callback of the following type may be connected:
239    * @code
240    *   void YourCallbackName( TouchData event );
241    * @endcode
242    *
243    * @return The touch signal to connect to
244    * @note Motion events are not emitted.
245    */
246   TouchSignalType& TouchSignal();
247
248   /**
249    * @brief This signal is emitted when wheel event is received.
250    *
251    * A callback of the following type may be connected:
252    * @code
253    *   void YourCallbackName(const WheelEvent& event);
254    * @endcode
255    * @return The signal to connect to
256    */
257   WheelEventSignalType& WheelEventSignal();
258
259 public: // Not intended for application developers
260
261   /**
262    * @brief This constructor is used by Dali::New() methods.
263    *
264    * @param[in] scene A pointer to an internal Scene resource
265    */
266   explicit DALI_INTERNAL Scene(Internal::Scene* scene);
267 };
268
269 } // namespace Integration
270
271 } // namespace Dali
272
273 #endif // DALI_SCENE_H