Revert "[Tizen] Modify DALI_KEY_H"
[platform/core/uifw/dali-adaptor.git] / dali / integration-api / scene-holder-impl.h
1 #ifndef DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
2 #define DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H
3
4 /*
5  * Copyright (c) 2019 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 // EXTERNAL INCLUDES
22 #include <memory>
23 #include <vector>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/common/intrusive-ptr.h>
26 #include <dali/integration-api/scene.h>
27 #include <dali/integration-api/events/key-event-integ.h>
28 #include <dali/integration-api/events/point.h>
29 #include <dali/integration-api/events/touch-event-combiner.h>
30
31 // INTERNAL INCLUDES
32 #ifdef DALI_ADAPTOR_COMPILATION
33 #include <dali/integration-api/render-surface-interface.h>
34 #include <dali/integration-api/scene-holder.h>
35 #else
36 #include <dali/integration-api/adaptors/render-surface-interface.h>
37 #include <dali/integration-api/adaptors/scene-holder.h>
38 #endif
39
40 namespace Dali
41 {
42
43 class Any;
44 class Adaptor;
45 class Actor;
46 class Layer;
47 struct TouchPoint;
48 struct WheelEvent;
49 struct KeyEvent;
50
51 namespace Integration
52 {
53
54 class Scene;
55 struct Point;
56 struct KeyEvent;
57 struct WheelEvent;
58
59 }
60
61 namespace Internal
62 {
63
64 namespace Adaptor
65 {
66
67 class Adaptor;
68 class SceneHolder;
69 using SceneHolderPtr = IntrusivePtr< SceneHolder >;
70
71 /**
72  * @brief SceneHolder creates a Scene for rendering.
73  */
74 class DALI_ADAPTOR_API SceneHolder : public BaseObject
75 {
76
77 public:
78
79   /**
80    * @copydoc Dali::Integration::SceneHolder::Add
81    */
82   void Add( Dali::Actor actor );
83
84   /**
85    * @copydoc Dali::Integration::SceneHolder::Remove
86    */
87   void Remove( Dali::Actor actor );
88
89   /**
90    * @copydoc Dali::Integration::SceneHolder::GetRootLayer
91    */
92   Dali::Layer GetRootLayer() const;
93
94   /**
95    * @brief Gets the window name.
96    * @return The name of the window
97    */
98   std::string GetName() const;
99
100   /**
101    * @brief Retrieve the unique ID of the window.
102    * @return The ID
103    */
104   uint32_t GetId() const;
105
106   /**
107    * @brief Retrieve the Scene.
108    * @return The Scene
109    */
110   Dali::Integration::Scene GetScene();
111
112   /**
113    * @brief Set the render surface
114    * @param[in] surface The render surface
115    */
116   void SetSurface( Dali::RenderSurfaceInterface* surface );
117
118   /**
119    * @brief Called when the surface set is resized.
120    */
121   void SurfaceResized();
122
123   /**
124    * @brief Get the render surface
125    * @return The render surface
126    */
127   Dali::RenderSurfaceInterface* GetSurface() const;
128
129   /**
130    * @brief Set the adaptor to the scene holder
131    * @param[in] adaptor An initialized adaptor
132    */
133   void SetAdaptor( Dali::Adaptor& adaptor );
134
135   /**
136    * @copydoc Dali::Integration::SceneHolder::SetBackgroundColor
137    */
138   void SetBackgroundColor( const Dali::Vector4& color );
139
140   /**
141    * @copydoc Dali::Integration::SceneHolder::GetBackgroundColor
142    */
143   Vector4 GetBackgroundColor() const;
144
145   /**
146    * @brief Pause the rendering of the scene holder.
147    */
148   void Pause();
149
150   /**
151    * @brief Resume the rendering of the scene holder (from pause).
152    */
153   void Resume();
154
155   /**
156    * @copydoc Dali::Integration::SceneHolder::FeedTouchPoint
157    */
158   void FeedTouchPoint( Dali::Integration::Point& point, int timeStamp );
159
160   /**
161    * @copydoc Dali::Integration::SceneHolder::FeedWheelEvent
162    */
163   void FeedWheelEvent( Dali::Integration::WheelEvent& wheelEvent );
164
165   /**
166    * @copydoc Dali::Integration::SceneHolder::FeedKeyEvent
167    */
168   void FeedKeyEvent( Dali::Integration::KeyEvent& keyEvent );
169
170   /**
171    * @copydoc Dali::Integration::SceneHolder::Get()
172    */
173   static Dali::Integration::SceneHolder Get( Dali::Actor actor );
174
175 public: // The following methods can be overridden if required
176
177   /**
178    * @brief Returns whether the Scene is visible or not.
179    * @return True if the Scene is visible, false otherwise.
180    */
181   virtual bool IsVisible() const;
182
183 public: // The following methods must be overridden
184
185   /**
186    * @copydoc Dali::Integration::SceneHolder::GetNativeHandle
187    */
188   virtual Dali::Any GetNativeHandle() const = 0;
189
190 protected:
191
192   // Constructor
193   SceneHolder();
194
195   // Undefined
196   SceneHolder(const SceneHolder&) = delete;
197
198   // Undefined
199   SceneHolder& operator=(const SceneHolder& rhs) = delete;
200
201   /**
202    * virtual destructor
203    */
204   virtual ~SceneHolder();
205
206 private: // The following methods can be overridden if required
207
208   /**
209    * @brief Called by the base class to inform deriving classes that the adaptor has been set.
210    * @param[in] adaptor The adaptor
211    */
212   virtual void OnAdaptorSet( Dali::Adaptor& adaptor ) {};
213
214   /**
215    * @brief Called by the base class to inform deriving classes that a new surface has been set.
216    * @param[in] surface The new render surface
217    */
218   virtual void OnSurfaceSet( Dali::RenderSurfaceInterface* surface ) {};
219
220   /**
221    * @brief Called by the base class to inform deriving classes that we are being paused.
222    */
223   virtual void OnPause() {};
224
225   /**
226    * @brief Called by the base class to inform deriving classes that we are resuming from a paused state.
227    */
228   virtual void OnResume() {};
229
230   /**
231    * Recalculate the touch position if required
232    * @param[in,out] point The touch point
233    */
234   virtual void RecalculateTouchPosition( Integration::Point& point ) {};
235
236 private:
237
238   /**
239    * Resets the event handling.
240    */
241   void Reset();
242
243 private:
244
245   static uint32_t                                 mSceneHolderCounter; ///< A counter to track the SceneHolder creation
246
247   class SceneHolderLifeCycleObserver;
248   std::unique_ptr< SceneHolderLifeCycleObserver > mLifeCycleObserver;  ///< The adaptor life cycle observer
249
250 protected:
251
252   uint32_t                                        mId;                 ///< A unique ID to identify the SceneHolder starting from 0
253   Dali::Integration::Scene                        mScene;              ///< The Scene
254   std::string                                     mName;               ///< The name of the SceneHolder
255
256   std::unique_ptr< Dali::RenderSurfaceInterface > mSurface;            ///< The window rendering surface
257   Adaptor*                                        mAdaptor;            ///< The adaptor
258
259   Dali::Integration::TouchEventCombiner           mCombiner;           ///< Combines multi-touch events.
260
261   bool                                            mAdaptorStarted:1;   ///< Whether the adaptor has started or not
262   bool                                            mVisible:1;          ///< Whether the scene is visible or not
263 };
264
265 } // Adaptor
266
267 } // Internal
268
269 // Get impl of handle
270 inline Internal::Adaptor::SceneHolder& GetImplementation( Dali::Integration::SceneHolder& sceneHolder )
271 {
272   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
273   Dali::RefObject& object = sceneHolder.GetBaseObject();
274   return static_cast<Internal::Adaptor::SceneHolder&>( object );
275 }
276
277 inline const Internal::Adaptor::SceneHolder& GetImplementation( const Dali::Integration::SceneHolder& sceneHolder )
278 {
279   DALI_ASSERT_ALWAYS( sceneHolder && "SceneHolder handle is empty" );
280   const Dali::RefObject& object = sceneHolder.GetBaseObject();
281   return static_cast<const Internal::Adaptor::SceneHolder&>( object );
282 }
283
284 } // Dali
285
286 #endif // DALI_INTEGRATION_INTERNAL_SCENEHOLDER_H