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