elm: change elm_object_content_part_set/get/unset to elm_object_part_content_set...
[framework/uifw/elementary.git] / src / bin / test_bg.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static void
8 _cb_radio_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
9 {
10    Evas_Object *o_bg = data;
11
12    elm_bg_option_set(o_bg, elm_radio_value_get((Evas_Object *)obj));
13 }
14
15 static void
16 _cb_overlay_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
17 {
18    Evas_Object *o_bg = data;
19
20    if (elm_check_state_get(obj))
21      {
22         Evas_Object *parent, *over;
23         char buff[PATH_MAX];
24
25         snprintf(buff, sizeof(buff), "%s/objects/test.edj", elm_app_data_dir_get());
26         parent = elm_object_parent_widget_get(o_bg);
27         over = edje_object_add(evas_object_evas_get(parent));
28         edje_object_file_set(over, buff, "bg_overlay");
29         elm_object_part_content_set(o_bg, "overlay", over);
30      }
31    else
32      elm_object_part_content_set(o_bg, "overlay", NULL);
33 }
34
35 static void
36 _cb_color_changed(void *data, Evas_Object *obj, void *event __UNUSED__)
37 {
38    Evas_Object *o_bg = data;
39    double val = 0.0;
40
41    val = elm_spinner_value_get(obj);
42    if (val == 1.0)
43      elm_bg_color_set(o_bg, 255, 255, 255);
44    else if (val == 2.0)
45      elm_bg_color_set(o_bg, 255, 0, 0);
46    else if (val == 3.0)
47      elm_bg_color_set(o_bg, 0, 0, 255);
48    else if (val == 4.0)
49      elm_bg_color_set(o_bg, 0, 255, 0);
50 }
51
52 void
53 test_bg_plain(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
54 {
55    Evas_Object *win, *bg;
56
57    win = elm_win_add(NULL, "bg-plain", ELM_WIN_BASIC);
58    elm_win_title_set(win, "Bg Plain");
59    elm_win_autodel_set(win, EINA_TRUE);
60
61    bg = elm_bg_add(win);
62    /* allow bg to expand in x & y */
63    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
64    elm_win_resize_object_add(win, bg);
65    evas_object_show(bg);
66
67    /* set size hints. a minimum size for the bg. this should propagate back
68     * to the window thus limiting its size based off the bg as the bg is one
69     * of the window's resize objects. */
70    evas_object_size_hint_min_set(bg, 160, 160);
71    /* and set a maximum size. not needed very often. normally used together
72     * with evas_object_size_hint_min_set() at the same size to make a
73     * window not resizable */
74    evas_object_size_hint_max_set(bg, 640, 640);
75    /* and now just resize the window to a size you want. normally widgets
76     * will determine the initial size though */
77    evas_object_resize(win, 320, 320);
78    /* and show the window */
79    evas_object_show(win);
80 }
81
82 void
83 test_bg_image(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
84 {
85    Evas_Object *win, *bg;
86    char buf[PATH_MAX];
87
88    win = elm_win_add(NULL, "bg-image", ELM_WIN_BASIC);
89    elm_win_title_set(win, "Bg Image");
90    elm_win_autodel_set(win, EINA_TRUE);
91
92    bg = elm_bg_add(win);
93    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
94    elm_bg_file_set(bg, buf, NULL);
95    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96    elm_win_resize_object_add(win, bg);
97    evas_object_show(bg);
98
99    evas_object_size_hint_min_set(bg, 160, 160);
100    evas_object_size_hint_max_set(bg, 640, 640);
101    evas_object_resize(win, 320, 320);
102    evas_object_show(win);
103 }
104
105 void
106 test_bg_options(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
107 {
108    Evas_Object *win, *bg;
109    Evas_Object *box, *hbox, *o_bg;
110    Evas_Object *rd, *rdg;
111    char buf[PATH_MAX];
112
113    win = elm_win_add(NULL, "bg-options", ELM_WIN_BASIC);
114    elm_win_title_set(win, "Bg Options");
115    elm_win_autodel_set(win, EINA_TRUE);
116
117    bg = elm_bg_add(win);
118    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119    elm_win_resize_object_add(win, bg);
120    evas_object_show(bg);
121
122    box = elm_box_add(win);
123    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124    elm_win_resize_object_add(win, box);
125    evas_object_show(box);
126
127    o_bg = elm_bg_add(win);
128    snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
129    elm_bg_file_set(o_bg, buf, NULL);
130    evas_object_size_hint_weight_set(o_bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
131    evas_object_size_hint_align_set(o_bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
132    elm_box_pack_end(box, o_bg);
133    evas_object_show(o_bg);
134
135    hbox = elm_box_add(win);
136    elm_box_horizontal_set(hbox, EINA_TRUE);
137    evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
138    evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
139
140    rd = elm_radio_add(win);
141    elm_radio_state_value_set(rd, ELM_BG_OPTION_CENTER);
142    elm_object_text_set(rd, "Center");
143    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
144    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
145    elm_box_pack_end(hbox, rd);
146    evas_object_show(rd);
147    rdg = rd;
148
149    rd = elm_radio_add(win);
150    elm_radio_state_value_set(rd, ELM_BG_OPTION_SCALE);
151    elm_radio_group_add(rd, rdg);
152    elm_object_text_set(rd, "Scale");
153    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
154    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
155    elm_box_pack_end(hbox, rd);
156    evas_object_show(rd);
157
158    rd = elm_radio_add(win);
159    elm_radio_state_value_set(rd, ELM_BG_OPTION_STRETCH);
160    elm_radio_group_add(rd, rdg);
161    elm_object_text_set(rd, "Stretch");
162    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
163    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
164    elm_box_pack_end(hbox, rd);
165    evas_object_show(rd);
166
167    rd = elm_radio_add(win);
168    elm_radio_state_value_set(rd, ELM_BG_OPTION_TILE);
169    elm_radio_group_add(rd, rdg);
170    elm_object_text_set(rd, "Tile");
171    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
172    evas_object_smart_callback_add(rd, "changed", _cb_radio_changed, o_bg);
173    elm_box_pack_end(hbox, rd);
174    evas_object_show(rd);
175
176    elm_radio_value_set(rdg, ELM_BG_OPTION_SCALE);
177
178    rd = elm_check_add(win);
179    elm_object_text_set(rd, "Show Overlay");
180    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_FILL);
181    evas_object_smart_callback_add(rd, "changed", _cb_overlay_changed, o_bg);
182    elm_box_pack_end(hbox, rd);
183    evas_object_show(rd);
184
185    /* color choices ... this is ghetto, but we don't have a 'colorpicker'
186     * widget yet :( */
187    rd = elm_spinner_add(win);
188    elm_object_style_set(rd, "vertical");
189    elm_spinner_min_max_set(rd, 1, 4);
190    elm_spinner_label_format_set(rd, "%.0f");
191    elm_spinner_editable_set(rd, EINA_FALSE);
192    elm_spinner_special_value_add(rd, 1, "White");
193    elm_spinner_special_value_add(rd, 2, "Red");
194    elm_spinner_special_value_add(rd, 3, "Blue");
195    elm_spinner_special_value_add(rd, 4, "Green");
196    evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197    evas_object_size_hint_align_set(rd, EVAS_HINT_FILL, EVAS_HINT_FILL);
198    evas_object_smart_callback_add(rd, "changed", _cb_color_changed, o_bg);
199    elm_box_pack_end(hbox, rd);
200    evas_object_show(rd);
201
202    elm_box_pack_end(box, hbox);
203    evas_object_show(hbox);
204
205    evas_object_size_hint_min_set(bg, 160, 160);
206    evas_object_size_hint_max_set(bg, 640, 640);
207    evas_object_resize(win, 320, 320);
208    evas_object_show(win);
209 }
210
211 #endif