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 * Multiple stage/window support is not currently provided.
55 * | %Signal Name | Method |
56 * |-------------------------|--------------------------------------|
57 * | keyEvent | @ref KeyEventSignal() |
58 * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
59 * | touched | @ref TouchedSignal() |
60 * | wheelEvent | @ref WheelEventSignal() |
61 * | contextLost | @ref ContextLostSignal() |
62 * | contextRegained | @ref ContextRegainedSignal() |
63 * | sceneCreated | @ref SceneCreatedSignal() |
66 class DALI_IMPORT_API Stage : public BaseHandle
70 typedef Signal< void (const KeyEvent&) > KeyEventSignalType; ///< Key event signal type @SINCE_1_0.0
71 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @SINCE_1_0.0
72 typedef Signal< void (const TouchEvent&) > TouchedSignalType; ///< @DEPRECATED_1_1.37 @brief Touched signal type @SINCE_1_0.0
73 typedef Signal< void (const TouchData&) > TouchSignalType; ///< Touch signal type @SINCE_1_1.37
74 typedef Signal< void (const WheelEvent&) > WheelEventSignalType; ///< Touched signal type @SINCE_1_0.0
75 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @SINCE_1_0.0
76 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @SINCE_1_0.0
78 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
79 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
82 * @brief Allows the creation of an empty stage handle.
84 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
90 * @brief Get the current Stage.
93 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed.
95 static Stage GetCurrent();
98 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
101 * @return True when it's safe to call Stage::GetCurrent().
103 static bool IsInstalled();
108 * This is non-virtual since derived Handle types must not contain data or virtual methods.
114 * @brief This copy constructor is required for (smart) pointer semantics.
117 * @param [in] handle A reference to the copied handle
119 Stage(const Stage& handle);
122 * @brief This assignment operator is required for (smart) pointer semantics.
125 * @param [in] rhs A reference to the copied handle
126 * @return A reference to this
128 Stage& operator=(const Stage& rhs);
133 * @brief Adds a child Actor to the Stage.
135 * The child will be referenced.
137 * @param [in] actor The child.
138 * @pre The actor has been initialized.
139 * @pre The actor does not have a parent.
141 void Add(Actor& actor);
144 * @brief Removes a child Actor from the Stage.
146 * The child will be unreferenced.
148 * @param [in] actor The child.
149 * @pre The actor has been added to the stage.
151 void Remove(Actor& actor);
154 * @brief Returns the size of the Stage in pixels as a Vector.
156 * The x component will be the width of the Stage in pixels
157 * The y component will be the height of the Stage in pixels
158 * The z component will be the distance between far and near planes
160 * @return The size of the Stage as a Vector.
162 Vector2 GetSize() const;
167 * @brief Retrieve the list of render-tasks.
170 * @return A valid handle to a RenderTaskList.
172 RenderTaskList GetRenderTaskList() const;
177 * @brief Query the number of on-stage layers.
179 * Note that a default layer is always provided (count >= 1).
181 * @return The number of layers.
183 unsigned int GetLayerCount() const;
186 * @brief Retrieve the layer at a specified depth.
189 * @param[in] depth The depth.
190 * @return The layer found at the given depth.
191 * @pre Depth is less than layer count; see GetLayerCount().
193 Layer GetLayer(unsigned int depth) const;
196 * @brief Returns the Stage's Root Layer.
199 * @return The root layer.
201 Layer GetRootLayer() const;
206 * @brief Set the background color of the stage.
209 * @param[in] color The new background color.
211 void SetBackgroundColor(Vector4 color);
214 * @brief Retrieve the background color of the stage.
217 * @return The background color.
219 Vector4 GetBackgroundColor() const;
222 * @brief Retrieve the DPI of the display device to which the stage is connected.
225 * @return The horizontal and vertical DPI
227 Vector2 GetDpi() const;
230 * @brief Get the Object registry.
233 * @return The object registry.
235 ObjectRegistry GetObjectRegistry() const;
240 * @brief Keep rendering for at least the given amount of time.
242 * By default Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
243 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
245 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
247 void KeepRendering( float durationSeconds );
252 * @brief This signal is emitted when key event is received.
254 * A callback of the following type may be connected:
256 * void YourCallbackName(const KeyEvent& event);
259 * @return The signal to connect to.
261 KeyEventSignalType& KeyEventSignal();
264 * @brief This signal is emitted just after the event processing is finished.
267 * @return The signal to connect to.
269 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
272 * @DEPRECATED_1_1.37 Use TouchSignal() instead.
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(const TouchEvent& event);
285 * @return The touch signal to connect to.
286 * @note Motion events are not emitted.
288 TouchedSignalType& TouchedSignal();
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( TouchData event );
303 * @return The touch signal to connect to.
304 * @note Motion events are not emitted.
306 TouchSignalType& TouchSignal();
309 * @brief This signal is emitted when wheel event is received.
311 * A callback of the following type may be connected:
313 * 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 recieved.
326 * @return The context lost signal to connect to.
328 ContextStatusSignal& ContextLostSignal();
331 * @brief This signal is emitted when the GL context is regained (Platform specific
334 * If the application is responsible for handling context loss, it should listen to
335 * this signal and rebuild UI components on receipt.
337 * @return The context regained signal to connect to.
339 ContextStatusSignal& ContextRegainedSignal();
342 * @brief This signal is emitted after the initial scene is created.
344 * It will be triggered after the
345 * application init signal.
347 * A callback of the following type may be connected:
349 * void YourCallbackName();
352 * @return The signal to connect to.
354 SceneCreatedSignalType& SceneCreatedSignal();
356 public: // Not intended for application developers
359 * @brief This constructor is used by Stage::GetCurrent() methods.
362 * @param [in] stage A pointer to a Dali resource
364 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
373 #endif // __DALI_STAGE_H__