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 * @addtogroup dali_core_common
32 namespace Internal DALI_INTERNAL
50 * @brief The Stage is a top-level object used for displaying a tree of Actors.
52 * Stage is a top-level object that represents the entire screen.
53 * It is used for displaying a hierarchy of actors managed by the scene graph structure,
54 * which means an actor inherits a position relative to its parent,
55 * and can be moved in relation to this point.
57 * The stage instance is a singleton object (the only instance of its class during the
58 * lifetime of the program). You can get it using a static function.
60 * To display the contents of an actor, it must be added to a stage.
61 * The following example shows how to connect a new actor to the stage:
63 * Actor actor = Actor::New();
64 * Stage::GetCurrent().Add( actor );
67 * The stage has a 2D size that matches the size of the application window.
68 * The default unit 1 is 1 pixel with the default camera.
70 * Multiple stage/window support is not currently provided.
73 * | %Signal Name | Method |
74 * |-------------------------|--------------------------------------|
75 * | keyEvent | @ref KeyEventSignal() |
76 * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
77 * | touched | @ref TouchedSignal() |
78 * | wheelEvent | @ref WheelEventSignal() |
79 * | contextLost | @ref ContextLostSignal() |
80 * | contextRegained | @ref ContextRegainedSignal() |
81 * | sceneCreated | @ref SceneCreatedSignal() |
84 class DALI_IMPORT_API Stage : public BaseHandle
88 typedef Signal< void (const KeyEvent&) > KeyEventSignalType; ///< Key event signal type @SINCE_1_0.0
89 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @SINCE_1_0.0
90 typedef Signal< void (const TouchEvent&) > TouchedSignalType; ///< @DEPRECATED_1_1.37 @brief Touched signal type @SINCE_1_0.0
91 typedef Signal< void (const TouchData&) > TouchSignalType; ///< Touch signal type @SINCE_1_1.37
92 typedef Signal< void (const WheelEvent&) > WheelEventSignalType; ///< Touched signal type @SINCE_1_0.0
93 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @SINCE_1_0.0
94 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @SINCE_1_0.0
96 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
97 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
100 * @brief Allows the creation of an empty stage handle.
102 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
108 * @brief Gets the current Stage.
111 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
113 static Stage GetCurrent();
116 * @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.
132 * @brief This copy constructor is required for (smart) pointer semantics.
135 * @param[in] handle A reference to the copied handle
137 Stage(const Stage& handle);
140 * @brief This assignment operator is required for (smart) pointer semantics.
143 * @param[in] rhs A reference to the copied handle
144 * @return A reference to this
146 Stage& operator=(const Stage& rhs);
151 * @brief Adds a child Actor to the Stage.
153 * The child will be referenced.
155 * @param[in] actor The child
156 * @pre The actor has been initialized.
157 * @pre The actor does not have a parent.
159 void Add(Actor& actor);
162 * @brief Removes a child Actor from the Stage.
164 * The child will be unreferenced.
166 * @param[in] actor The child
167 * @pre The actor has been added to the stage.
169 void Remove(Actor& actor);
172 * @brief Returns the size of the Stage in pixels as a Vector.
174 * The x component will be the width of the Stage in pixels.
175 * The y component will be the height of the Stage in pixels.
176 * The z component will be the distance between far and near planes.
178 * @return The size of the Stage as a Vector
180 Vector2 GetSize() const;
185 * @brief Retrieves the list of render-tasks.
188 * @return A valid handle to a RenderTaskList
190 RenderTaskList GetRenderTaskList() const;
195 * @brief Queries the number of on-stage layers.
197 * Note that a default layer is always provided (count >= 1).
199 * @return The number of layers
201 unsigned int GetLayerCount() const;
204 * @brief Retrieves the layer at a specified depth.
207 * @param[in] depth The depth
208 * @return The layer found at the given depth
209 * @pre Depth is less than layer count; see GetLayerCount().
211 Layer GetLayer(unsigned int depth) const;
214 * @brief Returns the Stage's Root Layer.
217 * @return The root layer
219 Layer GetRootLayer() const;
224 * @brief Sets the background color of the stage.
227 * @param[in] color The new background color
229 void SetBackgroundColor(Vector4 color);
232 * @brief Retrieves the background color of the stage.
235 * @return The background color
237 Vector4 GetBackgroundColor() const;
240 * @brief Retrieves the DPI of the display device to which the stage is connected.
243 * @return The horizontal and vertical DPI
245 Vector2 GetDpi() const;
248 * @brief Gets the Object registry.
251 * @return The object registry
253 ObjectRegistry GetObjectRegistry() const;
258 * @brief Keep rendering for at least the given amount of time.
260 * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
261 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
263 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
265 void KeepRendering( float durationSeconds );
270 * @brief This signal is emitted when key event is received.
272 * A callback of the following type may be connected:
274 * void YourCallbackName(const KeyEvent& event);
277 * @return The signal to connect to
279 KeyEventSignalType& KeyEventSignal();
282 * @brief This signal is emitted just after the event processing is finished.
285 * @return The signal to connect to
287 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
290 * @DEPRECATED_1_1.37 Use TouchSignal() instead.
291 * @brief This signal is emitted when the screen is touched and when the touch ends
292 * (i.e. the down & up touch events only).
294 * If there are multiple touch points, then this will be emitted when the first touch occurs and
295 * then when the last finger is lifted.
296 * An interrupted event will also be emitted (if it occurs).
297 * A callback of the following type may be connected:
299 * void YourCallbackName(const TouchEvent& event);
303 * @return The touch signal to connect to
304 * @note Motion events are not emitted.
306 TouchedSignalType& TouchedSignal() DALI_DEPRECATED_API;
309 * @brief This signal is emitted when the screen is touched and when the touch ends
310 * (i.e. the down & up touch events only).
312 * If there are multiple touch points, then this will be emitted when the first touch occurs and
313 * then when the last finger is lifted.
314 * An interrupted event will also be emitted (if it occurs).
315 * A callback of the following type may be connected:
317 * void YourCallbackName( TouchData event );
321 * @return The touch signal to connect to
322 * @note Motion events are not emitted.
324 TouchSignalType& TouchSignal();
327 * @brief This signal is emitted when wheel event is received.
329 * A callback of the following type may be connected:
331 * void YourCallbackName(const WheelEvent& event);
334 * @return The signal to connect to
336 WheelEventSignalType& WheelEventSignal();
339 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
341 * If the application is responsible for handling context loss, it should listen to
342 * this signal and tear down UI components when received.
344 * @return The context lost signal to connect to
346 ContextStatusSignal& ContextLostSignal();
349 * @brief This signal is emitted when the GL context is regained (Platform specific
352 * If the application is responsible for handling context loss, it should listen to
353 * this signal and rebuild UI components on receipt.
355 * @return The context regained signal to connect to
357 ContextStatusSignal& ContextRegainedSignal();
360 * @brief This signal is emitted after the initial scene is created.
362 * It will be triggered after the
363 * application init signal.
365 * A callback of the following type may be connected:
367 * void YourCallbackName();
370 * @return The signal to connect to
372 SceneCreatedSignalType& SceneCreatedSignal();
374 public: // Not intended for application developers
378 * @brief This constructor is used by Stage::GetCurrent() methods.
381 * @param[in] stage A pointer to a Dali resource
383 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
393 #endif // __DALI_STAGE_H__