summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Juyung Seo <seojuyung@gmail.com>2013-06-18 04:32:05 +0900
committerDaniel Juyung Seo <seojuyung@gmail.com>2013-06-18 04:32:05 +0900
commite2e5a9725d97cdead3719ea7bb5d4d03f6e4c956 (patch)
treeb8809cbf1a5ced21a8ac97ac513ed822b35cd849
parentc7bc8db92eb91c2b957b398a91783bb416eabde5 (diff)
main.c: refactoring.
-rw-r--r--source/3-final/src/main.c308
1 files changed, 189 insertions, 119 deletions
diff --git a/source/3-final/src/main.c b/source/3-final/src/main.c
index 74f00fa..fe9bc16 100644
--- a/source/3-final/src/main.c
+++ b/source/3-final/src/main.c
@@ -3,98 +3,34 @@
3#define PACKAGE_BIN_DIR "/usr/local/bin" 3#define PACKAGE_BIN_DIR "/usr/local/bin"
4#define PACKAGE_DATA_DIR "/usr/local/share/sample" 4#define PACKAGE_DATA_DIR "/usr/local/share/sample"
5 5
6Evas_Object * 6Evas_Object *create_button(Evas_Object *parent);
7create_button(Evas_Object *parent) 7Evas_Object *create_image(Evas_Object *parent, char *path, char *group);
8{ 8void btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info);
9 Evas_Object *btn; 9void btn_clicked(void *data, Evas_Object *obj, void *event_info);
10 btn = elm_button_add(parent); 10void _left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
11 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 11void _right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info);
12 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL); 12void _btn_effect(Evas_Object *obj);
13 evas_object_show(btn);
14
15 return btn;
16}
17 13
18Evas_Object * 14Evas_Object *
19create_image(Evas_Object *parent, char *path, char *group) 15create_win()
20{
21 Evas_Object *img;
22 img = elm_image_add(parent);
23 elm_image_file_set(img, path, group);
24 evas_object_show(img);
25
26 return img;
27}
28
29void
30_btn_effect(Evas_Object *obj)
31{
32 evas_object_raise(obj);
33
34 Elm_Transit *transit = elm_transit_add();
35 elm_transit_object_add(transit, obj);
36 elm_transit_duration_set(transit, 0.25);
37 elm_transit_auto_reverse_set(transit, EINA_TRUE);
38 elm_transit_effect_zoom_add(transit, 1.0, 1.25);
39 //elm_transit_smooth_set(transit, EINA_FALSE); // EFL 1.8
40 elm_transit_go(transit);
41}
42
43void
44btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info)
45{
46 _btn_effect(obj);
47}
48
49void
50btn_clicked(void *data, Evas_Object *obj, void *event_info)
51{ 16{
52 _btn_effect(obj); 17 Evas_Object *win = NULL;
53}
54 18
55void 19 win = elm_win_util_standard_add(elm_app_name_get(), elm_app_name_get());
56toolbar_it_cb(void *data, Evas_Object *obj, void *event_info)
57{
58 Elm_Object_Item *it = event_info;
59 printf("%s\n", elm_object_item_text_get(it));
60 Evas_Object *layout = data;
61 if (!layout) return;
62 elm_layout_text_set(layout, "elm.text.news", elm_object_item_text_get(it));
63}
64
65void
66_left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
67{
68 Evas_Object *layout = data;
69 if (!layout) return;
70 elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm");
71}
72
73void
74_right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
75{
76 Evas_Object *layout = data;
77 if (!layout) return;
78 elm_layout_signal_emit(layout, "elm,state,arrow,show" , "elm");
79}
80
81void
82init()
83{
84 Evas_Object *win, *layout, *table, *toolbar, *btn, *img, *label;
85 char buf[PATH_MAX], buf2[256];
86 int i, j;
87 Evas_Coord padding_size;
88
89 //Create a Window
90 //win = elm_win_util_standard_add(elm_app_name_get(), elm_app_name_get()); // EFL 1.8
91 win = elm_win_util_standard_add("sample", "Sample");
92 elm_win_focus_highlight_enabled_set(win, EINA_TRUE); 20 elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
93 elm_win_autodel_set(win, EINA_TRUE); 21 elm_win_autodel_set(win, EINA_TRUE);
94 evas_object_resize(win, 720, 400); 22 evas_object_resize(win, 720, 400);
95 evas_object_show(win); 23 evas_object_show(win);
96 24
97 //Create a Layout 25 return win;
26}
27
28Evas_Object *
29create_layout(Evas_Object *win)
30{
31 Evas_Object *layout = NULL;
32 char buf[PATH_MAX];
33
98 layout = elm_layout_add(win); 34 layout = elm_layout_add(win);
99 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get()); 35 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
100 elm_layout_file_set(layout, buf, "main"); 36 elm_layout_file_set(layout, buf, "main");
@@ -102,60 +38,85 @@ init()
102 elm_win_resize_object_add(win, layout); 38 elm_win_resize_object_add(win, layout);
103 evas_object_show(layout); 39 evas_object_show(layout);
104 40
105 //Create Top Contents 41 return layout;
42}
43
44void
45create_top_contents(Evas_Object *layout)
46{
47 Evas_Object *table = NULL, *btn = NULL, *img = NULL, *label = NULL;
48 int i =0;
49 char buf[PATH_MAX], buf2[PATH_MAX];
50
106 table = elm_table_add(layout); 51 table = elm_table_add(layout);
107 52
108 for (i = 0; i < 5; i++) 53 for (i = 0; i < 5; i++)
109 { 54 {
110 btn = create_button(table); 55 btn = create_button(table);
111 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get()); 56 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
112 snprintf(buf2, sizeof(buf2), "icon%d", i); 57 snprintf(buf2, sizeof(buf2), "icon%d", i);
113 img = create_image(btn, buf, buf2); 58 img = create_image(btn, buf, buf2);
114 elm_object_content_set(btn, img); 59 elm_object_content_set(btn, img);
115 60
116 elm_table_pack(table, btn, i, 0, 1, 1); 61 elm_table_pack(table, btn, i, 0, 1, 1);
117 62
118 label = elm_label_add(table); 63 label = elm_label_add(table);
119 snprintf(buf2, sizeof(buf2), "<color=#ffffff>item%d</color>", i); 64 snprintf(buf2, sizeof(buf2), "<color=#ffffff>item%d</color>", i);
120 elm_object_text_set(label, buf2); 65 elm_object_text_set(label, buf2);
121 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 66 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
122 evas_object_size_hint_align_set(label, 0.5, 0.5); 67 evas_object_size_hint_align_set(label, 0.5, 0.5);
123 evas_object_show(label); 68 evas_object_show(label);
124 69
125 elm_table_pack(table, label, i, 1, 1, 1); 70 elm_table_pack(table, label, i, 1, 1, 1);
126 } 71 }
127 72
128 elm_object_part_content_set(layout, "elm.swallow.top", table); 73 elm_object_part_content_set(layout, "elm.swallow.top", table);
129 evas_object_show(table); 74 evas_object_show(table);
130 75
131 //Create Middle Contents 76}
77
78void
79create_middle_contents(Evas_Object *layout)
80{
81 Evas_Object *table = NULL, *btn = NULL, *img = NULL;
82 Evas_Coord padding_size = 0;
83 int i = 0, j = 0;
84 char buf[PATH_MAX];
85
132 table = elm_table_add(layout); 86 table = elm_table_add(layout);
133 padding_size = 7 * elm_config_scale_get(); 87 padding_size = 7 * elm_config_scale_get();
134 elm_table_padding_set(table, padding_size, padding_size); 88 elm_table_padding_set(table, padding_size, padding_size);
135 89
136 for (i = 0; i < 3; i++) 90 for (i = 0; i < 3; i++)
137 { 91 {
138 for (j = 0; j < 6; j++) 92 for (j = 0; j < 6; j++)
139 { 93 {
140 btn = create_button(table); 94 btn = create_button(table);
141 95
142 // elm_button "clicked" smart callback 96 // elm_button "clicked" smart callback
143 //evas_object_smart_callback_add(btn, "clicked", btn_clicked, NULL); 97 //evas_object_smart_callback_add(btn, "clicked", btn_clicked, NULL);
144 98
145 // evas object mouse in callback 99 // evas object mouse in callback
146 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN, btn_mouse_in, NULL); 100 evas_object_event_callback_add(btn, EVAS_CALLBACK_MOUSE_IN, btn_mouse_in, NULL);
147 snprintf(buf, sizeof(buf), "%s/images/%d.jpg", elm_app_data_dir_get(), ((i * 6) + j)); 101 snprintf(buf, sizeof(buf), "%s/images/%d.jpg", elm_app_data_dir_get(), ((i * 6) + j));
148 img = create_image(btn, buf, NULL); 102 img = create_image(btn, buf, NULL);
149 elm_object_content_set(btn, img); 103 elm_object_content_set(btn, img);
150 elm_table_pack(table, btn, j, i, 1, 1); 104 elm_table_pack(table, btn, j, i, 1, 1);
151 } 105 }
152 } 106 }
153 107
154 elm_object_part_content_set(layout, "elm.swallow.middle", table); 108 elm_object_part_content_set(layout, "elm.swallow.middle", table);
155 evas_object_show(table); 109 evas_object_show(table);
110}
111
112void
113create_arrows(Evas_Object *layout)
114{
115 Evas_Object *btn = NULL, *img = NULL;
116 char buf[PATH_MAX];
156 117
157 //Create a Left arrow 118 //Create a Left arrow
158 btn = create_button(table); 119 btn = create_button(layout);
159 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get()); 120 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
160 img = create_image(btn, buf, "left_arrow"); 121 img = create_image(btn, buf, "left_arrow");
161 elm_object_content_set(btn, img); 122 elm_object_content_set(btn, img);
@@ -164,15 +125,30 @@ init()
164 evas_object_smart_callback_add(btn, "clicked", _left_arrow_clicked_cb, layout); 125 evas_object_smart_callback_add(btn, "clicked", _left_arrow_clicked_cb, layout);
165 126
166 //Create a Right arrow 127 //Create a Right arrow
167 btn = create_button(table); 128 btn = create_button(layout);
168 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get()); 129 snprintf(buf, sizeof(buf), "%s/edj/layout.edj", elm_app_data_dir_get());
169 img = create_image(btn, buf, "right_arrow"); 130 img = create_image(btn, buf, "right_arrow");
170 elm_object_content_set(btn, img); 131 elm_object_content_set(btn, img);
171 elm_object_part_content_set(layout, "elm.swallow.right_arrow", btn); 132 elm_object_part_content_set(layout, "elm.swallow.right_arrow", btn);
172 evas_object_show(btn); 133 evas_object_show(btn);
173 evas_object_smart_callback_add(btn, "clicked", _right_arrow_clicked_cb, layout); 134 evas_object_smart_callback_add(btn, "clicked", _right_arrow_clicked_cb, layout);
135}
136
137void
138toolbar_it_cb(void *data, Evas_Object *obj, void *event_info)
139{
140 Elm_Object_Item *it = event_info;
141 printf("%s\n", elm_object_item_text_get(it));
142 Evas_Object *layout = data;
143 if (!layout) return;
144 elm_layout_text_set(layout, "elm.text.news", elm_object_item_text_get(it));
145}
146
147void
148create_bottom_contents(Evas_Object *layout)
149{
150 Evas_Object *toolbar = NULL;
174 151
175 //Create Bottom Contents
176 toolbar = elm_toolbar_add(layout); 152 toolbar = elm_toolbar_add(layout);
177 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS); 153 elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
178 //elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE); // EFL 1.8 154 //elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE); // EFL 1.8
@@ -189,6 +165,100 @@ init()
189 evas_object_show(toolbar); 165 evas_object_show(toolbar);
190} 166}
191 167
168void
169init(void)
170{
171 Evas_Object *win = NULL, *layout = NULL;
172 Evas_Object *table = NULL, *toolbar = NULL;
173 Evas_Object *btn = NULL, *img = NULL, *label = NULL;
174 int i = 0, j = 0;
175
176 //Create a Window
177 win = create_win();
178
179 //Create a Layout
180 layout = create_layout(win);
181
182 //Create Top Contents
183 create_top_contents(layout);
184
185 //Create Middle Contents
186 create_middle_contents(layout);
187
188 //Create Arrows
189 create_arrows(layout);
190
191 //Create Bottom Contents
192 create_bottom_contents(layout);
193}
194
195Evas_Object *
196create_button(Evas_Object *parent)
197{
198 Evas_Object *btn = NULL;
199
200 btn = elm_button_add(parent);
201 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
202 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
203 evas_object_show(btn);
204
205 return btn;
206}
207
208Evas_Object *
209create_image(Evas_Object *parent, char *path, char *group)
210{
211 Evas_Object *img = NULL;
212
213 img = elm_image_add(parent);
214 elm_image_file_set(img, path, group);
215 evas_object_show(img);
216
217 return img;
218}
219
220void
221btn_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info)
222{
223 _btn_effect(obj);
224}
225
226void
227btn_clicked(void *data, Evas_Object *obj, void *event_info)
228{
229 _btn_effect(obj);
230}
231
232void
233_left_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
234{
235 Evas_Object *layout = data;
236 if (!layout) return;
237 elm_layout_signal_emit(layout, "elm,state,arrow,hide" , "elm");
238}
239
240void
241_right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
242{
243 Evas_Object *layout = data;
244 if (!layout) return;
245 elm_layout_signal_emit(layout, "elm,state,arrow,show" , "elm");
246}
247
248void
249_btn_effect(Evas_Object *obj)
250{
251 evas_object_raise(obj);
252
253 Elm_Transit *transit = elm_transit_add();
254 elm_transit_object_add(transit, obj);
255 elm_transit_duration_set(transit, 0.25);
256 elm_transit_auto_reverse_set(transit, EINA_TRUE);
257 elm_transit_effect_zoom_add(transit, 1.0, 1.25);
258 //elm_transit_smooth_set(transit, EINA_FALSE); // EFL 1.8
259 elm_transit_go(transit);
260}
261
192EAPI_MAIN int 262EAPI_MAIN int
193elm_main(int argc, char **argv) 263elm_main(int argc, char **argv)
194{ 264{