elm: change elm_object_content_part_set/get/unset to elm_object_part_content_set...
[framework/uifw/elementary.git] / src / bin / test_colorselector.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 _colorselector_clicked_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
9 {
10    Evas_Object *re = data;
11    int r, g, b, a;
12
13    elm_colorselector_color_get(obj, &r, &g, &b, &a);
14    printf("Current Color [r=%d g=%d b=%d a=%d]\n",r, g, b, a);
15
16    /* Fix Alpha pre multiplication by edje */
17    r = (r * a) / 255;
18    g = (g * a) / 255;
19    b = (b * a) / 255;
20
21    evas_object_color_set(re, r, g, b, a);
22 }
23
24 void
25 test_colorselector(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
26 {
27    Evas_Object *win, *bg, *bx, *cp, *fr, *ly, *re;
28    char buf[PATH_MAX];
29    int r, g, b, a;
30
31    win = elm_win_add(NULL, "colorselector", ELM_WIN_BASIC);
32    elm_win_title_set(win, "Color Selector");
33    elm_win_autodel_set(win, EINA_TRUE);
34
35    bg = elm_bg_add(win);
36    elm_win_resize_object_add(win, bg);
37    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
38    evas_object_color_set(bg, 255, 255, 255, 255);
39    evas_object_show(bg);
40
41    bx = elm_box_add(win);
42    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
43    elm_win_resize_object_add(win, bx);
44    evas_object_show(bx);
45
46    fr = elm_frame_add(win);
47    evas_object_size_hint_weight_set(fr, 1.0, 0.5);
48    evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
49    elm_object_text_set(fr, "Color View");
50    elm_box_pack_end(bx, fr);
51    evas_object_show(fr);
52
53    ly = elm_layout_add(win);
54    snprintf(buf, sizeof(buf), "%s/objects/colorpreview.edj", elm_app_data_dir_get());
55    elm_layout_file_set(ly, buf, "main");
56    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
57    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58    elm_object_content_set(fr, ly);
59    evas_object_show(ly);
60
61    re = evas_object_rectangle_add(evas_object_evas_get(win));
62    evas_object_show(re);
63    elm_object_part_content_set(ly, "ColorPreview", re);
64
65    fr = elm_frame_add(win);
66    evas_object_size_hint_weight_set(fr, 1.0, 0);
67    evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, 0);
68    elm_object_text_set(fr, "Color Selector");
69    elm_box_pack_end(bx, fr);
70    evas_object_show(fr);
71
72    cp = elm_colorselector_add(win);
73
74    a = 180;
75    r = 255;
76    g = 160;
77    b = 132;
78
79    elm_colorselector_color_set(cp, r, g, b, a);
80    evas_object_size_hint_weight_set(cp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
81    evas_object_size_hint_align_set(cp, EVAS_HINT_FILL, EVAS_HINT_FILL);
82    elm_object_content_set(fr, cp);
83    evas_object_show(cp);
84    evas_object_smart_callback_add(cp, "changed", _colorselector_clicked_cb, re);
85
86    elm_colorselector_color_get(cp, &r, &g, &b, &a);
87    /* Fix Alpha pre multiplication by edje */
88    r = (r * a) / 255;
89    g = (g * a) / 255;
90    b = (b * a) / 255;
91    evas_object_color_set(re, r, g, b, a);
92
93    evas_object_resize(win, 320, 480);
94    evas_object_show(win);
95
96 }
97 #endif