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