Add EmitWheelEventGeneratedSignal for custom wheel event
[platform/core/uifw/dali-core.git] / dali / internal / event / common / scene-impl.h
1 #ifndef DALI_INTERNAL_SCENE_H
2 #define DALI_INTERNAL_SCENE_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/scene.h>
23 #include <dali/internal/common/owner-pointer.h>
24 #include <dali/internal/event/actors/layer-impl.h>
25 #include <dali/internal/event/events/event-processor.h>
26 #include <dali/internal/event/render-tasks/render-task-defaults.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30
31 namespace Dali
32 {
33 namespace Integration
34 {
35 struct Event;
36
37 }
38
39 namespace Internal
40 {
41 namespace SceneGraph
42 {
43 class Scene;
44 } // namespace SceneGraph
45
46 class EventProcessor;
47 class Layer;
48 class LayerList;
49 class CameraActor;
50 class RenderTaskList;
51 class FrameBuffer;
52
53 using FrameBufferPtr = IntrusivePtr<FrameBuffer>;
54 using ScenePtr       = IntrusivePtr<Scene>;
55
56 /**
57  * @brief Scene creates a "world" that can be bound to a surface for rendering.
58  */
59 class Scene : public BaseObject, public RenderTaskDefaults
60 {
61 public:
62   /**
63    * @copydoc Dali::Integration::Scene::New
64    */
65   static ScenePtr New(Size size, int32_t orientation = 0);
66
67   /**
68    * virtual destructor
69    */
70   ~Scene() override;
71
72   /**
73    * @copydoc Dali::Integration::Scene::Add
74    */
75   void Add(Actor& actor);
76
77   /**
78    * @copydoc Dali::Integration::Scene::Remove
79    */
80   void Remove(Actor& actor);
81
82   /**
83    * @copydoc Dali::Integration::Scene::GetSize
84    */
85   Size GetSize() const;
86
87   /**
88    * @copydoc Dali::Integration::Scene::SetDpi
89    */
90   void SetDpi(Vector2 dpi);
91
92   /**
93    * @copydoc Dali::Integration::Scene::GetDpi
94    */
95   Vector2 GetDpi() const;
96
97   /**
98    * @copydoc Dali::Integration::Scene::GetRenderTaskList
99    */
100   RenderTaskList& GetRenderTaskList() const;
101
102   /**
103    * @copydoc Dali::Integration::Scene::GetRootLayer
104    */
105   Dali::Layer GetRootLayer() const;
106
107   /**
108    * @copydoc Dali::Integration::Scene::GetLayerCount
109    */
110   uint32_t GetLayerCount() const;
111
112   /**
113    * @copydoc Dali::Integration::Scene::GetLayer
114    */
115   Dali::Layer GetLayer(uint32_t depth) const;
116
117   /**
118    * Notify the surface has been resized.
119    *
120    * @param[in] width The new width of the set surface
121    * @param[in] height The new height of the set surface
122    */
123   void SurfaceResized(float width, float height);
124
125   /**
126    * @copydoc Dali::Integration::Scene::SurfaceReplaced
127    */
128   void SurfaceReplaced();
129
130   /**
131    * @copydoc Dali::Integration::Scene::Discard
132    */
133   void Discard();
134
135   /**
136    * Retrieve the ordered list of on-scene layers.
137    * @return The layer-list.
138    */
139   LayerList& GetLayerList() const;
140
141   /**
142    * Request that the depth tree is rebuilt
143    */
144   void RequestRebuildDepthTree();
145
146   /**
147    * This function is called when an event is queued.
148    * @param[in] event A event to queue.
149    */
150   void QueueEvent(const Integration::Event& event);
151
152   /**
153    * This function is called by Core when events are processed.
154    */
155   void ProcessEvents();
156
157   /**
158    * Rebuilds the depth tree at the end of the event frame if
159    * it was requested this frame.
160    */
161   void RebuildDepthTree();
162
163   /**
164    * @brief Sets the background color of the render surface.
165    * @param[in] color The new background color
166    */
167   void SetBackgroundColor(const Vector4& color);
168
169   /**
170    * @brief Gets the background color of the render surface.
171    * @return The background color
172    */
173   Vector4 GetBackgroundColor() const;
174
175   /**
176    * @brief Get the Scene scene graph object
177    *
178    * @return the Scene scene graph object
179    */
180   SceneGraph::Scene* GetSceneObject() const;
181
182   /**
183    * Notify the surface has been rotated.
184    * When the device is rotated or the rotation event is received by display manager,
185    * this function will be called by window implementation.
186    *
187    * @param[in] width The width of rotated surface
188    * @param[in] height The height of rotated surface
189    * @param[in] orientation The orientation of rotated surface
190    */
191   void SurfaceRotated(float width, float height, int32_t orientation);
192
193   /**
194    * @copydoc Dali::Integration::Scene::SetRotationCompletedAcknowledgement
195    */
196   void SetRotationCompletedAcknowledgement();
197
198   /**
199    * @copydoc Dali::Integration::Scene::IsRotationCompletedAcknowledgementSet
200    */
201   bool IsRotationCompletedAcknowledgementSet() const;
202
203   /**
204    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
205    */
206   int32_t GetCurrentSurfaceOrientation() const;
207
208   /**
209    * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
210    */
211   const Rect<int32_t>& GetCurrentSurfaceRect() const;
212
213   /**
214    * @copydoc Dali::Integration::Scene::IsSurfaceRectChanged
215    */
216   bool IsSurfaceRectChanged() const;
217
218   /**
219    * @copydoc Dali::Integration::Scene::SetSurfaceRenderTarget
220    */
221   void SetSurfaceRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo);
222
223   /**
224    * Used by the EventProcessor to emit key event signals.
225    * @param[in] event The key event.
226    */
227   void EmitKeyEventSignal(const Dali::KeyEvent& event);
228
229   /**
230    * Used by the KeyEventProcessor to emit KeyEventGenerated signals.
231    * @param[in] event The key event.
232    * @return The return is true if KeyEvent is consumed, otherwise false.
233    */
234   bool EmitKeyEventGeneratedSignal(const Dali::KeyEvent& event);
235
236   /**
237    * Emits the event processing finished signal.
238    *
239    * @see Dali::Scene::SignalEventProcessingFinished()
240    */
241   void EmitEventProcessingFinishedSignal();
242
243   /**
244    * Emits the touched signal.
245    * @param[in] touch The touch event details.
246    */
247   void EmitTouchedSignal(const Dali::TouchEvent& touch);
248
249   /**
250    * Used by the EventProcessor to emit wheel event signals.
251    * @param[in] event The wheel event.
252    */
253   void EmitWheelEventSignal(const Dali::WheelEvent& event);
254
255   /**
256    * Used by the WheelEventProcessor to emit WheelEventGenerated signals.
257    * @param[in] event The wheel event.
258    * @return The return is true if WheelEvent is consumed, otherwise false.
259    */
260   bool EmitWheelEventGeneratedSignal(const Dali::WheelEvent& event);
261
262   /**
263    * @copydoc Dali::Integration::Scene::AddFrameRenderedCallback
264    */
265   void AddFrameRenderedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
266
267   /**
268    * @copydoc Dali::Integration::Scene::AddFramePresentedCallback
269    */
270   void AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, int32_t frameId);
271
272   /**
273    * @copydoc Dali::Integration::Scene::GetFrameRenderedCallback
274    */
275   void GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
276
277   /**
278    * @copydoc Dali::Integration::Scene::GetFramePresentedCallback
279    */
280   void GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks);
281
282   /**
283    * @copydoc Integration::Scene::KeyEventSignal()
284    */
285   Integration::Scene::KeyEventSignalType& KeyEventSignal();
286
287   /**
288    * @copydoc Integration::Scene::KeyEventGeneratedSignal()
289    */
290   Integration::Scene::KeyEventGeneratedSignalType& KeyEventGeneratedSignal();
291
292   /**
293    * @copydoc Integration::Scene::SignalEventProcessingFinished()
294    */
295   Integration::Scene::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
296
297   /**
298     * @copydoc Integration::Scene::TouchedSignal()
299     */
300   Integration::Scene::TouchEventSignalType& TouchedSignal();
301
302   /**
303    * @copydoc Integration::Scene::sWheelEventSignal()
304    */
305   Integration::Scene::WheelEventSignalType& WheelEventSignal();
306
307   /**
308    * @copydoc Integration::Scene::WheelEventGeneratedSignal()
309    */
310   Integration::Scene::WheelEventGeneratedSignalType& WheelEventGeneratedSignal();
311
312 public:
313   /**
314    * From RenderTaskDefaults; retrieve the default root actor.
315    * @return The default root actor.
316    */
317   Actor& GetDefaultRootActor() override;
318
319   /**
320    * From RenderTaskDefaults; retrieve the default camera actor.
321    * @return The default camera actor.
322    */
323   CameraActor& GetDefaultCameraActor() const override;
324
325 private:
326   // Constructor
327   Scene();
328
329   /**
330    * Second-phase constructor.
331    *
332    * @param[in] size The size of the set surface
333    * @param[in] orientation The orientation of the set surface for this scene
334    */
335   void Initialize(Size size, int32_t orientation);
336
337   // Undefined
338   Scene(const Scene&) = delete;
339
340   // Undefined
341   Scene& operator=(const Scene& rhs) = delete;
342
343   /**
344    * Informs the scene that the set surface has been resized or rotated.
345    *
346    * @param[in] width The width of rotated surface
347    * @param[in] height The height of rotated surface
348    * @param[in] orientation The orientation of rotated surface
349    */
350   void ChangedSurface(float width, float height, int32_t orientation);
351
352 private:
353   Internal::SceneGraph::Scene* mSceneObject;
354
355   Size mSize;
356
357   Vector2 mDpi;
358
359   Vector4 mBackgroundColor;
360
361   LayerPtr mRootLayer;
362
363   // Ordered list of currently on-stage layers
364   OwnerPointer<LayerList> mLayerList;
365
366   IntrusivePtr<CameraActor> mDefaultCamera;
367
368   // The list of render-tasks
369   IntrusivePtr<RenderTaskList> mRenderTaskList;
370
371   bool mDepthTreeDirty : 1; ///< True if the depth tree needs recalculating
372
373   EventProcessor mEventProcessor;
374
375   // The Surface's orientation
376   int32_t mSurfaceOrientation;
377
378   // The key event signal
379   Integration::Scene::KeyEventSignalType          mKeyEventSignal;
380   Integration::Scene::KeyEventGeneratedSignalType mKeyEventGeneratedSignal;
381
382   // The event processing finished signal
383   Integration::Scene::EventProcessingFinishedSignalType mEventProcessingFinishedSignal;
384
385   // The touch signal
386   Integration::Scene::TouchEventSignalType mTouchedSignal;
387
388   // The wheel event signal
389   Integration::Scene::WheelEventSignalType          mWheelEventSignal;
390   Integration::Scene::WheelEventGeneratedSignalType mWheelEventGeneratedSignal;
391 };
392
393 } // namespace Internal
394
395 // Get impl of handle
396 inline Internal::Scene& GetImplementation(Dali::Integration::Scene& scene)
397 {
398   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
399   Dali::RefObject& object = scene.GetBaseObject();
400   return static_cast<Internal::Scene&>(object);
401 }
402
403 inline const Internal::Scene& GetImplementation(const Dali::Integration::Scene& scene)
404 {
405   DALI_ASSERT_ALWAYS(scene && "Scene handle is empty");
406   const Dali::RefObject& object = scene.GetBaseObject();
407   return static_cast<const Internal::Scene&>(object);
408 }
409
410 } // namespace Dali
411
412 #endif // DALI_INTERNAL_SCENE_H