1 #ifndef __DALI_INTERNAL_STAGE_H__
2 #define __DALI_INTERNAL_STAGE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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/internal/common/owner-pointer.h>
26 #include <dali/internal/event/actors/layer-impl.h>
27 #include <dali/internal/event/common/object-registry-impl.h>
28 #include <dali/internal/event/common/stage-def.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>
37 #ifdef DYNAMICS_SUPPORT
38 #include <dali/internal/event/dynamics/dynamics-declarations.h>
39 #include <dali/internal/event/dynamics/dynamics-notifier.h>
50 class DynamicsFactory;
61 class AnimationPlaylist;
62 class PropertyNotificationManager;
70 * Implementation of Stage
72 class Stage : public BaseObject, public RenderTaskDefaults
78 * @param[in] playlist for animations
79 * @param[in] propertyNotificationManager
80 * @param[in] updateManager
81 * @param[in] notificationManager
83 static StagePtr New( AnimationPlaylist& playlist,
84 PropertyNotificationManager& propertyNotificationManager,
85 SceneGraph::UpdateManager& updateManager,
86 NotificationManager& notificationManager );
89 * Initialize the stage.
94 * Uninitialize the stage.
99 * @copydoc Dali::Stage::GetCurrent()
101 static StagePtr GetCurrent();
104 * @copydoc Dali::Stage::IsInstalled().
106 static bool IsInstalled();
109 * @copydoc Dali::Stage::GetObjectRegistry()
111 ObjectRegistry& GetObjectRegistry();
114 * Retrieve the root actor (not publically accessible).
115 * @return The root actor.
117 Layer& GetRootActor();
120 * Retrieve the UpdateManager associated with this Stage
121 * @return The UpdateManager.
123 SceneGraph::UpdateManager& GetUpdateManager();
126 * Helper for actors, to retrieve the current Event buffer index.
127 * @return The buffer index.
129 BufferIndex GetEventBufferIndex() const
131 // inlined as its called often from event thread
132 return mUpdateManager.GetEventBufferIndex();
136 * Retrieve the interface for accessing update-thread data.
137 * @return The EventToUpdate interface.
139 EventToUpdate& GetUpdateInterface();
142 * Returns the animation playlist.
143 * @return reference to the animation playlist.
145 AnimationPlaylist& GetAnimationPlaylist();
148 * Returns the property notification manager.
149 * @return reference to the property notification manager.
151 PropertyNotificationManager& GetPropertyNotificationManager();
153 // Root actor accessors
156 * @copydoc Dali::Stage::Add()
158 void Add( Actor& actor );
161 * @copydoc Dali::Stage::Remove()
163 void Remove( Actor& actor );
166 * Sets the size of the stage and indirectly, the root actor.
167 * @param [in] width The new width.
168 * @param [in] height The new height.
170 void SetSize( float width, float height );
173 * Returns the size of the Stage in pixels as a Vector.
174 * The x component will be the width of the Stage in pixels
175 * The y component will be the height of the Stage in pixels
176 * @return The size of the Stage as a Vector.
178 Vector2 GetSize() const;
181 * @copydoc Dali::Stage::GetRenderTaskList()
183 RenderTaskList& GetRenderTaskList() const;
186 * Create a default camera actor
188 void CreateDefaultCameraActor();
191 * From RenderTaskDefaults; retrieve the default root actor.
192 * @return The default root actor.
194 virtual Actor& GetDefaultRootActor();
197 * From RenderTaskDefaults; retrieve the default camera actor.
198 * @return The default camera actor.
200 virtual CameraActor& GetDefaultCameraActor();
205 * @copydoc Dali::Stage::GetLayerCount()
207 unsigned int GetLayerCount() const;
210 * @copydoc Dali::Stage::GetLayer()
212 Dali::Layer GetLayer( unsigned int depth ) const;
215 * @copydoc Dali::Stage::GetRootLayer()
217 Dali::Layer GetRootLayer() const;
220 * Retrieve the ordered list of on-stage layers.
221 * @return The layer-list.
223 LayerList& GetLayerList();
225 // System-level overlay actors
228 * @copydoc Dali::Integration::Core::GetSystemOverlay()
230 Integration::SystemOverlay& GetSystemOverlay();
233 * Retrieve the internal implementation of the SystemOverlay.
234 * @return The implementation, or NULL if this has never been requested from Integration API.
236 SystemOverlay* GetSystemOverlayInternal();
241 * @copydoc Dali::Integration::Core::SetViewMode()
243 void SetViewMode( ViewMode viewMode );
246 * @copydoc Dali::Integration::Core::GetViewMode()
248 ViewMode GetViewMode() const;
251 * @copydoc Dali::Integration::Core::SetStereoBase()
253 void SetStereoBase( float stereoBase );
256 * @copydoc Dali::Integration::Core::GetStereoBase()
258 float GetStereoBase() const;
263 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
264 * set to receive keyboard input.
265 * @param[in] actor to receive keyboard input
267 void SetKeyboardFocusActor( Actor* actor );
270 * Get the actor that is currently set to receive keyboard inputs
271 * @return Pointer to the actor set to receive keyboard inputs.
273 Actor* GetKeyboardFocusActor() const;
276 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
277 * @param [in] actor which should be removed from focus.
279 void RemoveActorFromKeyFocus( Actor* actor );
284 * @copydoc Dali::Stage::SetBackgroundColor
286 void SetBackgroundColor(Vector4 color);
289 * @copydoc Dali::Stage::GetBackgroundColor
291 Vector4 GetBackgroundColor() const;
294 * @copydoc Dali::Stage::GetDpi
296 Vector2 GetDpi() const;
299 * Sets horizontal and vertical pixels per inch value that is used by the display
300 * @param[in] dpi Horizontal and vertical dpi value
302 void SetDpi( Vector2 dpi );
304 #ifdef DYNAMICS_SUPPORT
307 * Return the Dynamics Simulation Notifier object
308 * @return The Dynamics Simulation Notifier object
310 DynamicsNotifier& GetDynamicsNotifier();
313 * @copydoc Dali::Stage::InitializeDynamics
315 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
318 * @copydoc Dali::Stage::GetDynamicsWorld
320 DynamicsWorldPtr GetDynamicsWorld();
323 * @copydoc Dali::Stage::TerminateDynamics
325 void TerminateDynamics();
327 #endif // DYNAMICS_SUPPORT
329 NotificationManager& GetNotificationManager()
331 return mNotificationManager;
335 * @copydoc Dali::Stage::KeepRendering()
337 void KeepRendering( float durationSeconds );
340 * Used by the EventProcessor to emit key event signals.
341 * @param[in] event The key event.
343 void EmitKeyEventSignal(const KeyEvent& event);
346 * Emits the event processing finished signal.
348 * @see Dali::Stage::SignalEventProcessingFinished()
350 void EmitEventProcessingFinishedSignal();
353 * Emits the touched signal.
354 * @param[in] touch The touch event details.
356 void EmitTouchedSignal( const TouchEvent& touch );
359 * @copydoc Dali::Stage::KeyEventSignal()
361 Dali::Stage::KeyEventSignalV2& KeyEventSignal();
364 * @copydoc Dali::Stage::SignalEventProcessingFinished()
366 Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
369 * @copydoc Dali::Stage::TouchedSignal()
371 Dali::Stage::TouchedSignalV2& TouchedSignal();
376 * Protected constructor; see also Stage::New()
378 Stage( AnimationPlaylist& playlist,
379 PropertyNotificationManager& propertyNotificationManager,
380 SceneGraph::UpdateManager& updateManager,
381 NotificationManager& notificationManager );
384 * A reference counted object may only be deleted by calling Unreference()
390 // For 'Fire and forget' animation support
391 AnimationPlaylist& mAnimationPlaylist;
393 PropertyNotificationManager& mPropertyNotificationManager;
395 SceneGraph::UpdateManager& mUpdateManager;
397 NotificationManager& mNotificationManager;
399 // The Actual size of the stage.
402 // Cached for public GetBackgroundColor()
403 Vector4 mBackgroundColor;
407 // Ordered list of currently on-stage layers
408 OwnerPointer<LayerList> mLayerList;
410 IntrusivePtr<CameraActor> mDefaultCamera;
417 // The object registry
418 ObjectRegistryPtr mObjectRegistry;
420 #ifdef DYNAMICS_SUPPORT
422 DynamicsNotifier mDynamicsNotifier;
424 // The Dynamics simulation world object
425 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
426 DynamicsWorldPtr mDynamicsWorld;
428 #endif // DYNAMICS_SUPPORT
430 // The list of render-tasks
431 IntrusivePtr<RenderTaskList> mRenderTaskList;
433 Dali::RenderTask mRightRenderTask;
434 IntrusivePtr<CameraActor> mRightCamera;
435 Dali::RenderTask mLeftRenderTask;
436 IntrusivePtr<CameraActor> mLeftCamera;
438 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
440 // The key event signal
441 Dali::Stage::KeyEventSignalV2 mKeyEventSignalV2;
443 // The event processing finished signal
444 Dali::Stage::EventProcessingFinishedSignalV2 mEventProcessingFinishedSignalV2;
446 // The touched signal
447 Dali::Stage::TouchedSignalV2 mTouchedSignalV2;
450 } // namespace Internal
452 // Helpers for public-api forwarding methods
454 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
456 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
458 BaseObject& handle = stage.GetBaseObject();
460 return static_cast<Internal::Stage&>(handle);
463 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
465 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
467 const BaseObject& handle = stage.GetBaseObject();
469 return static_cast<const Internal::Stage&>(handle);
474 #endif // __DALI_INTERNAL_STAGE_H__