summaryrefslogtreecommitdiff
path: root/source/3-final/src/main.c
blob: 6b12c7ea56af60cfa77d69a51b361d8924247848 (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
#include <Elementary.h>

#define PACKAGE_BIN_DIR "/usr/local/bin"
#define PACKAGE_DATA_DIR "/usr/local/share/sample"

Evas_Object *create_button(Evas_Object *parent);
Evas_Object *create_image(Evas_Object *parent, char *path, char *group);
void btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
void btn_clicked(void *data, Evas_Object *obj, void *event_info);
void _left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
void _right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
void _btn_effect(Evas_Object *obj);

Evas_Object *
create_win()
{
   Evas_Object *win = NULL;

   // TODO 2
   win = elm_win_util_standard_add(elm_app_name_get(), elm_app_name_get());
   // TODO 7
   elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
   elm_win_autodel_set(win, EINA_TRUE);
   evas_object_resize(win, 720, 400);
   evas_object_show(win);

   return win;
}

Evas_Object *
create_layout(Evas_Object *win)
{
   Evas_Object *layout = NULL;
   char buf[PATH_MAX];

   layout = elm_layout_add(win);
   // TODO 2
   snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
   // TODO 2
   elm_layout_file_set(layout, buf, "main");
   // TODO 2
   evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, layout);
   evas_object_show(layout);

   return layout;
}

void
create_top_contents(Evas_Object *layout)
{
   Evas_Object *table = NULL, *btn = NULL, *img = NULL, *label = NULL;
   int i =0;
   char buf[PATH_MAX], buf2[PATH_MAX];

   // TODO 3
   table = elm_table_add(layout);

   for (i = 0; i < 5; i++)
	 {
		btn = create_button(table);
		snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
		snprintf(buf2, sizeof(buf2), "icon%d", i);
		img = create_image(btn, buf, buf2);
	    // TODO 3
		elm_object_content_set(btn, img);

		elm_table_pack(table, btn, i, 0, 1, 1);

		label = elm_label_add(table);
		snprintf(buf2, sizeof(buf2), "<color=#ffffff>item%d</color>", i);
		// TODO 3
		elm_object_text_set(label, buf2);
		evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		evas_object_show(label);

		elm_table_pack(table, label, i, 1, 1, 1);
	 }

   elm_layout_content_set(layout, "elm.swallow.top", table);
   evas_object_show(table);

}

void
create_middle_contents(Evas_Object *layout)
{
   Evas_Object *table = NULL, *btn = NULL, *img = NULL;
   Evas_Coord padding_size = 0;
   int i = 0, j = 0;
   char buf[PATH_MAX];

   table = elm_table_add(layout);
   // TODO 4
   padding_size = 7 * elm_config_scale_get();
   elm_table_padding_set(table, padding_size, padding_size);

   for (i = 0; i < 3; i++)
	 {
		for (j = 0; j < 6; j++)
		  {
			 btn = create_button(table);

			 // TODO 10
			 // elm_button "clicked" smart callback
			 //evas_object_smart_callback_add(btn, "clicked", btn_clicked, NULL);

			 // TODO 10
			 // evas object mouse in callback
			 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN, btn_mouse_in, NULL);

			 snprintf(buf, sizeof(buf), "%s/images/%d.jpg", elm_app_data_dir_get(), ((i * 6) + j));
			 img = create_image(btn, buf, NULL);
			 elm_object_content_set(btn, img);
			 // TODO 4
			 elm_table_pack(table, btn, j, i, 1, 1);
		  }
	 }

   // TODO 4
   elm_layout_content_set(layout, "elm.swallow.middle", table);
   evas_object_show(table);
}

void
create_arrows(Evas_Object *layout)
{
   Evas_Object *btn = NULL, *img = NULL;
   char buf[PATH_MAX];

   //Create a Left arrow
   btn = create_button(layout);
   snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
   // TODO 5
   img = create_image(btn, buf, "left_arrow");
   elm_object_content_set(btn, img);
   // TODO 5
   elm_layout_content_set(layout, "elm.swallow.left_arrow", btn);
   evas_object_show(btn);
   // TODO 10
   evas_object_smart_callback_add(btn, "clicked", _left_arrow_clicked_cb, layout);

   //Create a Right arrow
   btn = create_button(layout);
   snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
   // TODO 5
   img = create_image(btn, buf, "right_arrow");
   elm_object_content_set(btn, img);
   // TODO 5
   elm_layout_content_set(layout, "elm.swallow.right_arrow", btn);
   evas_object_show(btn);
   // TODO 10
   evas_object_smart_callback_add(btn, "clicked", _right_arrow_clicked_cb, layout);
}

void
toolbar_it_cb(void *data, Evas_Object *obj, void *event_info)
{
   Elm_Object_Item *it = event_info;
   printf("%s\n", elm_object_item_text_get(it));
   Evas_Object *layout = data;
   if (!layout) return;
   // TODO 6
   elm_layout_text_set(layout, "elm.text.news", elm_object_item_text_get(it));
}

void
create_bottom_contents(Evas_Object *layout)
{
   Evas_Object *toolbar = NULL;

   // TODO 6
   toolbar = elm_toolbar_add(layout);
   elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
   elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
   elm_toolbar_homogeneous_set(toolbar, EINA_TRUE);

   // TODO 6
   elm_toolbar_item_append(toolbar, NULL, "Guide", toolbar_it_cb, layout);
   elm_toolbar_item_append(toolbar, NULL, "Time Line View", toolbar_it_cb, layout);
   elm_toolbar_item_append(toolbar, NULL, "Recorded TV", toolbar_it_cb, layout);
   elm_toolbar_item_append(toolbar, NULL, "Downloads", toolbar_it_cb, layout);
   elm_toolbar_item_append(toolbar, NULL, "Favorites", toolbar_it_cb, layout);
   elm_toolbar_item_append(toolbar, NULL, "YouTube", toolbar_it_cb, layout);

   elm_layout_content_set(layout, "elm.swallow.bottom", toolbar);
   evas_object_show(toolbar);
}

void
init(void)
{
   Evas_Object *win = NULL, *layout = NULL;

   //Create a Window
   // TODO 2
   win = create_win();

   //Create a Layout
   // TODO 2
   layout = create_layout(win);

   //Create Top Contents
   // TODO 3
   create_top_contents(layout);

   //Create Middle Contents
   // TODO 4
   create_middle_contents(layout);

   //Create Arrows
   // TODO 5
   create_arrows(layout);

   //Create Bottom Contents
   // TODO 6
   create_bottom_contents(layout);
}

Evas_Object *
create_button(Evas_Object *parent)
{
   Evas_Object *btn = NULL;

   btn = elm_button_add(parent);
   evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_show(btn);

   return btn;
}

Evas_Object *
create_image(Evas_Object *parent, char *path, char *group)
{
   Evas_Object *img = NULL;

   img = elm_image_add(parent);
   elm_image_file_set(img, path, group);
   evas_object_show(img);

   return img;
}

void
btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   _btn_effect(obj);
}

void
btn_clicked(void *data, Evas_Object *obj, void *event_info)
{
   _btn_effect(obj);
}

Eina_Bool
_left_arrow_timer_cb(void *data)
{
   Evas_Object *layout = data;
   if (!data) return ECORE_CALLBACK_CANCEL;
   // TODO 11
   elm_layout_signal_emit(layout, "elm,state,arrow,show", "elm");

   // TODO 11
   return ECORE_CALLBACK_CANCEL;
}

// TODO 10
void
_left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
{
   Evas_Object *layout = data;
   if (!layout) return;
   // TODO 10
   elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm");

   // TODO 11
   ecore_timer_add(1.0, _left_arrow_timer_cb, layout);
}

// TODO 10
void
_right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
{
   Evas_Object *layout = data;
   if (!layout) return;
   elm_exit();
}

void
_btn_effect(Evas_Object *obj)
{
   evas_object_raise(obj);

   Elm_Transit *transit = elm_transit_add();
   elm_transit_object_add(transit, obj);
   elm_transit_duration_set(transit, 0.25);
   // TODO 8
   elm_transit_auto_reverse_set(transit, EINA_TRUE);
   elm_transit_effect_zoom_add(transit, 1.0, 1.25);
   elm_transit_smooth_set(transit, EINA_FALSE);
   elm_transit_go(transit);
}

EAPI_MAIN int
elm_main(int argc, char **argv)
{
   //Set App Directory
   // TODO 2
   elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
   elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
   elm_app_info_set(elm_main, "sample", "images/bg.jpg");

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   init();

   elm_run();

   elm_shutdown();

   return 0;
}
ELM_MAIN()