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