Merge "Removed troubleshooting section from README" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor.h
1 #ifndef __DALI_ADAPTOR_H__
2 #define __DALI_ADAPTOR_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_ADAPTOR_MODULE
23  * @{
24  */
25
26 // EXTERNAL INCLUDES
27 #include <boost/function.hpp>
28 #include "window.h"
29 #include "tts-player.h"
30 #include <dali/public-api/signals/dali-signal-v2.h>
31 #include <dali/public-api/math/rect.h>
32 #include <dali/public-api/events/touch-event.h>
33
34 namespace Dali DALI_IMPORT_API
35 {
36
37 struct DeviceLayout;
38 class RenderSurface;
39
40 namespace Internal DALI_INTERNAL
41 {
42 namespace Adaptor
43 {
44 class Adaptor;
45 }
46 }
47
48 /**
49  * @brief An Adaptor object is used to initialize and control how Dali runs.
50  *
51  * It provides a lifecycle interface that allows the application
52  * writer to provide their own main loop and other platform related
53  * features.
54  *
55  * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
56  *
57  * When dealing with platform events, the application writer MUST ensure that Dali is called in a
58  * thread-safe manner.
59  *
60  * As soon as the Adaptor class is created and started, the application writer can initialise their
61  * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
62  * need to wait for an initialise signal as per the Dali::Application class).
63  *
64  * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
65  * Tizen and Linux Adaptors should follow the example below:
66  *
67  * @code
68  * void CreateProgram(DaliAdaptor& adaptor)
69  * {
70  *   // Create Dali components...
71  *   // Can instantiate adaptor here instead, if required
72  * }
73  *
74  * int main ()
75  * {
76  *   // Initialise platform
77  *   MyPlatform.Init();
78  *
79  *   // Create an 800 by 1280 window positioned at (0,0).
80  *   Dali::PositionSize positionSize(0, 0, 800, 1280);
81  *   Dali::Window window = Dali::Window::New( positionSize, "My Application" );
82  *
83  *   // Create an adaptor which uses that window for rendering
84  *   Dali::Adaptor adaptor = Dali::Adaptor::New( window );
85  *   adaptor.Start();
86  *
87  *   CreateProgram(adaptor);
88  *   // Or use this as a callback function depending on the platform initialisation sequence.
89  *
90  *   // Start Main Loop of your platform
91  *   MyPlatform.StartMainLoop();
92  *
93  *   return 0;
94  * }
95  * @endcode
96  *
97  * If required, you can also connect class member functions to a signal:
98  *
99  * @code
100  * MyApplication application;
101  * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
102  * @endcode
103  *
104  * @see RenderSurface
105  */
106 class Adaptor
107 {
108 public:
109
110   typedef SignalV2< void (Adaptor&) > AdaptorSignalV2; ///< Generic Type for adaptor signals
111
112 public:
113   /**
114    * @brief Create a new adaptor using the window.
115    *
116    * @param[in] window The window to draw onto
117    * @note The default base layout DeviceLayout::DEFAULT_BASE_LAYOUT will be used.
118    * @return a reference to the adaptor handle
119    */
120   static Adaptor& New( Window window );
121
122   /**
123    * @brief Create a new adaptor using the window.
124    *
125    * @param[in] window The window to draw onto
126    * @param[in] baseLayout  The base layout that the application has been written for
127    * @return a reference to the adaptor handle
128    */
129   static Adaptor& New( Window window, const DeviceLayout& baseLayout );
130
131   /**
132    * @brief Virtual Destructor.
133    */
134   virtual ~Adaptor();
135
136 public:
137
138   /**
139    * @brief Starts the Adaptor.
140    */
141   void Start();
142
143   /**
144    * @brief Pauses the Adaptor.
145    */
146   void Pause();
147
148   /**
149    * @brief Resumes the Adaptor, if previously paused.
150    *
151    * @note If the adaptor is not paused, this does not do anything.
152    */
153   void Resume();
154
155   /**
156    * @brief Stops the Adaptor.
157    */
158   void Stop();
159
160   /**
161    * @brief Ensures that the function passed in is called from the main loop when it is idle.
162    *
163    * A callback of the following type may be used:
164    * @code
165    *   void MyFunction();
166    * @endcode
167    *
168    * @param[in]  callBack  The function to call.
169    * @return true if added successfully, false otherwise
170    */
171   bool AddIdle( boost::function<void(void)> callBack );
172
173   /**
174    * @brief Get the render surface the adaptor is using to render to.
175    *
176    * @return reference to current render surface
177    */
178   RenderSurface& GetSurface();
179
180   /**
181    * @brief Returns a reference to the instance of the adaptor used by the current thread.
182    *
183    * @return A reference to the adaptor.
184    * @pre The adaptor has been initialised.
185    * @note This is only valid in the main thread.
186    */
187   static Adaptor& Get();
188
189   /**
190    * @brief Checks whether the adaptor is available.
191    *
192    * @return true, if it is available, false otherwise.
193    */
194   static bool IsAvailable();
195
196   /**
197    * @brief Registers the singleton of Dali handle with its type info.
198    *
199    * The singleton will be kept alive for the life time of the
200    * adaptor.
201    * @note This is not intended for application developers.
202    * @param[in] info The type info of the Dali handle generated by the compiler.
203    * @param[in] singleton The Dali handle to be registered
204    */
205   void RegisterSingleton(const std::type_info& info, BaseHandle singleton);
206
207   /**
208    * @brief Gets the singleton for the given type.
209    *
210    * @note This is not intended for application developers.
211    * @param[in] info The type info of the given type.
212    * @return the Dali handle if it is registered as a singleton or an uninitialized handle.
213    */
214   BaseHandle GetSingleton(const std::type_info& info) const;
215
216   /**
217    * @brief Call this method to notify Dali when the system language changes.
218    *
219    * Use this only when NOT using Dali::Application, As Application created using
220    * Dali::Application will automatically receive notification of language change.
221    * When Dali::Application is not used, the application developer should
222    * use app-core to receive language change notifications and should update Dali
223    * by calling this method.
224    */
225   void NotifyLanguageChanged();
226
227   /**
228    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
229    * trigger a pinch gesture
230    *
231    * @param[in] distance The minimum pinch distance in pixels
232    */
233   void SetMinimumPinchDistance(float distance);
234
235 public:  // Signals
236
237   /**
238    * @brief The user should connect to this signal if they need to perform any
239    * special activities when the surface Dali is being rendered on is resized.
240    *
241    * @return The signal to connect to
242    */
243   AdaptorSignalV2& ResizedSignal();
244
245   /**
246    * @brief This signal is emitted when the language is changed on the device.
247    *
248    * @return The signal to connect to
249    */
250   AdaptorSignalV2& LanguageChangedSignal();
251
252 private:
253
254   // Undefined
255   Adaptor(const Adaptor&);
256   Adaptor& operator=(Adaptor&);
257
258 private:
259
260   /**
261    * @brief Create an uninitialized Adaptor.
262    */
263   DALI_INTERNAL Adaptor();
264
265   Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
266   friend class Internal::Adaptor::Adaptor;
267 };
268
269 } // namespace Dali
270
271 /**
272  * @}
273  */
274 #endif // __DALI_ADAPTOR_H__