5 * Copyright (c) 2020 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 <cstdint> // uint32_t
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/signals/dali-signal.h>
31 * @addtogroup dali_core_common
35 namespace Internal DALI_INTERNAL
53 * @brief The Stage is a top-level object used for displaying a tree of Actors.
55 * Stage is a top-level object that represents the entire screen.
56 * It is used for displaying a hierarchy of actors managed by the scene graph structure,
57 * which means an actor inherits a position relative to its parent,
58 * and can be moved in relation to this point.
60 * The stage instance is a singleton object (the only instance of its class during the
61 * lifetime of the program). You can get it using a static function.
63 * To display the contents of an actor, it must be added to a stage.
64 * The following example shows how to connect a new actor to the stage:
66 * Actor actor = Actor::New();
67 * Stage::GetCurrent().Add( actor );
70 * The stage has a 2D size that matches the size of the application window.
71 * The default unit 1 is 1 pixel with the default camera.
73 * Multiple stage/window support is not currently provided.
76 * | %Signal Name | Method |
77 * |-------------------------|--------------------------------------|
78 * | keyEvent | @ref KeyEventSignal() |
79 * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
80 * | touched | @ref TouchedSignal() |
81 * | wheelEvent | @ref WheelEventSignal() |
82 * | contextLost | @ref ContextLostSignal() |
83 * | contextRegained | @ref ContextRegainedSignal() |
84 * | sceneCreated | @ref SceneCreatedSignal() |
87 class DALI_CORE_API Stage : public BaseHandle
91 typedef Signal< void (const KeyEvent&) > KeyEventSignalType; ///< Key event signal type @SINCE_1_0.0
92 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @SINCE_1_0.0
93 typedef Signal< void (const TouchEvent&) > TouchedSignalType; ///< @DEPRECATED_1_1.37 @brief Touched signal type @SINCE_1_0.0
94 typedef Signal< void (const TouchData&) > TouchSignalType; ///< Touch signal type @SINCE_1_1.37
95 typedef Signal< void (const WheelEvent&) > WheelEventSignalType; ///< Touched signal type @SINCE_1_0.0
96 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @SINCE_1_0.0
97 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @SINCE_1_0.0
99 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
100 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
103 * @brief Allows the creation of an empty stage handle.
105 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
110 * @brief Gets the current Stage.
112 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
114 static Stage GetCurrent();
117 * @brief Queries whether the Stage exists; this should only return false during or after destruction of Dali core.
119 * @return True when it's safe to call Stage::GetCurrent()
121 static bool IsInstalled();
126 * This is non-virtual since derived Handle types must not contain data or virtual methods.
131 * @brief This copy constructor is required for (smart) pointer semantics.
133 * @param[in] handle A reference to the copied handle
135 Stage(const Stage& handle);
138 * @brief This assignment operator is required for (smart) pointer semantics.
140 * @param[in] rhs A reference to the copied handle
141 * @return A reference to this
143 Stage& operator=(const Stage& rhs);
148 * @brief Adds a child Actor to the Stage.
150 * The child will be referenced.
151 * @param[in] actor The child
152 * @pre The actor has been initialized.
153 * @pre The actor does not have a parent.
155 void Add(Actor& actor);
158 * @brief Removes a child Actor from the Stage.
160 * The child will be unreferenced.
161 * @param[in] actor The child
162 * @pre The actor has been added to the stage.
164 void Remove(Actor& actor);
167 * @brief Returns the size of the Stage in pixels as a Vector.
169 * The x component will be the width of the Stage in pixels.
170 * The y component will be the height of the Stage in pixels.
171 * The z component will be the distance between far and near planes.
173 * @return The size of the Stage as a Vector
175 Vector2 GetSize() const;
180 * @brief Retrieves the list of render-tasks.
182 * @return A valid handle to a RenderTaskList
184 RenderTaskList GetRenderTaskList() const;
189 * @brief Queries the number of on-stage layers.
191 * Note that a default layer is always provided (count >= 1).
192 * @return The number of layers
194 uint32_t GetLayerCount() const;
197 * @brief Retrieves the layer at a specified depth.
199 * @param[in] depth The depth
200 * @return The layer found at the given depth
201 * @pre Depth is less than layer count; see GetLayerCount().
203 Layer GetLayer(uint32_t depth) const;
206 * @brief Returns the Stage's Root Layer.
208 * @return The root layer
210 Layer GetRootLayer() const;
215 * @brief Sets the background color of the stage.
217 * @param[in] color The new background color
219 void SetBackgroundColor(Vector4 color);
222 * @brief Retrieves the background color of the stage.
224 * @return The background color
226 Vector4 GetBackgroundColor() const;
229 * @brief Retrieves the DPI of the display device to which the stage is connected.
231 * @return The horizontal and vertical DPI
233 Vector2 GetDpi() const;
236 * @brief Gets the Object registry.
238 * @return The object registry
240 ObjectRegistry GetObjectRegistry() const;
245 * @brief Keep rendering for at least the given amount of time.
247 * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
248 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
249 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
251 void KeepRendering( float durationSeconds );
256 * @brief This signal is emitted when key event is received.
258 * A callback of the following type may be connected:
260 * void YourCallbackName(const KeyEvent& event);
263 * @return The signal to connect to
265 KeyEventSignalType& KeyEventSignal();
268 * @brief This signal is emitted just after the event processing is finished.
270 * @return The signal to connect to
272 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
275 * @DEPRECATED_1_1.37 Use TouchSignal() instead.
276 * @brief This signal is emitted when the screen is touched and when the touch ends
277 * (i.e. the down & up touch events only).
279 * If there are multiple touch points, then this will be emitted when the first touch occurs and
280 * then when the last finger is lifted.
281 * An interrupted event will also be emitted (if it occurs).
282 * A callback of the following type may be connected:
284 * void YourCallbackName(const TouchEvent& event);
287 * @return The touch signal to connect to
288 * @note Motion events are not emitted.
290 TouchedSignalType& TouchedSignal() DALI_DEPRECATED_API;
293 * @brief This signal is emitted when the screen is touched and when the touch ends
294 * (i.e. the down & up touch events only).
296 * If there are multiple touch points, then this will be emitted when the first touch occurs and
297 * then when the last finger is lifted.
298 * An interrupted event will also be emitted (if it occurs).
299 * A callback of the following type may be connected:
301 * void YourCallbackName( TouchData event );
304 * @return The touch signal to connect to
305 * @note Motion events are not emitted.
307 TouchSignalType& TouchSignal();
310 * @brief This signal is emitted when wheel event is received.
312 * A callback of the following type may be connected:
314 * void YourCallbackName(const WheelEvent& event);
316 * @return The signal to connect to
318 WheelEventSignalType& WheelEventSignal();
321 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
323 * If the application is responsible for handling context loss, it should listen to
324 * this signal and tear down UI components when received.
325 * @return The context lost signal to connect to
327 ContextStatusSignal& ContextLostSignal();
330 * @brief This signal is emitted when the GL context is regained (Platform specific
333 * If the application is responsible for handling context loss, it should listen to
334 * this signal and rebuild UI components on receipt.
335 * @return The context regained signal to connect to
337 ContextStatusSignal& ContextRegainedSignal();
340 * @brief This signal is emitted after the initial scene is created.
342 * It will be triggered after the
343 * application init signal.
345 * A callback of the following type may be connected:
347 * void YourCallbackName();
349 * @return The signal to connect to
351 SceneCreatedSignalType& SceneCreatedSignal();
353 public: // Not intended for application developers
357 * @brief This constructor is used by Stage::GetCurrent() methods.
359 * @param[in] stage A pointer to a Dali resource
361 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
371 #endif // DALI_STAGE_H