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