5 * Copyright (c) 2020 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.
25 #include <dali/public-api/object/handle.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector4.h>
28 #include <dali/public-api/common/vector-wrapper.h>
40 namespace Internal DALI_INTERNAL
53 * Scene creates a "world" that can be bound to a surface for rendering.
56 class DALI_CORE_API Scene : public BaseHandle
59 typedef Signal< void () > EventProcessingFinishedSignalType; ///< Event Processing finished signal type
60 typedef Signal< void (const Dali::KeyEvent&) > KeyEventSignalType; ///< Key event signal type
61 typedef Signal< bool (const Dali::KeyEvent&) > KeyEventGeneratedSignalType; ///< key event generated signal type
62 typedef Signal< void (const Dali::TouchData&) > TouchSignalType; ///< Touch signal type
63 typedef Signal< void (const Dali::WheelEvent&) > WheelEventSignalType; ///< Touched signal type
65 using FrameCallbackContainer = std::vector< std::pair< std::unique_ptr< CallbackBase >, int32_t > >;
68 * @brief Create an initialized Scene handle.
70 * @param[in] size The size of the set surface for this scene
72 * @return a handle to a newly allocated Dali resource.
74 static Scene New( Size size );
77 * @brief Downcast an Object handle to Scene handle.
79 * If handle points to a Scene object the downcast produces
80 * valid handle. If not the returned handle is left uninitialized.
81 * @param[in] handle to An object
82 * @return handle to a Scene object or an uninitialized handle
84 static Scene DownCast( BaseHandle handle );
87 * @brief Create an uninitialized Scene handle.
89 * This can be initialized with Scene::New(). Calling member
90 * functions with an uninitialized Dali::Object is not allowed.
97 * 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.
104 * @param [in] handle A reference to the copied handle
106 Scene(const Scene& handle);
109 * @brief This assignment operator is required for (smart) pointer semantics.
111 * @param [in] rhs A reference to the copied handle
112 * @return A reference to this
114 Scene& operator=(const Scene& rhs);
117 * @brief Adds a child Actor to the Scene.
119 * The child will be referenced.
120 * @param[in] actor The child
121 * @pre The actor has been initialized.
122 * @pre The actor does not have a parent.
124 void Add(Actor actor);
127 * @brief Removes a child Actor from the Scene.
129 * The child will be unreferenced.
130 * @param[in] actor The child
131 * @pre The actor has been added to the stage.
133 void Remove(Actor actor);
136 * @brief Returns the size of the Scene in pixels as a Vector.
138 * The x component will be the width of the Scene in pixels.
139 * The y component will be the height of the Scene in pixels.
141 * @return The size of the Scene as a Vector
143 Size GetSize() const;
146 * Sets horizontal and vertical pixels per inch value that is used by the display
147 * @param[in] dpi Horizontal and vertical dpi value
149 void SetDpi( Vector2 dpi );
152 * @brief Retrieves the DPI of the display device to which the scene is connected.
154 * @return The horizontal and vertical DPI
156 Vector2 GetDpi() const;
159 * @brief Sets the background color.
161 * @param[in] color The new background color
163 void SetBackgroundColor( const Vector4& color );
166 * @brief Gets the background color of the render surface.
168 * @return The background color
170 Vector4 GetBackgroundColor() const;
173 * @brief Retrieves the list of render-tasks.
175 * @return A valid handle to a RenderTaskList
177 Dali::RenderTaskList GetRenderTaskList() const;
180 * @brief Returns the Scene's Root Layer.
182 * @return The root layer
184 Layer GetRootLayer() const;
187 * @brief Queries the number of on-stage layers.
189 * Note that a default layer is always provided (count >= 1).
190 * @return The number of layers
192 uint32_t GetLayerCount() const;
195 * @brief Retrieves the layer at a specified depth.
197 * @param[in] depth The depth
198 * @return The layer found at the given depth
199 * @pre Depth is less than layer count; see GetLayerCount().
201 Layer GetLayer( uint32_t depth ) const;
204 * @brief Informs the scene that the set surface has been resized.
206 * @param[in] width The new width of the set surface
207 * @param[in] height The new height of the set surface
208 * @param[in] orientation The orientation of the surface
209 * @param[in] forceUpdate The flag to update force
211 void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
214 * @brief Informs the scene that the surface has been replaced.
216 void SurfaceReplaced();
219 * @brief Discards this Scene from the Core.
224 * @brief Retrieve the Scene that the given actor belongs to.
227 static Integration::Scene Get( Actor actor );
230 * This function is called when an event is queued.
231 * @param[in] event A event to queue.
233 void QueueEvent( const Integration::Event& event );
236 * This function is called by Core when events are processed.
238 void ProcessEvents();
241 * @brief Adds a callback that is called when the frame rendering is done by the graphics driver.
243 * @param[in] callback The function to call
244 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
246 * @note A callback of the following type may be used:
248 * void MyFunction( int frameId );
250 * This callback will be deleted once it is called.
252 * @note Ownership of the callback is passed onto this class.
254 void AddFrameRenderedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
257 * @brief Adds a callback that is called when the frame is displayed on the display.
259 * @param[in] callback The function to call
260 * @param[in] frameId The Id to specify the frame. It will be passed when the callback is called.
262 * @note A callback of the following type may be used:
264 * void MyFunction( int frameId );
266 * This callback will be deleted once it is called.
268 * @note Ownership of the callback is passed onto this class.
270 void AddFramePresentedCallback( std::unique_ptr< CallbackBase > callback, int32_t frameId );
273 * @brief Gets the callback list that is called when the frame rendering is done by the graphics driver.
275 * @param[out] callbacks The callback list
277 * @note This is called in the update thread.
279 void GetFrameRenderedCallback( FrameCallbackContainer& callbacks );
282 * @brief Gets the callback list that is called when the frame is displayed on the display.
284 * @param[out] callbacks The callback list
286 * @note This is called in the update thread.
288 void GetFramePresentedCallback( FrameCallbackContainer& callbacks );
291 * @brief This signal is emitted just after the event processing is finished.
293 * @return The signal to connect to
295 EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
298 * @brief This signal is emitted when key event is received.
300 * A callback of the following type may be connected:
302 * void YourCallbackName(const KeyEvent& event);
304 * @return The signal to connect to
306 KeyEventSignalType& KeyEventSignal();
309 * @brief The user would connect to this signal to get a KeyEvent when KeyEvent is generated.
311 * If the control already consumed key event, KeyEventProcessor do not need to Emit keyEvent.
312 * Therefore, KeyinputManager first checks whether KeyEvent is generated as KeyEventGeneratedSignal.
313 * After that keyEventProcessor must invoke KeyEvent only if KeyEventGeneratedSignal () is not consumed.
315 * A callback of the following type may be connected:
317 * bool YourCallbackName(const KeyEvent& event);
320 * @return The return is true if KeyEvent is consumed, otherwise false.
322 KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
325 * @brief This signal is emitted when the screen is touched and when the touch ends
326 * (i.e. the down & up touch events only).
328 * If there are multiple touch points, then this will be emitted when the first touch occurs and
329 * then when the last finger is lifted.
330 * An interrupted event will also be emitted (if it occurs).
331 * A callback of the following type may be connected:
333 * void YourCallbackName( TouchData event );
336 * @return The touch signal to connect to
337 * @note Motion events are not emitted.
339 TouchSignalType& TouchSignal();
342 * @brief This signal is emitted when wheel event is received.
344 * A callback of the following type may be connected:
346 * void YourCallbackName(const WheelEvent& event);
348 * @return The signal to connect to
350 WheelEventSignalType& WheelEventSignal();
352 public: // Not intended for application developers
355 * @brief This constructor is used by Dali::New() methods.
357 * @param[in] scene A pointer to an internal Scene resource
359 explicit DALI_INTERNAL Scene(Internal::Scene* scene);
362 } // namespace Integration
366 #endif // DALI_SCENE_H