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 * @addtogroup CAPI_DALI_COMMON_MODULE
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/signals/dali-signal-v2.h>
30 namespace Dali DALI_IMPORT_API
33 namespace Internal DALI_INTERNAL
46 class DynamicsWorldConfig;
51 * @brief The Stage is a top-level object used for displaying a tree of Actors.
53 * Multiple stage/window support is not currently provided.
55 class Stage : public BaseHandle
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
63 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
64 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
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"
72 * @brief Allows the creation of an empty stage handle.
74 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
79 * @brief Get the current Stage.
81 * @return The current stage or an empty handle if Core has not been created or has been already destroyed.
83 static Stage GetCurrent();
86 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
88 * @return True when it's safe to call Stage::GetCurrent().
90 static bool IsInstalled();
93 * @brief Virtual destructor.
95 * Dali::Object derived classes typically do not contain member data.
100 * @copydoc Dali::BaseHandle::operator=
102 using BaseHandle::operator=;
107 * @brief Adds a child Actor to the Stage.
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.
114 void Add(Actor& actor);
117 * @brief Removes a child Actor from the Stage.
119 * The child will be unreferenced.
120 * @pre The actor has been added to the stage.
121 * @param [in] actor The child.
123 void Remove(Actor& actor);
126 * @brief Returns the size of the Stage in pixels as a Vector.
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.
133 Vector2 GetSize() const;
138 * @brief Retrieve the list of render-tasks.
140 * @return A valid handle to a RenderTaskList.
142 RenderTaskList GetRenderTaskList() const;
147 * @brief Query the number of on-stage layers.
149 * Note that a default layer is always provided (count >= 1).
150 * @return The number of layers.
152 unsigned int GetLayerCount() const;
155 * @brief Retrieve the layer at a specified depth.
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.
161 Layer GetLayer(unsigned int depth) const;
164 * @brief Returns the Stage's Root Layer.
166 * @return The root layer.
168 Layer GetRootLayer() const;
173 * @brief Set the background color of the stage.
175 * @param[in] color The new background color.
177 void SetBackgroundColor(Vector4 color);
180 * @brief Retrieve the background color of the stage.
182 * @return The background color.
184 Vector4 GetBackgroundColor() const;
187 * @brief Retrieve the DPI of the display device to which the stage is connected.
189 * @return the horizontal and vertical DPI
191 Vector2 GetDpi() const;
194 * @brief Get the Object registry.
196 * @return The object registry.
198 ObjectRegistry GetObjectRegistry() const;
203 * @brief Initialise the dynamics simulation and create a DynamicsWorld object.
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.
211 DynamicsWorld InitializeDynamics(DynamicsWorldConfig config);
214 * @brief Get a handle to the world object of the dynamics simulation.
216 * @return A handle to the world object of the dynamics simulation
218 DynamicsWorld GetDynamicsWorld();
221 * @brief Terminate the dynamics simulation.
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.
227 void TerminateDynamics();
232 * @brief Keep rendering for at least the given amount of time.
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
238 void KeepRendering( float durationSeconds );
243 * @brief This signal is emitted when key event is received.
245 * A callback of the following type may be connected:
247 * void YourCallbackName(const KeyEvent& event);
249 * @return The signal to connect to.
251 KeyEventSignalV2& KeyEventSignal();
254 * @brief This signal is emitted just after the event processing is finished.
256 * @return The signal to connect to.
258 EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
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).
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:
269 * void YourCallbackName(const TouchEvent& event);
272 * @note Motion events are not emitted.
273 * @return The touch signal to connect to.
275 TouchedSignalV2& TouchedSignal();
277 public: // Not intended for application developers
280 * @brief This constructor is used by Dali GetCurrent() methods.
282 * @param [in] stage A pointer to a Dali resource
284 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
292 #endif // __DALI_STAGE_H__