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