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