1 #ifndef __DALI_STAGE_H__
2 #define __DALI_STAGE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/signals/dali-signal-v2.h>
28 namespace Internal DALI_INTERNAL
41 class DynamicsWorldConfig;
46 * @brief The Stage is a top-level object used for displaying a tree of Actors.
48 * Multiple stage/window support is not currently provided.
50 class DALI_IMPORT_API Stage : public BaseHandle
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
59 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
60 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
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"
70 * @brief Allows the creation of an empty stage handle.
72 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
77 * @brief Get the current Stage.
79 * @return The current stage or an empty handle if Core has not been created or has been already destroyed.
81 static Stage GetCurrent();
84 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
86 * @return True when it's safe to call Stage::GetCurrent().
88 static bool IsInstalled();
93 * This is non-virtual since derived Handle types must not contain data or virtual methods.
98 * @brief This copy constructor is required for (smart) pointer semantics.
100 * @param [in] handle A reference to the copied handle
102 Stage(const Stage& handle);
105 * @brief This assignment operator is required for (smart) pointer semantics.
107 * @param [in] rhs A reference to the copied handle
108 * @return A reference to this
110 Stage& operator=(const Stage& rhs);
113 * @brief This method is defined to allow assignment of the NULL value,
114 * and will throw an exception if passed any other value.
116 * Assigning to NULL is an alias for Reset().
117 * @param [in] rhs A NULL pointer
118 * @return A reference to this handle
120 Stage& operator=(BaseHandle::NullType* rhs);
125 * @brief Adds a child Actor to the Stage.
127 * The child will be referenced.
128 * @pre The actor has been initialized.
129 * @pre The actor does not have a parent.
130 * @param [in] actor The child.
132 void Add(Actor& actor);
135 * @brief Removes a child Actor from the Stage.
137 * The child will be unreferenced.
138 * @pre The actor has been added to the stage.
139 * @param [in] actor The child.
141 void Remove(Actor& actor);
144 * @brief Returns the size of the Stage in pixels as a Vector.
146 * The x component will be the width of the Stage in pixels
147 * The y component will be the height of the Stage in pixels
148 * The z component will be the distance between far and near planes
149 * @return The size of the Stage as a Vector.
151 Vector2 GetSize() const;
156 * @brief Retrieve the list of render-tasks.
158 * @return A valid handle to a RenderTaskList.
160 RenderTaskList GetRenderTaskList() const;
165 * @brief Query the number of on-stage layers.
167 * Note that a default layer is always provided (count >= 1).
168 * @return The number of layers.
170 unsigned int GetLayerCount() const;
173 * @brief Retrieve the layer at a specified depth.
175 * @pre depth is less than layer count; see GetLayerCount().
176 * @param[in] depth The depth.
177 * @return The layer found at the given depth.
179 Layer GetLayer(unsigned int depth) const;
182 * @brief Returns the Stage's Root Layer.
184 * @return The root layer.
186 Layer GetRootLayer() const;
191 * @brief Set the background color of the stage.
193 * @param[in] color The new background color.
195 void SetBackgroundColor(Vector4 color);
198 * @brief Retrieve the background color of the stage.
200 * @return The background color.
202 Vector4 GetBackgroundColor() const;
205 * @brief Retrieve the DPI of the display device to which the stage is connected.
207 * @return the horizontal and vertical DPI
209 Vector2 GetDpi() const;
212 * @brief Get the Object registry.
214 * @return The object registry.
216 ObjectRegistry GetObjectRegistry() const;
221 * @brief Initialise the dynamics simulation and create a DynamicsWorld object.
223 * Only one instance of DynamicsWorld will be created, so calling this method multiple times
224 * will return the same DynamicsWorld object.
225 * @param[in] config A DynamicsWorldConfig object describing the required capabilities of the dynamics world.
226 * @return A handle to the world object of the dynamics simulation, or an empty handle if Dynamics capable
227 * of supporting the requirement in config is not available on the platform.
229 DynamicsWorld InitializeDynamics(DynamicsWorldConfig config);
232 * @brief Get a handle to the world object of the dynamics simulation.
234 * @return A handle to the world object of the dynamics simulation
236 DynamicsWorld GetDynamicsWorld();
239 * @brief Terminate the dynamics simulation.
241 * Calls Actor::DisableDynamics on all dynamics enabled actors,
242 * all handles to any DynamicsBody or DynamicsJoint objects held by applications
243 * will become detached from their actors and the simulation therefore should be discarded.
245 void TerminateDynamics();
250 * @brief Keep rendering for at least the given amount of time.
252 * By default Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
253 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
254 * @param durationSeconds to keep rendering, 0 means render at least one more frame
256 void KeepRendering( float durationSeconds );
261 * @brief This signal is emitted when key event is received.
263 * A callback of the following type may be connected:
265 * void YourCallbackName(const KeyEvent& event);
267 * @return The signal to connect to.
269 KeyEventSignalV2& KeyEventSignal();
272 * @brief This signal is emitted just after the event processing is finished.
274 * @return The signal to connect to.
276 EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
279 * @brief This signal is emitted when the screen is touched and when the touch ends
280 * (i.e. the down & up touch events only).
282 * If there are multiple touch points, then this will be emitted when the first touch occurs and
283 * then when the last finger is lifted.
284 * An interrupted event will also be emitted.
285 * A callback of the following type may be connected:
287 * void YourCallbackName(const TouchEvent& event);
290 * @note Motion events are not emitted.
291 * @return The touch signal to connect to.
293 TouchedSignalV2& TouchedSignal();
296 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
298 * If the application is responsible for handling context loss, it should listen to
299 * this signal and tear down UI components when recieved.
300 * @return The ContextLost signal to connect to.
302 ContextStatusSignal& ContextLostSignal();
305 * @brief This signal is emitted when the GL context is regained (Platform specific
308 * If the application is responsible for handling context loss, it should listen to
309 * this signal and rebuild UI components on receipt.
310 * @return The ContextRegained signal to connect to.
312 ContextStatusSignal& ContextRegainedSignal();
314 public: // Not intended for application developers
317 * @brief This constructor is used by Dali GetCurrent() methods.
319 * @param [in] stage A pointer to a Dali resource
321 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
326 #endif // __DALI_STAGE_H__