Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / devel-api / common / stage.h
1 #ifndef DALI_STAGE_H
2 #define DALI_STAGE_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 <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/signals/dali-signal.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_common
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class Stage;
38 }
39
40 class Actor;
41 class Layer;
42 class ObjectRegistry;
43 class TouchData;
44 class RenderTaskList;
45 struct Vector2;
46 struct Vector3;
47 struct Vector4;
48 struct KeyEvent;
49 struct TouchEvent;
50 struct WheelEvent;
51
52 /**
53  * @brief The Stage is a top-level object used for displaying a tree of Actors.
54  *
55  * Stage is a top-level object that represents the entire screen.
56  * It is used for displaying a hierarchy of actors managed by the scene graph structure,
57  * which means an actor inherits a position relative to its parent,
58  * and can be moved in relation to this point.
59  *
60  * The stage instance is a singleton object (the only instance of its class during the
61  * lifetime of the program). You can get it using a static function.
62  *
63  * To display the contents of an actor, it must be added to a stage.
64  * The following example shows how to connect a new actor to the stage:
65  * @code
66  * Actor actor = Actor::New();
67  * Stage::GetCurrent().Add( actor );
68  * @endcode
69  *
70  * The stage has a 2D size that matches the size of the application window.
71  * The default unit 1 is 1 pixel with the default camera.
72  *
73  * Multiple stage/window support is not currently provided.
74  *
75  * Signals
76  * | %Signal Name            | Method                               |
77  * |-------------------------|--------------------------------------|
78  * | keyEvent                | @ref KeyEventSignal()                |
79  * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
80  * | touched                 | @ref TouchedSignal()                 |
81  * | wheelEvent              | @ref WheelEventSignal()              |
82  * | contextLost             | @ref ContextLostSignal()             |
83  * | contextRegained         | @ref ContextRegainedSignal()         |
84  * | sceneCreated            | @ref SceneCreatedSignal()            |
85  * @SINCE_1_0.0
86  */
87 class DALI_CORE_API Stage : public BaseHandle
88 {
89 public:
90
91   typedef Signal< void (const KeyEvent&) > KeyEventSignalType;       ///< Key event signal type @SINCE_1_0.0
92   typedef Signal< void () > EventProcessingFinishedSignalType;       ///< Event Processing finished signal type @SINCE_1_0.0
93   typedef Signal< void (const TouchEvent&) > TouchedSignalType;      ///< @DEPRECATED_1_1.37 @brief Touched signal type @SINCE_1_0.0
94   typedef Signal< void (const TouchData&) > TouchSignalType;                ///< Touch signal type @SINCE_1_1.37
95   typedef Signal< void (const WheelEvent&) > WheelEventSignalType;   ///< Touched signal type @SINCE_1_0.0
96   typedef Signal< void () > ContextStatusSignal;                     ///< Context status signal type @SINCE_1_0.0
97   typedef Signal< void () > SceneCreatedSignalType;                  ///< Scene created signal type @SINCE_1_0.0
98
99   static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
100   static const Vector4 DEBUG_BACKGROUND_COLOR;   ///< Green background, useful when debugging.
101
102   /**
103    * @brief Allows the creation of an empty stage handle.
104    *
105    * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
106    */
107   Stage();
108
109   /**
110    * @brief Gets the current Stage.
111    *
112    * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
113    */
114   static Stage GetCurrent();
115
116   /**
117    * @brief Queries whether the Stage exists; this should only return false during or after destruction of Dali core.
118    *
119    * @return True when it's safe to call Stage::GetCurrent()
120    */
121   static bool IsInstalled();
122
123   /**
124    * @brief Destructor.
125    *
126    * This is non-virtual since derived Handle types must not contain data or virtual methods.
127    */
128   ~Stage();
129
130   /**
131    * @brief This copy constructor is required for (smart) pointer semantics.
132    *
133    * @param[in] handle A reference to the copied handle
134    */
135   Stage(const Stage& handle);
136
137   /**
138    * @brief This assignment operator is required for (smart) pointer semantics.
139    *
140    * @param[in] rhs A reference to the copied handle
141    * @return A reference to this
142    */
143   Stage& operator=(const Stage& rhs);
144
145   // Containment
146
147   /**
148    * @brief Adds a child Actor to the Stage.
149    *
150    * The child will be referenced.
151    * @param[in] actor The child
152    * @pre The actor has been initialized.
153    * @pre The actor does not have a parent.
154    */
155   void Add(Actor& actor);
156
157   /**
158    * @brief Removes a child Actor from the Stage.
159    *
160    * The child will be unreferenced.
161    * @param[in] actor The child
162    * @pre The actor has been added to the stage.
163    */
164   void Remove(Actor& actor);
165
166   /**
167    * @brief Returns the size of the Stage in pixels as a Vector.
168    *
169    * The x component will be the width of the Stage in pixels.
170    * The y component will be the height of the Stage in pixels.
171    * The z component will be the distance between far and near planes.
172    * @SINCE_1_0.0
173    * @return The size of the Stage as a Vector
174    */
175   Vector2 GetSize() const;
176
177   // Render Tasks
178
179   /**
180    * @brief Retrieves the list of render-tasks.
181    *
182    * @return A valid handle to a RenderTaskList
183    */
184   RenderTaskList GetRenderTaskList() const;
185
186   // Layers
187
188   /**
189    * @brief Queries the number of on-stage layers.
190    *
191    * Note that a default layer is always provided (count >= 1).
192    * @return The number of layers
193    */
194   uint32_t GetLayerCount() const;
195
196   /**
197    * @brief Retrieves the layer at a specified depth.
198    *
199    * @param[in] depth The depth
200    * @return The layer found at the given depth
201    * @pre Depth is less than layer count; see GetLayerCount().
202    */
203   Layer GetLayer(uint32_t depth) const;
204
205   /**
206    * @brief Returns the Stage's Root Layer.
207    *
208    * @return The root layer
209    */
210   Layer GetRootLayer() const;
211
212   // Background color
213
214   /**
215    * @brief Sets the background color of the stage.
216    *
217    * @param[in] color The new background color
218    */
219   void SetBackgroundColor(Vector4 color);
220
221   /**
222    * @brief Retrieves the background color of the stage.
223    *
224    * @return The background color
225    */
226   Vector4 GetBackgroundColor() const;
227
228   /**
229    * @brief Retrieves the DPI of the display device to which the stage is connected.
230    *
231    * @return The horizontal and vertical DPI
232    */
233   Vector2 GetDpi() const;
234
235   /**
236    * @brief Gets the Object registry.
237    *
238    * @return The object registry
239    */
240   ObjectRegistry GetObjectRegistry() const;
241
242   // Rendering
243
244   /**
245    * @brief Keep rendering for at least the given amount of time.
246    *
247    * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
248    * This method is useful to force screen refreshes e.g. when updating a NativeImage.
249    * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
250    */
251   void KeepRendering( float durationSeconds );
252
253   // Signals
254
255   /**
256    * @brief This signal is emitted when key event is received.
257    *
258    * A callback of the following type may be connected:
259    * @code
260    *   void YourCallbackName(const KeyEvent& event);
261    * @endcode
262    * @SINCE_1_0.0
263    * @return The signal to connect to
264    */
265   KeyEventSignalType& KeyEventSignal();
266
267   /**
268    * @brief This signal is emitted just after the event processing is finished.
269    *
270    * @return The signal to connect to
271    */
272   EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
273
274   /**
275    * @DEPRECATED_1_1.37 Use TouchSignal() instead.
276    * @brief This signal is emitted when the screen is touched and when the touch ends
277    * (i.e. the down & up touch events only).
278    *
279    * If there are multiple touch points, then this will be emitted when the first touch occurs and
280    * then when the last finger is lifted.
281    * An interrupted event will also be emitted (if it occurs).
282    * A callback of the following type may be connected:
283    * @code
284    *   void YourCallbackName(const TouchEvent& event);
285    * @endcode
286    *
287    * @return The touch signal to connect to
288    * @note Motion events are not emitted.
289    */
290   TouchedSignalType& TouchedSignal() DALI_DEPRECATED_API;
291
292   /**
293    * @brief This signal is emitted when the screen is touched and when the touch ends
294    * (i.e. the down & up touch events only).
295    *
296    * If there are multiple touch points, then this will be emitted when the first touch occurs and
297    * then when the last finger is lifted.
298    * An interrupted event will also be emitted (if it occurs).
299    * A callback of the following type may be connected:
300    * @code
301    *   void YourCallbackName( TouchData event );
302    * @endcode
303    *
304    * @return The touch signal to connect to
305    * @note Motion events are not emitted.
306    */
307   TouchSignalType& TouchSignal();
308
309   /**
310    * @brief This signal is emitted when wheel event is received.
311    *
312    * A callback of the following type may be connected:
313    * @code
314    *   void YourCallbackName(const WheelEvent& event);
315    * @endcode
316    * @return The signal to connect to
317    */
318   WheelEventSignalType& WheelEventSignal();
319
320   /**
321    * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
322    *
323    * If the application is responsible for handling context loss, it should listen to
324    * this signal and tear down UI components when received.
325    * @return The context lost signal to connect to
326    */
327   ContextStatusSignal& ContextLostSignal();
328
329   /**
330    * @brief This signal is emitted when the GL context is regained (Platform specific
331    * behavior).
332    *
333    * If the application is responsible for handling context loss, it should listen to
334    * this signal and rebuild UI components on receipt.
335    * @return The context regained signal to connect to
336    */
337   ContextStatusSignal& ContextRegainedSignal();
338
339   /**
340    * @brief This signal is emitted after the initial scene is created.
341    *
342    * It will be triggered after the
343    * application init signal.
344    *
345    * A callback of the following type may be connected:
346    * @code
347    *   void YourCallbackName();
348    * @endcode
349    * @return The signal to connect to
350    */
351   SceneCreatedSignalType& SceneCreatedSignal();
352
353 public: // Not intended for application developers
354
355   /// @cond internal
356   /**
357    * @brief This constructor is used by Stage::GetCurrent() methods.
358    *
359    * @param[in] stage A pointer to a Dali resource
360    */
361   explicit DALI_INTERNAL Stage(Internal::Stage* stage);
362   /// @endcond
363 };
364
365 /**
366  * @}
367  */
368
369 } // namespace Dali
370
371 #endif // DALI_STAGE_H