1 #ifndef __DALI_STAGE_H__
2 #define __DALI_STAGE_H__
5 * Copyright (c) 2018 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().
111 * @brief Gets the current Stage.
114 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
116 static Stage GetCurrent();
119 * @brief Queries whether the Stage exists; this should only return false during or after destruction of Dali core.
122 * @return True when it's safe to call Stage::GetCurrent()
124 static bool IsInstalled();
129 * This is non-virtual since derived Handle types must not contain data or virtual methods.
135 * @brief This copy constructor is required for (smart) pointer semantics.
138 * @param[in] handle A reference to the copied handle
140 Stage(const Stage& handle);
143 * @brief This assignment operator is required for (smart) pointer semantics.
146 * @param[in] rhs A reference to the copied handle
147 * @return A reference to this
149 Stage& operator=(const Stage& rhs);
154 * @brief Adds a child Actor to the Stage.
156 * The child will be referenced.
158 * @param[in] actor The child
159 * @pre The actor has been initialized.
160 * @pre The actor does not have a parent.
162 void Add(Actor& actor);
165 * @brief Removes a child Actor from the Stage.
167 * The child will be unreferenced.
169 * @param[in] actor The child
170 * @pre The actor has been added to the stage.
172 void Remove(Actor& actor);
175 * @brief Returns the size of the Stage in pixels as a Vector.
177 * The x component will be the width of the Stage in pixels.
178 * The y component will be the height of the Stage in pixels.
179 * The z component will be the distance between far and near planes.
181 * @return The size of the Stage as a Vector
183 Vector2 GetSize() const;
188 * @brief Retrieves the list of render-tasks.
191 * @return A valid handle to a RenderTaskList
193 RenderTaskList GetRenderTaskList() const;
198 * @brief Queries the number of on-stage layers.
200 * Note that a default layer is always provided (count >= 1).
202 * @return The number of layers
204 uint32_t GetLayerCount() const;
207 * @brief Retrieves the layer at a specified depth.
210 * @param[in] depth The depth
211 * @return The layer found at the given depth
212 * @pre Depth is less than layer count; see GetLayerCount().
214 Layer GetLayer(uint32_t depth) const;
217 * @brief Returns the Stage's Root Layer.
220 * @return The root layer
222 Layer GetRootLayer() const;
227 * @brief Sets the background color of the stage.
230 * @param[in] color The new background color
232 void SetBackgroundColor(Vector4 color);
235 * @brief Retrieves the background color of the stage.
238 * @return The background color
240 Vector4 GetBackgroundColor() const;
243 * @brief Retrieves the DPI of the display device to which the stage is connected.
246 * @return The horizontal and vertical DPI
248 Vector2 GetDpi() const;
251 * @brief Gets the Object registry.
254 * @return The object registry
256 ObjectRegistry GetObjectRegistry() const;
261 * @brief Keep rendering for at least the given amount of time.
263 * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
264 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
266 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
268 void KeepRendering( float durationSeconds );
273 * @brief This signal is emitted when key event is received.
275 * A callback of the following type may be connected:
277 * void YourCallbackName(const KeyEvent& event);
280 * @return The signal to connect to
282 KeyEventSignalType& KeyEventSignal();
285 * @brief This signal is emitted just after the event processing is finished.
288 * @return The signal to connect to
290 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
293 * @DEPRECATED_1_1.37 Use TouchSignal() instead.
294 * @brief This signal is emitted when the screen is touched and when the touch ends
295 * (i.e. the down & up touch events only).
297 * If there are multiple touch points, then this will be emitted when the first touch occurs and
298 * then when the last finger is lifted.
299 * An interrupted event will also be emitted (if it occurs).
300 * A callback of the following type may be connected:
302 * void YourCallbackName(const TouchEvent& event);
306 * @return The touch signal to connect to
307 * @note Motion events are not emitted.
309 TouchedSignalType& TouchedSignal() DALI_DEPRECATED_API;
312 * @brief This signal is emitted when the screen is touched and when the touch ends
313 * (i.e. the down & up touch events only).
315 * If there are multiple touch points, then this will be emitted when the first touch occurs and
316 * then when the last finger is lifted.
317 * An interrupted event will also be emitted (if it occurs).
318 * A callback of the following type may be connected:
320 * void YourCallbackName( TouchData event );
324 * @return The touch signal to connect to
325 * @note Motion events are not emitted.
327 TouchSignalType& TouchSignal();
330 * @brief This signal is emitted when wheel event is received.
332 * A callback of the following type may be connected:
334 * void YourCallbackName(const WheelEvent& event);
337 * @return The signal to connect to
339 WheelEventSignalType& WheelEventSignal();
342 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
344 * If the application is responsible for handling context loss, it should listen to
345 * this signal and tear down UI components when received.
347 * @return The context lost signal to connect to
349 ContextStatusSignal& ContextLostSignal();
352 * @brief This signal is emitted when the GL context is regained (Platform specific
355 * If the application is responsible for handling context loss, it should listen to
356 * this signal and rebuild UI components on receipt.
358 * @return The context regained signal to connect to
360 ContextStatusSignal& ContextRegainedSignal();
363 * @brief This signal is emitted after the initial scene is created.
365 * It will be triggered after the
366 * application init signal.
368 * A callback of the following type may be connected:
370 * void YourCallbackName();
373 * @return The signal to connect to
375 SceneCreatedSignalType& SceneCreatedSignal();
377 public: // Not intended for application developers
381 * @brief This constructor is used by Stage::GetCurrent() methods.
384 * @param[in] stage A pointer to a Dali resource
386 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
396 #endif // __DALI_STAGE_H__