summaryrefslogtreecommitdiff
path: root/src/view.c
blob: e99640d3108c842498693405a244c2e02b8d79f9 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
 * Copyright (c) 2016 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 <Elementary.h>
#include <efl_extension.h>
#include <dlog.h>

#include "classic-watch.h"
#include "view.h"

static struct view_info {
	Evas_Object *bg;
	Evas_Object *module_moonphase_layout;
	Evas_Object *module_day_layout;
	Evas_Object *module_month_layout;
	Evas_Object *module_weekday_layout;
} s_info = {
	.bg = NULL,
	.module_moonphase_layout = NULL,
	.module_day_layout = NULL,
	.module_month_layout = NULL,
	.module_weekday_layout = NULL,
};

/**
 * @brief Set the module moon phase layout.
 */
void view_set_module_moonphase_layout(Evas_Object *layout)
{
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL");
		return;
	}

	s_info.module_moonphase_layout = layout;
}

/**
 * @brief Set the module day layout.
 */
void view_set_module_day_layout(Evas_Object *layout)
{
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL");
		return;
	}

	s_info.module_day_layout = layout;
}

/**
 * @brief Set the module month layout.
 */
void view_set_module_month_layout(Evas_Object *layout)
{
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL");
		return;
	}

	s_info.module_month_layout = layout;
}

/**
 * @brief Set the module month layout.
 */
void view_set_module_weekday_layout(Evas_Object *layout)
{
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL");
		return;
	}

	s_info.module_weekday_layout = layout;
}

/**
 * @brief Get the bg object.
 */
Evas_Object *view_get_bg(void)
{
	return s_info.bg;
}

/**
 * @brief Get the module moon phase layout.
 */
Evas_Object *view_get_module_moonphase_layout(void)
{
	return s_info.module_moonphase_layout;
}

/**
 * @brief Get the module day layout.
 */
Evas_Object *view_get_module_day_layout(void)
{
	return s_info.module_day_layout;
}

/**
 * @brief Get the module month layout.
 */
Evas_Object *view_get_module_month_layout(void)
{
	return s_info.module_month_layout;
}

/**
 * @brief Get the module weekday layout.
 */
Evas_Object *view_get_module_weekday_layout(void)
{
	return s_info.module_weekday_layout;
}

/**
 * @brief Set text to the part.
 * @param[in] parent Object has part to which you want to set text
 * @param[in] part_name Part name to which you want to set the text
 * @param[in] text Text you want to set to the part
 */
void view_set_text(Evas_Object *parent, const char *part_name, const char *text)
{
	if (parent == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
		return;
	}

	/* Set text of target part object */
	elm_object_part_text_set(parent, part_name, text);
}

/**
 * @brief Rotate hands of the watch.
 * @param[in] hand The hand you want to rotate
 * @param[in] degree The degree you want to rotate
 * @param[in] cx The rotation's center horizontal position
 * @param[in] cy The rotation's center vertical position
 */
void view_rotate_hand(Evas_Object *hand, double degree, Evas_Coord cx, Evas_Coord cy)
{
	Evas_Map *m = NULL;

	if (hand == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "hand is NULL");
		return;
	}

	m = evas_map_new(4);
	evas_map_util_points_populate_from_object(m, hand);
	evas_map_util_rotate(m, degree, cx, cy);
	evas_object_map_set(hand, m);
	evas_object_map_enable_set(hand, EINA_TRUE);
	evas_map_free(m);
}

/**
 * @brief Rotate hands of the watch.
 * @param[in] degree The degree you want to rotate
 */
void view_rotate_moonphase(float degree)
{
	Evas_Object *module_moonphase_layout = NULL;
	Evas_Object *edj_obj = NULL;
	Edje_Message_Float msg;

	module_moonphase_layout = view_get_module_moonphase_layout();
	if (module_moonphase_layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get moon phase layout");
		return;
	}

	edj_obj = elm_layout_edje_get(module_moonphase_layout);
	if (edj_obj == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get edje object");
		return;
	}

	msg.val = degree;

	edje_object_message_send(edj_obj, EDJE_MESSAGE_FLOAT, 1, &msg);
}

/**
 * @breif Create a bg object for the watch
 * @param[in] win The window object
 * @param[in] image_path The image path for bg
 * @param[in] width The width size of bg
 * @param[in] height The height size of bg
 */
Evas_Object *view_create_bg(Evas_Object *win, const char *image_path, int width, int height)
{
	Evas_Object *bg = NULL;
	Eina_Bool ret = EINA_FALSE;

	if (win == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "window is NULL");
		return NULL;
	}

	bg = elm_bg_add(win);
	if (bg == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add bg");
		return NULL;
	}

	ret = elm_bg_file_set(bg, image_path, NULL);
	if (ret != EINA_TRUE) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set the background image");
		evas_object_del(bg);
		return NULL;
	}

	elm_bg_option_set(bg, ELM_BG_OPTION_CENTER);

	evas_object_move(bg, 0, 0);
	evas_object_resize(bg, width, height);
	evas_object_show(bg);

	s_info.bg = bg;

	return bg;
}

/**
 * @brief Make a layout to target parent object with edje file.
 * @param[in] parent The object to which you want to add this layout
 * @param[in] file_path File path of EDJ file will be used
 * @param[in] group_name Name of group in EDJ you want to set to
 * @param[in] user_data The user data to be passed to the callback functions
 */
Evas_Object *view_create_layout(Evas_Object *parent, const char *file_path, const char *group_name, void *user_data)
{
	Evas_Object *layout = NULL;

	if (parent == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL.");
		return NULL;
	}

	/*
	 * Create layout by EDC(edje file)
	 */
	layout = elm_layout_add(parent);
	elm_layout_file_set(layout, file_path, group_name);

	/*
	 * Layout size setting
	 */
	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	evas_object_show(layout);

	return layout;
}

/**
 * @brief Set property for module layout.
 * @param[in] layout The object to which you want to set
 * @param[in] x The X coordinate of the module layout
 * @param[in] y The Y coordinate of the module layout
 * @param[in] w The width size of the module layout
 * @param[in] h The height size of the module layout
 */
void view_set_module_property(Evas_Object *layout, int x, int y, int w, int h)
{
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "layout is NULL");
		return;
	}

	evas_object_move(layout, x, y);
	evas_object_resize(layout, w, h);
}

/**
 * @brief Create day num layout for the watch.
 * @param[in] parent The object to which you want to add this layout
 * @param[in] file_path File path of EDJ file will be used
 * @param[in] group_name Group name of EDJ group will be used
 */
Evas_Object *view_create_module_layout(Evas_Object *parent, const char *file_path, const char *group_name)
{
	Evas_Object *layout = NULL;

	if (parent == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "parent is NULL");
		return NULL;
	}

	if (file_path == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "file path is NULL");
		return NULL;
	}

	if (group_name == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "group name is NULL");
		return NULL;
	}

	layout = view_create_layout(parent, file_path, group_name, NULL);
	if (layout == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create module layout");
		return NULL;
	}

	evas_object_show(layout);

	return layout;
}

/**
 * @brief Set opacity to parts of watch.
 * @param[in] parts The parts of watch
 */
void view_set_opacity_to_parts(Evas_Object *parts)
{
	if (parts == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set opacity to parts");
		return;
	}

	evas_object_color_set(parts, 255, 255, 255, 255 * 0.5);
}

/**
 * @brief Create a part for the watch.
 * @param[in] parent The object to which you want to add this object
 * @param[in] image_path The path of the image file you want to set
 * @param[in] x The X coordinate of the part
 * @param[in] y The Y coordinate of the part
 * @param[in] w The width size of the part
 * @param[in] h The height size of the part
 */
Evas_Object *view_create_parts(Evas_Object *parent, const char *image_path, int x, int y, int w, int h)
{
	Evas_Object *parts = NULL;
	Eina_Bool ret = EINA_FALSE;

	if (parent == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "bg is NULL");
		return NULL;
	}

	parts = elm_image_add(parent);
	if (parts == NULL) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add minute hand image");
		return NULL;
	}

	ret = elm_image_file_set(parts, image_path, NULL);
	if (ret != EINA_TRUE) {
		dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set minute hand image");
		evas_object_del(parts);
		return NULL;
	}

	evas_object_move(parts, x, y);
	evas_object_resize(parts, w, h);
	evas_object_show(parts);

	return parts;
}

/**
 * @brief Destroy base GUI.
 */
void view_destroy_base_gui(void)
{
	if (s_info.module_day_layout) {
		evas_object_del(s_info.module_day_layout);
		s_info.module_day_layout = NULL;
	}

	if (s_info.module_month_layout) {
		evas_object_del(s_info.module_month_layout);
		s_info.module_month_layout = NULL;
	}

	if (s_info.module_weekday_layout) {
		evas_object_del(s_info.module_weekday_layout);
		s_info.module_weekday_layout = NULL;
	}

	if (s_info.bg) {
		evas_object_data_del(s_info.bg, "__HANDS_SEC__");
		evas_object_data_del(s_info.bg, "__HANDS_MIN__");
		evas_object_data_del(s_info.bg, "__HANDS_HOUR__");
		evas_object_data_del(s_info.bg, "__HANDS_MODULE_MONTH__");
		evas_object_data_del(s_info.bg, "__HANDS_MODULE_WEEKDAY__");
		evas_object_data_del(s_info.bg, "__HANDS_SEC_SHADOW__");
		evas_object_data_del(s_info.bg, "__HANDS_MIN_SHADOW__");
		evas_object_data_del(s_info.bg, "__HANDS_HOUR_SHADOW__");
		evas_object_data_del(s_info.bg, "__HANDS_MODULE_MONTH_SHADOW__");
		evas_object_data_del(s_info.bg, "__HANDS_MODULE_WEEKDAY_SHADOW__");
		evas_object_del(s_info.bg);
		s_info.bg = NULL;
	}
}