1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
5 * Copyright (c) 2019 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/integration-api/render-surface.h>
27 #include <dali/internal/common/owner-pointer.h>
28 #include <dali/internal/event/actors/layer-impl.h>
29 #include <dali/internal/event/events/event-processor.h>
30 #include <dali/internal/event/render-tasks/render-task-defaults.h>
52 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
53 using ScenePtr = IntrusivePtr<Scene>;
56 * @brief Scene creates a "world" that can be bound to a surface for rendering.
58 class Scene : public BaseObject, public RenderTaskDefaults
63 * @copydoc Dali::Integration::Scene::New
65 static ScenePtr New( const Size& size );
73 * @copydoc Dali::Integration::Scene::Add
75 void Add(Actor& actor);
78 * @copydoc Dali::Integration::Scene::Remove
80 void Remove(Actor& actor);
83 * @copydoc Dali::Integration::Scene::GetSize
88 * @copydoc Dali::Integration::Scene::SetDpi
90 void SetDpi( Vector2 dpi );
93 * @copydoc Dali::Integration::Scene::GetDpi
95 Vector2 GetDpi() const;
98 * @copydoc Dali::Integration::Scene::GetRenderTaskList
100 RenderTaskList& GetRenderTaskList() const;
103 * @copydoc Dali::Integration::Scene::GetRootLayer
105 Dali::Layer GetRootLayer() const;
108 * @copydoc Dali::Integration::Scene::GetLayerCount
110 uint32_t GetLayerCount() const;
113 * @copydoc Dali::Integration::Scene::GetLayer
115 Dali::Layer GetLayer(uint32_t depth) const;
118 * @copydoc Dali::Integration::Scene::SetSurface
120 void SetSurface( Integration::RenderSurface& surface );
123 * Retrieve the render surface the scene is binded to.
124 * @return The render surface.
126 Integration::RenderSurface* GetSurface() const;
129 * Retrieve the ordered list of on-scene layers.
130 * @return The layer-list.
132 LayerList& GetLayerList() const;
135 * Request that the depth tree is rebuilt
137 void RequestRebuildDepthTree();
140 * This function is called when an event is queued.
141 * @param[in] event A event to queue.
143 void QueueEvent( const Integration::Event& event );
146 * This function is called by Core when events are processed.
148 void ProcessEvents();
151 * Rebuilds the depth tree at the end of the event frame if
152 * it was requested this frame.
154 void RebuildDepthTree();
157 * @brief Sets the background color of the render surface.
158 * @param[in] color The new background color
160 void SetBackgroundColor(Vector4 color);
163 * @brief Gets the background color of the render surface.
164 * @return The background color
166 Vector4 GetBackgroundColor() const;
169 * Used by the EventProcessor to emit key event signals.
170 * @param[in] event The key event.
172 void EmitKeyEventSignal(const KeyEvent& event);
175 * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
176 * @param[in] event The key event.
177 * @return The return is true if KeyEvent is consumed, otherwise false.
179 bool EmitKeyEventGeneratedSignal(const KeyEvent& event);
182 * Emits the event processing finished signal.
184 * @see Dali::Scene::SignalEventProcessingFinished()
186 void EmitEventProcessingFinishedSignal();
189 * Emits the touched signal.
190 * @param[in] touchEvent The touch event details (Old API).
191 * @param[in] touch The touch event details.
193 void EmitTouchedSignal( const TouchEvent& touchEvent, const Dali::TouchData& touch );
196 * Used by the EventProcessor to emit wheel event signals.
197 * @param[in] event The wheel event.
199 void EmitWheelEventSignal( const WheelEvent& event );
202 * @copydoc Integration::Scene::KeyEventSignal()
204 Integration::Scene::KeyEventSignalType& KeyEventSignal();
207 * @copydoc Integration::Scene::KeyEventGeneratedSignal()
209 Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
212 * @copydoc Integration::Scene::SignalEventProcessingFinished()
214 Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
216 // The touched signal, to support Stage touched signal, will be removed when deprecated in public Stage API
217 using TouchedSignalType = Signal< void (const TouchEvent&) >;
220 * Touched signal to support deprecated stage touched signal.
222 TouchedSignalType& TouchedSignal();
225 * @copydoc Integration::Scene::TouchSignal()
227 Integration::Scene::TouchSignalType& TouchSignal();
230 * @copydoc Integration::Scene::sWheelEventSignal()
232 Integration::Scene::WheelEventSignalType& WheelEventSignal();
237 * From RenderTaskDefaults; retrieve the default root actor.
238 * @return The default root actor.
240 virtual Actor& GetDefaultRootActor();
243 * From RenderTaskDefaults; retrieve the default camera actor.
244 * @return The default camera actor.
246 virtual CameraActor& GetDefaultCameraActor();
251 Scene( const Size& size );
254 * Second-phase constructor.
259 Scene(const Scene&) = delete;
262 Scene& operator=(const Scene& rhs) = delete;
265 Integration::RenderSurface* mSurface;
267 // The scene-size may be different with the surface-size
275 // Ordered list of currently on-stage layers
276 OwnerPointer<LayerList> mLayerList;
278 IntrusivePtr<CameraActor> mDefaultCamera;
280 // The list of render-tasks
281 IntrusivePtr<RenderTaskList> mRenderTaskList;
284 FrameBufferPtr mFrameBuffer;
286 bool mDepthTreeDirty:1; ///< True if the depth tree needs recalculating
288 EventProcessor mEventProcessor;
290 // The key event signal
291 Integration::Scene::KeyEventSignalType mKeyEventSignal;
292 Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
294 // The event processing finished signal
295 Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
298 Integration::Scene::TouchSignalType mTouchSignal;
300 // The touched signal
301 TouchedSignalType mTouchedSignal;
303 // The wheel event signal
304 Integration::Scene::WheelEventSignalType mWheelEventSignal;
309 // Get impl of handle
310 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
312 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
313 Dali::RefObject& object = scene.GetBaseObject();
314 return static_cast<Internal::Scene&>(object);
317 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
319 DALI_ASSERT_ALWAYS( scene && "Scene handle is empty" );
320 const Dali::RefObject& object = scene.GetBaseObject();
321 return static_cast<const Internal::Scene&>(object);
326 #endif // DALI_INTERNAL_SCENE_H