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