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
49 * @brief The Stage is a top-level object used for displaying a tree of Actors.
51 * Multiple stage/window support is not currently provided.
54 * | %Signal Name | Method |
55 * |-------------------------|--------------------------------------|
56 * | keyEvent | @ref KeyEventSignal() |
57 * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
58 * | touched | @ref TouchedSignal() |
59 * | wheelEvent | @ref WheelEventSignal() |
60 * | contextLost | @ref ContextLostSignal() |
61 * | contextRegained | @ref ContextRegainedSignal() |
62 * | sceneCreated | @ref SceneCreatedSignal() |
65 class DALI_IMPORT_API Stage : public BaseHandle
69 typedef Signal< void (const KeyEvent&)> KeyEventSignalType; ///< Key event signal type @SINCE_1_0.0
70 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @SINCE_1_0.0
71 typedef Signal< void (const TouchEvent&)> TouchedSignalType; ///< Touched signal type @SINCE_1_0.0
72 typedef Signal< void (const WheelEvent&)> WheelEventSignalType; ///< Touched signal type @SINCE_1_0.0
73 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @SINCE_1_0.0
74 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @SINCE_1_0.0
76 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
77 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
80 * @brief Allows the creation of an empty stage handle.
82 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
88 * @brief Get the current Stage.
91 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed.
93 static Stage GetCurrent();
96 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
99 * @return True when it's safe to call Stage::GetCurrent().
101 static bool IsInstalled();
106 * This is non-virtual since derived Handle types must not contain data or virtual methods.
112 * @brief This copy constructor is required for (smart) pointer semantics.
115 * @param [in] handle A reference to the copied handle
117 Stage(const Stage& handle);
120 * @brief This assignment operator is required for (smart) pointer semantics.
123 * @param [in] rhs A reference to the copied handle
124 * @return A reference to this
126 Stage& operator=(const Stage& rhs);
131 * @brief Adds a child Actor to the Stage.
133 * The child will be referenced.
135 * @param [in] actor The child.
136 * @pre The actor has been initialized.
137 * @pre The actor does not have a parent.
139 void Add(Actor& actor);
142 * @brief Removes a child Actor from the Stage.
144 * The child will be unreferenced.
146 * @param [in] actor The child.
147 * @pre The actor has been added to the stage.
149 void Remove(Actor& actor);
152 * @brief Returns the size of the Stage in pixels as a Vector.
154 * The x component will be the width of the Stage in pixels
155 * The y component will be the height of the Stage in pixels
156 * The z component will be the distance between far and near planes
158 * @return The size of the Stage as a Vector.
160 Vector2 GetSize() const;
165 * @brief Retrieve the list of render-tasks.
168 * @return A valid handle to a RenderTaskList.
170 RenderTaskList GetRenderTaskList() const;
175 * @brief Query the number of on-stage layers.
177 * Note that a default layer is always provided (count >= 1).
179 * @return The number of layers.
181 unsigned int GetLayerCount() const;
184 * @brief Retrieve the layer at a specified depth.
187 * @param[in] depth The depth.
188 * @return The layer found at the given depth.
189 * @pre Depth is less than layer count; see GetLayerCount().
191 Layer GetLayer(unsigned int depth) const;
194 * @brief Returns the Stage's Root Layer.
197 * @return The root layer.
199 Layer GetRootLayer() const;
204 * @brief Set the background color of the stage.
207 * @param[in] color The new background color.
209 void SetBackgroundColor(Vector4 color);
212 * @brief Retrieve the background color of the stage.
215 * @return The background color.
217 Vector4 GetBackgroundColor() const;
220 * @brief Retrieve the DPI of the display device to which the stage is connected.
223 * @return The horizontal and vertical DPI
225 Vector2 GetDpi() const;
228 * @brief Get the Object registry.
231 * @return The object registry.
233 ObjectRegistry GetObjectRegistry() const;
238 * @brief Keep rendering for at least the given amount of time.
240 * By default Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
241 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
243 * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
245 void KeepRendering( float durationSeconds );
250 * @brief This signal is emitted when key event is received.
252 * A callback of the following type may be connected:
254 * void YourCallbackName(const KeyEvent& event);
257 * @return The signal to connect to.
259 KeyEventSignalType& KeyEventSignal();
262 * @brief This signal is emitted just after the event processing is finished.
265 * @return The signal to connect to.
267 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
270 * @brief This signal is emitted when the screen is touched and when the touch ends
271 * (i.e. the down & up touch events only).
273 * If there are multiple touch points, then this will be emitted when the first touch occurs and
274 * then when the last finger is lifted.
275 * An interrupted event will also be emitted.
276 * A callback of the following type may be connected:
278 * void YourCallbackName(const TouchEvent& event);
282 * @return The touch signal to connect to.
283 * @note Motion events are not emitted.
285 TouchedSignalType& TouchedSignal();
288 * @brief This signal is emitted when wheel event is received.
290 * A callback of the following type may be connected:
292 * void YourCallbackName(const WheelEvent& event);
295 * @return The signal to connect to.
297 WheelEventSignalType& WheelEventSignal();
300 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
302 * If the application is responsible for handling context loss, it should listen to
303 * this signal and tear down UI components when recieved.
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.
316 * @return The context regained signal to connect to.
318 ContextStatusSignal& ContextRegainedSignal();
321 * @brief This signal is emitted after the initial scene is created.
323 * It will be triggered after the
324 * application init signal.
326 * A callback of the following type may be connected:
328 * void YourCallbackName();
331 * @return The signal to connect to.
333 SceneCreatedSignalType& SceneCreatedSignal();
335 public: // Not intended for application developers
338 * @brief This constructor is used by Stage::GetCurrent() methods.
341 * @param [in] stage A pointer to a Dali resource
343 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
352 #endif // __DALI_STAGE_H__