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