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/dynamics/dynamics-declarations.h>
29 #include <dali/internal/event/render-tasks/render-task-defaults.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/public-api/common/view-mode.h>
32 #include <dali/public-api/math/vector2.h>
33 #include <dali/public-api/math/vector3.h>
34 #include <dali/public-api/math/vector4.h>
35 #include <dali/public-api/render-tasks/render-task.h>
45 class DynamicsFactory;
56 class AnimationPlaylist;
57 class PropertyNotificationManager;
65 * Implementation of Stage
67 class Stage : public BaseObject, public RenderTaskDefaults
73 * @param playlist for animations
74 * @param dynamicsNotifier
75 * @param updateManager
76 * @param notificationManager
78 static StagePtr New( AnimationPlaylist& playlist,
79 PropertyNotificationManager& propertyNotificationManager,
80 DynamicsNotifier& dynamicsNotifier,
81 SceneGraph::UpdateManager& updateManager,
82 NotificationManager& notificationManager );
85 * Initialize the stage.
90 * Uninitialize the stage.
95 * @copydoc Dali::Stage::GetCurrent()
97 static StagePtr GetCurrent();
100 * @copydoc Dali::Stage::IsInstalled().
102 static bool IsInstalled();
105 * @copydoc Dali::Stage::GetObjectRegistry()
107 ObjectRegistry& GetObjectRegistry();
110 * Retrieve the root actor (not publically accessible).
111 * @return The root actor.
113 Layer& GetRootActor();
116 * Retrieve the UpdateManager associated with this Stage
117 * @return The UpdateManager.
119 SceneGraph::UpdateManager& GetUpdateManager();
122 * Helper for actors, to retrieve the current Event buffer index.
123 * @return The buffer index.
125 BufferIndex GetEventBufferIndex() const
127 // inlined as its called often from event thread
128 return mUpdateManager.GetEventBufferIndex();
132 * Retrieve the interface for accessing update-thread data.
133 * @return The EventToUpdate interface.
135 EventToUpdate& GetUpdateInterface();
138 * Returns the animation playlist.
139 * @return reference to the animation playlist.
141 AnimationPlaylist& GetAnimationPlaylist();
144 * Returns the property notification manager.
145 * @return reference to the property notification manager.
147 PropertyNotificationManager& GetPropertyNotificationManager();
150 * Return the Dynamics Simulation Notifier object
151 * @return The Dynamics Simulation Notifier object
153 DynamicsNotifier& GetDynamicsNotifier();
155 // Root actor accessors
158 * @copydoc Dali::Stage::Add()
160 void Add( Actor& actor );
163 * @copydoc Dali::Stage::Remove()
165 void Remove( Actor& actor );
168 * Sets the size of the stage and indirectly, the root actor.
169 * @param [in] width The new width.
170 * @param [in] height The new height.
172 void SetSize( float width, float height );
175 * Returns the size of the Stage in pixels as a Vector.
176 * The x component will be the width of the Stage in pixels
177 * The y component will be the height of the Stage in pixels
178 * @return The size of the Stage as a Vector.
180 Vector2 GetSize() const;
183 * @copydoc Dali::Stage::GetRenderTaskList()
185 RenderTaskList& GetRenderTaskList() const;
188 * Create a default camera actor
190 void CreateDefaultCameraActor();
193 * From RenderTaskDefaults; retrieve the default root actor.
194 * @return The default root actor.
196 virtual Actor& GetDefaultRootActor();
199 * From RenderTaskDefaults; retrieve the default camera actor.
200 * @return The default camera actor.
202 virtual CameraActor& GetDefaultCameraActor();
207 * @copydoc Dali::Stage::GetLayerCount()
209 unsigned int GetLayerCount() const;
212 * @copydoc Dali::Stage::GetLayer()
214 Dali::Layer GetLayer( unsigned int depth ) const;
217 * @copydoc Dali::Stage::GetRootLayer()
219 Dali::Layer GetRootLayer() const;
222 * Retrieve the ordered list of on-stage layers.
223 * @return The layer-list.
225 LayerList& GetLayerList();
227 // System-level overlay actors
230 * @copydoc Dali::Integration::Core::GetSystemOverlay()
232 Integration::SystemOverlay& GetSystemOverlay();
235 * Retrieve the internal implementation of the SystemOverlay.
236 * @return The implementation, or NULL if this has never been requested from Integration API.
238 SystemOverlay* GetSystemOverlayInternal();
243 * @copydoc Dali::Integration::Core::SetViewMode()
245 void SetViewMode( ViewMode viewMode );
248 * @copydoc Dali::Integration::Core::GetViewMode()
250 ViewMode GetViewMode() const;
253 * @copydoc Dali::Integration::Core::SetStereoBase()
255 void SetStereoBase( float stereoBase );
258 * @copydoc Dali::Integration::Core::GetStereoBase()
260 float GetStereoBase() const;
265 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
266 * set to receive keyboard input.
267 * @param[in] actor to receive keyboard input
269 void SetKeyboardFocusActor( Actor* actor );
272 * Get the actor that is currently set to receive keyboard inputs
273 * @return Pointer to the actor set to receive keyboard inputs.
275 Actor* GetKeyboardFocusActor() const;
278 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
279 * @param [in] actor which should be removed from focus.
281 void RemoveActorFromKeyFocus( Actor* actor );
286 * @copydoc Dali::Stage::SetBackgroundColor
288 void SetBackgroundColor(Vector4 color);
291 * @copydoc Dali::Stage::GetBackgroundColor
293 Vector4 GetBackgroundColor() const;
296 * @copydoc Dali::Stage::GetDpi
298 Vector2 GetDpi() const;
301 * Sets horizontal and vertical pixels per inch value that is used by the display
302 * @param[in] dpi Horizontal and vertical dpi value
304 void SetDpi( Vector2 dpi );
307 * @copydoc Dali::Stage::InitializeDynamics
309 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
312 * @copydoc Dali::Stage::GetDynamicsWorld
314 DynamicsWorldPtr GetDynamicsWorld();
317 * @copydoc Dali::Stage::TerminateDynamics
319 void TerminateDynamics();
321 NotificationManager& GetNotificationManager()
323 return mNotificationManager;
327 * @copydoc Dali::Stage::KeepRendering()
329 void KeepRendering( float durationSeconds );
332 * Used by the EventProcessor to emit key event signals.
333 * @param[in] event The key event.
335 void EmitKeyEventSignal(const KeyEvent& event);
338 * Emits the event processing finished signal.
340 * @see Dali::Stage::SignalEventProcessingFinished()
342 void EmitEventProcessingFinishedSignal();
345 * Emits the touched signal.
346 * @param[in] touch The touch event details.
348 void EmitTouchedSignal( const TouchEvent& touch );
351 * @copydoc Dali::Stage::KeyEventSignal()
353 Dali::Stage::KeyEventSignalV2& KeyEventSignal();
356 * @copydoc Dali::Stage::SignalEventProcessingFinished()
358 Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
361 * @copydoc Dali::Stage::TouchedSignal()
363 Dali::Stage::TouchedSignalV2& TouchedSignal();
368 * Protected constructor; see also Stage::New()
370 Stage( AnimationPlaylist& playlist,
371 PropertyNotificationManager& propertyNotificationManager,
372 DynamicsNotifier& dynamicsNotifier,
373 SceneGraph::UpdateManager& updateManager,
374 NotificationManager& notificationManager );
377 * A reference counted object may only be deleted by calling Unreference()
383 // For 'Fire and forget' animation support
384 AnimationPlaylist& mAnimationPlaylist;
386 PropertyNotificationManager& mPropertyNotificationManager;
388 DynamicsNotifier& mDynamicsNotifier;
390 SceneGraph::UpdateManager& mUpdateManager;
392 NotificationManager& mNotificationManager;
394 // The Actual size of the stage.
397 // Cached for public GetBackgroundColor()
398 Vector4 mBackgroundColor;
402 // Ordered list of currently on-stage layers
403 OwnerPointer<LayerList> mLayerList;
405 IntrusivePtr<CameraActor> mDefaultCamera;
412 // The object registry
413 ObjectRegistryPtr mObjectRegistry;
415 // The Dynamics simulation world object
416 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
417 DynamicsWorldPtr mDynamicsWorld;
419 // The list of render-tasks
420 IntrusivePtr<RenderTaskList> mRenderTaskList;
422 Dali::RenderTask mRightRenderTask;
423 IntrusivePtr<CameraActor> mRightCamera;
424 Dali::RenderTask mLeftRenderTask;
425 IntrusivePtr<CameraActor> mLeftCamera;
427 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
429 // The key event signal
430 Dali::Stage::KeyEventSignalV2 mKeyEventSignalV2;
432 // The event processing finished signal
433 Dali::Stage::EventProcessingFinishedSignalV2 mEventProcessingFinishedSignalV2;
435 // The touched signal
436 Dali::Stage::TouchedSignalV2 mTouchedSignalV2;
439 } // namespace Internal
441 // Helpers for public-api forwarding methods
443 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
445 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
447 BaseObject& handle = stage.GetBaseObject();
449 return static_cast<Internal::Stage&>(handle);
452 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
454 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
456 const BaseObject& handle = stage.GetBaseObject();
458 return static_cast<const Internal::Stage&>(handle);
463 #endif // __DALI_INTERNAL_STAGE_H__