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