Merge "Remove unnecessary stream operators from radian and degree as well as unnecess...
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / application.h
1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_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 // EXTERNAL INCLUDES
22 #include <string>
23 #include <dali/public-api/common/view-mode.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
26
27
28 // INTERNAL INCLUDES
29 #include "application-configuration.h"
30 #include "style-monitor.h"
31 #include "device-layout.h"
32 #include "window.h"
33
34 namespace Dali
35 {
36
37 namespace Internal DALI_INTERNAL
38 {
39 namespace Adaptor
40 {
41 class Application;
42 }
43 }
44
45 /**
46  * An Application class object should be created by every application
47  * that wishes to use Dali.  It provides a means for initialising the
48  * resources required by the Dali::Core.
49  *
50  * The Application class emits several signals which the user can
51  * connect to.  The user should not create any Dali objects in the main
52  * function and instead should connect to the Init signal of the
53  * Application and create the Dali objects in the connected callback.
54  *
55  * Applications should follow the example below:
56  *
57  * @code
58  * void CreateProgram(Application app)
59  * {
60  *   // Create Dali components...
61  *   // Can instantiate here, if required
62  * }
63  *
64  * int main (int argc, char **argv)
65  * {
66  *   Application app = Application::New(&argc, &argv);
67  *   app.InitSignal().Connect(&CreateProgram);
68  *   app.MainLoop();
69  * }
70  * @endcode
71  *
72  * If required, you can also connect class member functions to a signal:
73  *
74  * @code
75  * MyApplication app;
76  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
77  * @endcode
78  *
79  * This class accepts command line arguments as well. The following options are supported:
80  *
81  * @code
82  *     --no-vsync       Disable VSync on Render
83  *  -w|--width          Stage Width
84  *  -h|--height         Stage Height
85  *  -d|--dpi            Emulated DPI
86  *     --help           Help
87  * @endcode
88  *
89  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
90  */
91 class DALI_IMPORT_API Application : public BaseHandle
92 {
93 public:
94
95   typedef Signal< void (Application&) > AppSignalType;
96   typedef Signal< void (Application&, void *) > AppControlSignalType;
97
98   /**
99    * Decides whether a Dali application window is opaque or transparent.
100    */
101   enum WINDOW_MODE
102   {
103     OPAQUE = 0,       ///< The window will be opaque
104     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor()
105   };
106
107 public:
108
109   /**
110    * This is the constructor for applications without an argument list.
111    *
112    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
113    */
114   static Application New();
115
116   /**
117    * This is the constructor for applications.
118    *
119    * @param[in,out]  argc        A pointer to the number of arguments
120    * @param[in,out]  argv        A pointer the the argument list
121    *
122    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
123    * @note Supported options are stripped from argv, and argc is updated appropriately.
124    */
125   static Application New( int* argc, char **argv[] );
126
127   /**
128    * This is the constructor for applications with a name
129    *
130    * @param[in,out]  argc  A pointer to the number of arguments
131    * @param[in,out]  argv  A pointer the the argument list
132    * @param[in]  name  A name of application
133    *
134    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
135    * @note Supported options are stripped from argv, and argc is updated appropriately.
136    */
137   static Application New( int* argc, char **argv[], const std::string& name );
138
139   /**
140    * This is the constructor for applications with a name, and also require a
141    * transparent top-level window
142    *
143    * @param[in,out]  argc  A pointer to the number of arguments
144    * @param[in,out]  argv  A pointer the the argument list
145    * @param[in]  name  A name of application
146    * @param[in]  windowMode A member of WINDOW_MODE
147    *
148    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
149    * @note Supported options are stripped from argv, and argc is updated appropriately.
150    */
151   static Application New( int* argc, char **argv[], const std::string& name, WINDOW_MODE windowMode );
152
153   /**
154    * This is the constructor for applications when a layout for the application is specified.
155    *
156    * @param[in,out]  argc        A pointer to the number of arguments
157    * @param[in,out]  argv        A pointer the the argument list
158    * @param[in]  baseLayout  The base layout that the application has been written for
159    *
160    * @note Supported options are stripped from argv, and argc is updated appropriately.
161    */
162   static Application New( int* argc, char **argv[], const DeviceLayout& baseLayout );
163
164   /**
165    * This is the constructor for applications with a name and when a layout for the application is specified.
166    *
167    * @param[in,out]  argc  A pointer to the number of arguments
168    * @param[in,out]  argv  A pointer the the argument list
169    * @param[in]  name  A name of application
170    * @param[in]  baseLayout  The base layout that the application has been written for
171    *
172    * @note Supported options are stripped from argv, and argc is updated appropriately.
173    */
174   static Application New( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout );
175
176   /**
177    * Construct an empty handle
178    */
179   Application();
180
181   /**
182    * Copy Constructor
183    */
184   Application( const Application& application );
185
186   /**
187    * Assignment operator
188    */
189   Application& operator=( const Application& applicaton );
190
191   /**
192    * @brief Destructor
193    *
194    * This is non-virtual since derived Handle types must not contain data or virtual methods.
195    */
196   ~Application();
197
198 public:
199   /**
200    * This starts the application. Choosing this form of main loop indicates that the default
201    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
202    * context loss can occur, the application is responsible for tearing down and re-loading UI.
203    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
204    */
205   void MainLoop();
206
207   /**
208    * This starts the application, and allows the app to choose a different configuration.
209    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
210    * trigger context loss & regain.
211    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
212    */
213   void MainLoop(Configuration::ContextLoss configuration);
214
215   /**
216    * This lowers the application to bottom without actually quitting it
217    */
218   void Lower();
219
220   /**
221    * This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
222    */
223   void Quit();
224
225   /**
226    * Ensures that the function passed in is called from the main loop when it is idle.
227    *
228    * A callback of the following type may be used:
229    * @code
230    *   void MyFunction();
231    * @endcode
232    *
233    * @param[in]  callback  The function to call.
234    * @return true if added successfully, false otherwise
235    *
236    * @note Ownership of the callback is passed onto this class.
237    */
238   bool AddIdle( CallbackBase* callback );
239
240   /**
241    * Retrieves the window used by the Application class.
242    * The application writer can use the window to change indicator and orientation
243    * properties.
244    * @return A handle to the window
245    */
246   Window GetWindow();
247
248   /**
249    * Replace the current window.
250    * This will force context loss.
251    * If you plan on using this API in your application, then you should configure
252    * it to prevent discard behaviour when handling the Init signal.
253    * @param[in] windowPosition The position and size parameters of the new window
254    * @param[in] name The name of the new window
255    */
256   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
257
258 public: // Stereoscopy
259
260   /**
261    * Set the viewing mode for the application.
262    * @param[in] viewMode The new viewing mode.
263    */
264   void SetViewMode( ViewMode viewMode );
265
266   /**
267    * Get the current viewing mode.
268    * @return The current viewing mode.
269    */
270   ViewMode GetViewMode() const;
271
272   /**
273    * Set the stereo base (eye separation) for Stereoscopic 3D
274    *
275    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
276    */
277   void SetStereoBase( float stereoBase );
278
279   /**
280    * Get the stereo base (eye separation) for Stereoscopic 3D
281    *
282    * @return The stereo base (eye separation) for Stereoscopic 3D
283    */
284   float GetStereoBase() const;
285
286 public:  // Signals
287
288   /**
289    * The user should connect to this signal to determine when they should initialise
290    * their application.
291    */
292   AppSignalType& InitSignal();
293
294   /**
295    * The user should connect to this signal to determine when they should terminate
296    * their application
297    */
298   AppSignalType& TerminateSignal();
299
300   /**
301    * The user should connect to this signal if they need to perform any special
302    * activities when the application is about to be paused.
303    */
304   AppSignalType& PauseSignal();
305
306   /**
307    * The user should connect to this signal if they need to perform any special
308    * activities when the application has resumed.
309    */
310   AppSignalType& ResumeSignal();
311
312   /**
313    * This signal is sent when the system requires the user to reinitialise itself.
314    */
315   AppSignalType& ResetSignal();
316
317   /**
318    * This signal is emitted when the window the application is rendering on is resized.
319    */
320   AppSignalType& ResizeSignal();
321
322   /**
323   * This signal is emitted when another application sends a launch request to the application.
324   * When the application is launched, this signal is emitted after the main loop of the application starts up.
325   * The passed parameter describes the launch request and contains the information about why the application is launched.
326   */
327   AppControlSignalType& AppControlSignal();
328
329   /**
330    * This signal is emitted when the language is changed on the device.
331    */
332   AppSignalType& LanguageChangedSignal();
333
334   /**
335   * This signal is emitted when the region of the device is changed.
336   */
337   AppSignalType& RegionChangedSignal();
338
339   /**
340   * This signal is emitted when the battery level of the device is low.
341   */
342   AppSignalType& BatteryLowSignal();
343
344   /**
345   * This signal is emitted when the memory level of the device is low.
346   */
347   AppSignalType& MemoryLowSignal();
348
349 public: // Not intended for application developers
350   /**
351    * Internal constructor
352    */
353   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
354 };
355
356 } // namespace Dali
357
358 #endif // __DALI_APPLICATION_H__