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
52 * @brief The Stage is a top-level object used for displaying a tree of Actors.
54 * Stage is a top-level object that represents the entire screen.
55 * It is used for displaying a hierarchy of actors managed by the scene graph structure,
56 * which means an actor inherits a position relative to its parent,
57 * and can be moved in relation to this point.
59 * The stage instance is a singleton object (the only instance of its class during the
60 * lifetime of the program). You can get it using a static function.
62 * To display the contents of an actor, it must be added to a stage.
63 * The following example shows how to connect a new actor to the stage:
65 * Actor actor = Actor::New();
66 * Stage::GetCurrent().Add( actor );
69 * The stage has a 2D size that matches the size of the application window.
70 * The default unit 1 is 1 pixel with the default camera.
72 * Multiple stage/window support is not currently provided.
75 * | %Signal Name | Method |
76 * |-------------------------|--------------------------------------|
77 * | keyEvent | @ref KeyEventSignal() |
78 * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
79 * | touch | @ref TouchSignal() |
80 * | wheelEvent | @ref WheelEventSignal() |
81 * | contextLost | @ref ContextLostSignal() |
82 * | contextRegained | @ref ContextRegainedSignal() |
83 * | sceneCreated | @ref SceneCreatedSignal() |
86 class DALI_CORE_API Stage : public BaseHandle
90 typedef Signal< void (const KeyEvent&) > KeyEventSignalType; ///< Key event signal type @SINCE_1_0.0
91 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @SINCE_1_0.0
92 typedef Signal< void (const TouchEvent&) > TouchSignalType; ///< Touch signal type @SINCE_1_1.37
93 typedef Signal< void (const WheelEvent&) > WheelEventSignalType; ///< Wheel signal type @SINCE_1_0.0
94 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @SINCE_1_0.0
95 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @SINCE_1_0.0
97 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
98 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
101 * @brief Allows the creation of an empty stage handle.
103 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
108 * @brief Gets the current Stage.
110 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
112 static Stage GetCurrent();
115 * @brief Queries whether the Stage exists; this should only return false during or after destruction of Dali core.
117 * @return True when it's safe to call Stage::GetCurrent()
119 static bool IsInstalled();
124 * This is non-virtual since derived Handle types must not contain data or virtual methods.
129 * @brief This copy constructor is required for (smart) pointer semantics.
131 * @param[in] handle A reference to the copied handle
133 Stage(const Stage& handle);
136 * @brief This assignment operator is required for (smart) pointer semantics.
138 * @param[in] rhs A reference to the copied handle
139 * @return A reference to this
141 Stage& operator=(const Stage& rhs);
146 * @brief Adds a child Actor to the Stage.
148 * The child will be referenced.
149 * @param[in] actor The child
150 * @pre The actor has been initialized.
151 * @pre The actor does not have a parent.
153 void Add(Actor& actor);
156 * @brief Removes a child Actor from the Stage.
158 * The child will be unreferenced.
159 * @param[in] actor The child
160 * @pre The actor has been added to the stage.
162 void Remove(Actor& actor);
165 * @brief Returns the size of the Stage in pixels as a Vector.
167 * The x component will be the width of the Stage in pixels.
168 * The y component will be the height of the Stage in pixels.
169 * The z component will be the distance between far and near planes.
171 * @return The size of the Stage as a Vector
173 Vector2 GetSize() const;
178 * @brief Retrieves the list of render-tasks.
180 * @return A valid handle to a RenderTaskList
182 RenderTaskList GetRenderTaskList() const;
187 * @brief Queries the number of on-stage layers.
189 * Note that a default layer is always provided (count >= 1).
190 * @return The number of layers
192 uint32_t GetLayerCount() const;
195 * @brief Retrieves the layer at a specified depth.
197 * @param[in] depth The depth
198 * @return The layer found at the given depth
199 * @pre Depth is less than layer count; see GetLayerCount().
201 Layer GetLayer(uint32_t depth) const;
204 * @brief Returns the Stage's Root Layer.
206 * @return The root layer
208 Layer GetRootLayer() const;
213 * @brief Sets the background color of the stage.
215 * @param[in] color The new background color
217 void SetBackgroundColor(Vector4 color);
220 * @brief Retrieves the background color of the stage.
222 * @return The background color
224 Vector4 GetBackgroundColor() const;
227 * @brief Retrieves the DPI of the display device to which the stage is connected.
229 * @return The horizontal and vertical DPI
231 Vector2 GetDpi() const;
234 * @brief Gets the Object registry.
236 * @return The object registry
238 ObjectRegistry GetObjectRegistry() const;
243 * @brief Keep rendering for at least the given amount of time.
245 * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
246 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
247 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
249 void KeepRendering( float durationSeconds );
254 * @brief This signal is emitted when key event is received.
256 * A callback of the following type may be connected:
258 * 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 (if it occurs).
279 * A callback of the following type may be connected:
281 * void YourCallbackName( TouchEvent event );
284 * @return The touch signal to connect to
285 * @note Motion events are not emitted.
287 TouchSignalType& TouchSignal();
290 * @brief This signal is emitted when wheel event is received.
292 * A callback of the following type may be connected:
294 * void YourCallbackName(const WheelEvent& event);
296 * @return The signal to connect to
298 WheelEventSignalType& WheelEventSignal();
301 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
303 * If the application is responsible for handling context loss, it should listen to
304 * this signal and tear down UI components when received.
305 * @return The context lost signal to connect to
307 ContextStatusSignal& ContextLostSignal();
310 * @brief This signal is emitted when the GL context is regained (Platform specific
313 * If the application is responsible for handling context loss, it should listen to
314 * this signal and rebuild UI components on receipt.
315 * @return The context regained signal to connect to
317 ContextStatusSignal& ContextRegainedSignal();
320 * @brief This signal is emitted after the initial scene is created.
322 * It will be triggered after the
323 * application init signal.
325 * A callback of the following type may be connected:
327 * void YourCallbackName();
329 * @return The signal to connect to
331 SceneCreatedSignalType& SceneCreatedSignal();
333 public: // Not intended for application developers
337 * @brief This constructor is used by Stage::GetCurrent() methods.
339 * @param[in] stage A pointer to a Dali resource
341 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
351 #endif // DALI_STAGE_H