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/math/vector2.h>
32 #include <dali/public-api/math/vector3.h>
33 #include <dali/public-api/math/vector4.h>
43 class DynamicsFactory;
54 class AnimationPlaylist;
55 class PropertyNotificationManager;
63 * Implementation of Stage
65 class Stage : public BaseObject, public RenderTaskDefaults
71 * @param playlist for animations
72 * @param dynamicsNotifier
73 * @param updateManager
74 * @param notificationManager
76 static StagePtr New( AnimationPlaylist& playlist,
77 PropertyNotificationManager& propertyNotificationManager,
78 DynamicsNotifier& dynamicsNotifier,
79 SceneGraph::UpdateManager& updateManager,
80 NotificationManager& notificationManager );
83 * Initialize the stage.
88 * Uninitialize the stage.
93 * @copydoc Dali::Stage::GetCurrent()
95 static StagePtr GetCurrent();
98 * @copydoc Dali::Stage::IsInstalled().
100 static bool IsInstalled();
103 * @copydoc Dali::Stage::GetObjectRegistry()
105 ObjectRegistry& GetObjectRegistry();
108 * Retrieve the root actor (not publically accessible).
109 * @return The root actor.
111 Layer& GetRootActor();
114 * Retrieve the UpdateManager associated with this Stage
115 * @return The UpdateManager.
117 SceneGraph::UpdateManager& GetUpdateManager();
120 * Helper for actors, to retrieve the current Event buffer index.
121 * @return The buffer index.
123 BufferIndex GetEventBufferIndex() const
125 // inlined as its called often from event thread
126 return mUpdateManager.GetEventBufferIndex();
130 * Retrieve the interface for accessing update-thread data.
131 * @return The EventToUpdate interface.
133 EventToUpdate& GetUpdateInterface();
136 * Returns the animation playlist.
137 * @return reference to the animation playlist.
139 AnimationPlaylist& GetAnimationPlaylist();
142 * Returns the property notification manager.
143 * @return reference to the property notification manager.
145 PropertyNotificationManager& GetPropertyNotificationManager();
148 * Return the Dynamics Simulation Notifier object
149 * @return The Dynamics Simulation Notifier object
151 DynamicsNotifier& GetDynamicsNotifier();
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 * As one virtual keyboard per stage, the stage will hold a pointer to the Actor currently
242 * set to receive keyboard input.
243 * @param[in] actor to receive keyboard input
245 void SetKeyboardFocusActor( Actor* actor );
248 * Get the actor that is currently set to receive keyboard inputs
249 * @return Pointer to the actor set to receive keyboard inputs.
251 Actor* GetKeyboardFocusActor() const;
254 * Removes the given actor from keyboard focus so it will no longer receive key events from keyboard.
255 * @param [in] actor which should be removed from focus.
257 void RemoveActorFromKeyFocus( Actor* actor );
262 * @copydoc Dali::Stage::SetBackgroundColor
264 void SetBackgroundColor(Vector4 color);
267 * @copydoc Dali::Stage::GetBackgroundColor
269 Vector4 GetBackgroundColor() const;
272 * @copydoc Dali::Stage::GetDpi
274 Vector2 GetDpi() const;
277 * Sets horizontal and vertical pixels per inch value that is used by the display
278 * @param[in] dpi Horizontal and vertical dpi value
280 void SetDpi( Vector2 dpi );
283 * @copydoc Dali::Stage::InitializeDynamics
285 DynamicsWorldPtr InitializeDynamics(DynamicsWorldConfigPtr config);
288 * @copydoc Dali::Stage::GetDynamicsWorld
290 DynamicsWorldPtr GetDynamicsWorld();
293 * @copydoc Dali::Stage::TerminateDynamics
295 void TerminateDynamics();
297 NotificationManager& GetNotificationManager()
299 return mNotificationManager;
303 * @copydoc Dali::Stage::KeepRendering()
305 void KeepRendering( float durationSeconds );
308 * Used by the EventProcessor to emit key event signals.
309 * @param[in] event The key event.
311 void EmitKeyEventSignal(const KeyEvent& event);
314 * Emits the event processing finished signal.
316 * @see Dali::Stage::SignalEventProcessingFinished()
318 void EmitEventProcessingFinishedSignal();
321 * Emits the touched signal.
322 * @param[in] touch The touch event details.
324 void EmitTouchedSignal( const TouchEvent& touch );
327 * @copydoc Dali::Stage::KeyEventSignal()
329 Dali::Stage::KeyEventSignalV2& KeyEventSignal();
332 * @copydoc Dali::Stage::SignalEventProcessingFinished()
334 Dali::Stage::EventProcessingFinishedSignalV2& EventProcessingFinishedSignal();
337 * @copydoc Dali::Stage::TouchedSignal()
339 Dali::Stage::TouchedSignalV2& TouchedSignal();
344 * Protected constructor; see also Stage::New()
346 Stage( AnimationPlaylist& playlist,
347 PropertyNotificationManager& propertyNotificationManager,
348 DynamicsNotifier& dynamicsNotifier,
349 SceneGraph::UpdateManager& updateManager,
350 NotificationManager& notificationManager );
353 * A reference counted object may only be deleted by calling Unreference()
359 // For 'Fire and forget' animation support
360 AnimationPlaylist& mAnimationPlaylist;
362 PropertyNotificationManager& mPropertyNotificationManager;
364 DynamicsNotifier& mDynamicsNotifier;
366 SceneGraph::UpdateManager& mUpdateManager;
368 NotificationManager& mNotificationManager;
370 // The Actual size of the stage.
373 // Cached for public GetBackgroundColor()
374 Vector4 mBackgroundColor;
378 // Ordered list of currently on-stage layers
379 OwnerPointer<LayerList> mLayerList;
381 IntrusivePtr<CameraActor> mDefaultCamera;
385 // The object registry
386 ObjectRegistryPtr mObjectRegistry;
388 // The Dynamics simulation world object
389 Integration::DynamicsFactory* mDynamicsFactory; // Not owned pointer to DynamicsFactory (PlatformAbstraction will clean up)
390 DynamicsWorldPtr mDynamicsWorld;
392 // The list of render-tasks
393 IntrusivePtr<RenderTaskList> mRenderTaskList;
395 Integration::SystemOverlay* mSystemOverlay; ///< SystemOverlay stage access
397 // The key event signal
398 Dali::Stage::KeyEventSignalV2 mKeyEventSignalV2;
400 // The event processing finished signal
401 Dali::Stage::EventProcessingFinishedSignalV2 mEventProcessingFinishedSignalV2;
403 // The touched signal
404 Dali::Stage::TouchedSignalV2 mTouchedSignalV2;
407 } // namespace Internal
409 // Helpers for public-api forwarding methods
411 inline Internal::Stage& GetImplementation(Dali::Stage& stage)
413 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
415 BaseObject& handle = stage.GetBaseObject();
417 return static_cast<Internal::Stage&>(handle);
420 inline const Internal::Stage& GetImplementation(const Dali::Stage& stage)
422 DALI_ASSERT_ALWAYS( stage && "Stage handle is empty" );
424 const BaseObject& handle = stage.GetBaseObject();
426 return static_cast<const Internal::Stage&>(handle);
431 #endif // __DALI_INTERNAL_STAGE_H__