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