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