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