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