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