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