3 Evas_Smart *_e_spectrum_smart = NULL;
5 typedef struct _E_Spectrum E_Spectrum;
9 Evas_Object *o_spectrum;
11 Evas_Object *o_cursor;
13 int iw, ih; /* square image width/height */
14 E_Color_Component mode;
17 Ecore_Timer *draw_timer;
20 static Eina_Bool _e_spectrum_redraw(void *d);
23 _e_spectrum_smart_add(Evas_Object *o)
26 sp = E_NEW(E_Spectrum, 1);
30 evas_object_smart_data_set(o, sp);
32 sp->mode = E_COLOR_COMPONENT_R;
34 sp->o_spectrum = evas_object_image_add(evas_object_evas_get(o));
35 sp->iw = sp->ih = 255;
36 evas_object_image_size_set(sp->o_spectrum, sp->iw, sp->ih);
37 evas_object_image_alpha_set(sp->o_spectrum, 1);
39 evas_object_smart_member_add(sp->o_spectrum, o);
43 _e_spectrum_smart_del(Evas_Object *o)
47 sp = evas_object_smart_data_get(o);
50 evas_object_del(sp->o_spectrum);
51 evas_object_del(sp->o_event);
52 evas_object_del(sp->o_cursor);
54 if (sp->draw_timer) ecore_timer_del(sp->draw_timer);
60 _e_spectrum_smart_show(Evas_Object *o)
64 sp = evas_object_smart_data_get(o);
67 evas_object_show(sp->o_spectrum);
68 evas_object_show(sp->o_event);
69 evas_object_show(sp->o_cursor);
73 _e_spectrum_smart_hide(Evas_Object *o)
77 sp = evas_object_smart_data_get(o);
80 evas_object_hide(sp->o_spectrum);
81 evas_object_hide(sp->o_event);
82 evas_object_hide(sp->o_cursor);
86 _e_spectrum_smart_move(Evas_Object *o, Evas_Coord x, Evas_Coord y)
90 sp = evas_object_smart_data_get(o);
93 evas_object_move(sp->o_spectrum, x, y);
94 evas_object_move(sp->o_event, x, y);
95 evas_object_move(sp->o_cursor, x, y);
99 _e_spectrum_smart_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h)
103 sp = evas_object_smart_data_get(o);
106 evas_object_image_fill_set(sp->o_spectrum, 0, 0, w, h);
108 evas_object_resize(sp->o_spectrum, w, h);
109 evas_object_resize(sp->o_event, w, h);
110 evas_object_resize(sp->o_cursor, w, h);
114 _e_spectrum_smart_color_set(Evas_Object *o, int r, int g, int b, int a)
118 sp = evas_object_smart_data_get(o);
120 evas_object_color_set(sp->o_spectrum, r, g, b, a);
121 evas_object_color_set(sp->o_event, r, g, b, a);
122 evas_object_color_set(sp->o_cursor, r, g, b, a);
126 _e_spectrum_smart_clip_set(Evas_Object *o, Evas_Object *o_clip)
130 sp = evas_object_smart_data_get(o);
132 evas_object_clip_set(sp->o_spectrum, o_clip);
133 evas_object_clip_set(sp->o_event, o_clip);
134 evas_object_clip_set(sp->o_cursor, o_clip);
138 _e_spectrum_smart_clip_unset(Evas_Object *o)
142 sp = evas_object_smart_data_get(o);
144 evas_object_clip_unset(sp->o_spectrum);
145 evas_object_clip_unset(sp->o_event);
146 evas_object_clip_unset(sp->o_cursor);
150 _e_spectrum_smart_init(void)
152 if (_e_spectrum_smart) return;
154 static const Evas_Smart_Class sc =
157 EVAS_SMART_CLASS_VERSION,
158 _e_spectrum_smart_add,
159 _e_spectrum_smart_del,
160 _e_spectrum_smart_move,
161 _e_spectrum_smart_resize,
162 _e_spectrum_smart_show,
163 _e_spectrum_smart_hide,
164 _e_spectrum_smart_color_set,
165 _e_spectrum_smart_clip_set,
166 _e_spectrum_smart_clip_unset,
175 _e_spectrum_smart = evas_smart_class_new(&sc);
180 _e_spectrum_color_calc(E_Spectrum *sp, float vx, float vy, float vz, int *r, int *g, int *b)
184 case E_COLOR_COMPONENT_R:
189 case E_COLOR_COMPONENT_G:
194 case E_COLOR_COMPONENT_B:
199 case E_COLOR_COMPONENT_H:
200 evas_color_hsv_to_rgb(vz * 360.0, vy, vx, r, g, b);
202 case E_COLOR_COMPONENT_S:
203 evas_color_hsv_to_rgb(vx * 360.0, vz, vy, r, g, b);
205 case E_COLOR_COMPONENT_V:
206 evas_color_hsv_to_rgb(vy * 360.0, vx, vz, r, g, b);
214 _e_spectrum_2d_color_at(E_Spectrum *sp, int x, int y, int *r, int *g, int *b)
219 if (!sp || !sp->cv) return;
223 case E_COLOR_COMPONENT_R:
225 gg = (1 - (y / (double)(sp->ih))) * 255;
226 bb = (x / (double)(sp->iw)) * 255;
228 case E_COLOR_COMPONENT_G:
229 rr = (x / (double)(sp->iw)) * 255;
231 bb = (1 - (y / (double)(sp->ih))) * 255;
233 case E_COLOR_COMPONENT_B:
234 rr = (1 - (y / (double)(sp->ih))) * 255;
235 gg = (x / (double)(sp->iw)) * 255;
238 case E_COLOR_COMPONENT_H:
240 s = 1 - (y / (double)(sp->ih));
241 v = x / (double)(sp->iw);
242 evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
244 case E_COLOR_COMPONENT_S:
246 v = 1 - (y / (double)(sp->ih));
247 h = x / (double)(sp->iw) * 360;
248 evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
250 case E_COLOR_COMPONENT_V:
252 h = (1 - (y / (double)(sp->ih))) * 360;
253 s = x / (double)(sp->iw);
254 evas_color_hsv_to_rgb(h, s, v, &rr, &gg, &bb);
256 case E_COLOR_COMPONENT_MAX:
267 _e_spectrum_redraw(void *d)
273 float vx, vy, vz = 0;
275 data = evas_object_image_data_get(sp->o_spectrum, 1);
278 sp->draw_timer = NULL;
279 return ECORE_CALLBACK_CANCEL;
284 case E_COLOR_COMPONENT_R:
285 vz = (float)sp->cv->r / 255;
287 case E_COLOR_COMPONENT_G:
288 vz = (float)sp->cv->g / 255;
290 case E_COLOR_COMPONENT_B:
291 vz = (float)sp->cv->b / 255;
293 case E_COLOR_COMPONENT_H:
294 vz = sp->cv->h / 360;
296 case E_COLOR_COMPONENT_S:
299 case E_COLOR_COMPONENT_V:
302 case E_COLOR_COMPONENT_MAX:
306 for (i = 0; i < sp->ih; i++)
308 vy = (float)i / sp->ih;
309 for (j = 0; j < sp->iw; j++)
311 vx = (float)j / sp->iw;
312 _e_spectrum_color_calc(sp, vx, vy, vz, &r, &g, &b);
313 data[(i * sp->iw) + j] =
315 (((r * sp->cv->a) / 255) << 16) |
316 (((g * sp->cv->a) / 255) << 8) |
317 (((b * sp->cv->a) / 255) );
321 evas_object_image_data_set(sp->o_spectrum, data);
322 evas_object_image_data_update_add(sp->o_spectrum, 0, 0, sp->iw, sp->ih);
323 sp->draw_timer = NULL;
324 return ECORE_CALLBACK_CANCEL;
328 _e_spectrum_update(E_Spectrum *sp)
330 if (!sp || !sp->cv) return;
332 if (sp->draw_timer) ecore_timer_del(sp->draw_timer);
333 sp->draw_timer = ecore_timer_add(.001, _e_spectrum_redraw, sp);
337 e_spectrum_add(Evas *e)
339 _e_spectrum_smart_init();
340 return evas_object_smart_add(e, _e_spectrum_smart);
344 e_spectrum_mode_set(Evas_Object *o, E_Color_Component mode)
348 if (evas_object_smart_smart_get(o) != _e_spectrum_smart) SMARTERRNR();
349 sp = evas_object_smart_data_get(o);
352 if (sp->mode == mode) return;
354 _e_spectrum_update(sp);
358 e_spectrum_mode_get(Evas_Object *o)
362 if (evas_object_smart_smart_get(o) != _e_spectrum_smart) SMARTERR(0);
363 sp = evas_object_smart_data_get(o);
370 e_spectrum_color_value_set(Evas_Object *o, E_Color *cv)
374 if (evas_object_smart_smart_get(o) != _e_spectrum_smart) SMARTERRNR();
375 sp = evas_object_smart_data_get(o);
379 _e_spectrum_update(sp);
383 e_spectrum_update(Evas_Object *o)
387 if (evas_object_smart_smart_get(o) != _e_spectrum_smart) SMARTERRNR();
388 sp = evas_object_smart_data_get(o);
391 _e_spectrum_update(sp);