1 #ifndef __DALI_STAGE_H__
2 #define __DALI_STAGE_H__
5 * Copyright (c) 2015 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.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.
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() |
60 class DALI_IMPORT_API Stage : public BaseHandle
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
70 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
71 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
74 * @brief Allows the creation of an empty stage handle.
76 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
81 * @brief Get the current Stage.
83 * @return The current stage or an empty handle if Core has not been created or has been already destroyed.
85 static Stage GetCurrent();
88 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
90 * @return True when it's safe to call Stage::GetCurrent().
92 static bool IsInstalled();
97 * This is non-virtual since derived Handle types must not contain data or virtual methods.
102 * @brief This copy constructor is required for (smart) pointer semantics.
104 * @param [in] handle A reference to the copied handle
106 Stage(const Stage& handle);
109 * @brief This assignment operator is required for (smart) pointer semantics.
111 * @param [in] rhs A reference to the copied handle
112 * @return A reference to this
114 Stage& operator=(const Stage& rhs);
119 * @brief Adds a child Actor to the Stage.
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.
126 void Add(Actor& actor);
129 * @brief Removes a child Actor from the Stage.
131 * The child will be unreferenced.
132 * @pre The actor has been added to the stage.
133 * @param [in] actor The child.
135 void Remove(Actor& actor);
138 * @brief Returns the size of the Stage in pixels as a Vector.
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.
145 Vector2 GetSize() const;
150 * @brief Retrieve the list of render-tasks.
152 * @return A valid handle to a RenderTaskList.
154 RenderTaskList GetRenderTaskList() const;
159 * @brief Query the number of on-stage layers.
161 * Note that a default layer is always provided (count >= 1).
162 * @return The number of layers.
164 unsigned int GetLayerCount() const;
167 * @brief Retrieve the layer at a specified depth.
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.
173 Layer GetLayer(unsigned int depth) const;
176 * @brief Returns the Stage's Root Layer.
178 * @return The root layer.
180 Layer GetRootLayer() const;
185 * @brief Set the background color of the stage.
187 * @param[in] color The new background color.
189 void SetBackgroundColor(Vector4 color);
192 * @brief Retrieve the background color of the stage.
194 * @return The background color.
196 Vector4 GetBackgroundColor() const;
199 * @brief Retrieve the DPI of the display device to which the stage is connected.
201 * @return the horizontal and vertical DPI
203 Vector2 GetDpi() const;
206 * @brief Get the Object registry.
208 * @return The object registry.
210 ObjectRegistry GetObjectRegistry() const;
215 * @brief Initialise the dynamics simulation and create a DynamicsWorld object.
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.
223 DynamicsWorld InitializeDynamics(DynamicsWorldConfig config);
226 * @brief Get a handle to the world object of the dynamics simulation.
228 * @return A handle to the world object of the dynamics simulation
230 DynamicsWorld GetDynamicsWorld();
233 * @brief Terminate the dynamics simulation.
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.
239 void TerminateDynamics();
244 * @brief Keep rendering for at least the given amount of time.
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
250 void KeepRendering( float durationSeconds );
255 * @brief This signal is emitted when key event is received.
257 * A callback of the following type may be connected:
259 * void YourCallbackName(const KeyEvent& event);
261 * @return The signal to connect to.
263 KeyEventSignalType& KeyEventSignal();
266 * @brief This signal is emitted just after the event processing is finished.
268 * @return The signal to connect to.
270 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
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).
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:
281 * void YourCallbackName(const TouchEvent& event);
284 * @note Motion events are not emitted.
285 * @return The touch signal to connect to.
287 TouchedSignalType& TouchedSignal();
290 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
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.
296 ContextStatusSignal& ContextLostSignal();
299 * @brief This signal is emitted when the GL context is regained (Platform specific
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.
306 ContextStatusSignal& ContextRegainedSignal();
309 * @brief This signal is emitted after the initial scene is created. It will be triggered after the
310 * application init signal.
312 * A callback of the following type may be connected:
314 * void YourCallbackName();
316 * @return The signal to connect to.
318 SceneCreatedSignalType& SceneCreatedSignal();
320 public: // Not intended for application developers
323 * @brief This constructor is used by Dali GetCurrent() methods.
325 * @param [in] stage A pointer to a Dali resource
327 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
332 #endif // __DALI_STAGE_H__