[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / event / common / stage-impl.h
1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/common/stage.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/internal/common/owner-pointer.h>
25 #include <dali/internal/event/actors/layer-impl.h>
26 #include <dali/internal/event/common/object-registry-impl.h>
27 #include <dali/internal/event/common/stage-def.h>
28 #include <dali/internal/event/dynamics/dynamics-declarations.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/public-api/math/vector2.h>
32 #include <dali/public-api/math/vector3.h>
33 #include <dali/public-api/math/vector4.h>
34
35 namespace Dali
36 {
37
38 struct Vector2;
39
40 namespace Integration
41 {
42 class SystemOverlay;
43 class DynamicsFactory;
44 }
45
46 namespace Internal
47 {
48
49 namespace SceneGraph
50 {
51 class UpdateManager;
52 }
53
54 class AnimationPlaylist;
55 class PropertyNotificationManager;
56 class Layer;
57 class LayerList;
58 class SystemOverlay;
59 class CameraActor;
60 class RenderTaskList;
61
62 /**
63  * Implementation of Stage
64  */
65 class Stage : public BaseObject, public RenderTaskDefaults
66 {
67 public:
68
69   /**
70    * Create the stage
71    * @param playlist for animations
72    * @param dynamicsNotifier
73    * @param updateManager
74    * @param notificationManager
75    */
76   static StagePtr New( AnimationPlaylist& playlist,
77                        PropertyNotificationManager& propertyNotificationManager,
78                        DynamicsNotifier& dynamicsNotifier,
79                        SceneGraph::UpdateManager& updateManager,
80                        NotificationManager& notificationManager );
81
82   /**
83    * Initialize the stage.
84    */
85   void Initialize();
86
87   /**
88    * Uninitialize the stage.
89    */
90   void Uninitialize();
91
92   /**
93    * @copydoc Dali::Stage::GetCurrent()
94    */
95   static StagePtr GetCurrent();
96
97   /**
98    * @copydoc Dali::Stage::IsInstalled().
99    */
100   static bool IsInstalled();
101
102   /**
103    * @copydoc Dali::Stage::GetObjectRegistry()
104    */
105   ObjectRegistry& GetObjectRegistry();
106
107   /**
108    * Retrieve the root actor (not publically accessible).
109    * @return The root actor.
110    */
111   Layer& GetRootActor();
112
113   /**
114    * Retrieve the UpdateManager associated with this Stage
115    * @return The UpdateManager.
116    */
117   SceneGraph::UpdateManager& GetUpdateManager();
118
119   /**
120    * Helper for actors, to retrieve the current Event buffer index.
121    * @return The buffer index.
122    */
123   BufferIndex GetEventBufferIndex() const
124   {
125     // inlined as its called often from event thread
126     return mUpdateManager.GetEventBufferIndex();
127   }
128
129   /**
130    * Retrieve the interface for accessing update-thread data.
131    * @return The EventToUpdate interface.
132    */
133   EventToUpdate& GetUpdateInterface();
134
135   /**
136    * Returns the animation playlist.
137    * @return reference to the animation playlist.
138    */
139   AnimationPlaylist& GetAnimationPlaylist();
140
141   /**
142    * Returns the property notification manager.
143    * @return reference to the property notification manager.
144    */
145   PropertyNotificationManager& GetPropertyNotificationManager();
146
147   /**
148    * Return the Dynamics Simulation Notifier object
149    * @return The Dynamics Simulation Notifier object
150    */
151   DynamicsNotifier& GetDynamicsNotifier();
152
153   // Root actor accessors
154
155   /**
156    * @copydoc Dali::Stage::Add()
157    */
158   void Add( Actor& actor );
159
160   /**
161    * @copydoc Dali::Stage::Remove()
162    */
163   void Remove( Actor& actor );
164
165   /**
166    * Sets the size of the stage and indirectly, the root actor.
167    * @param [in] width  The new width.
168    * @param [in] height The new height.
169    */
170   void SetSize( float width, float height );
171
172   /**
173    * Returns the size of the Stage in pixels as a Vector.
174    * The x component will be the width of the Stage in pixels
175    * The y component will be the height of the Stage in pixels
176    * @return The size of the Stage as a Vector.
177    */
178   Vector2 GetSize() const;
179
180   /**
181    * @copydoc Dali::Stage::GetRenderTaskList()
182    */
183   RenderTaskList& GetRenderTaskList() const;
184
185   /**
186    * Create a default camera actor
187    */
188   void CreateDefaultCameraActor();
189
190   /**
191    * From RenderTaskDefaults; retrieve the default root actor.
192    * @return The default root actor.
193    */
194   virtual Actor& GetDefaultRootActor();
195
196   /**
197    * From RenderTaskDefaults; retrieve the default camera actor.
198    * @return The default camera actor.
199    */
200   virtual CameraActor& GetDefaultCameraActor();
201
202   // Layers
203
204   /**
205    * @copydoc Dali::Stage::GetLayerCount()
206    */
207   unsigned int GetLayerCount() const;
208
209   /**
210    * @copydoc Dali::Stage::GetLayer()
211    */
212   Dali::Layer GetLayer( unsigned int depth ) const;
213
214   /**
215    * @copydoc Dali::Stage::GetRootLayer()
216    */
217   Dali::Layer GetRootLayer() const;
218
219   /**
220    * Retrieve the ordered list of on-stage layers.
221    * @return The layer-list.
222    */
223   LayerList& GetLayerList();
224
225   // System-level overlay actors
226
227   /**
228    * @copydoc Dali::Integration::Core::GetSystemOverlay()
229    */
230   Integration::SystemOverlay& GetSystemOverlay();
231
232   /**
233    * Retrieve the internal implementation of the SystemOverlay.
234    * @return The implementation, or NULL if this has never been requested from Integration API.
235    */
236   SystemOverlay* GetSystemOverlayInternal();
237
238   // Keyboard stuff
239
240   /**
241    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
242    * set to receive keyboard input.
243    * @param[in] actor to receive keyboard input
244    */
245   void SetKeyboardFocusActor( Actor* actor );
246
247   /**
248    * Get the actor that is currently set to receive keyboard inputs
249    * @return Pointer to the actor set to receive keyboard inputs.
250    */
251   Actor* GetKeyboardFocusActor() const;
252
253   /**
254    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
255    * @param [in] actor which should be removed from focus.
256    */
257   void RemoveActorFromKeyFocus( Actor* actor );
258
259   // Misc
260
261   /**
262    * @copydoc Dali::Stage::SetBackgroundColor
263    */
264   void SetBackgroundColor(Vector4 color);
265
266   /**
267    * @copydoc Dali::Stage::GetBackgroundColor
268    */
269   Vector4 GetBackgroundColor() const;
270
271   /**
272    * @copydoc Dali::Stage::GetDpi
273    */
274   Vector2 GetDpi() const;
275
276   /**
277    * Sets horizontal and vertical pixels per inch value that is used by the display
278    * @param[in] dpi Horizontal and vertical dpi value
279    */
280   void SetDpi( Vector2 dpi );
281
282   /**
283    * @copydoc Dali::Stage::InitializeDynamics
284    */
285   DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
286
287   /**
288    * @copydoc Dali::Stage::GetDynamicsWorld
289    */
290   DynamicsWorldPtr GetDynamicsWorld();
291
292   /**
293    * @copydoc Dali::Stage::TerminateDynamics
294    */
295   void TerminateDynamics();
296
297   NotificationManager& GetNotificationManager()
298   {
299     return mNotificationManager;
300   }
301
302   /**
303    * @copydoc Dali::Stage::KeepRendering()
304    */
305   void KeepRendering( float durationSeconds );
306
307   /**
308    * Used by the EventProcessor to emit key event signals.
309    * @param[in] event The key event.
310    */
311   void EmitKeyEventSignal(const KeyEvent& event);
312
313   /**
314    * Emits the event processing finished signal.
315    *
316    * @see Dali::Stage::SignalEventProcessingFinished()
317    */
318   void EmitEventProcessingFinishedSignal();
319
320   /**
321    * Emits the touched signal.
322    * @param[in] touch The touch event details.
323    */
324   void EmitTouchedSignal( const TouchEvent& touch );
325
326   /**
327    * @copydoc Dali::Stage::KeyEventSignal()
328    */
329   Dali::Stage::KeyEventSignalV2& KeyEventSignal();
330
331   /**
332    * @copydoc Dali::Stage::SignalEventProcessingFinished()
333    */
334   Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
335
336   /**
337     * @copydoc Dali::Stage::TouchedSignal()
338     */
339   Dali::Stage::TouchedSignalV2& TouchedSignal();
340
341 private:
342
343   /**
344    * Protected constructor; see also Stage::New()
345    */
346   Stage( AnimationPlaylist& playlist,
347          PropertyNotificationManager& propertyNotificationManager,
348          DynamicsNotifier& dynamicsNotifier,
349          SceneGraph::UpdateManager& updateManager,
350          NotificationManager& notificationManager );
351
352   /**
353    * A reference counted object may only be deleted by calling Unreference()
354    */
355   virtual ~Stage();
356
357 private:
358
359   // For 'Fire and forget' animation support
360   AnimationPlaylist& mAnimationPlaylist;
361
362   PropertyNotificationManager& mPropertyNotificationManager;
363
364   DynamicsNotifier& mDynamicsNotifier;
365
366   SceneGraph::UpdateManager& mUpdateManager;
367
368   NotificationManager& mNotificationManager;
369
370   // The Actual size of the stage.
371   Vector2 mSize;
372
373   // Cached for public GetBackgroundColor()
374   Vector4 mBackgroundColor;
375
376   LayerPtr mRootLayer;
377
378   // Ordered list of currently on-stage layers
379   OwnerPointer<LayerList> mLayerList;
380
381   IntrusivePtr<CameraActor> mDefaultCamera;
382
383   Vector2 mDpi;
384
385   // The object registry
386   ObjectRegistryPtr mObjectRegistry;
387
388   // The Dynamics simulation world object
389   Integration::DynamicsFactory* mDynamicsFactory;   // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
390   DynamicsWorldPtr mDynamicsWorld;
391
392   // The list of render-tasks
393   IntrusivePtr<RenderTaskList> mRenderTaskList;
394
395   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
396
397   // The key event signal
398   Dali::Stage::KeyEventSignalV2                 mKeyEventSignalV2;
399
400   // The event processing finished signal
401   Dali::Stage::EventProcessingFinishedSignalV2  mEventProcessingFinishedSignalV2;
402
403   // The touched signal
404   Dali::Stage::TouchedSignalV2                  mTouchedSignalV2;
405 };
406
407 } // namespace Internal
408
409 // Helpers for public-api forwarding methods
410
411 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
412 {
413   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
414
415   BaseObject& handle = stage.GetBaseObject();
416
417   return static_cast<Internal::Stage&>(handle);
418 }
419
420 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
421 {
422   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
423
424   const BaseObject& handle = stage.GetBaseObject();
425
426   return static_cast<const Internal::Stage&>(handle);
427 }
428
429 } // namespace Dali
430
431 #endif // __DALI_INTERNAL_STAGE_H__