2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 #include <system_info.h>
19 #include "gear-racing-controller.h"
20 #include "view/view_base.h"
22 void view_base_get_resource(const char *edj_file_in, char *edj_path_out)
24 char *res_path = app_get_resource_path();
26 snprintf(edj_path_out, PATH_MAX, "%s%s", res_path, edj_file_in);
31 Evas_Object *view_base_create_layout(Evas_Object *parent, char *edj_file, char *group)
33 char edj_path[PATH_MAX] = { 0 };
34 view_base_get_resource(edj_file, edj_path);
35 Evas_Object *layout = elm_layout_add(parent);
37 assert(!"Failed to create controller");
40 if (!elm_layout_file_set(layout, edj_path, GRP_MAIN)) {
41 assert(!"Failed to load file");
44 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45 // elm_object_content_set(parent, layout);
50 Evas_Object *view_base_create_image(Evas_Object *parent, char *path)
52 char edj_path[PATH_MAX] = { 0 };
53 view_base_get_resource(path, edj_path);
55 Evas_Object *image = elm_image_add(parent);
56 evas_object_size_hint_weight_set(parent, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58 if (!elm_image_file_set(image, edj_path, NULL)) {
59 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to load file: %s", path);
65 Evas_Object *view_base_create_button(Evas_Object *parent, char *part, char *text, char *image_path, char *style, Evas_Smart_Cb callback, void *data)
67 Evas_Object *button = elm_button_add(parent);
69 assert(!"Failed to create button");
72 evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74 if (style && !elm_object_style_set(button, style)) {
75 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set style: %s", style);
79 elm_object_text_set(button, text);
83 Evas_Object *image = view_base_create_image(button, image_path);
84 elm_object_content_set(button, image);
88 evas_object_smart_callback_add(button, "clicked", callback, data);
92 elm_layout_content_set(parent, part, button);
98 void get_screen_size(int *width, int *height)
100 system_info_get_platform_int("http://tizen.org/feature/screen.width", width);
101 system_info_get_platform_int("http://tizen.org/feature/screen.height", height);
104 void view_base_set_position(Evas_Object *obj, int pos_x, int pos_y,
105 e_horizontal_align horizontal_align, e_vertical_align vertical_align)
112 if (horizontal_align != HORIZONTAL_ALIGN_LEFT || vertical_align != VERTICAL_ALIGN_TOP) {
113 evas_object_geometry_get(obj, NULL, NULL, &width, &height);
116 switch (horizontal_align) {
117 case HORIZONTAL_ALIGN_LEFT:
120 case HORIZONTAL_ALIGN_CENTER:
121 x = pos_x - width / 2;
123 case HORIZONTAL_ALIGN_RIGHT:
130 switch (vertical_align) {
131 case VERTICAL_ALIGN_TOP:
134 case VERTICAL_ALIGN_CENTER:
135 y = pos_y - height / 2;
137 case VERTICAL_ALIGN_BOTTOM:
144 evas_object_move(obj, x, y);
147 void view_base_set_angle(Evas_Object *image, float angle, float rotation_center_x, float rotation_center_y)
149 Evas_Map *map = evas_map_new(4);
150 evas_map_util_points_populate_from_object(map, image);
151 evas_map_util_rotate(map, angle, rotation_center_x, rotation_center_y);
152 evas_object_map_set(image, map);
153 evas_object_map_enable_set(image, true);
157 void view_base_show(s_view_base *view)
159 if (view && view->show_cb) {
164 void view_base_hide(s_view_base *view)
166 if (view && view->hide_cb) {
171 void view_base_update(s_view_base *view)
173 if (view && view->update_cb) {