1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
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/render-tasks/render-task-defaults.h>
29 #include <dali/internal/update/manager/update-manager.h>
30 #include <dali/public-api/common/view-mode.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 #include <dali/public-api/render-tasks/render-task.h>
36 #ifdef DYNAMICS_SUPPORT
37 #include <dali/internal/event/dynamics/dynamics-declarations.h>
38 #include <dali/internal/event/dynamics/dynamics-notifier.h>
49 class DynamicsFactory;
60 class AnimationPlaylist;
61 class PropertyNotificationManager;
69 * Implementation of Stage
71 class Stage : public BaseObject, public RenderTaskDefaults
77 * @param[in] playlist for animations
78 * @param[in] propertyNotificationManager
79 * @param[in] updateManager
80 * @param[in] notificationManager
82 static StagePtr New( AnimationPlaylist& playlist,
83 PropertyNotificationManager& propertyNotificationManager,
84 SceneGraph::UpdateManager& updateManager,
85 NotificationManager& notificationManager );
88 * Initialize the stage.
93 * Uninitialize the stage.
98 * @copydoc Dali::Stage::GetCurrent()
100 static StagePtr GetCurrent();
103 * @copydoc Dali::Stage::IsInstalled().
105 static bool IsInstalled();
108 * @copydoc Dali::Stage::GetObjectRegistry()
110 ObjectRegistry& GetObjectRegistry();
113 * Retrieve the root actor (not publically accessible).
114 * @return The root actor.
116 Layer& GetRootActor();
119 * Retrieve the UpdateManager associated with this Stage
120 * @return The UpdateManager.
122 SceneGraph::UpdateManager& GetUpdateManager();
125 * Helper for actors, to retrieve the current Event buffer index.
126 * @return The buffer index.
128 BufferIndex GetEventBufferIndex() const
130 // inlined as its called often from event thread
131 return mUpdateManager.GetEventBufferIndex();
135 * Retrieve the interface for accessing update-thread data.
136 * @return The EventToUpdate interface.
138 EventToUpdate& GetUpdateInterface();
141 * Returns the animation playlist.
142 * @return reference to the animation playlist.
144 AnimationPlaylist& GetAnimationPlaylist();
147 * Returns the property notification manager.
148 * @return reference to the property notification manager.
150 PropertyNotificationManager& GetPropertyNotificationManager();
152 // Root actor accessors
155 * @copydoc Dali::Stage::Add()
157 void Add( Actor& actor );
160 * @copydoc Dali::Stage::Remove()
162 void Remove( Actor& actor );
165 * Sets the size of the stage and indirectly, the root actor.
166 * @param [in] width The new width.
167 * @param [in] height The new height.
169 void SetSize( float width, float height );
172 * Returns the size of the Stage in pixels as a Vector.
173 * The x component will be the width of the Stage in pixels
174 * The y component will be the height of the Stage in pixels
175 * @return The size of the Stage as a Vector.
177 Vector2 GetSize() const;
180 * @copydoc Dali::Stage::GetRenderTaskList()
182 RenderTaskList& GetRenderTaskList() const;
185 * Create a default camera actor
187 void CreateDefaultCameraActor();
190 * From RenderTaskDefaults; retrieve the default root actor.
191 * @return The default root actor.
193 virtual Actor& GetDefaultRootActor();
196 * From RenderTaskDefaults; retrieve the default camera actor.
197 * @return The default camera actor.
199 virtual CameraActor& GetDefaultCameraActor();
204 * @copydoc Dali::Stage::GetLayerCount()
206 unsigned int GetLayerCount() const;
209 * @copydoc Dali::Stage::GetLayer()
211 Dali::Layer GetLayer( unsigned int depth ) const;
214 * @copydoc Dali::Stage::GetRootLayer()
216 Dali::Layer GetRootLayer() const;
219 * Retrieve the ordered list of on-stage layers.
220 * @return The layer-list.
222 LayerList& GetLayerList();
224 // System-level overlay actors
227 * @copydoc Dali::Integration::Core::GetSystemOverlay()
229 Integration::SystemOverlay& GetSystemOverlay();
232 * Retrieve the internal implementation of the SystemOverlay.
233 * @return The implementation, or NULL if this has never been requested from Integration API.
235 SystemOverlay* GetSystemOverlayInternal();
240 * @copydoc Dali::Integration::Core::SetViewMode()
242 void SetViewMode( ViewMode viewMode );
245 * @copydoc Dali::Integration::Core::GetViewMode()
247 ViewMode GetViewMode() const;
250 * @copydoc Dali::Integration::Core::SetStereoBase()
252 void SetStereoBase( float stereoBase );
255 * @copydoc Dali::Integration::Core::GetStereoBase()
257 float GetStereoBase() const;
262 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
263 * set to receive keyboard input.
264 * @param[in] actor to receive keyboard input
266 void SetKeyboardFocusActor( Actor* actor );
269 * Get the actor that is currently set to receive keyboard inputs
270 * @return Pointer to the actor set to receive keyboard inputs.
272 Actor* GetKeyboardFocusActor() const;
275 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
276 * @param [in] actor which should be removed from focus.
278 void RemoveActorFromKeyFocus( Actor* actor );
283 * @copydoc Dali::Stage::SetBackgroundColor
285 void SetBackgroundColor(Vector4 color);
288 * @copydoc Dali::Stage::GetBackgroundColor
290 Vector4 GetBackgroundColor() const;
293 * @copydoc Dali::Stage::GetDpi
295 Vector2 GetDpi() const;
298 * Sets horizontal and vertical pixels per inch value that is used by the display
299 * @param[in] dpi Horizontal and vertical dpi value
301 void SetDpi( Vector2 dpi );
303 #ifdef DYNAMICS_SUPPORT
306 * Return the Dynamics Simulation Notifier object
307 * @return The Dynamics Simulation Notifier object
309 DynamicsNotifier& GetDynamicsNotifier();
312 * @copydoc Dali::Stage::InitializeDynamics
314 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
317 * @copydoc Dali::Stage::GetDynamicsWorld
319 DynamicsWorldPtr GetDynamicsWorld();
322 * @copydoc Dali::Stage::TerminateDynamics
324 void TerminateDynamics();
326 #endif // DYNAMICS_SUPPORT
328 NotificationManager& GetNotificationManager()
330 return mNotificationManager;
334 * @copydoc Dali::Stage::KeepRendering()
336 void KeepRendering( float durationSeconds );
339 * Used by the EventProcessor to emit key event signals.
340 * @param[in] event The key event.
342 void EmitKeyEventSignal(const KeyEvent& event);
345 * Emits the event processing finished signal.
347 * @see Dali::Stage::SignalEventProcessingFinished()
349 void EmitEventProcessingFinishedSignal();
352 * Emits the touched signal.
353 * @param[in] touch The touch event details.
355 void EmitTouchedSignal( const TouchEvent& touch );
358 * @copydoc Dali::Stage::KeyEventSignal()
360 Dali::Stage::KeyEventSignalV2& KeyEventSignal();
363 * @copydoc Dali::Stage::SignalEventProcessingFinished()
365 Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
368 * @copydoc Dali::Stage::TouchedSignal()
370 Dali::Stage::TouchedSignalV2& TouchedSignal();
375 * Protected constructor; see also Stage::New()
377 Stage( AnimationPlaylist& playlist,
378 PropertyNotificationManager& propertyNotificationManager,
379 SceneGraph::UpdateManager& updateManager,
380 NotificationManager& notificationManager );
383 * A reference counted object may only be deleted by calling Unreference()
389 // For 'Fire and forget' animation support
390 AnimationPlaylist& mAnimationPlaylist;
392 PropertyNotificationManager& mPropertyNotificationManager;
394 SceneGraph::UpdateManager& mUpdateManager;
396 NotificationManager& mNotificationManager;
398 // The Actual size of the stage.
401 // Cached for public GetBackgroundColor()
402 Vector4 mBackgroundColor;
406 // Ordered list of currently on-stage layers
407 OwnerPointer<LayerList> mLayerList;
409 IntrusivePtr<CameraActor> mDefaultCamera;
416 // The object registry
417 ObjectRegistryPtr mObjectRegistry;
419 #ifdef DYNAMICS_SUPPORT
421 DynamicsNotifier mDynamicsNotifier;
423 // The Dynamics simulation world object
424 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
425 DynamicsWorldPtr mDynamicsWorld;
427 #endif // DYNAMICS_SUPPORT
429 // The list of render-tasks
430 IntrusivePtr<RenderTaskList> mRenderTaskList;
432 Dali::RenderTask mRightRenderTask;
433 IntrusivePtr<CameraActor> mRightCamera;
434 Dali::RenderTask mLeftRenderTask;
435 IntrusivePtr<CameraActor> mLeftCamera;
437 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
439 // The key event signal
440 Dali::Stage::KeyEventSignalV2 mKeyEventSignalV2;
442 // The event processing finished signal
443 Dali::Stage::EventProcessingFinishedSignalV2 mEventProcessingFinishedSignalV2;
445 // The touched signal
446 Dali::Stage::TouchedSignalV2 mTouchedSignalV2;
449 } // namespace Internal
451 // Helpers for public-api forwarding methods
453 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
455 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
457 BaseObject& handle = stage.GetBaseObject();
459 return static_cast<Internal::Stage&>(handle);
462 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
464 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
466 const BaseObject& handle = stage.GetBaseObject();
468 return static_cast<const Internal::Stage&>(handle);
473 #endif // __DALI_INTERNAL_STAGE_H__