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. It provides a means for initialising the
49 * resources required by the Dali::Core.
51 * The Application class emits several signals which the user can
52 * connect to. The user should not create any Dali objects in the main
53 * function and instead should connect to the Init signal of the
54 * Application and create the Dali objects in the connected callback.
56 * Applications should follow the example below:
59 * void CreateProgram(Application app)
61 * // Create Dali components...
62 * // Can instantiate here, if required
65 * int main (int argc, char **argv)
67 * Application app = Application::New(&argc, &argv);
68 * app.InitSignal().Connect(&CreateProgram);
73 * If required, you can also connect class member functions to a signal:
77 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
80 * This class accepts command line arguments as well. The following options are supported:
83 * --no-vsync Disable VSync on Render
84 * -w|--width Stage Width
85 * -h|--height Stage Height
86 * -d|--dpi Emulated DPI
90 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
93 class DALI_IMPORT_API Application : public BaseHandle
97 typedef Signal< void (Application&) > AppSignalType;
98 typedef Signal< void (Application&, void *) > AppControlSignalType;
101 * @brief Decides whether a Dali application window is opaque or transparent.
106 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
107 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
113 * @brief This is the constructor for applications without an argument list.
116 static Application New();
119 * @brief This is the constructor for applications.
122 * @param[in,out] argc A pointer to the number of arguments
123 * @param[in,out] argv A pointer the the argument list
125 static Application New( int* argc, char **argv[] );
128 * @brief This is the constructor for applications with a name
131 * @param[in,out] argc A pointer to the number of arguments
132 * @param[in,out] argv A pointer the the argument list
133 * @param[in] stylesheet The path to user defined theme file
135 static Application New( int* argc, char **argv[], const std::string& stylesheet );
138 * @brief This is the constructor for applications with a name
141 * @param[in,out] argc A pointer to the number of arguments
142 * @param[in,out] argv A pointer the the argument list
143 * @param[in] stylesheet The path to user defined theme file
144 * @param[in] windowMode A member of WINDOW_MODE
146 static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
149 * @brief Construct an empty handle
155 * @brief Copy Constructor
158 Application( const Application& application );
161 * @brief Assignment operator
164 Application& operator=( const Application& applicaton );
169 * This is non-virtual since derived Handle types must not contain data or virtual methods.
176 * @brief This starts the application. Choosing this form of main loop indicates that the default
177 * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
178 * context loss can occur, the application is responsible for tearing down and re-loading UI.
179 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
185 * @brief This starts the application, and allows the app to choose a different configuration.
186 * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
187 * trigger context loss & regain.
188 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
191 void MainLoop(Configuration::ContextLoss configuration);
194 * @brief This lowers the application to bottom without actually quitting it
200 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
206 * @brief Ensures that the function passed in is called from the main loop when it is idle.
208 * @param[in] callback The function to call.
209 * @return true if added successfully, false otherwise
211 * @note Function must be called from main event thread only
213 * A callback of the following type may be used:
218 * @note Ownership of the callback is passed onto this class.
220 bool AddIdle( CallbackBase* callback );
223 * @brief Retrieves the window used by the Application class.
224 * The application writer can use the window to change indicator and orientation
227 * @return A handle to the window
232 * @brief Replace the current window.
233 * This will force context loss.
234 * If you plan on using this API in your application, then you should configure
235 * it to prevent discard behaviour when handling the Init signal.
237 * @param[in] windowPosition The position and size parameters of the new window
238 * @param[in] name The name of the new window
240 void ReplaceWindow(PositionSize windowPosition, const std::string& name);
242 public: // Stereoscopy
245 * @brief Set the viewing mode for the application.
247 * @param[in] viewMode The new viewing mode.
249 void SetViewMode( ViewMode viewMode );
252 * @brief Get the current viewing mode.
254 * @return The current viewing mode.
256 ViewMode GetViewMode() const;
259 * @brief Set the stereo base (eye separation) for Stereoscopic 3D
262 * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
264 void SetStereoBase( float stereoBase );
267 * @brief Get the stereo base (eye separation) for Stereoscopic 3D
270 * @return The stereo base (eye separation) for Stereoscopic 3D
272 float GetStereoBase() const;
277 * @brief The user should connect to this signal to determine when they should initialise
281 AppSignalType& InitSignal();
284 * @brief The user should connect to this signal to determine when they should terminate
288 AppSignalType& TerminateSignal();
291 * @brief The user should connect to this signal if they need to perform any special
292 * activities when the application is about to be paused.
295 AppSignalType& PauseSignal();
298 * @brief The user should connect to this signal if they need to perform any special
299 * activities when the application has resumed.
302 AppSignalType& ResumeSignal();
305 * @brief This signal is sent when the system requires the user to reinitialise itself.
308 AppSignalType& ResetSignal();
311 * @brief This signal is emitted when the window the application is rendering on is resized.
314 AppSignalType& ResizeSignal();
317 * @brief This signal is emitted when another application sends a launch request to the application.
318 * When the application is launched, this signal is emitted after the main loop of the application starts up.
319 * The passed parameter describes the launch request and contains the information about why the application is launched.
322 AppControlSignalType& AppControlSignal();
325 * @brief This signal is emitted when the language is changed on the device.
328 AppSignalType& LanguageChangedSignal();
331 * @brief This signal is emitted when the region of the device is changed.
334 AppSignalType& RegionChangedSignal();
337 * @brief This signal is emitted when the battery level of the device is low.
340 AppSignalType& BatteryLowSignal();
343 * @brief This signal is emitted when the memory level of the device is low.
346 AppSignalType& MemoryLowSignal();
348 public: // Not intended for application developers
350 * @brief Internal constructor
353 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
361 #endif // __DALI_APPLICATION_H__