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