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