4240536f13762bace8abfe174500d598266596fe
[apps/native/gear-racing-controller.git] / src / view / view_base.c
1 /*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3 *
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
7 *
8 * http://floralicense.org/license/
9 *
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.
15 */
16
17 #include <system_info.h>
18 #include <assert.h>
19 #include "gear-racing-controller.h"
20 #include "view/view_base.h"
21
22 void view_base_get_resource(const char *edj_file_in, char *edj_path_out)
23 {
24         char *res_path = app_get_resource_path();
25         if (res_path) {
26                 snprintf(edj_path_out, PATH_MAX, "%s%s", res_path, edj_file_in);
27                 free(res_path);
28         }
29 }
30
31 Evas_Object *view_base_create_layout(Evas_Object *parent, char *edj_file, char *group)
32 {
33         char edj_path[PATH_MAX] = { 0 };
34         view_base_get_resource(edj_file, edj_path);
35         Evas_Object *layout = elm_layout_add(parent);
36         if (!layout) {
37                 assert(!"Failed to create controller");
38         }
39
40         if (!elm_layout_file_set(layout, edj_path, GRP_MAIN)) {
41                 assert(!"Failed to load file");
42         }
43
44         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45 //      elm_object_content_set(parent, layout);
46
47         return layout;
48 }
49
50 Evas_Object *view_base_create_button(Evas_Object *parent, char *part, char *text, Evas_Smart_Cb callback, void *data)
51 {
52         Evas_Object *button = elm_button_add(parent);
53         if (!button) {
54                 assert(!"Failed to create button");
55         }
56
57         evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58         elm_object_text_set(button, text);
59
60         if (callback) {
61                 evas_object_smart_callback_add(button, "clicked", callback, data);
62         }
63
64         if (part) {
65                 elm_layout_content_set(parent, part, button);
66         }
67
68         return button;
69 }
70
71 void get_screen_size(int *width, int *height)
72 {
73         system_info_get_platform_int("http://tizen.org/feature/screen.width", width);
74         system_info_get_platform_int("http://tizen.org/feature/screen.height", height);
75 }
76
77 void view_base_set_position(Evas_Object *obj, int pos_x, int pos_y,
78                 e_horizontal_align horizontal_align, e_vertical_align vertical_align)
79 {
80         int width = 0;
81         int height = 0;
82         int x = 0;
83         int y = 0;
84
85         if (horizontal_align != HORIZONTAL_ALIGN_LEFT || vertical_align != VERTICAL_ALIGN_TOP) {
86                 evas_object_geometry_get(obj, NULL, NULL, &width, &height);
87         }
88
89         switch (horizontal_align) {
90                 case HORIZONTAL_ALIGN_LEFT:
91                         x = pos_x;
92                         break;
93                 case HORIZONTAL_ALIGN_CENTER:
94                         x = pos_x - width / 2;
95                         break;
96                 case HORIZONTAL_ALIGN_RIGHT:
97                         x = pos_x - width;
98                         break;
99                 default:
100                         break;
101         }
102
103         switch (vertical_align) {
104                 case VERTICAL_ALIGN_TOP:
105                         y = pos_y;
106                         break;
107                 case VERTICAL_ALIGN_CENTER:
108                         y = pos_y - height / 2;
109                         break;
110                 case VERTICAL_ALIGN_BOTTOM:
111                         y = pos_y - height;
112                         break;
113                 default:
114                         break;
115         }
116
117         evas_object_move(obj, x, y);
118 }
119
120 void view_base_set_angle(Evas_Object *image, float angle, float rotation_center_x, float rotation_center_y)
121 {
122         Evas_Map *map = evas_map_new(4);
123         evas_map_util_points_populate_from_object(map, image);
124         evas_map_util_rotate(map, angle, rotation_center_x, rotation_center_y);
125         evas_object_map_set(image, map);
126         evas_object_map_enable_set(image, true);
127         evas_map_free(map);
128 }
129
130 void view_base_show(s_view_base *view)
131 {
132         if (view && view->show_cb) {
133                 view->show_cb();
134         }
135 }
136
137 void view_base_hide(s_view_base *view)
138 {
139         if (view && view->hide_cb) {
140                 view->hide_cb();
141         }
142 }
143
144 void view_base_update(s_view_base *view)
145 {
146         if (view && view->update_cb) {
147                 view->update_cb();
148         }
149 }
150