1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
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.
22 #include <dali/integration-api/scene.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/actors/layer.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/events/event-processor.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
56 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
57 using ScenePtr = IntrusivePtr<Scene>;
60 * @brief Scene creates a "world" that can be bound to a surface for rendering.
62 class Scene : public BaseObject, public RenderTaskDefaults
67 * @copydoc Dali::Integration::Scene::New
69 static ScenePtr New( Size size );
77 * @copydoc Dali::Integration::Scene::Add
79 void Add(Actor& actor);
82 * @copydoc Dali::Integration::Scene::Remove
84 void Remove(Actor& actor);
87 * @copydoc Dali::Integration::Scene::GetSize
92 * @copydoc Dali::Integration::Scene::SetDpi
94 void SetDpi( Vector2 dpi );
97 * @copydoc Dali::Integration::Scene::GetDpi
99 Vector2 GetDpi() const;
102 * @copydoc Dali::Integration::Scene::GetRenderTaskList
104 RenderTaskList& GetRenderTaskList() const;
107 * @copydoc Dali::Integration::Scene::GetRootLayer
109 Dali::Layer GetRootLayer() const;
112 * @copydoc Dali::Integration::Scene::GetLayerCount
114 uint32_t GetLayerCount() const;
117 * @copydoc Dali::Integration::Scene::GetLayer
119 Dali::Layer GetLayer(uint32_t depth) const;
122 * Notify the surface has been resized.
124 * @param[in] width The new width of the set surface
125 * @param[in] height The new height of the set surface
126 * @param[in] orientation The orientation of the surface
127 * @param[in] forceUpdate The flag to update force
129 void SurfaceResized( float width, float height, int orientation, bool forceUpdate );
132 * @copydoc Dali::Integration::Scene::SurfaceReplaced
134 void SurfaceReplaced();
137 * @copydoc Dali::Integration::Scene::Discard
142 * Retrieve the ordered list of on-scene layers.
143 * @return The layer-list.
145 LayerList& GetLayerList() const;
148 * Request that the depth tree is rebuilt
150 void RequestRebuildDepthTree();
153 * This function is called when an event is queued.
154 * @param[in] event A event to queue.
156 void QueueEvent( const Integration::Event& event );
159 * This function is called by Core when events are processed.
161 void ProcessEvents();
164 * Rebuilds the depth tree at the end of the event frame if
165 * it was requested this frame.
167 void RebuildDepthTree();
170 * @brief Sets the background color of the render surface.
171 * @param[in] color The new background color
173 void SetBackgroundColor( const Vector4& color );
176 * @brief Gets the background color of the render surface.
177 * @return The background color
179 Vector4 GetBackgroundColor() const;
182 * @brief Get the Scene scene graph object
184 * @return the Scene scene graph object
186 SceneGraph::Scene* GetSceneObject() const;
189 * Used by the EventProcessor to emit key event signals.
190 * @param[in] event The key event.
192 void EmitKeyEventSignal(const KeyEvent& event);
195 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
196 * @param[in] event The key event.
197 * @return The return is true if KeyEvent is consumed, otherwise false.
199 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
202 * Emits the event processing finished signal.
204 * @see Dali::Scene::SignalEventProcessingFinished()
206 void EmitEventProcessingFinishedSignal();
209 * Emits the touched signal.
210 * @param[in] touchEvent The touch event details (Old API).
211 * @param[in] touch The touch event details.
213 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
216 * Used by the EventProcessor to emit wheel event signals.
217 * @param[in] event The wheel event.
219 void EmitWheelEventSignal( const WheelEvent& event );
222 * @copydoc Integration::Scene::KeyEventSignal()
224 Integration::Scene::KeyEventSignalType& KeyEventSignal();
227 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
229 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
232 * @copydoc Integration::Scene::SignalEventProcessingFinished()
234 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
236 // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
237 using TouchedSignalType = Signal< void (const TouchEvent&) >;
240 * Touched signal to support deprecated stage touched signal.
242 TouchedSignalType& TouchedSignal();
245 * @copydoc Integration::Scene::TouchSignal()
247 Integration::Scene::TouchSignalType& TouchSignal();
250 * @copydoc Integration::Scene::sWheelEventSignal()
252 Integration::Scene::WheelEventSignalType& WheelEventSignal();
257 * From RenderTaskDefaults; retrieve the default root actor.
258 * @return The default root actor.
260 virtual Actor& GetDefaultRootActor();
263 * From RenderTaskDefaults; retrieve the default camera actor.
264 * @return The default camera actor.
266 virtual CameraActor& GetDefaultCameraActor();
274 * Second-phase constructor.
276 * @param[in] size The size of the set surface
278 void Initialize( Size size );
281 Scene(const Scene&) = delete;
284 Scene& operator=(const Scene& rhs) = delete;
287 Internal::SceneGraph::Scene* mSceneObject;
293 Vector4 mBackgroundColor;
295 // The SurfaceOrientation
296 int mSurfaceOrientation;
300 // Ordered list of currently on-stage layers
301 OwnerPointer<LayerList> mLayerList;
303 IntrusivePtr<CameraActor> mDefaultCamera;
305 // The list of render-tasks
306 IntrusivePtr<RenderTaskList> mRenderTaskList;
308 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
310 EventProcessor mEventProcessor;
312 // The key event signal
313 Integration::Scene::KeyEventSignalType mKeyEventSignal;
314 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
316 // The event processing finished signal
317 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
320 Integration::Scene::TouchSignalType mTouchSignal;
322 // The touched signal
323 TouchedSignalType mTouchedSignal;
325 // The wheel event signal
326 Integration::Scene::WheelEventSignalType mWheelEventSignal;
331 // Get impl of handle
332 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
334 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
335 Dali::RefObject& object = scene.GetBaseObject();
336 return static_cast<Internal::Scene&>(object);
339 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
341 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
342 const Dali::RefObject& object = scene.GetBaseObject();
343 return static_cast<const Internal::Scene&>(object);
348 #endif // DALI_INTERNAL_SCENE_H