1 #ifndef DALI_APPLICATION_H
2 #define DALI_APPLICATION_H
5 * Copyright (c) 2018 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.
22 #include <dali/public-api/common/view-mode.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/callback.h>
27 #include <dali/public-api/adaptor-framework/application-configuration.h>
28 #include <dali/public-api/adaptor-framework/device-status.h>
29 #include <dali/public-api/adaptor-framework/window.h>
34 * @addtogroup dali_adaptor_framework
38 namespace Internal DALI_INTERNAL
48 * @brief An Application class object should be created by every application
49 * that wishes to use Dali.
51 * It provides a means for initializing the
52 * resources required by the Dali::Core.
54 * The Application class emits several signals which the user can
55 * connect to. The user should not create any Dali objects in the main
56 * function and instead should connect to the Init signal of the
57 * Application and create the Dali objects in the connected callback.
59 * Applications should follow the example below:
62 * class ExampleController: public ConnectionTracker
65 * ExampleController( Application& application )
66 * : mApplication( application )
68 * mApplication.InitSignal().Connect( this, &ExampleController::Create );
71 * void Create( Application& application )
73 * // Create Dali components...
77 * Application& mApplication;
80 * int main (int argc, char **argv)
82 * Application app = Application::New(&argc, &argv);
83 * ExampleController example( app );
88 * If required, you can also connect class member functions to a signal:
92 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
95 * This class accepts command line arguments as well. The following options are supported:
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_ADAPTOR_API Application : public BaseHandle
111 typedef Signal< void (DeviceStatus::Battery::Status) > LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
112 typedef Signal< void (DeviceStatus::Memory::Status) > LowMemorySignalType; ///< Application device signal type @SINCE_1_2.62
113 typedef Signal< void (Application&) > AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
114 typedef Signal< void (Application&, void *) > AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
117 * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
122 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
123 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
131 * @brief This is the constructor for applications without an argument list.
135 * @return A handle to the Application
137 static Application New();
142 * @brief This is the constructor for applications.
147 * @param[in,out] argc A pointer to the number of arguments
148 * @param[in,out] argv A pointer to the argument list
149 * @return A handle to the Application
151 static Application New( int* argc, char **argv[] );
156 * @brief This is the constructor for applications with a name.
161 * @param[in,out] argc A pointer to the number of arguments
162 * @param[in,out] argv A pointer to the argument list
163 * @param[in] stylesheet The path to user defined theme file
164 * @return A handle to the Application
165 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
167 static Application New( int* argc, char **argv[], const std::string& stylesheet );
172 * @brief This is the constructor for applications with a name.
177 * @param[in,out] argc A pointer to the number of arguments
178 * @param[in,out] argv A pointer to the argument list
179 * @param[in] stylesheet The path to user defined theme file
180 * @param[in] windowMode A member of WINDOW_MODE
181 * @return A handle to the Application
182 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
184 static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
189 * @brief This is the constructor for applications.
194 * @param[in,out] argc A pointer to the number of arguments
195 * @param[in,out] argv A pointer to the argument list
196 * @param[in] stylesheet The path to user defined theme file
197 * @param[in] windowMode A member of WINDOW_MODE
198 * @param[in] positionSize A position and a size of the window
199 * @return A handle to the Application
200 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
202 static Application New( int* argc, char **argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize );
205 * @brief Constructs an empty handle.
211 * @brief Copy Constructor.
213 * @param[in] application Handle to an object
215 Application( const Application& application );
218 * @brief Assignment operator.
220 * @param[in] application Handle to an object
221 * @return A reference to this
223 Application& operator=( const Application& application );
228 * This is non-virtual since derived Handle types must not contain data or virtual methods.
235 * @brief This starts the application.
237 * Choosing this form of main loop indicates that the default
238 * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
239 * context loss can occur, the application is responsible for tearing down and re-loading UI.
240 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
246 * @brief This starts the application, and allows the app to choose a different configuration.
248 * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
249 * trigger context loss & regain.
250 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
252 * @param[in] configuration The context loss configuration
254 void MainLoop(Configuration::ContextLoss configuration);
257 * @brief This lowers the application to bottom without actually quitting it.
263 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
269 * @brief Ensures that the function passed in is called from the main loop when it is idle.
271 * @param[in] callback The function to call
272 * @return @c true if added successfully, @c false otherwise
274 * @note Function must be called from main event thread only
276 * A callback of the following type may be used:
280 * This callback will be deleted once it is called.
282 * @note Ownership of the callback is passed onto this class.
284 bool AddIdle( CallbackBase* callback );
287 * @brief Retrieves the main window used by the Application class.
289 * The application writer can use the window to change indicator and orientation
292 * @return A handle to the window
298 * @brief Replaces the current window.
300 * This will force context loss.
301 * If you plan on using this API in your application, then you should configure
302 * it to prevent discard behavior when handling the Init signal.
304 * @param[in] windowPosition The position and size parameters of the new window
305 * @param[in] name The name of the new window
307 void ReplaceWindow(PositionSize windowPosition, const std::string& name) DALI_DEPRECATED_API;
310 * @brief Get path application resources are stored at
313 * @return the full path of the resources
315 static std::string GetResourcePath();
318 * @brief This is used to get region information from device.
321 * @return Region information
323 std::string GetRegion() const;
326 * @brief This is used to get language information from device.
329 * @return Language information
331 std::string GetLanguage() const;
333 public: // Stereoscopy
337 * @brief Sets the viewing mode for the application.
339 * @param[in] viewMode The new viewing mode
341 void SetViewMode( ViewMode viewMode );
345 * @brief Gets the current viewing mode.
347 * @return The current viewing mode
349 ViewMode GetViewMode() const;
353 * @brief Sets the stereo base (eye separation) for Stereoscopic 3D.
355 * The stereo base is the distance in millimetres between the eyes. Typical values are
356 * between 50mm and 70mm. The default value is 65mm.
358 * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
360 void SetStereoBase( float stereoBase );
364 * @brief Gets the stereo base (eye separation) for Stereoscopic 3D.
367 * @return The stereo base (eye separation) for Stereoscopic 3D
369 float GetStereoBase() const;
374 * @brief The user should connect to this signal to determine when they should initialize
377 * @return The signal to connect to
379 AppSignalType& InitSignal();
382 * @brief The user should connect to this signal to determine when they should terminate
385 * @return The signal to connect to
387 AppSignalType& TerminateSignal();
390 * @brief The user should connect to this signal if they need to perform any special
391 * activities when the application is about to be paused.
393 * @return The signal to connect to
395 AppSignalType& PauseSignal();
398 * @brief The user should connect to this signal if they need to perform any special
399 * activities when the application has resumed.
401 * @return The signal to connect to
403 AppSignalType& ResumeSignal();
406 * @brief This signal is sent when the system requires the user to reinitialize itself.
408 * @return The signal to connect to
410 AppSignalType& ResetSignal();
413 * @DEPRECATED_1_2.62 Use Window::ResizedSignal() instead.
414 * @brief This signal is emitted when the window application rendering on is resized.
416 * @return The signal to connect to
418 AppSignalType& ResizeSignal() DALI_DEPRECATED_API;
421 * @brief This signal is emitted when another application sends a launch request to the application.
423 * When the application is launched, this signal is emitted after the main loop of the application starts up.
424 * The passed parameter describes the launch request and contains the information about why the application is launched.
426 * @return The signal to connect to
428 AppControlSignalType& AppControlSignal();
431 * @brief This signal is emitted when the language is changed on the device.
433 * @return The signal to connect to
435 AppSignalType& LanguageChangedSignal();
438 * @brief This signal is emitted when the region of the device is changed.
440 * @return The signal to connect to
442 AppSignalType& RegionChangedSignal();
445 * @DEPRECATED_1_2.62 Use LowBatterySignal() instead.
446 * @brief This signal is emitted when the battery level of the device is low.
448 * @return The signal to connect to
450 AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API;
453 * @DEPRECATED_1_2.62 Use LowMemorySignal() instead.
454 * @brief This signal is emitted when the memory level of the device is low.
456 * @return The signal to connect to
458 AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API;
461 * @brief This signal is emitted when the battery level of the device is low.
463 * @return The signal to connect to
465 LowBatterySignalType& LowBatterySignal();
468 * @brief This signal is emitted when the memory level of the device is low.
470 * @return The signal to connect to
472 LowMemorySignalType& LowMemorySignal();
474 public: // Not intended for application developers
477 * @brief Internal constructor.
480 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
489 #endif // DALI_APPLICATION_H