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