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