Public API headers are installed in the correct folder
[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.
107    *
108    * @param[in,out]  argc        A pointer to the number of arguments
109    * @param[in,out]  argv        A pointer the the argument list
110    *
111    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
112    * @note Supported options are stripped from argv, and argc is updated appropriately.
113    */
114   static Application New( int* argc, char **argv[] );
115
116   /**
117    * This is the constructor for applications with a name
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    * @param[in]  name  A name of application
122    *
123    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
124    * @note Supported options are stripped from argv, and argc is updated appropriately.
125    */
126   static Application New( int* argc, char **argv[], const std::string& name );
127
128   /**
129    * This is the constructor for applications with a name, and also require a
130    * transparent top-level window
131    *
132    * @param[in,out]  argc  A pointer to the number of arguments
133    * @param[in,out]  argv  A pointer the the argument list
134    * @param[in]  name  A name of application
135    * @param[in]  windowMode A member of WINDOW_MODE
136    *
137    * @note The default base layout (DeviceLayout::DEFAULT_BASE_LAYOUT) will be used with this constructor.
138    * @note Supported options are stripped from argv, and argc is updated appropriately.
139    */
140   static Application New( int* argc, char **argv[], const std::string& name, WINDOW_MODE windowMode );
141
142   /**
143    * This is the constructor for applications when a layout for the application is specified.
144    *
145    * @param[in,out]  argc        A pointer to the number of arguments
146    * @param[in,out]  argv        A pointer the the argument list
147    * @param[in]  baseLayout  The base layout that the application has been written for
148    *
149    * @note Supported options are stripped from argv, and argc is updated appropriately.
150    */
151   static Application New( int* argc, char **argv[], const DeviceLayout& baseLayout );
152
153   /**
154    * This is the constructor for applications with a name and 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]  name  A name of application
159    * @param[in]  baseLayout  The base layout that the application has been written for
160    *
161    * @note Supported options are stripped from argv, and argc is updated appropriately.
162    */
163   static Application New( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout );
164
165   /**
166    * Construct an empty handle
167    */
168   Application();
169
170   /**
171    * Copy Constructor
172    */
173   Application( const Application& application );
174
175   /**
176    * Assignment operator
177    */
178   Application& operator=( const Application& applicaton );
179
180   /**
181    * @brief Destructor
182    *
183    * This is non-virtual since derived Handle types must not contain data or virtual methods.
184    */
185   ~Application();
186
187 public:
188   /**
189    * This starts the application.
190    */
191   void MainLoop();
192
193   /**
194    * This lowers the application to bottom without actually quitting it
195    */
196   void Lower();
197
198   /**
199    * This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
200    */
201   void Quit();
202
203   /**
204    * This returns a handle to the Orientation object used by Application which allows
205    * the user to determine the orientation of the device and connect to a
206    * signal emitted whenever the orientation changes.
207    * @return A handle to the Orientation object used by the Application
208    */
209   Orientation GetOrientation();
210
211   /**
212    * Ensures that the function passed in is called from the main loop when it is idle.
213    *
214    * A callback of the following type may be used:
215    * @code
216    *   void MyFunction();
217    * @endcode
218    *
219    * @param[in]  callBack  The function to call.
220    * @return true if added successfully, false otherwise
221    */
222   bool AddIdle(boost::function<void(void)> callBack);
223
224   /**
225    * Retrieves the window used by the Application class.
226    * The application writer can use the window to change indicator and orientation
227    * properties.
228    * @return A handle to the window
229    */
230   Window GetWindow();
231
232   /**
233    * Returns the local thread's instance of the Application class.
234    * @return A reference to the local thread's Application class instance.
235    * @pre The Application class has been initialised.
236    * @note This is only valid in the main thread.
237    */
238   static Application Get();
239
240 public: // Stereoscopy
241
242   /**
243    * Set the viewing mode for the application.
244    * @param[in] viewMode The new viewing mode.
245    */
246   void SetViewMode( ViewMode viewMode );
247
248   /**
249    * Get the current viewing mode.
250    * @return The current viewing mode.
251    */
252   ViewMode GetViewMode() const;
253
254   /**
255    * Set the stereo base (eye seperation) for stereoscopic 3D
256    * @param[in] stereoBase The stereo base (eye seperation) for stereoscopic 3D
257    */
258   void SetStereoBase( float stereoBase );
259
260   /**
261    * Get the stereo base (eye seperation) for stereoscopic 3D
262    * @return The stereo base (eye seperation) for stereoscopic 3D
263    */
264   float GetStereoBase() const;
265
266 public:  // Signals
267
268   /**
269    * The user should connect to this signal to determine when they should initialise
270    * their application
271    */
272   AppSignalV2& InitSignal();
273
274   /**
275    * The user should connect to this signal to determine when they should terminate
276    * their application
277    */
278   AppSignalV2& TerminateSignal();
279
280   /**
281    * The user should connect to this signal if they need to perform any special
282    * activities when the application is about to be paused.
283    */
284   AppSignalV2& PauseSignal();
285
286   /**
287    * The user should connect to this signal if they need to perform any special
288    * activities when the application has resumed.
289    */
290   AppSignalV2& ResumeSignal();
291
292   /**
293    * This signal is sent when the system requires the user to reinitialise itself.
294    */
295   AppSignalV2& ResetSignal();
296
297   /**
298    * This signal is emitted when the window the application is rendering on is resized.
299    */
300   AppSignalV2& ResizeSignal();
301
302   /**
303    * This signal is emitted when the language is changed on the device.
304    */
305   AppSignalV2& LanguageChangedSignal();
306
307 public: // Not intended for application developers
308   /**
309    * Internal constructor
310    */
311   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
312 };
313
314 } // namespace Dali
315
316 #endif // __DALI_APPLICATION_H__