Merge "remove (unnecessarily) exported signal and action names" into tizen
[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 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/public-api/object/ref-object.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/integration-api/context-notifier.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/event/actors/layer-impl.h>
28 #include <dali/internal/event/common/object-registry-impl.h>
29 #include <dali/internal/event/common/stage-def.h>
30 #include <dali/internal/event/render-tasks/render-task-defaults.h>
31 #include <dali/internal/update/manager/update-manager.h>
32 #include <dali/public-api/common/view-mode.h>
33 #include <dali/public-api/math/vector2.h>
34 #include <dali/public-api/math/vector3.h>
35 #include <dali/public-api/math/vector4.h>
36 #include <dali/public-api/render-tasks/render-task.h>
37
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
40 #include <dali/internal/event/dynamics/dynamics-notifier.h>
41 #endif
42
43 namespace Dali
44 {
45
46 struct Vector2;
47
48 namespace Integration
49 {
50 class SystemOverlay;
51 class DynamicsFactory;
52 }
53
54 namespace Internal
55 {
56
57 namespace SceneGraph
58 {
59 class UpdateManager;
60 }
61
62 class AnimationPlaylist;
63 class PropertyNotificationManager;
64 class Layer;
65 class LayerList;
66 class SystemOverlay;
67 class CameraActor;
68 class RenderTaskList;
69
70 /**
71  * Implementation of Stage
72  */
73 class Stage : public BaseObject, public RenderTaskDefaults, public Integration::ContextNotifierInterface
74 {
75 public:
76
77   /**
78    * Create the stage
79    * @param[in] playlist for animations
80    * @param[in] propertyNotificationManager
81    * @param[in] updateManager
82    * @param[in] notificationManager
83    */
84   static StagePtr New( AnimationPlaylist& playlist,
85                        PropertyNotificationManager& propertyNotificationManager,
86                        SceneGraph::UpdateManager& updateManager,
87                        NotificationManager& notificationManager );
88
89   /**
90    * Initialize the stage.
91    */
92   void Initialize();
93
94   /**
95    * Uninitialize the stage.
96    */
97   void Uninitialize();
98
99   /**
100    * @copydoc Dali::Stage::GetCurrent()
101    * @note this version is for internal usage so it does not assert
102    */
103   static StagePtr GetCurrent();
104
105   /**
106    * @copydoc Dali::Stage::IsInstalled().
107    */
108   static bool IsInstalled();
109
110   /**
111    * @copydoc Dali::Stage::GetObjectRegistry()
112    */
113   ObjectRegistry& GetObjectRegistry();
114
115   /**
116    * @copydoc Dali::Internal::ObjectRegistry::RegisterObject
117    */
118   void RegisterObject( Dali::BaseObject* object );
119
120   /**
121    * @copydoc Dali::Internal::ObjectRegistry::UnregisterObject
122    */
123   void UnregisterObject( Dali::BaseObject* object );
124
125   /**
126    * Retrieve the root actor (not publically accessible).
127    * @return The root actor.
128    */
129   Layer& GetRootActor();
130
131   /**
132    * Retrieve the UpdateManager associated with this Stage
133    * @return The UpdateManager.
134    */
135   SceneGraph::UpdateManager& GetUpdateManager();
136
137   /**
138    * Helper for actors, to retrieve the current Event buffer index.
139    * @return The buffer index.
140    */
141   BufferIndex GetEventBufferIndex() const
142   {
143     // inlined as its called often from event thread
144     return mUpdateManager.GetEventBufferIndex();
145   }
146
147   /**
148    * Retrieve the interface for accessing update-thread data.
149    * @return The EventToUpdate interface.
150    */
151   EventToUpdate& GetUpdateInterface();
152
153   /**
154    * Returns the animation playlist.
155    * @return reference to the animation playlist.
156    */
157   AnimationPlaylist& GetAnimationPlaylist();
158
159   /**
160    * Returns the property notification manager.
161    * @return reference to the property notification manager.
162    */
163   PropertyNotificationManager& GetPropertyNotificationManager();
164
165   // Root actor accessors
166
167   /**
168    * @copydoc Dali::Stage::Add()
169    */
170   void Add( Actor& actor );
171
172   /**
173    * @copydoc Dali::Stage::Remove()
174    */
175   void Remove( Actor& actor );
176
177   /**
178    * Sets the size of the stage and indirectly, the root actor.
179    * @param [in] width  The new width.
180    * @param [in] height The new height.
181    */
182   void SetSize( float width, float height );
183
184   /**
185    * Returns the size of the Stage in pixels as a Vector.
186    * The x component will be the width of the Stage in pixels
187    * The y component will be the height of the Stage in pixels
188    * @return The size of the Stage as a Vector.
189    */
190   Vector2 GetSize() const;
191
192   /**
193    * @copydoc Dali::Stage::GetRenderTaskList()
194    */
195   RenderTaskList& GetRenderTaskList() const;
196
197   /**
198    * Create a default camera actor
199    */
200   void CreateDefaultCameraActor();
201
202   /**
203    * From RenderTaskDefaults; retrieve the default root actor.
204    * @return The default root actor.
205    */
206   virtual Actor& GetDefaultRootActor();
207
208   /**
209    * From RenderTaskDefaults; retrieve the default camera actor.
210    * @return The default camera actor.
211    */
212   virtual CameraActor& GetDefaultCameraActor();
213
214   // Layers
215
216   /**
217    * @copydoc Dali::Stage::GetLayerCount()
218    */
219   unsigned int GetLayerCount() const;
220
221   /**
222    * @copydoc Dali::Stage::GetLayer()
223    */
224   Dali::Layer GetLayer( unsigned int depth ) const;
225
226   /**
227    * @copydoc Dali::Stage::GetRootLayer()
228    */
229   Dali::Layer GetRootLayer() const;
230
231   /**
232    * Retrieve the ordered list of on-stage layers.
233    * @return The layer-list.
234    */
235   LayerList& GetLayerList();
236
237   // System-level overlay actors
238
239   /**
240    * @copydoc Dali::Integration::Core::GetSystemOverlay()
241    */
242   Integration::SystemOverlay& GetSystemOverlay();
243
244   /**
245    * Retrieve the internal implementation of the SystemOverlay.
246    * @return The implementation, or NULL if this has never been requested from Integration API.
247    */
248   SystemOverlay* GetSystemOverlayInternal();
249
250   // Stereoscopy
251
252   /**
253    * @copydoc Dali::Integration::Core::SetViewMode()
254    */
255   void SetViewMode( ViewMode viewMode );
256
257   /**
258    * @copydoc Dali::Integration::Core::GetViewMode()
259    */
260   ViewMode GetViewMode() const;
261
262   /**
263    * @copydoc Dali::Integration::Core::SetStereoBase()
264    */
265   void SetStereoBase( float stereoBase );
266
267   /**
268    * @copydoc Dali::Integration::Core::GetStereoBase()
269    */
270   float GetStereoBase() const;
271
272   // Keyboard stuff
273
274   /**
275    * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
276    * set to receive keyboard input.
277    * @param[in] actor to receive keyboard input
278    */
279   void SetKeyboardFocusActor( Actor* actor );
280
281   /**
282    * Get the actor that is currently set to receive keyboard inputs
283    * @return Pointer to the actor set to receive keyboard inputs.
284    */
285   Actor* GetKeyboardFocusActor() const;
286
287   /**
288    * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
289    * @param [in] actor which should be removed from focus.
290    */
291   void RemoveActorFromKeyFocus( Actor* actor );
292
293   // Misc
294
295   /**
296    * @copydoc Dali::Stage::SetBackgroundColor
297    */
298   void SetBackgroundColor(Vector4 color);
299
300   /**
301    * @copydoc Dali::Stage::GetBackgroundColor
302    */
303   Vector4 GetBackgroundColor() const;
304
305   /**
306    * @copydoc Dali::Stage::GetDpi
307    */
308   Vector2 GetDpi() const;
309
310   /**
311    * Sets horizontal and vertical pixels per inch value that is used by the display
312    * @param[in] dpi Horizontal and vertical dpi value
313    */
314   void SetDpi( Vector2 dpi );
315
316 #ifdef DYNAMICS_SUPPORT
317
318   /**
319    * Return the Dynamics Simulation Notifier object
320    * @return The Dynamics Simulation Notifier object
321    */
322   DynamicsNotifier& GetDynamicsNotifier();
323
324   /**
325    * @copydoc Dali::Stage::InitializeDynamics
326    */
327   DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
328
329   /**
330    * @copydoc Dali::Stage::GetDynamicsWorld
331    */
332   DynamicsWorldPtr GetDynamicsWorld();
333
334   /**
335    * @copydoc Dali::Stage::TerminateDynamics
336    */
337   void TerminateDynamics();
338
339 #endif // DYNAMICS_SUPPORT
340
341   NotificationManager& GetNotificationManager()
342   {
343     return mNotificationManager;
344   }
345
346   /**
347    * @copydoc Dali::Stage::KeepRendering()
348    */
349   void KeepRendering( float durationSeconds );
350
351   /**
352    * Used by the EventProcessor to emit key event signals.
353    * @param[in] event The key event.
354    */
355   void EmitKeyEventSignal(const KeyEvent& event);
356
357   /**
358    * Emits the event processing finished signal.
359    *
360    * @see Dali::Stage::SignalEventProcessingFinished()
361    */
362   void EmitEventProcessingFinishedSignal();
363
364   /**
365    * Emits the touched signal.
366    * @param[in] touch The touch event details.
367    */
368   void EmitTouchedSignal( const TouchEvent& touch );
369
370   /**
371    * Emits the scene created.
372    */
373   void EmitSceneCreatedSignal();
374
375   /**
376    * @copydoc Dali::Stage::KeyEventSignal()
377    */
378   Dali::Stage::KeyEventSignalType& KeyEventSignal();
379
380   /**
381    * @copydoc Dali::Stage::SignalEventProcessingFinished()
382    */
383   Dali::Stage::EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
384
385   /**
386     * @copydoc Dali::Stage::TouchedSignal()
387     */
388   Dali::Stage::TouchedSignalType& TouchedSignal();
389
390   /**
391    * @copydoc Dali::Stage::ContextLostSignal()
392    */
393   Dali::Stage::ContextStatusSignal& ContextLostSignal();
394
395   /**
396    * @copydoc Dali::Stage::ContextRegainedSignal()
397    */
398   Dali::Stage::ContextStatusSignal& ContextRegainedSignal();
399
400   /**
401    * @copydoc Dali::Stage::SceneCreatedSignal()
402    */
403   Dali::Stage::SceneCreatedSignalType& SceneCreatedSignal();
404
405   /**
406    * Connects a callback function with the object's signals.
407    * @param[in] object The object providing the signal.
408    * @param[in] tracker Used to disconnect the signal.
409    * @param[in] signalName The signal to connect to.
410    * @param[in] functor A newly allocated FunctorDelegate.
411    * @return True if the signal was connected.
412    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
413    */
414   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
415
416 private: // Implementation of ContextNotificationInterface:
417
418   /**
419    * @copydoc Dali::Integration::NotifyContextLost();
420    */
421   virtual void NotifyContextLost();
422
423   /**
424    * @copydoc Dali::Integration::NotifyContextRegained();
425    */
426   virtual void NotifyContextRegained();
427
428 private:
429
430   /**
431    * Protected constructor; see also Stage::New()
432    */
433   Stage( AnimationPlaylist& playlist,
434          PropertyNotificationManager& propertyNotificationManager,
435          SceneGraph::UpdateManager& updateManager,
436          NotificationManager& notificationManager );
437
438   /**
439    * A reference counted object may only be deleted by calling Unreference()
440    */
441   virtual ~Stage();
442
443 private:
444
445   // For 'Fire and forget' animation support
446   AnimationPlaylist& mAnimationPlaylist;
447
448   PropertyNotificationManager& mPropertyNotificationManager;
449
450   SceneGraph::UpdateManager& mUpdateManager;
451
452   NotificationManager& mNotificationManager;
453
454   // The Actual size of the stage.
455   Vector2 mSize;
456
457   // Cached for public GetBackgroundColor()
458   Vector4 mBackgroundColor;
459
460   LayerPtr mRootLayer;
461
462   // Ordered list of currently on-stage layers
463   OwnerPointer<LayerList> mLayerList;
464
465   IntrusivePtr<CameraActor> mDefaultCamera;
466
467   ViewMode mViewMode;
468   float mStereoBase;
469
470   Vector2 mDpi;
471
472   // The object registry
473   ObjectRegistryPtr mObjectRegistry;
474
475 #ifdef DYNAMICS_SUPPORT
476
477   DynamicsNotifier mDynamicsNotifier;
478
479   // The Dynamics simulation world object
480   Integration::DynamicsFactory* mDynamicsFactory;   // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
481   DynamicsWorldPtr mDynamicsWorld;
482
483 #endif // DYNAMICS_SUPPORT
484
485   // The list of render-tasks
486   IntrusivePtr<RenderTaskList> mRenderTaskList;
487
488   Dali::RenderTask mRightRenderTask;
489   IntrusivePtr<CameraActor> mRightCamera;
490   Dali::RenderTask mLeftRenderTask;
491   IntrusivePtr<CameraActor> mLeftCamera;
492
493   Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
494
495   // The key event signal
496   Dali::Stage::KeyEventSignalType                 mKeyEventSignal;
497
498   // The event processing finished signal
499   Dali::Stage::EventProcessingFinishedSignalType  mEventProcessingFinishedSignal;
500
501   // The touched signal
502   Dali::Stage::TouchedSignalType                  mTouchedSignal;
503
504   Dali::Stage::ContextStatusSignal mContextLostSignal;
505   Dali::Stage::ContextStatusSignal mContextRegainedSignal;
506
507   Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal;
508 };
509
510 } // namespace Internal
511
512 // Helpers for public-api forwarding methods
513
514 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
515 {
516   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
517
518   BaseObject& handle = stage.GetBaseObject();
519
520   return static_cast<Internal::Stage&>(handle);
521 }
522
523 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
524 {
525   DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
526
527   const BaseObject& handle = stage.GetBaseObject();
528
529   return static_cast<const Internal::Stage&>(handle);
530 }
531
532 } // namespace Dali
533
534 #endif // __DALI_INTERNAL_STAGE_H__