elementary/colorselector - send signal when mode is changed so as to set the padding...
[framework/uifw/elementary.git] / src / bin / test_colorselector.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static void
8 _colorselector_clicked_cb(void *data, Evas_Object *obj,
9                           void *event_info __UNUSED__)
10 {
11    Evas_Object *re = data;
12    int r, g, b, a;
13
14    elm_colorselector_color_get(obj, &r, &g, &b, &a);
15    printf("Current Color [r=%d g=%d b=%d a=%d]\n",r, g, b, a);
16
17    /* Fix Alpha pre multiplication by edje */
18    r = (r * a) / 255;
19    g = (g * a) / 255;
20    b = (b * a) / 255;
21
22    evas_object_color_set(re, r, g, b, a);
23 }
24
25 static void
26 _colorpalette_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
27                          void *event_info)
28 {
29    int r = 0, g = 0, b = 0 ,a = 0;
30    Elm_Object_Item *color_it = (Elm_Object_Item *) event_info;
31    elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
32    evas_object_color_set((Evas_Object *) data, r, g, b , a);
33 }
34
35 static void
36 _colorpalette_longpressed_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
37                              void *event_info)
38 {
39    int r = 0,g = 0,b = 0 ,a = 0;
40    Elm_Object_Item *color_it = (Elm_Object_Item *) event_info;
41    elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
42    printf("\ncolor = %d-%d-%d-%d\n", r, g, b, a);
43 }
44
45 static void
46 _palette_cb(void *data, Evas_Object *obj __UNUSED__,
47             void *event_info __UNUSED__)
48 {
49    Evas_Object *cs = data;
50    Evas_Object *win = evas_object_data_get(cs, "win");
51    elm_colorselector_mode_set(cs, ELM_COLORSELECTOR_PALETTE);
52    evas_object_resize(win, 320, 300);
53 }
54
55 static void
56 _components_cb(void *data, Evas_Object *obj __UNUSED__,
57                void *event_info __UNUSED__)
58 {
59    Evas_Object *cs = data;
60    Evas_Object *win = evas_object_data_get(cs, "win");
61    elm_colorselector_mode_set(cs, ELM_COLORSELECTOR_COMPONENTS);
62    evas_object_resize(win, 320, 455);
63 }
64
65 static void
66 _both_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
67 {
68    Evas_Object *cs = data;
69    Evas_Object *win = evas_object_data_get(cs, "win");
70    elm_colorselector_mode_set(cs, ELM_COLORSELECTOR_BOTH);
71    evas_object_resize(win, 320, 535);
72 }
73
74 void
75 test_colorselector(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
76                    void *event_info __UNUSED__)
77 {
78    Evas_Object *win, *bg, *bx, *bx2, *cs, *fr, *re, *bt;
79    int r, g, b, a;
80
81    win = elm_win_add(NULL, "colorselector", ELM_WIN_BASIC);
82    elm_win_title_set(win, "Color Selector");
83    elm_win_autodel_set(win, EINA_TRUE);
84
85    bg = elm_bg_add(win);
86    elm_win_resize_object_add(win, bg);
87    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
88    evas_object_show(bg);
89
90    bx = elm_box_add(win);
91    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92    elm_win_resize_object_add(win, bx);
93    evas_object_show(bx);
94
95    fr = elm_frame_add(bx);
96    evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, 0);
97    evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
98    elm_object_text_set(fr, "Color View");
99    elm_box_pack_end(bx, fr);
100    evas_object_show(fr);
101
102    re = evas_object_rectangle_add(evas_object_evas_get(win));
103    evas_object_size_hint_min_set(re, 1, 100);
104    evas_object_show(re);
105    elm_object_content_set(fr, re);
106
107    fr = elm_frame_add(bx);
108    evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109    evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
110    elm_object_text_set(fr, "Color Selector");
111    elm_box_pack_end(bx, fr);
112    evas_object_show(fr);
113
114    cs = elm_colorselector_add(fr);
115    elm_colorselector_palette_color_add(cs, 255, 90, 18, 255);
116    elm_colorselector_palette_color_add(cs, 255, 213, 0, 255);
117    elm_colorselector_palette_color_add(cs, 146, 255, 11, 255);
118    elm_colorselector_palette_color_add(cs, 9, 186, 10, 255);
119    elm_colorselector_palette_color_add(cs, 86, 201, 242, 255);
120    elm_colorselector_palette_color_add(cs, 18, 83, 128, 255);
121    elm_colorselector_palette_color_add(cs, 140, 53, 238, 255);
122    elm_colorselector_palette_color_add(cs, 255, 145, 145, 255);
123    elm_colorselector_palette_color_add(cs, 255, 59, 119, 255);
124    elm_colorselector_palette_color_add(cs, 133, 100, 69, 255);
125    elm_colorselector_palette_color_add(cs, 255, 255, 119, 255);
126    elm_colorselector_palette_color_add(cs, 133, 100, 255, 255);
127
128    a = 180;
129    r = 255;
130    g = 160;
131    b = 132;
132
133    elm_colorselector_color_set(cs, r, g, b, a);
134    evas_object_size_hint_weight_set(cs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135    evas_object_size_hint_align_set(cs, EVAS_HINT_FILL, EVAS_HINT_FILL);
136    elm_object_content_set(fr, cs);
137    evas_object_show(cs);
138    evas_object_smart_callback_add(cs, "changed", _colorselector_clicked_cb, re);
139    evas_object_smart_callback_add(cs, "color,item,selected",
140                                   _colorpalette_clicked_cb, re);
141    evas_object_smart_callback_add(cs, "color,item,longpressed",
142                                   _colorpalette_longpressed_cb, re);
143    evas_object_data_set(cs, "win", win);
144
145    elm_colorselector_color_get(cs, &r, &g, &b, &a);
146    /* Fix Alpha pre multiplication by edje */
147    r = (r * a) / 255;
148    g = (g * a) / 255;
149    b = (b * a) / 255;
150    evas_object_color_set(re, r, g, b, a);
151
152    bx2 = elm_box_add(bx);
153    elm_box_horizontal_set(bx2, EINA_TRUE);
154    evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0);
155    evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, EVAS_HINT_FILL);
156    evas_object_show(bx2);
157    elm_box_pack_end(bx, bx2);
158
159    bt = elm_button_add(bx2);
160    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
161    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
162    evas_object_smart_callback_add(bt, "clicked", _palette_cb, cs);
163    elm_object_text_set(bt, "Palette");
164    evas_object_show(bt);
165    elm_box_pack_end(bx2, bt);
166
167    bt = elm_button_add(bx2);
168    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
170    evas_object_smart_callback_add(bt, "clicked", _components_cb, cs);
171    elm_object_text_set(bt, "Components");
172    evas_object_show(bt);
173    elm_box_pack_end(bx2, bt);
174
175    bt = elm_button_add(bx2);
176    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
178    evas_object_smart_callback_add(bt, "clicked", _both_cb, cs);
179    elm_object_text_set(bt, "Both");
180    evas_object_show(bt);
181    elm_box_pack_end(bx2, bt);
182
183    evas_object_resize(win, 320, 500);
184    evas_object_show(win);
185 }
186 #endif