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