elm examples: Adjust directory names.
[framework/uifw/elementary.git] / src / examples / bg_example_03.c
1 //Compile with:
2 //gcc -o bg_example_03 bg_example_03.c -g `pkg-config --cflags --libs elementary` -DDATA_DIR="\"<directory>\""
3 //where directory is the a path where images/plant_01.jpg can be found.
4
5 #include <Elementary.h>
6 #ifndef DATA_DIR
7 # define DATA_DIR "/usr/share/elementary"
8 #endif
9
10 static void
11 on_done(void *data, Evas_Object *obj, void *event_info)
12 {
13    /* quit the mainloop (elm_run) */
14    elm_exit();
15 }
16
17 static void
18 _cb_radio_changed(void *data, Evas_Object *obj, void *event)
19 {
20    Evas_Object *o_bg = data;
21
22    elm_bg_option_set(o_bg, elm_radio_value_get((Evas_Object *)obj));
23 }
24
25 static void
26 _cb_overlay_changed(void *data, Evas_Object *obj, void *event)
27 {
28    Evas_Object *o_bg = data;
29
30    if (elm_check_state_get(obj))
31      {
32         Evas_Object *parent, *over;
33         char buff[PATH_MAX];
34
35         snprintf(buff, sizeof(buff), "%s/objects/test.edj", DATA_DIR);
36         parent = elm_object_parent_widget_get(o_bg);
37         over = edje_object_add(evas_object_evas_get(parent));
38         edje_object_file_set(over, buff, "bg_overlay");
39         elm_object_part_content_set(o_bg, "overlay", over);
40      }
41    else
42      elm_object_part_content_set(o_bg, "overlay", NULL);
43 }
44
45 static void
46 _cb_color_changed(void *data, Evas_Object *obj, void *event)
47 {
48    Evas_Object *o_bg = data;
49    double val = 0.0;
50
51    val = elm_spinner_value_get(obj);
52    if (val == 1.0)
53      elm_bg_color_set(o_bg, 255, 255, 255);
54    else if (val == 2.0)
55      elm_bg_color_set(o_bg, 255, 0, 0);
56    else if (val == 3.0)
57      elm_bg_color_set(o_bg, 0, 0, 255);
58    else if (val == 4.0)
59      elm_bg_color_set(o_bg, 0, 255, 0);
60 }
61
62 EAPI_MAIN int
63 elm_main(int argc, char **argv)
64 {
65    Evas_Object *win, *bg;
66    Evas_Object *box, *hbox, *o_bg;
67    Evas_Object *rd, *rdg;
68    char buf[PATH_MAX];
69
70    win = elm_win_add(NULL, "bg-options", ELM_WIN_BASIC);
71    elm_win_title_set(win, "Bg Options");
72    evas_object_smart_callback_add(win, "delete,request", on_done, NULL);
73    elm_win_autodel_set(win, EINA_TRUE);
74
75    bg = elm_bg_add(win);
76    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
77    elm_win_resize_object_add(win, bg);
78    evas_object_show(bg);
79
80    box = elm_box_add(win);
81    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
82    elm_win_resize_object_add(win, box);
83    evas_object_show(box);
84
85    o_bg = elm_bg_add(win);
86    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", DATA_DIR);
87    elm_bg_file_set(o_bg, buf, NULL);
88    evas_object_size_hint_weight_set(o_bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
89    evas_object_size_hint_align_set(o_bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
90    elm_box_pack_end(box, o_bg);
91    evas_object_show(o_bg);
92
93    hbox = elm_box_add(win);
94    elm_box_horizontal_set(hbox, EINA_TRUE);
95    evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
96    evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
97
98    rd = elm_radio_add(win);
99    elm_radio_state_value_set(rd, ELM_BG_OPTION_CENTER);
100    elm_object_text_set(rd, "Center");
101    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
102    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
103    elm_box_pack_end(hbox, rd);
104    evas_object_show(rd);
105    rdg = rd;
106
107    rd = elm_radio_add(win);
108    elm_radio_state_value_set(rd, ELM_BG_OPTION_SCALE);
109    elm_radio_group_add(rd, rdg);
110    elm_object_text_set(rd, "Scale");
111    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
112    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
113    elm_box_pack_end(hbox, rd);
114    evas_object_show(rd);
115
116    rd = elm_radio_add(win);
117    elm_radio_state_value_set(rd, ELM_BG_OPTION_STRETCH);
118    elm_radio_group_add(rd, rdg);
119    elm_object_text_set(rd, "Stretch");
120    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
121    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
122    elm_box_pack_end(hbox, rd);
123    evas_object_show(rd);
124
125    rd = elm_radio_add(win);
126    elm_radio_state_value_set(rd, ELM_BG_OPTION_TILE);
127    elm_radio_group_add(rd, rdg);
128    elm_object_text_set(rd, "Tile");
129    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
130    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
131    elm_box_pack_end(hbox, rd);
132    evas_object_show(rd);
133
134    elm_radio_value_set(rdg, ELM_BG_OPTION_SCALE);
135
136    rd = elm_check_add(win);
137    elm_object_text_set(rd, "Show Overlay");
138    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
139    evas_object_smart_callback_add(rd, "changed", _cb_overlay_changed, o_bg);
140    elm_box_pack_end(hbox, rd);
141    evas_object_show(rd);
142
143    /* color choices ... this is ghetto, but we don't have a 'colorpicker'
144     * widget yet :( */
145    rd = elm_spinner_add(win);
146    elm_object_style_set(rd, "vertical");
147    elm_spinner_min_max_set(rd, 1, 4);
148    elm_spinner_label_format_set(rd, "%.0f");
149    elm_spinner_editable_set(rd, EINA_FALSE);
150    elm_spinner_special_value_add(rd, 1, "White");
151    elm_spinner_special_value_add(rd, 2, "Red");
152    elm_spinner_special_value_add(rd, 3, "Blue");
153    elm_spinner_special_value_add(rd, 4, "Green");
154    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155    evas_object_size_hint_align_set(rd, EVAS_HINT_FILL, EVAS_HINT_FILL);
156    evas_object_smart_callback_add(rd, "changed", _cb_color_changed, o_bg);
157    elm_box_pack_end(hbox, rd);
158    evas_object_show(rd);
159
160    elm_box_pack_end(box, hbox);
161    evas_object_show(hbox);
162
163    evas_object_size_hint_min_set(bg, 160, 160);
164    evas_object_size_hint_max_set(bg, 640, 640);
165    evas_object_resize(win, 320, 320);
166    evas_object_show(win);
167
168    elm_run();
169    elm_shutdown();
170
171    return 0;
172 }
173
174 ELM_MAIN()