summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Juyung Seo <seojuyung2@gmail.com>2013-06-18 06:30:51 +0900
committerDaniel Juyung Seo <seojuyung2@gmail.com>2013-06-18 06:30:51 +0900
commitc2cfbbcffa45a280c9742e7cc253d0c68d39d298 (patch)
treeca222be7acc509771ac48a1b0724c09ba2521398
parentda6f078905b834dc5363a9a2b1381e1a4d90c2ac (diff)
updated
-rw-r--r--source/2-step/12-final/main.c325
-rw-r--r--source/3-final/src/main.c7
2 files changed, 332 insertions, 0 deletions
diff --git a/source/2-step/12-final/main.c b/source/2-step/12-final/main.c
new file mode 100644
index 0000000..6b12c7e
--- /dev/null
+++ b/source/2-step/12-final/main.c
@@ -0,0 +1,325 @@
1#include <Elementary.h>
2
3#define PACKAGE_BIN_DIR "/usr/local/bin"
4#define PACKAGE_DATA_DIR "/usr/local/share/sample"
5
6Evas_Object *create_button(Evas_Object *parent);
7Evas_Object *create_image(Evas_Object *parent, char *path, char *group);
8void btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
9void btn_clicked(void *data, Evas_Object *obj, void *event_info);
10void _left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
11void _right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
12void _btn_effect(Evas_Object *obj);
13
14Evas_Object *
15create_win()
16{
17 Evas_Object *win = NULL;
18
19 // TODO 2
20 win = elm_win_util_standard_add(elm_app_name_get(), elm_app_name_get());
21 // TODO 7
22 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
23 elm_win_autodel_set(win, EINA_TRUE);
24 evas_object_resize(win, 720, 400);
25 evas_object_show(win);
26
27 return win;
28}
29
30Evas_Object *
31create_layout(Evas_Object *win)
32{
33 Evas_Object *layout = NULL;
34 char buf[PATH_MAX];
35
36 layout = elm_layout_add(win);
37 // TODO 2
38 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
39 // TODO 2
40 elm_layout_file_set(layout, buf, "main");
41 // TODO 2
42 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
43 elm_win_resize_object_add(win, layout);
44 evas_object_show(layout);
45
46 return layout;
47}
48
49void
50create_top_contents(Evas_Object *layout)
51{
52 Evas_Object *table = NULL, *btn = NULL, *img = NULL, *label = NULL;
53 int i =0;
54 char buf[PATH_MAX], buf2[PATH_MAX];
55
56 // TODO 3
57 table = elm_table_add(layout);
58
59 for (i = 0; i < 5; i++)
60 {
61 btn = create_button(table);
62 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
63 snprintf(buf2, sizeof(buf2), "icon%d", i);
64 img = create_image(btn, buf, buf2);
65 // TODO 3
66 elm_object_content_set(btn, img);
67
68 elm_table_pack(table, btn, i, 0, 1, 1);
69
70 label = elm_label_add(table);
71 snprintf(buf2, sizeof(buf2), "<color=#ffffff>item%d</color>", i);
72 // TODO 3
73 elm_object_text_set(label, buf2);
74 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75 evas_object_show(label);
76
77 elm_table_pack(table, label, i, 1, 1, 1);
78 }
79
80 elm_layout_content_set(layout, "elm.swallow.top", table);
81 evas_object_show(table);
82
83}
84
85void
86create_middle_contents(Evas_Object *layout)
87{
88 Evas_Object *table = NULL, *btn = NULL, *img = NULL;
89 Evas_Coord padding_size = 0;
90 int i = 0, j = 0;
91 char buf[PATH_MAX];
92
93 table = elm_table_add(layout);
94 // TODO 4
95 padding_size = 7 * elm_config_scale_get();
96 elm_table_padding_set(table, padding_size, padding_size);
97
98 for (i = 0; i < 3; i++)
99 {
100 for (j = 0; j < 6; j++)
101 {
102 btn = create_button(table);
103
104 // TODO 10
105 // elm_button "clicked" smart callback
106 //evas_object_smart_callback_add(btn, "clicked", btn_clicked, NULL);
107
108 // TODO 10
109 // evas object mouse in callback
110 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN, btn_mouse_in, NULL);
111
112 snprintf(buf, sizeof(buf), "%s/images/%d.jpg", elm_app_data_dir_get(), ((i * 6) + j));
113 img = create_image(btn, buf, NULL);
114 elm_object_content_set(btn, img);
115 // TODO 4
116 elm_table_pack(table, btn, j, i, 1, 1);
117 }
118 }
119
120 // TODO 4
121 elm_layout_content_set(layout, "elm.swallow.middle", table);
122 evas_object_show(table);
123}
124
125void
126create_arrows(Evas_Object *layout)
127{
128 Evas_Object *btn = NULL, *img = NULL;
129 char buf[PATH_MAX];
130
131 //Create a Left arrow
132 btn = create_button(layout);
133 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
134 // TODO 5
135 img = create_image(btn, buf, "left_arrow");
136 elm_object_content_set(btn, img);
137 // TODO 5
138 elm_layout_content_set(layout, "elm.swallow.left_arrow", btn);
139 evas_object_show(btn);
140 // TODO 10
141 evas_object_smart_callback_add(btn, "clicked", _left_arrow_clicked_cb, layout);
142
143 //Create a Right arrow
144 btn = create_button(layout);
145 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
146 // TODO 5
147 img = create_image(btn, buf, "right_arrow");
148 elm_object_content_set(btn, img);
149 // TODO 5
150 elm_layout_content_set(layout, "elm.swallow.right_arrow", btn);
151 evas_object_show(btn);
152 // TODO 10
153 evas_object_smart_callback_add(btn, "clicked", _right_arrow_clicked_cb, layout);
154}
155
156void
157toolbar_it_cb(void *data, Evas_Object *obj, void *event_info)
158{
159 Elm_Object_Item *it = event_info;
160 printf("%s\n", elm_object_item_text_get(it));
161 Evas_Object *layout = data;
162 if (!layout) return;
163 // TODO 6
164 elm_layout_text_set(layout, "elm.text.news", elm_object_item_text_get(it));
165}
166
167void
168create_bottom_contents(Evas_Object *layout)
169{
170 Evas_Object *toolbar = NULL;
171
172 // TODO 6
173 toolbar = elm_toolbar_add(layout);
174 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
175 elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
176 elm_toolbar_homogeneous_set(toolbar, EINA_TRUE);
177
178 // TODO 6
179 elm_toolbar_item_append(toolbar, NULL, "Guide", toolbar_it_cb, layout);
180 elm_toolbar_item_append(toolbar, NULL, "Time Line View", toolbar_it_cb, layout);
181 elm_toolbar_item_append(toolbar, NULL, "Recorded TV", toolbar_it_cb, layout);
182 elm_toolbar_item_append(toolbar, NULL, "Downloads", toolbar_it_cb, layout);
183 elm_toolbar_item_append(toolbar, NULL, "Favorites", toolbar_it_cb, layout);
184 elm_toolbar_item_append(toolbar, NULL, "YouTube", toolbar_it_cb, layout);
185
186 elm_layout_content_set(layout, "elm.swallow.bottom", toolbar);
187 evas_object_show(toolbar);
188}
189
190void
191init(void)
192{
193 Evas_Object *win = NULL, *layout = NULL;
194
195 //Create a Window
196 // TODO 2
197 win = create_win();
198
199 //Create a Layout
200 // TODO 2
201 layout = create_layout(win);
202
203 //Create Top Contents
204 // TODO 3
205 create_top_contents(layout);
206
207 //Create Middle Contents
208 // TODO 4
209 create_middle_contents(layout);
210
211 //Create Arrows
212 // TODO 5
213 create_arrows(layout);
214
215 //Create Bottom Contents
216 // TODO 6
217 create_bottom_contents(layout);
218}
219
220Evas_Object *
221create_button(Evas_Object *parent)
222{
223 Evas_Object *btn = NULL;
224
225 btn = elm_button_add(parent);
226 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
228 evas_object_show(btn);
229
230 return btn;
231}
232
233Evas_Object *
234create_image(Evas_Object *parent, char *path, char *group)
235{
236 Evas_Object *img = NULL;
237
238 img = elm_image_add(parent);
239 elm_image_file_set(img, path, group);
240 evas_object_show(img);
241
242 return img;
243}
244
245void
246btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info)
247{
248 _btn_effect(obj);
249}
250
251void
252btn_clicked(void *data, Evas_Object *obj, void *event_info)
253{
254 _btn_effect(obj);
255}
256
257Eina_Bool
258_left_arrow_timer_cb(void *data)
259{
260 Evas_Object *layout = data;
261 if (!data) return ECORE_CALLBACK_CANCEL;
262 // TODO 11
263 elm_layout_signal_emit(layout, "elm,state,arrow,show", "elm");
264
265 // TODO 11
266 return ECORE_CALLBACK_CANCEL;
267}
268
269// TODO 10
270void
271_left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
272{
273 Evas_Object *layout = data;
274 if (!layout) return;
275 // TODO 10
276 elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm");
277
278 // TODO 11
279 ecore_timer_add(1.0, _left_arrow_timer_cb, layout);
280}
281
282// TODO 10
283void
284_right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
285{
286 Evas_Object *layout = data;
287 if (!layout) return;
288 elm_exit();
289}
290
291void
292_btn_effect(Evas_Object *obj)
293{
294 evas_object_raise(obj);
295
296 Elm_Transit *transit = elm_transit_add();
297 elm_transit_object_add(transit, obj);
298 elm_transit_duration_set(transit, 0.25);
299 // TODO 8
300 elm_transit_auto_reverse_set(transit, EINA_TRUE);
301 elm_transit_effect_zoom_add(transit, 1.0, 1.25);
302 elm_transit_smooth_set(transit, EINA_FALSE);
303 elm_transit_go(transit);
304}
305
306EAPI_MAIN int
307elm_main(int argc, char **argv)
308{
309 //Set App Directory
310 // TODO 2
311 elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
312 elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
313 elm_app_info_set(elm_main, "sample", "images/bg.jpg");
314
315 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
316
317 init();
318
319 elm_run();
320
321 elm_shutdown();
322
323 return 0;
324}
325ELM_MAIN()
diff --git a/source/3-final/src/main.c b/source/3-final/src/main.c
index 9456e6a..6b12c7e 100644
--- a/source/3-final/src/main.c
+++ b/source/3-final/src/main.c
@@ -193,21 +193,27 @@ init(void)
193 Evas_Object *win = NULL, *layout = NULL; 193 Evas_Object *win = NULL, *layout = NULL;
194 194
195 //Create a Window 195 //Create a Window
196 // TODO 2
196 win = create_win(); 197 win = create_win();
197 198
198 //Create a Layout 199 //Create a Layout
200 // TODO 2
199 layout = create_layout(win); 201 layout = create_layout(win);
200 202
201 //Create Top Contents 203 //Create Top Contents
204 // TODO 3
202 create_top_contents(layout); 205 create_top_contents(layout);
203 206
204 //Create Middle Contents 207 //Create Middle Contents
208 // TODO 4
205 create_middle_contents(layout); 209 create_middle_contents(layout);
206 210
207 //Create Arrows 211 //Create Arrows
212 // TODO 5
208 create_arrows(layout); 213 create_arrows(layout);
209 214
210 //Create Bottom Contents 215 //Create Bottom Contents
216 // TODO 6
211 create_bottom_contents(layout); 217 create_bottom_contents(layout);
212} 218}
213 219
@@ -266,6 +272,7 @@ _left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
266{ 272{
267 Evas_Object *layout = data; 273 Evas_Object *layout = data;
268 if (!layout) return; 274 if (!layout) return;
275 // TODO 10
269 elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm"); 276 elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm");
270 277
271 // TODO 11 278 // TODO 11