1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
29 #include "application-configuration.h"
35 * @addtogroup dali_adaptor_framework
39 namespace Internal DALI_INTERNAL
47 * @brief An Application class object should be created by every application
48 * that wishes to use Dali.
50 * It provides a means for initialising the
51 * resources required by the Dali::Core.
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.
58 * Applications should follow the example below:
61 * class ExampleController: public ConnectionTracker
64 * ExampleController( Application& application )
65 * : mApplication( application )
67 * mApplication.InitSignal().Connect( this, &ExampleController::Create );
70 * void Create( Application& application )
72 * // Create Dali components...
76 * Application& mApplication;
79 * int main (int argc, char **argv)
81 * Application app = Application::New(&argc, &argv);
82 * ExampleController example( app );
87 * If required, you can also connect class member functions to a signal:
91 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
94 * This class accepts command line arguments as well. The following options are supported:
97 * --no-vsync Disable VSync on Render
98 * -w|--width Stage Width
99 * -h|--height Stage Height
100 * -d|--dpi Emulated DPI
104 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
107 class DALI_IMPORT_API Application : public BaseHandle
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
115 * @brief Decides whether a Dali application window is opaque or transparent.
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
127 * @brief This is the constructor for applications without an argument list.
131 * @return A handle to the Application
133 static Application New();
136 * @brief This is the constructor for applications.
141 * @param[in,out] argc A pointer to the number of arguments
142 * @param[in,out] argv A pointer the the argument list
143 * @return A handle to the Application
145 static Application New( int* argc, char **argv[] );
148 * @brief This is the constructor for applications with a name
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] stylesheet The path to user defined theme file
156 * @return A handle to the Application
157 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
159 static Application New( int* argc, char **argv[], const std::string& stylesheet );
162 * @brief This is the constructor for applications with a name
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] stylesheet The path to user defined theme file
170 * @param[in] windowMode A member of WINDOW_MODE
171 * @return A handle to the Application
172 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
174 static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
177 * @brief Construct an empty handle
183 * @brief Copy Constructor
185 * @param[in] application Handle to an object
187 Application( const Application& application );
190 * @brief Assignment operator
192 * @param[in] application Handle to an object
193 * @return A reference to this
195 Application& operator=( const Application& application );
200 * This is non-virtual since derived Handle types must not contain data or virtual methods.
207 * @brief This starts the application.
209 * Choosing this form of main loop indicates that the default
210 * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
211 * context loss can occur, the application is responsible for tearing down and re-loading UI.
212 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
218 * @brief This starts the application, and allows the app to choose a different configuration.
220 * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
221 * trigger context loss & regain.
222 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
224 * @param[in] configuration The context loss configuration
226 void MainLoop(Configuration::ContextLoss configuration);
229 * @brief This lowers the application to bottom without actually quitting it
235 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
241 * @brief Ensures that the function passed in is called from the main loop when it is idle.
243 * @param[in] callback The function to call.
244 * @return true if added successfully, false otherwise
246 * @note Function must be called from main event thread only
248 * A callback of the following type may be used:
253 * @note Ownership of the callback is passed onto this class.
255 bool AddIdle( CallbackBase* callback );
258 * @brief Retrieves the window used by the Application class.
260 * The application writer can use the window to change indicator and orientation
263 * @return A handle to the window
268 * @brief Replace the current window.
270 * This will force context loss.
271 * If you plan on using this API in your application, then you should configure
272 * it to prevent discard behaviour when handling the Init signal.
274 * @param[in] windowPosition The position and size parameters of the new window
275 * @param[in] name The name of the new window
277 void ReplaceWindow(PositionSize windowPosition, const std::string& name);
279 public: // Stereoscopy
282 * @brief Set the viewing mode for the application.
284 * @param[in] viewMode The new viewing mode.
286 void SetViewMode( ViewMode viewMode );
289 * @brief Get the current viewing mode.
291 * @return The current viewing mode.
293 ViewMode GetViewMode() const;
296 * @brief Set the stereo base (eye separation) for Stereoscopic 3D
298 * The stereo base is the distance in millimetres between the eyes. Typical values are
299 * between 50mm and 70mm. The default value is 65mm.
301 * @remarks SetStereoBase() is supported in mobile applications only.
302 * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
304 void SetStereoBase( float stereoBase );
307 * @brief Get the stereo base (eye separation) for Stereoscopic 3D
310 * @remarks GetStereoBase() is supported in mobile applications only.
311 * @return The stereo base (eye separation) for Stereoscopic 3D
313 float GetStereoBase() const;
318 * @brief The user should connect to this signal to determine when they should initialise
321 * @return The signal to connect to
323 AppSignalType& InitSignal();
326 * @brief The user should connect to this signal to determine when they should terminate
329 * @return The signal to connect to
331 AppSignalType& TerminateSignal();
334 * @brief The user should connect to this signal if they need to perform any special
335 * activities when the application is about to be paused.
337 * @return The signal to connect to
339 AppSignalType& PauseSignal();
342 * @brief The user should connect to this signal if they need to perform any special
343 * activities when the application has resumed.
345 * @return The signal to connect to
347 AppSignalType& ResumeSignal();
350 * @brief This signal is sent when the system requires the user to reinitialise itself.
352 * @return The signal to connect to
354 AppSignalType& ResetSignal();
357 * @brief This signal is emitted when the window the application is rendering on is resized.
359 * @return The signal to connect to
361 AppSignalType& ResizeSignal();
364 * @brief This signal is emitted when another application sends a launch request to the application.
366 * When the application is launched, this signal is emitted after the main loop of the application starts up.
367 * The passed parameter describes the launch request and contains the information about why the application is launched.
369 * @return The signal to connect to
371 AppControlSignalType& AppControlSignal();
374 * @brief This signal is emitted when the language is changed on the device.
376 * @return The signal to connect to
378 AppSignalType& LanguageChangedSignal();
381 * @brief This signal is emitted when the region of the device is changed.
383 * @return The signal to connect to
385 AppSignalType& RegionChangedSignal();
388 * @brief This signal is emitted when the battery level of the device is low.
390 * @return The signal to connect to
392 AppSignalType& BatteryLowSignal();
395 * @brief This signal is emitted when the memory level of the device is low.
397 * @return The signal to connect to
399 AppSignalType& MemoryLowSignal();
401 public: // Not intended for application developers
404 * @brief Internal constructor
407 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
415 #endif // __DALI_APPLICATION_H__