2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <Elementary.h>
20 #include "cscl-ui-nui.h"
21 #include "cscl-ui-graphics-backend.h"
22 #include "cscl-ui-window-backend.h"
23 #include "cscl-ui-event-callback.h"
31 #define LOG_TAG "CSCLUINUI"
36 static Evas_Object *g_win = NULL;
39 static CSCLUI *g_ui = NULL;
41 static scl_nui_draw_text_cb g_draw_text_cb;
42 static void *g_draw_text_cb_data = NULL;
44 static scl_nui_draw_image_cb g_draw_image_cb = NULL;
45 static void *g_draw_image_cb_data = NULL;
47 static scl_nui_draw_rectangle_cb g_draw_rectangle_cb = NULL;
48 static void *g_draw_rectangle_cb_data = NULL;
50 static scl_nui_update_window_cb g_update_window_cb = NULL;
51 static void *g_update_window_cb_data = NULL;
53 void CUIGraphicsBackendCallback::on_draw_text(const SclFontInfo& font_info, const SclColor& color, const char *str, int pos_x, int pos_y, int w, int h,
54 SCLLabelAlignment align, int padding_x, int padding_y, int inner_width, int inner_height, void* user_data)
55 //const char *str, int x, int y, int w, int h, int fontsize, void* user_data)
57 LOGD("draw text : %p", g_draw_text_cb);
59 //g_draw_text_cb(str, pos_x, pos_y, w, h, font_info.font_size, user_data);
62 strcpy(fi.font_name, font_info.font_name);
63 fi.font_size = font_info.font_size;
64 fi.is_bold = font_info.is_bold;
65 fi.is_italic = font_info.is_italic;
75 g_draw_text_cb(fi, ci, str, pos_x, pos_y, w, h,
76 (LabelAlignment)align, padding_x, padding_y, inner_width, inner_height, user_data);
78 g_draw_text_cb(font_info.font_name, font_info.font_size, font_info.is_bold, font_info.is_italic,
79 color.r, color.g, color.b, color.a,
80 str, pos_x, pos_y, w, h,
81 (LabelAlignment)align, padding_x, padding_y, inner_width, inner_height, user_data);
85 void CUIGraphicsBackendCallback::on_draw_image(const char *image_path, int dest_x, int dest_y, int dest_weight, int dest_height, int src_x, int src_y, int src_width, int src_height, void* user_data)
87 LOGD("draw image : %p", g_draw_image_cb);
88 if (g_draw_image_cb) {
89 g_draw_image_cb(image_path, dest_x, dest_y, dest_weight, dest_height, src_x, src_y, src_width, src_height, user_data);
93 void CUIGraphicsBackendCallback::on_draw_rectangle(int pos_x, int pos_y, int width, int height, bool fill, int fill_color_r, int fill_color_g, int fill_color_b, int fill_color_a, void* user_data)
95 LOGD("draw rectangle : %p", g_draw_rectangle_cb);
96 if (g_draw_rectangle_cb) {
97 g_draw_rectangle_cb(pos_x, pos_y, width, height,
98 fill, fill_color_r, fill_color_g, fill_color_b, fill_color_a, user_data);
102 void CUIWindowBackendCallback::update_window(int x, int y, int width, int height, void* user_data)
104 LOGD("update_window : %p", g_update_window_cb);
105 if (g_update_window_cb) {
106 g_update_window_cb(x, y, width, height, user_data);
110 SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_desc)
113 return SCL_EVENT_PASS_ON;
116 SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info)
119 return SCL_EVENT_PASS_ON;
122 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
125 return SCL_EVENT_PASS_ON;
128 static CUIGraphicsBackendCallback callback;
130 static CUIWindowBackendCallback window_callback;
132 static CUIEventCallback event_callback;
134 Evas_Object *get_main_window()
139 EXPORT_API int scl_nui_init(const char *entry_filepath)
145 //LOGI("################## Hello ################");
157 g_win = elm_win_add(NULL, "test", ELM_WIN_UTILITY);
160 g_ui->init(g_win, SCL_PARSER_TYPE_XML, entry_filepath);
162 g_ui->set_graphics_backend_callback(&callback, NULL);
164 g_ui->set_window_backend_callback(&window_callback, NULL);
166 /* Default ISE callback */
167 g_ui->set_ui_event_callback(&event_callback);
172 EXPORT_API int scl_nui_fini()
178 evas_object_del(g_win);
195 EXPORT_API int scl_nui_set_input_mode(const char *input_mode)
200 g_ui->set_input_mode(input_mode);
205 EXPORT_API int scl_nui_set_update_pending(bool pend)
210 g_ui->set_update_pending(pend);
214 EXPORT_API int scl_nui_set_draw_text_cb(scl_nui_draw_text_cb callback, void *user_data)
216 g_draw_text_cb = callback;
217 g_draw_text_cb_data = user_data;
222 EXPORT_API int scl_nui_set_draw_image_cb(scl_nui_draw_image_cb callback, void *user_data)
224 g_draw_image_cb = callback;
225 g_draw_image_cb_data = user_data;
230 EXPORT_API int scl_nui_set_draw_rectangle_cb(scl_nui_draw_rectangle_cb callback, void *user_data)
232 g_draw_rectangle_cb = callback;
233 g_draw_rectangle_cb_data = user_data;
238 EXPORT_API int scl_nui_set_cur_sublayout(const char *sub_layout_name)
243 LOGD("cur sublayout : %s", sub_layout_name);
245 g_ui->set_cur_sublayout(sub_layout_name);
250 EXPORT_API int scl_nui_set_string_substitution(const char *original, const char *substitute)
255 LOGD("original : %s, substitute : %s", original, substitute);
257 g_ui->set_string_substitution(original, substitute);
262 EXPORT_API int scl_nui_set_update_window_cb(scl_nui_update_window_cb callback, void *user_data)
264 g_update_window_cb = callback;
265 g_update_window_cb_data = user_data;