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