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