summaryrefslogtreecommitdiff
path: root/source/3-final/src/main.c
blob: 74f00fadf9345ae4cca9bcb1a605d653f5b8fec4 (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
#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 *btn;
   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;
   img = elm_image_add(parent);
   elm_image_file_set(img, path, group);
   evas_object_show(img);

   return img;
}

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);
   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); // EFL 1.8
   elm_transit_go(transit);
}

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);
}

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;
   elm_layout_text_set(layout, "elm.text.news", elm_object_item_text_get(it));
}

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

void
_right_arrow_clicked_cb(void *data, Evas_Object *obj, void *info)
{
   Evas_Object *layout = data;
   if (!layout) return;
   elm_layout_signal_emit(layout, "elm,state,arrow,show" , "elm");
}

void
init()
{
   Evas_Object *win, *layout, *table, *toolbar, *btn, *img, *label;
   char buf[PATH_MAX], buf2[256];
   int i, j;
   Evas_Coord padding_size;

   //Create a Window
   //win = elm_win_util_standard_add(elm_app_name_get(), elm_app_name_get()); // EFL 1.8
   win = elm_win_util_standard_add("sample", "Sample");
   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);

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

   //Create Top Contents
   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);
        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);
        elm_object_text_set(label, buf2);
        evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(label, 0.5, 0.5);
        evas_object_show(label);

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

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

   //Create Middle Contents
   table = elm_table_add(layout);
   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);

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

             // 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);
             elm_table_pack(table, btn, j, i, 1, 1);
          }
     }

   elm_object_part_content_set(layout, "elm.swallow.middle", table);
   evas_object_show(table);

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

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

   //Create Bottom Contents
   toolbar = elm_toolbar_add(layout);
   elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
   //elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE); // EFL 1.8
   elm_toolbar_homogeneous_set(toolbar, EINA_TRUE);

   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_object_part_content_set(layout, "elm.swallow.bottom", toolbar);
   evas_object_show(toolbar);
}

EAPI_MAIN int
elm_main(int argc, char **argv)
{
   //Set App Directory
   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()