1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_H__
5 * Copyright (c) 2014 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 <boost/function.hpp>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/common/view-mode.h>
27 #include "style-monitor.h"
28 #include "device-layout.h"
31 namespace Dali DALI_IMPORT_API
34 namespace Internal DALI_INTERNAL
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.
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.
52 * Applications should follow the example below:
55 * void CreateProgram(Application app)
57 * // Create Dali components...
58 * // Can instantiate here, if required
61 * int main (int argc, char **argv)
63 * Application app = Application::New(&argc, &argv);
64 * app.InitSignal().Connect(&CreateProgram);
69 * If required, you can also connect class member functions to a signal:
73 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
76 * This class accepts command line arguments as well. The following options are supported:
79 * --no-vsync Disable VSync on Render
80 * -w|--width Stage Width
81 * -h|--height Stage Height
82 * -d|--dpi Emulated DPI
86 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
88 class Application : public BaseHandle
92 typedef SignalV2< void (Application&) > AppSignalV2;
95 * Decides whether a Dali application window is opaque or transparent.
99 OPAQUE = 0, ///< The window will be opaque
100 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor()
106 * This is the constructor for applications.
108 * @param[in,out] argc A pointer to the number of arguments
109 * @param[in,out] argv A pointer the the argument list
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.
114 static Application New( int* argc, char **argv[] );
117 * This is the constructor for applications with a name
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
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.
126 static Application New( int* argc, char **argv[], const std::string& name );
129 * This is the constructor for applications with a name, and also require a
130 * transparent top-level window
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
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.
140 static Application New( int* argc, char **argv[], const std::string& name, WINDOW_MODE windowMode );
143 * This is the constructor for applications when a layout for the application is specified.
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
149 * @note Supported options are stripped from argv, and argc is updated appropriately.
151 static Application New( int* argc, char **argv[], const DeviceLayout& baseLayout );
154 * This is the constructor for applications with a name and when a layout for the application is specified.
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
161 * @note Supported options are stripped from argv, and argc is updated appropriately.
163 static Application New( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout );
166 * Construct an empty handle
173 Application( const Application& application );
176 * Assignment operator
178 Application& operator=( const Application& applicaton );
183 * This is non-virtual since derived Handle types must not contain data or virtual methods.
189 * This starts the application.
194 * This lowers the application to bottom without actually quitting it
199 * This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
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
209 Orientation GetOrientation();
212 * Ensures that the function passed in is called from the main loop when it is idle.
214 * A callback of the following type may be used:
219 * @param[in] callBack The function to call.
220 * @return true if added successfully, false otherwise
222 bool AddIdle(boost::function<void(void)> callBack);
225 * Retrieves the window used by the Application class.
226 * The application writer can use the window to change indicator and orientation
228 * @return A handle to the window
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.
238 static Application Get();
240 public: // Stereoscopy
243 * Set the viewing mode for the application.
244 * @param[in] viewMode The new viewing mode.
246 void SetViewMode( ViewMode viewMode );
249 * Get the current viewing mode.
250 * @return The current viewing mode.
252 ViewMode GetViewMode() const;
255 * Set the stereo base (eye seperation) for stereoscopic 3D
256 * @param[in] stereoBase The stereo base (eye seperation) for stereoscopic 3D
258 void SetStereoBase( float stereoBase );
261 * Get the stereo base (eye seperation) for stereoscopic 3D
262 * @return The stereo base (eye seperation) for stereoscopic 3D
264 float GetStereoBase() const;
269 * The user should connect to this signal to determine when they should initialise
272 AppSignalV2& InitSignal();
275 * The user should connect to this signal to determine when they should terminate
278 AppSignalV2& TerminateSignal();
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.
284 AppSignalV2& PauseSignal();
287 * The user should connect to this signal if they need to perform any special
288 * activities when the application has resumed.
290 AppSignalV2& ResumeSignal();
293 * This signal is sent when the system requires the user to reinitialise itself.
295 AppSignalV2& ResetSignal();
298 * This signal is emitted when the window the application is rendering on is resized.
300 AppSignalV2& ResizeSignal();
303 * This signal is emitted when the language is changed on the device.
305 AppSignalV2& LanguageChangedSignal();
307 public: // Not intended for application developers
309 * Internal constructor
311 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
316 #endif // __DALI_APPLICATION_H__