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.
55 class DALI_IMPORT_API Stage : public BaseHandle
59 typedef Signal< void (const KeyEvent&)> KeyEventSignalType; ///< Key event signal type @since_tizen 2.4
60 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type @since_tizen 2.4
61 typedef Signal< void (const TouchEvent&)> TouchedSignalType; ///< Touched signal type @since_tizen 2.4
62 typedef Signal< void (const WheelEvent&)> WheelEventSignalType; ///< Touched signal type @since_tizen 2.4
63 typedef Signal< void () > ContextStatusSignal; ///< Context status signal type @since_tizen 2.4
64 typedef Signal< void () > SceneCreatedSignalType; ///< Scene created signal type @since_tizen 2.4
66 static const Vector4 DEFAULT_BACKGROUND_COLOR; ///< Default black background.
67 static const Vector4 DEBUG_BACKGROUND_COLOR; ///< Green background, useful when debugging.
70 * @brief Allows the creation of an empty stage handle.
72 * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
78 * @brief Get the current Stage.
81 * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed.
83 static Stage GetCurrent();
86 * @brief Query whether the Stage exists; this should only return false during or after destruction of Dali core.
89 * @return True when it's safe to call Stage::GetCurrent().
91 static bool IsInstalled();
96 * This is non-virtual since derived Handle types must not contain data or virtual methods.
102 * @brief This copy constructor is required for (smart) pointer semantics.
105 * @param [in] handle A reference to the copied handle
107 Stage(const Stage& handle);
110 * @brief This assignment operator is required for (smart) pointer semantics.
113 * @param [in] rhs A reference to the copied handle
114 * @return A reference to this
116 Stage& operator=(const Stage& rhs);
121 * @brief Adds a child Actor to the Stage.
123 * The child will be referenced.
125 * @param [in] actor The child.
126 * @pre The actor has been initialized.
127 * @pre The actor does not have a parent.
129 void Add(Actor& actor);
132 * @brief Removes a child Actor from the Stage.
134 * The child will be unreferenced.
136 * @param [in] actor The child.
137 * @pre The actor has been added to the stage.
139 void Remove(Actor& actor);
142 * @brief Returns the size of the Stage in pixels as a Vector.
144 * The x component will be the width of the Stage in pixels
145 * The y component will be the height of the Stage in pixels
146 * The z component will be the distance between far and near planes
148 * @return The size of the Stage as a Vector.
150 Vector2 GetSize() const;
155 * @brief Retrieve the list of render-tasks.
158 * @return A valid handle to a RenderTaskList.
160 RenderTaskList GetRenderTaskList() const;
165 * @brief Query the number of on-stage layers.
167 * Note that a default layer is always provided (count >= 1).
169 * @return The number of layers.
171 unsigned int GetLayerCount() const;
174 * @brief Retrieve the layer at a specified depth.
177 * @param[in] depth The depth.
178 * @return The layer found at the given depth.
179 * @pre Depth is less than layer count; see GetLayerCount().
181 Layer GetLayer(unsigned int depth) const;
184 * @brief Returns the Stage's Root Layer.
187 * @return The root layer.
189 Layer GetRootLayer() const;
194 * @brief Set the background color of the stage.
197 * @param[in] color The new background color.
199 void SetBackgroundColor(Vector4 color);
202 * @brief Retrieve the background color of the stage.
205 * @return The background color.
207 Vector4 GetBackgroundColor() const;
210 * @brief Retrieve the DPI of the display device to which the stage is connected.
213 * @return The horizontal and vertical DPI
215 Vector2 GetDpi() const;
218 * @brief Get the Object registry.
221 * @return The object registry.
223 ObjectRegistry GetObjectRegistry() const;
228 * @brief Keep rendering for at least the given amount of time.
230 * By default Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
231 * This method is useful to force screen refreshes e.g. when updating a NativeImage.
233 * @param[i] durationSeconds Time to keep rendering, 0 means render at least one more frame
235 void KeepRendering( float durationSeconds );
240 * @brief This signal is emitted when key event is received.
242 * A callback of the following type may be connected:
244 * void YourCallbackName(const KeyEvent& event);
247 * @return The signal to connect to.
249 KeyEventSignalType& KeyEventSignal();
252 * @brief This signal is emitted just after the event processing is finished.
255 * @return The signal to connect to.
257 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
260 * @brief This signal is emitted when the screen is touched and when the touch ends
261 * (i.e. the down & up touch events only).
263 * If there are multiple touch points, then this will be emitted when the first touch occurs and
264 * then when the last finger is lifted.
265 * An interrupted event will also be emitted.
266 * A callback of the following type may be connected:
268 * void YourCallbackName(const TouchEvent& event);
272 * @return The touch signal to connect to.
273 * @note Motion events are not emitted.
275 TouchedSignalType& TouchedSignal();
278 * @brief This signal is emitted when wheel event is received.
280 * A callback of the following type may be connected:
282 * void YourCallbackName(const WheelEvent& event);
285 * @return The signal to connect to.
287 WheelEventSignalType& WheelEventSignal();
290 * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
292 * If the application is responsible for handling context loss, it should listen to
293 * this signal and tear down UI components when recieved.
295 * @return The context lost signal to connect to.
297 ContextStatusSignal& ContextLostSignal();
300 * @brief This signal is emitted when the GL context is regained (Platform specific
303 * If the application is responsible for handling context loss, it should listen to
304 * this signal and rebuild UI components on receipt.
306 * @return The context regained signal to connect to.
308 ContextStatusSignal& ContextRegainedSignal();
311 * @brief This signal is emitted after the initial scene is created.
313 * It will be triggered after the
314 * application init signal.
316 * A callback of the following type may be connected:
318 * void YourCallbackName();
321 * @return The signal to connect to.
323 SceneCreatedSignalType& SceneCreatedSignal();
325 public: // Not intended for application developers
328 * @brief This constructor is used by Stage::GetCurrent() methods.
331 * @param [in] stage A pointer to a Dali resource
333 explicit DALI_INTERNAL Stage(Internal::Stage* stage);
342 #endif // __DALI_STAGE_H__