1 #ifndef __DALI_EXTENSION_EVAS_PLUGIN_H__
2 #define __DALI_EXTENSION_EVAS_PLUGIN_H__
5 * Copyright (c) 2019 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 * @addtogroup CAPI_DALI_EXTENSION_FRAMEWORK_MODULE
29 #include <dali/public-api/object/base-handle.h>
30 #include <dali/public-api/signals/dali-signal.h>
44 * @brief Application class used by EFL applications that wish to use Dali
46 * An EvasPlugin class object should be created by EFL applications
47 * that wish to use Dali. It provides a means for initializing the
48 * resources required by the Dali::Core.
50 * The EvasPlugin class emits several signals which the user can
51 * connect to. The user should not create any Dali objects in the main
52 * function and instead should connect to the Init signal of the
53 * EvasPlugin and create the Dali objects in the connected callback.
55 * Tizen and EFL applications should follow the example below:
59 * #include <app_extension.h>
60 * #include <Elementary.h>
62 * #include <dali/dali.h>
63 * #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
64 * #include <dali-extension/dali-extension.h>
66 * using namespace Dali;
67 * using namespace Dali::Toolkit;
68 * using namespace Dali::Extension;
72 * const char* const APPLICATION_TITLE = "EvasPluginExample";
73 * const int EVAS_PLUGIN_WIDTH = 480;
74 * const int EVAS_PLUGIN_HEIGHT = 800;
77 * class DaliApplication : public ConnectionTracker
80 * DaliApplication(EvasPlugin evasPlugin)
81 * : mEvasPlugin(evasPlugin)
83 * mEvasPlugin.InitSignal().Connect(this, &DaliApplication::OnInitialize);
92 * void OnInitialize(EvasPlugin& evasPlugin)
94 * Stage stage = Stage::GetCurrent();
96 * TextLabel textLabel = TextLabel::New( "Hello World" );
97 * textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
98 * textLabel.SetName( "helloWorldLabel" );
99 * stage.Add( textLabel );
103 * EvasPlugin mEvasPlugin;
108 * Evas_Object* elm_win;
109 * DaliApplication* daliApplication;
112 * static void win_del(void *data, Evas_Object * obj, void *event_info)
116 * static bool app_create(void *data)
118 * struct app_data* ad = (struct app_data*)data;
120 * // Sets the GL backend for rendering
121 * elm_config_accel_preference_set("3d");
123 * // Creates the elm window
124 * ad->elm_win = elm_win_add(NULL, APPLICATION_TITLE, ELM_WIN_BASIC);
126 * DALI_ASSERT_ALWAYS(ad->elm_win != NULL && "Fail to create elm window.");
128 * elm_win_title_set(ad->elm_win, APPLICATION_TITLE);
129 * elm_win_rotation_with_resize_set(ad->elm_win, 0);
130 * evas_object_smart_callback_add(ad->elm_win, "delete,request", win_del, ad->elm_win);
131 * evas_object_show(ad->elm_win);
133 * // Adds the background
134 * Evas_Object* bg = elm_bg_add(ad->elm_win);
135 * elm_bg_color_set(bg, 255, 255, 255);
136 * evas_object_size_hint_weight_set(bg, 0,0);
137 * elm_win_resize_object_add(ad->elm_win, bg);
138 * evas_object_show(bg);
140 * // Creates an Evas plugin
141 * EvasPlugin evasPlugin = EvasPlugin::New(ad->elm_win, EVAS_PLUGIN_WIDTH, EVAS_PLUGIN_HEIGHT, true);
143 * // Creates a Dali application
144 * ad->daliApplication = new DaliApplication(evasPlugin);
149 * static void app_terminate(void *data)
151 * struct app_data* ad = (struct app_data*)data;
153 * delete ad->daliApplication;
154 * ad->daliApplication = NULL;
157 * static void app_pause(void *data)
161 * static void app_resume(void *data)
165 * static void app_control(app_control_h service, void *data)
169 * int main(int argc, char *argv[])
171 * // Initializes the Tizen application framework
172 * ui_app_lifecycle_callback_s event_callback;
174 * event_callback.create = app_create;
175 * event_callback.terminate = app_terminate;
176 * event_callback.pause = app_pause;
177 * event_callback.resume = app_resume;
178 * event_callback.app_control = app_control;
180 * struct app_data ad;
181 * memset(&ad, 0x0, sizeof(ad));
183 * // Runs the Tizen application framework
184 * return ui_app_main(argc, argv, &event_callback, &ad);
188 class DALI_IMPORT_API EvasPlugin : public BaseHandle
192 typedef Signal<void (void)> EvasPluginSignalType;
197 * @brief This is the constructor for Tizen EFL applications
199 * @param[in] parentEvasObject Parent of the new Evas object
200 * @param[in] width The initial width of the Dali view port
201 * @param[in] height The initial height of the Dali view port
202 * @param[in] transparent Whether the Evas object is transparent or not
204 static EvasPlugin New(Evas_Object* parentEvasObject, int width, int height, bool transparent);
207 * @brief Constructs an empty handle
212 * @brief Copy constructor
214 EvasPlugin(const EvasPlugin& evasPlugin);
217 * @brief Assignment operator
219 EvasPlugin& operator=(const EvasPlugin& evasPlugin);
229 * @brief Runs the Evas plugin (rendering, event handling, etc)
234 * @brief Pauses the Evas plugin
239 * @brief Resumes the Evas plugin
244 * @brief Stops the Evas plugin
249 * @brief This returns the Evas_Object* which is created internally for accessibility.
251 * Applications should append this access object to custom focus chain for accessibility
253 * e.g., elm_object_focus_custom_chain_append(layout, dali_access_object, NULL);
255 * @return Evas_Object* Elm access object which Dali image Evas object is registered
257 Evas_Object* GetDaliAccessEvasObject();
260 * @brief This returns the Evas_Object* which is created internally
262 * @return Evas_Object* Evas object which is rendered by Dali
264 Evas_Object* GetDaliEvasObject();
269 * @brief Signal to notify the client when the application is ready to be initialized
273 EvasPluginSignalType& InitSignal();
276 * @brief Signal to notify the user when the application is about to be terminated
280 EvasPluginSignalType& TerminateSignal();
283 * @brief Signal to notify the client when the adaptor is about to be paused
285 * The user should connect to this signal if the user needs to perform any special
286 * activities when the application is about to be paused.
289 EvasPluginSignalType& PauseSignal();
292 * @brief Signal to notify the client when the adpator has resumed
294 * The user should connect to this signal if the user needs to perform any special
295 * activities when the application has resumed.
298 EvasPluginSignalType& ResumeSignal();
301 * @brief Signal to notify the client when the Evas object is resized
305 EvasPluginSignalType& ResizeSignal();
308 * @brief Signal to notify the client when the Evas object gets the keyboard focus
312 EvasPluginSignalType& FocusedSignal();
315 * @brief Signal to notify the client when the Evas object loses the keyboard focus
319 EvasPluginSignalType& UnFocusedSignal();
321 public: // Not intended for application developers
323 * @brief Internal constructor
325 explicit DALI_INTERNAL EvasPlugin(Internal::EvasPlugin* evasPlugin);
332 } // namespace Extension
336 #endif // __DALI_EXTENSION_EVAS_PLUGIN_H__