summaryrefslogtreecommitdiff
path: root/src/view/view_base.c
blob: fdc7ef6e6b30539aa494290937cf9eb9227acf03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Flora License, Version 1.1 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <system_info.h>
#include <assert.h>
#include "gear-racing-controller.h"
#include "view/view_base.h"

void view_base_get_resource(const char *edj_file_in, char *edj_path_out)
{
	char *res_path = app_get_resource_path();
	if (res_path) {
		snprintf(edj_path_out, PATH_MAX, "%s%s", res_path, edj_file_in);
		free(res_path);
	}
}

Evas_Object *view_base_create_layout(Evas_Object *parent, char *edj_file, char *group)
{
	char edj_path[PATH_MAX] = { 0 };
	view_base_get_resource(edj_file, edj_path);
	Evas_Object *layout = elm_layout_add(parent);
	if (!layout) {
		assert(!"Failed to create controller");
	}

	if (!elm_layout_file_set(layout, edj_path, GRP_MAIN)) {
		assert(!"Failed to load file");
	}

	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_content_set(parent, layout);

	return layout;
}

Evas_Object *view_base_create_button(Evas_Object *parent, char *part, char *text, Evas_Smart_Cb callback, void *data)
{
	Evas_Object *button = elm_button_add(parent);
	if (!button) {
		assert(!"Failed to create button");
	}

	evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_text_set(button, text);

	if (callback) {
		evas_object_smart_callback_add(button, "clicked", callback, data);
	}

	if (part) {
		elm_layout_content_set(parent, part, button);
	}

	return button;
}

void get_screen_size(int *width, int *height)
{
	system_info_get_platform_int("http://tizen.org/feature/screen.width", width);
	system_info_get_platform_int("http://tizen.org/feature/screen.height", height);
}

void view_base_set_position(Evas_Object *obj, int pos_x, int pos_y,
		e_horizontal_align horizontal_align, e_vertical_align vertical_align)
{
	int width = 0;
	int height = 0;
	int x = 0;
	int y = 0;

	if (horizontal_align != HORIZONTAL_ALIGN_LEFT || vertical_align != VERTICAL_ALIGN_TOP) {
		evas_object_geometry_get(obj, NULL, NULL, &width, &height);
	}

	switch (horizontal_align) {
		case HORIZONTAL_ALIGN_LEFT:
			x = pos_x;
			break;
		case HORIZONTAL_ALIGN_CENTER:
			x = pos_x - width / 2;
			break;
		case HORIZONTAL_ALIGN_RIGHT:
			x = pos_x - width;
			break;
		default:
			break;
	}

	switch (vertical_align) {
		case VERTICAL_ALIGN_TOP:
			y = pos_y;
			break;
		case VERTICAL_ALIGN_CENTER:
			y = pos_y - height / 2;
			break;
		case VERTICAL_ALIGN_BOTTOM:
			y = pos_y - height;
			break;
		default:
			break;
	}

	evas_object_move(obj, x, y);
}

void view_base_set_angle(Evas_Object *image, float angle, float rotation_center_x, float rotation_center_y)
{
	Evas_Map *map = evas_map_new(4);
	evas_map_util_points_populate_from_object(map, image);
	evas_map_util_rotate(map, angle, rotation_center_x, rotation_center_y);
	evas_object_map_set(image, map);
	evas_object_map_enable_set(image, true);
	evas_map_free(map);
}