eeb191f5bb4116128bffc47cf9a5ac316ffba9a1
[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) 2020 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 // EXTERNAL INCLUDES
22 #include <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/public-api/object/handle.h>
29
30 namespace Dali
31 {
32 class Actor;
33 class KeyEvent;
34 class Layer;
35 class RenderTaskList;
36 class TouchEvent;
37 class WheelEvent;
38
39 namespace Internal DALI_INTERNAL
40 {
41 class Scene;
42 }
43
44 namespace Integration
45 {
46 struct Event;
47
48 /**
49  * @brief
50  *
51  * Scene creates a "world" that can be bound to a surface for rendering.
52  *
53  */
54 class DALI_CORE_API Scene : public BaseHandle
55 {
56 public:
57   using EventProcessingFinishedSignalType = Signal<void()>;                        ///< Event Processing finished signal type
58   using KeyEventSignalType                = Signal<void(const Dali::KeyEvent&)>;   ///< Key event signal type
59   using KeyEventGeneratedSignalType       = Signal<bool(const Dali::KeyEvent&)>;   ///< key event generated signal type
60   using TouchEventSignalType              = Signal<void(const Dali::TouchEvent&)>; ///< Touch signal type
61   using WheelEventSignalType              = Signal<void(const Dali::WheelEvent&)>; ///< WheelEvent signal type
62
63   using FrameCallbackContainer = std::vector<std::pair<std::unique_ptr<CallbackBase>, int32_t> >;
64
65   /**
66    * @brief Create an initialized Scene handle.
67    *
68    * @param[in] size The size of the set surface for this scene
69    * @param[in] orientation The rotated angle of the set surface for this scene
70    *
71    * @return a handle to a newly allocated Dali resource.
72    */
73   static Scene New(Size size, int orientation = 0);
74
75   /**
76    * @brief Downcast an Object handle to Scene handle.
77    *
78    * If handle points to a Scene object the downcast produces
79    * valid handle. If not the returned handle is left uninitialized.
80    * @param[in] handle to An object
81    * @return handle to a Scene object or an uninitialized handle
82    */
83   static Scene DownCast(BaseHandle handle);
84
85   /**
86    * @brief Create an uninitialized Scene handle.
87    *
88    * This can be initialized with Scene::New(). Calling member
89    * functions with an uninitialized Dali::Object is not allowed.
90    */
91   Scene();
92
93   /**
94    * @brief Destructor
95    *
96    * This is non-virtual since derived Handle types must not contain data or virtual methods.
97    */
98   ~Scene();
99
100   /**
101    * @brief This copy constructor is required for (smart) pointer semantics.
102    *
103    * @param [in] handle A reference to the copied handle
104    */
105   Scene(const Scene& handle);
106
107   /**
108    * @brief This assignment operator is required for (smart) pointer semantics.
109    *
110    * @param [in] rhs  A reference to the copied handle
111    * @return A reference to this
112    */
113   Scene& operator=(const Scene& rhs);
114
115   /**
116    * @brief Adds a child Actor to the Scene.
117    *
118    * The child will be referenced.
119    * @param[in] actor The child
120    * @pre The actor has been initialized.
121    * @pre The actor does not have a parent.
122    */
123   void Add(Actor actor);
124
125   /**
126    * @brief Removes a child Actor from the Scene.
127    *
128    * The child will be unreferenced.
129    * @param[in] actor The child
130    * @pre The actor has been added to the stage.
131    */
132   void Remove(Actor actor);
133
134   /**
135    * @brief Returns the size of the Scene in pixels as a Vector.
136    *
137    * The x component will be the width of the Scene in pixels.
138    * The y component will be the height of the Scene in pixels.
139    *
140    * @return The size of the Scene as a Vector
141    */
142   Size GetSize() const;
143
144   /**
145    * Sets horizontal and vertical pixels per inch value that is used by the display
146    * @param[in] dpi Horizontal and vertical dpi value
147    */
148   void SetDpi(Vector2 dpi);
149
150   /**
151    * @brief Retrieves the DPI of the display device to which the scene is connected.
152    *
153    * @return The horizontal and vertical DPI
154    */
155   Vector2 GetDpi() const;
156
157   /**
158    * @brief Sets the background color.
159    *
160    * @param[in] color The new background color
161    */
162   void SetBackgroundColor(const Vector4& color);
163
164   /**
165    * @brief Gets the background color of the render surface.
166    *
167    * @return The background color
168    */
169   Vector4 GetBackgroundColor() const;
170
171   /**
172    * @brief Retrieves the list of render-tasks.
173    *
174    * @return A valid handle to a RenderTaskList
175    */
176   Dali::RenderTaskList GetRenderTaskList() const;
177
178   /**
179    * @brief Returns the Scene's Root Layer.
180    *
181    * @return The root layer
182    */
183   Layer GetRootLayer() const;
184
185   /**
186    * @brief Queries the number of on-stage layers.
187    *
188    * Note that a default layer is always provided (count >= 1).
189    * @return The number of layers
190    */
191   uint32_t GetLayerCount() const;
192
193   /**
194    * @brief Retrieves the layer at a specified depth.
195    *
196    * @param[in] depth The depth
197    * @return The layer found at the given depth
198    * @pre Depth is less than layer count; see GetLayerCount().
199    */
200   Layer GetLayer(uint32_t depth) const;
201
202   /**
203    * @brief Informs the scene that the set surface has been resized.
204    *
205    * @param[in] width The new width of the set surface
206    * @param[in] height The new height of the set surface
207    */
208   void SurfaceResized(float width, float height);
209
210   /**
211    * @brief Informs the scene that the surface has been replaced.
212    */
213   void SurfaceReplaced();
214
215   /**
216    * @brief Discards this Scene from the Core.
217    */
218   void Discard();
219
220   /**
221    * @brief Retrieve the Scene that the given actor belongs to.
222    * @return The Scene.
223    */
224   static Integration::Scene Get(Actor actor);
225
226   /**
227    * This function is called when an event is queued.
228    * @param[in] event A event to queue.
229    */
230   void QueueEvent(const Integration::Event& event);
231
232   /**
233    * This function is called by Core when events are processed.
234    */
235   void ProcessEvents();
236
237   /**
238    * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
239    *
240    * @param[in] callback The function to call
241    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
242    *
243    * @note A callback of the following type may be used:
244    * @code
245    *   void MyFunction( int frameId );
246    * @endcode
247    * This callback will be deleted once it is called.
248    *
249    * @note Ownership of the callback is passed onto this class.
250    */
251   void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
252
253   /**
254    * @brief Adds a callback that is called when the frame is displayed on the display.
255    *
256    * @param[in] callback The function to call
257    * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
258    *
259    * @note A callback of the following type may be used:
260    * @code
261    *   void MyFunction( int frameId );
262    * @endcode
263    * This callback will be deleted once it is called.
264    *
265    * @note Ownership of the callback is passed onto this class.
266    */
267   void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
268
269   /**
270    * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
271    *
272    * @param[out] callbacks The callback list
273    *
274    * @note This is called in the update thread.
275    */
276   void GetFrameRenderedCallback(FrameCallbackContainer& callbacks);
277
278   /**
279    * @brief Gets the callback list that is called when the frame is displayed on the display.
280    *
281    * @param[out] callbacks The callback list
282    *
283    * @note This is called in the update thread.
284    */
285   void GetFramePresentedCallback(FrameCallbackContainer& callbacks);
286
287   /**
288    * @brief Informs the scene that the set surface has been rotated.
289    *
290    * @param[in] width The width of rotated surface
291    * @param[in] height The height of rotated surface
292    * @param[in] orientation The orientation of rotated surface
293    */
294   void SurfaceRotated(float width, float height, int orientation);
295
296   /**
297    * Query wheter the surface rect is changed or not.
298    * @return true if the surface rect is changed.
299    */
300   bool IsSurfaceRectChanged() const;
301
302   /**
303    * @brief This signal is emitted just after the event processing is finished.
304    *
305    * @return The signal to connect to
306    */
307   EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
308
309   /**
310    * @brief This signal is emitted when key event is received.
311    *
312    * A callback of the following type may be connected:
313    * @code
314    *   void YourCallbackName(const KeyEvent& event);
315    * @endcode
316    * @return The signal to connect to
317    */
318   KeyEventSignalType& KeyEventSignal();
319
320   /**
321    * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated.
322    *
323    * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent.
324    * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal.
325    * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed.
326    *
327    * A callback of the following type may be connected:
328    * @code
329    *   bool YourCallbackName(const KeyEvent& event);
330    * @endcode
331    *
332    * @return The return is true if KeyEvent is consumed, otherwise false.
333    */
334   KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
335
336   /**
337    * @brief This signal is emitted when the screen is touched and when the touch ends
338    * (i.e. the down & up touch events only).
339    *
340    * If there are multiple touch points, then this will be emitted when the first touch occurs and
341    * then when the last finger is lifted.
342    * An interrupted event will also be emitted (if it occurs).
343    * A callback of the following type may be connected:
344    * @code
345    *   void YourCallbackName( TouchEvent event );
346    * @endcode
347    *
348    * @return The touch signal to connect to
349    * @note Motion events are not emitted.
350    */
351   TouchEventSignalType& TouchedSignal();
352
353   /**
354    * @brief This signal is emitted when wheel event is received.
355    *
356    * A callback of the following type may be connected:
357    * @code
358    *   void YourCallbackName(const WheelEvent& event);
359    * @endcode
360    * @return The signal to connect to
361    */
362   WheelEventSignalType& WheelEventSignal();
363
364 public: // Not intended for application developers
365   /**
366    * @brief This constructor is used by Dali::New() methods.
367    *
368    * @param[in] scene A pointer to an internal Scene resource
369    */
370   explicit DALI_INTERNAL Scene(Internal::Scene* scene);
371 };
372
373 } // namespace Integration
374
375 } // namespace Dali
376
377 #endif // DALI_SCENE_H