Renamed TouchSignal to TouchedSignal
[platform/core/uifw/dali-core.git] / dali / devel-api / common / stage.h
1 #ifndef DALI_STAGE_H
2 #define DALI_STAGE_H
3
4 /*
5  * Copyright (c) 2020 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 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/signals/dali-signal.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_common
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 class Stage;
38 }
39
40 class Actor;
41 class Layer;
42 class ObjectRegistry;
43 class TouchEvent;
44 class RenderTaskList;
45 class WheelEvent;
46 struct Vector2;
47 struct Vector3;
48 struct Vector4;
49 class KeyEvent;
50
51 /**
52  * @brief The Stage is a top-level object used for displaying a tree of Actors.
53  *
54  * Stage is a top-level object that represents the entire screen.
55  * It is used for displaying a hierarchy of actors managed by the scene graph structure,
56  * which means an actor inherits a position relative to its parent,
57  * and can be moved in relation to this point.
58  *
59  * The stage instance is a singleton object (the only instance of its class during the
60  * lifetime of the program). You can get it using a static function.
61  *
62  * To display the contents of an actor, it must be added to a stage.
63  * The following example shows how to connect a new actor to the stage:
64  * @code
65  * Actor actor = Actor::New();
66  * Stage::GetCurrent().Add( actor );
67  * @endcode
68  *
69  * The stage has a 2D size that matches the size of the application window.
70  * The default unit 1 is 1 pixel with the default camera.
71  *
72  * Multiple stage/window support is not currently provided.
73  *
74  * Signals
75  * | %Signal Name            | Method                               |
76  * |-------------------------|--------------------------------------|
77  * | keyEvent                | @ref KeyEventSignal()                |
78  * | eventProcessingFinished | @ref EventProcessingFinishedSignal() |
79  * | touched                 | @ref TouchedSignal()                 |
80  * | wheelEvent              | @ref WheelEventSignal()              |
81  * | contextLost             | @ref ContextLostSignal()             |
82  * | contextRegained         | @ref ContextRegainedSignal()         |
83  * | sceneCreated            | @ref SceneCreatedSignal()            |
84  */
85 class DALI_CORE_API Stage : public BaseHandle
86 {
87 public:
88
89   typedef Signal< void (const KeyEvent&) > KeyEventSignalType;       ///< Key event signal type
90   typedef Signal< void () > EventProcessingFinishedSignalType;       ///< Event Processing finished signal type
91   typedef Signal< void (const TouchEvent&) > TouchEventSignalType;   ///< Touch signal type
92   typedef Signal< void (const WheelEvent&) > WheelEventSignalType;   ///< Wheel signal type
93   typedef Signal< void () > ContextStatusSignal;                     ///< Context status signal type
94   typedef Signal< void () > SceneCreatedSignalType;                  ///< Scene created signal type
95
96   /**
97    * @brief Allows the creation of an empty stage handle.
98    *
99    * To retrieve the current stage, this handle can be set using Stage::GetCurrent().
100    */
101   Stage();
102
103   /**
104    * @brief Gets the current Stage.
105    *
106    * @return The current stage or an empty handle if the internal core has not been created or has been already destroyed
107    */
108   static Stage GetCurrent();
109
110   /**
111    * @brief Queries whether the Stage exists; this should only return false during or after destruction of Dali core.
112    *
113    * @return True when it's safe to call Stage::GetCurrent()
114    */
115   static bool IsInstalled();
116
117   /**
118    * @brief Destructor.
119    *
120    * This is non-virtual since derived Handle types must not contain data or virtual methods.
121    */
122   ~Stage();
123
124   /**
125    * @brief This copy constructor is required for (smart) pointer semantics.
126    *
127    * @param[in] handle A reference to the copied handle
128    */
129   Stage(const Stage& handle);
130
131   /**
132    * @brief This assignment operator is required for (smart) pointer semantics.
133    *
134    * @param[in] rhs A reference to the copied handle
135    * @return A reference to this
136    */
137   Stage& operator=(const Stage& rhs);
138
139   // Containment
140
141   /**
142    * @brief Adds a child Actor to the Stage.
143    *
144    * The child will be referenced.
145    * @param[in] actor The child
146    * @pre The actor has been initialized.
147    * @pre The actor does not have a parent.
148    */
149   void Add(Actor& actor);
150
151   /**
152    * @brief Removes a child Actor from the Stage.
153    *
154    * The child will be unreferenced.
155    * @param[in] actor The child
156    * @pre The actor has been added to the stage.
157    */
158   void Remove(Actor& actor);
159
160   /**
161    * @brief Returns the size of the Stage in pixels as a Vector.
162    *
163    * The x component will be the width of the Stage in pixels.
164    * The y component will be the height of the Stage in pixels.
165    * The z component will be the distance between far and near planes.
166    * @return The size of the Stage as a Vector
167    */
168   Vector2 GetSize() const;
169
170   // Render Tasks
171
172   /**
173    * @brief Retrieves the list of render-tasks.
174    *
175    * @return A valid handle to a RenderTaskList
176    */
177   RenderTaskList GetRenderTaskList() const;
178
179   // Layers
180
181   /**
182    * @brief Queries the number of on-stage layers.
183    *
184    * Note that a default layer is always provided (count >= 1).
185    * @return The number of layers
186    */
187   uint32_t GetLayerCount() const;
188
189   /**
190    * @brief Retrieves the layer at a specified depth.
191    *
192    * @param[in] depth The depth
193    * @return The layer found at the given depth
194    * @pre Depth is less than layer count; see GetLayerCount().
195    */
196   Layer GetLayer(uint32_t depth) const;
197
198   /**
199    * @brief Returns the Stage's Root Layer.
200    *
201    * @return The root layer
202    */
203   Layer GetRootLayer() const;
204
205   // Background color
206
207   /**
208    * @brief Sets the background color of the stage.
209    *
210    * @param[in] color The new background color
211    */
212   void SetBackgroundColor(Vector4 color);
213
214   /**
215    * @brief Retrieves the background color of the stage.
216    *
217    * @return The background color
218    */
219   Vector4 GetBackgroundColor() const;
220
221   /**
222    * @brief Retrieves the DPI of the display device to which the stage is connected.
223    *
224    * @return The horizontal and vertical DPI
225    */
226   Vector2 GetDpi() const;
227
228   /**
229    * @brief Gets the Object registry.
230    *
231    * @return The object registry
232    */
233   ObjectRegistry GetObjectRegistry() const;
234
235   // Rendering
236
237   /**
238    * @brief Keep rendering for at least the given amount of time.
239    *
240    * By default, Dali will stop rendering when no Actor positions are being set, and when no animations are running etc.
241    * This method is useful to force screen refreshes e.g. when updating a NativeImage.
242    * @param[in] durationSeconds Time to keep rendering, 0 means render at least one more frame
243    */
244   void KeepRendering( float durationSeconds );
245
246   // Signals
247
248   /**
249    * @brief This signal is emitted when key event is received.
250    *
251    * A callback of the following type may be connected:
252    * @code
253    *   void YourCallbackName(const KeyEvent& event);
254    * @endcode
255    * @return The signal to connect to
256    */
257   KeyEventSignalType& KeyEventSignal();
258
259   /**
260    * @brief This signal is emitted just after the event processing is finished.
261    *
262    * @return The signal to connect to
263    */
264   EventProcessingFinishedSignalType& EventProcessingFinishedSignal();
265
266   /**
267    * @brief This signal is emitted when the screen is touched and when the touch ends
268    * (i.e. the down & up touch events only).
269    *
270    * If there are multiple touch points, then this will be emitted when the first touch occurs and
271    * then when the last finger is lifted.
272    * An interrupted event will also be emitted (if it occurs).
273    * A callback of the following type may be connected:
274    * @code
275    *   void YourCallbackName( TouchEvent event );
276    * @endcode
277    *
278    * @return The touch signal to connect to
279    * @note Motion events are not emitted.
280    */
281   TouchEventSignalType& TouchedSignal();
282
283   /**
284    * @brief This signal is emitted when wheel event is received.
285    *
286    * A callback of the following type may be connected:
287    * @code
288    *   void YourCallbackName(const WheelEvent& event);
289    * @endcode
290    * @return The signal to connect to
291    */
292   WheelEventSignalType& WheelEventSignal();
293
294   /**
295    * @brief This signal is emitted when the GL context is lost (Platform specific behaviour).
296    *
297    * If the application is responsible for handling context loss, it should listen to
298    * this signal and tear down UI components when received.
299    * @return The context lost signal to connect to
300    */
301   ContextStatusSignal& ContextLostSignal();
302
303   /**
304    * @brief This signal is emitted when the GL context is regained (Platform specific
305    * behavior).
306    *
307    * If the application is responsible for handling context loss, it should listen to
308    * this signal and rebuild UI components on receipt.
309    * @return The context regained signal to connect to
310    */
311   ContextStatusSignal& ContextRegainedSignal();
312
313   /**
314    * @brief This signal is emitted after the initial scene is created.
315    *
316    * It will be triggered after the
317    * application init signal.
318    *
319    * A callback of the following type may be connected:
320    * @code
321    *   void YourCallbackName();
322    * @endcode
323    * @return The signal to connect to
324    */
325   SceneCreatedSignalType& SceneCreatedSignal();
326
327 public: // Not intended for application developers
328
329   /// @cond internal
330   /**
331    * @brief This constructor is used by Stage::GetCurrent() methods.
332    *
333    * @param[in] stage A pointer to a Dali resource
334    */
335   explicit DALI_INTERNAL Stage(Internal::Stage* stage);
336   /// @endcond
337 };
338
339 /**
340  * @}
341  */
342
343 } // namespace Dali
344
345 #endif // DALI_STAGE_H