forked from enlightenment/efl
Elementary Colorpicker, widget designed to select a color.
This is one more widget whose idea come from Samsung set of contributions to Elementary. SVN revision: 53313
This commit is contained in:
parent
76f7bd543e
commit
34fd688815
|
@ -6,11 +6,12 @@ EDJE_FLAGS = -v -id $(top_srcdir)/data/objects -fd $(top_srcdir)/data/objects
|
|||
|
||||
filesdir = $(datadir)/elementary/objects
|
||||
|
||||
files_DATA = test.edj multip.edj
|
||||
files_DATA = test.edj multip.edj colorpreview.edj
|
||||
|
||||
EXTRA_DIST = \
|
||||
test.edc \
|
||||
multip.edc \
|
||||
grid_bg.png \
|
||||
over.png \
|
||||
under.png \
|
||||
sky.jpg \
|
||||
|
@ -26,6 +27,11 @@ multip.edj: Makefile $(EXTRA_DIST)
|
|||
$(EDJE_CC) $(EDJE_FLAGS) \
|
||||
$(top_srcdir)/data/objects/multip.edc \
|
||||
$(top_builddir)/data/objects/multip.edj
|
||||
|
||||
colorpreview.edj: Makefile $(EXTRA_DIST)
|
||||
$(EDJE_CC) $(EDJE_FLAGS) \
|
||||
$(top_srcdir)/data/objects/colorpreview.edc \
|
||||
$(top_builddir)/data/objects/colorpreview.edj
|
||||
|
||||
clean-local:
|
||||
rm -f *.edj
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
images {
|
||||
image: "grid_bg.png" COMP;
|
||||
}
|
||||
|
||||
collections {
|
||||
group { name: "main";
|
||||
parts {
|
||||
part { name: "Grid";
|
||||
type: IMAGE;
|
||||
description { state: "default" 0;
|
||||
image.normal: "grid_bg.png";
|
||||
}
|
||||
}
|
||||
part { name: "ColorPreview";
|
||||
type: SWALLOW;
|
||||
mouse_events: 0;
|
||||
description { state: "default" 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -200,7 +200,10 @@ tooltip-corner-bottom-right-tip.png \
|
|||
tooltip-edge-left-tip.png \
|
||||
tooltip-edge-bottom-tip.png \
|
||||
tooltip-edge-right-tip.png \
|
||||
tooltip-corner-top-right-tip.png
|
||||
tooltip-corner-top-right-tip.png \
|
||||
color_picker_brightness.png \
|
||||
color_picker_color.png \
|
||||
color_picker_opacity.png
|
||||
|
||||
|
||||
default.edj: Makefile $(EXTRA_DIST)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 974 B |
Binary file not shown.
After Width: | Height: | Size: 657 B |
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -27358,6 +27358,457 @@ collections {
|
|||
#undef CIT
|
||||
#undef CH
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// colorpicker
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
group { name: "elm/colorpicker/bg/default";
|
||||
parts {
|
||||
part { name: "elm.colorbar_0";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 120 30;
|
||||
rel1.relative: 0.0 (2/306);
|
||||
rel2.relative: 1.0 (78/306);
|
||||
}
|
||||
}
|
||||
part { name: "elm.colorbar_1";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 120 30;
|
||||
rel1.relative: 0.0 (78/306);
|
||||
rel2.relative: 1.0 (154/306);
|
||||
}
|
||||
}
|
||||
part { name: "elm.colorbar_2";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 120 30;
|
||||
rel1.relative: 0.0 (154/306);
|
||||
rel2.relative: 1.0 (230/306);
|
||||
}
|
||||
}
|
||||
part { name: "elm.colorbar_3";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 120 30;
|
||||
rel1.relative: 0.0 (230/306);
|
||||
rel2.relative: 1.0 (306/306);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/base/default";
|
||||
parts {
|
||||
part { name: "elm.l_button";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
scale: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 24 24;
|
||||
max: 24 24;
|
||||
fixed: 1 0;
|
||||
rel1 {
|
||||
relative: 0 (33/99);
|
||||
}
|
||||
rel2 {
|
||||
relative: 0 (66/99);
|
||||
}
|
||||
align: 0.0 0.5;
|
||||
}
|
||||
}
|
||||
part { name: "elm.r_button";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
scale: 1;
|
||||
description {
|
||||
state: "default" 0.0;
|
||||
min: 24 24;
|
||||
max: 24 24;
|
||||
fixed: 1 0;
|
||||
rel1 {
|
||||
relative: 1 (33/99);
|
||||
}
|
||||
rel2 {
|
||||
relative: 1 (66/99);
|
||||
}
|
||||
align: 1.0 0.5;
|
||||
}
|
||||
}
|
||||
part { name: "elm.bar_bg";
|
||||
type: SWALLOW;
|
||||
mouse_events: 0;
|
||||
description { state: "default" 0.0;
|
||||
max: 99999 22;
|
||||
min: 60 22;
|
||||
rel1 {
|
||||
relative: 0 (33/99);
|
||||
to_x: "elm.arrow_bg";
|
||||
offset: 11 0;
|
||||
}
|
||||
rel2 {
|
||||
relative: 1 (66/99);
|
||||
to_x: "elm.arrow_bg";
|
||||
offset: -11 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "elm.bar";
|
||||
type: SWALLOW;
|
||||
mouse_events: 0;
|
||||
description { state: "default" 0.0;
|
||||
rel1.to: "elm.bar_bg";
|
||||
rel2.to: "elm.bar_bg";
|
||||
}
|
||||
}
|
||||
part { name: "elm.arrow_bg";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel1 {
|
||||
relative: 1.0 (17/99);
|
||||
offset: -8 0;
|
||||
to_x: "elm.l_button";
|
||||
}
|
||||
rel2 {
|
||||
relative: 0.0 (83/99);
|
||||
offset: 7 0;
|
||||
to_x: "elm.r_button";
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "elm.arrow";
|
||||
type: SWALLOW;
|
||||
mouse_events: 1;
|
||||
scale: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 25 10;
|
||||
fixed: 1 1;
|
||||
rel1 {
|
||||
relative: 0 (17/99);
|
||||
to_x: "elm.arrow_bg";
|
||||
}
|
||||
rel2 {
|
||||
relative: 0 (87/99);
|
||||
to_x: "elm.arrow_bg";
|
||||
}
|
||||
}
|
||||
dragable {
|
||||
confine: "elm.arrow_bg";
|
||||
x: 1 1 1530;
|
||||
y: 0 0 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group{ name: "elm/colorpicker/image/colorbar_0";
|
||||
images {
|
||||
image: "color_picker_color.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "colorbar_0_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: -1 -1;
|
||||
image.normal: "color_picker_color.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/image/colorbar_1";
|
||||
images {
|
||||
image: "color_picker_opacity.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "colorbar_1_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: -1 -1;
|
||||
image.normal: "color_picker_opacity.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/image/colorbar_2";
|
||||
images {
|
||||
image: "color_picker_brightness.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "colorbar_2_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: -1 -1;
|
||||
image.normal: "color_picker_brightness.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/image/colorbar_3";
|
||||
images {
|
||||
image: "color_picker_alpha.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "colorbar_3_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: -1 -1;
|
||||
image.normal: "color_picker_alpha.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/bg_image/colorbar_3";
|
||||
images {
|
||||
image: "color_picker_alpha_bg.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "colorbar_3_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: -1 -1;
|
||||
image.normal: "color_picker_alpha_bg.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/image/updown";
|
||||
images {
|
||||
image: "icon_arrow_down.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "bg";
|
||||
type: RECT;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
color: 0 0 0 0;
|
||||
}
|
||||
}
|
||||
part { name: "arrow_image";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
rel2.offset: 0 -30;
|
||||
image.normal: "icon_arrow_down.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/button/left";
|
||||
images {
|
||||
image: "bt_base1.png" COMP;
|
||||
image: "bt_shine.png" COMP;
|
||||
image: "sp_bt_l.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "button_image";
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
image.normal: "bt_base1.png";
|
||||
image.border: 6 6 6 6;
|
||||
image.middle: SOLID;
|
||||
}
|
||||
|
||||
description { state: "clicked" 0.0;
|
||||
inherit: "default" 0.0;
|
||||
image.normal: "bt_shine.png";
|
||||
image.border: 6 6 6 6;
|
||||
image.middle: SOLID;
|
||||
}
|
||||
}
|
||||
part { name: "btn_over";
|
||||
type: IMAGE;
|
||||
mouse_events: 0;
|
||||
description { state: "default" 0.0;
|
||||
rel1.to: "button_image";
|
||||
rel2 {
|
||||
relative: 1.0 0.5;
|
||||
to: "button_image";
|
||||
}
|
||||
image {
|
||||
normal: "bt_hilight.png";
|
||||
border: 7 7 7 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "btn_over2";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
repeat_events: 1;
|
||||
ignore_flags: ON_HOLD;
|
||||
description { state: "default" 0.0;
|
||||
rel1.to: "button_image";
|
||||
rel2.to: "button_image";
|
||||
image {
|
||||
normal: "bt_shine.png";
|
||||
border: 7 7 7 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "focus_image";
|
||||
type: IMAGE;
|
||||
description { state: "default" 0.0;
|
||||
color: 255 255 255 0;
|
||||
rel1.to: "button_image";
|
||||
rel2.to: "button_image";
|
||||
image {
|
||||
normal: "bt_glow.png";
|
||||
border: 12 12 12 12;
|
||||
}
|
||||
fill.smooth: 0;
|
||||
|
||||
}
|
||||
description { state: "clicked" 0.0;
|
||||
inherit: "default" 0.0;
|
||||
visible: 1;
|
||||
color: 255 255 255 255;
|
||||
}
|
||||
}
|
||||
part { name: "left_arrow";
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 16 16;
|
||||
max: 16 16;
|
||||
image.normal: "sp_bt_l.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
programs {
|
||||
program {
|
||||
name: "button_down";
|
||||
signal: "elm,state,left,button,down";
|
||||
source: "left_button";
|
||||
action: STATE_SET "clicked" 0.0;
|
||||
target: "button_image";
|
||||
target: "focus_image";
|
||||
}
|
||||
program {
|
||||
name: "button_up";
|
||||
signal: "elm,state,left,button,up";
|
||||
source: "left_button";
|
||||
action: STATE_SET "default" 0.0;
|
||||
target: "button_image";
|
||||
target: "focus_image";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group { name: "elm/colorpicker/button/right";
|
||||
images {
|
||||
image: "bt_base1.png" COMP;
|
||||
image: "bt_shine.png" COMP;
|
||||
image: "sp_bt_r.png" COMP;
|
||||
}
|
||||
parts {
|
||||
part { name: "button_image";
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
image.normal: "bt_base1.png";
|
||||
image.border: 6 6 6 6;
|
||||
image.middle: SOLID;
|
||||
}
|
||||
|
||||
description { state: "clicked" 0.0;
|
||||
inherit: "default" 0.0;
|
||||
image.normal: "bt_shine.png";
|
||||
image.border: 6 6 6 6;
|
||||
image.middle: SOLID;
|
||||
}
|
||||
}
|
||||
part { name: "btn_over";
|
||||
type: IMAGE;
|
||||
mouse_events: 0;
|
||||
description { state: "default" 0.0;
|
||||
rel1.to: "button_image";
|
||||
rel2 {
|
||||
relative: 1.0 0.5;
|
||||
to: "button_image";
|
||||
}
|
||||
image {
|
||||
normal: "bt_hilight.png";
|
||||
border: 7 7 7 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "btn_over2";
|
||||
type: IMAGE;
|
||||
mouse_events: 1;
|
||||
repeat_events: 1;
|
||||
ignore_flags: ON_HOLD;
|
||||
description { state: "default" 0.0;
|
||||
rel1.to: "button_image";
|
||||
rel2.to: "button_image";
|
||||
image {
|
||||
normal: "bt_shine.png";
|
||||
border: 7 7 7 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
part { name: "focus_image";
|
||||
type: IMAGE;
|
||||
description { state: "default" 0.0;
|
||||
color: 255 255 255 0;
|
||||
rel1.to: "button_image";
|
||||
rel2.to: "button_image";
|
||||
image {
|
||||
normal: "bt_glow.png";
|
||||
border: 12 12 12 12;
|
||||
}
|
||||
fill.smooth: 0;
|
||||
|
||||
}
|
||||
description { state: "clicked" 0.0;
|
||||
inherit: "default" 0.0;
|
||||
visible: 1;
|
||||
color: 255 255 255 255;
|
||||
}
|
||||
}
|
||||
part { name: "right_arrow";
|
||||
mouse_events: 1;
|
||||
description { state: "default" 0.0;
|
||||
min: 16 16;
|
||||
max: 16 16;
|
||||
image.normal: "sp_bt_r.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
programs {
|
||||
program {
|
||||
name: "button_down";
|
||||
signal: "elm,state,right,button,down";
|
||||
source: "right_button";
|
||||
action: STATE_SET "clicked" 0.0;
|
||||
target: "button_image";
|
||||
target: "focus_image";
|
||||
}
|
||||
program {
|
||||
name: "button_up";
|
||||
signal: "elm,state,right,button,up";
|
||||
source: "right_button";
|
||||
action: STATE_SET "default" 0.0;
|
||||
target: "button_image";
|
||||
target: "focus_image";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CURSOR
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -88,7 +88,8 @@ test_cursor.c \
|
|||
test_focus.c \
|
||||
test_focus2.c \
|
||||
test_flippicker.c \
|
||||
test_diskpicker.c
|
||||
test_diskpicker.c \
|
||||
test_colorpicker.c
|
||||
|
||||
elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la @ELEMENTARY_EWEATHER_LIBS@
|
||||
elementary_test_LDFLAGS =
|
||||
|
|
|
@ -91,6 +91,7 @@ void test_focus(void *data, Evas_Object *obj, void *event_info);
|
|||
void test_focus2(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_flippicker(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_diskpicker(void *data, Evas_Object *obj, void *event_info);
|
||||
void test_colorpicker(void *data, Evas_Object *obj, void *event_info);
|
||||
|
||||
struct elm_test
|
||||
{
|
||||
|
@ -302,6 +303,7 @@ my_win_main(char *autorun)
|
|||
ADD_TEST("Focus 2", test_focus2);
|
||||
ADD_TEST("Flippicker", test_flippicker);
|
||||
ADD_TEST("Diskpicker", test_diskpicker);
|
||||
ADD_TEST("Colorpicker", test_colorpicker);
|
||||
#undef ADD_TEST
|
||||
|
||||
if (autorun)
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#include <Elementary.h>
|
||||
#ifndef ELM_LIB_QUICKLAUNCH
|
||||
|
||||
static void
|
||||
_colorpicker_clicked_cb(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Evas_Object *re = data;
|
||||
int r, g, b, a;
|
||||
|
||||
elm_colorpicker_color_get(obj, &r, &g, &b, &a);
|
||||
printf("Current Color [r=%d g=%d b=%d a=%d]\n",r, g, b, a);
|
||||
|
||||
/* Fix Alpha pre multiplication by edje */
|
||||
r = (r * a) / 255;
|
||||
g = (g * a) / 255;
|
||||
b = (b * a) / 255;
|
||||
|
||||
evas_object_color_set(re, r, g, b, a);
|
||||
}
|
||||
|
||||
void
|
||||
test_colorpicker(void *data, Evas_Object *obj, void *event_info)
|
||||
{
|
||||
Evas_Object *win, *bg, *bx, *cp, *fr, *ly, *re;
|
||||
char buf[PATH_MAX];
|
||||
int r, g, b, a;
|
||||
|
||||
win = elm_win_add(NULL, "colorpicker", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Colorpicker");
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
||||
bg = elm_bg_add(win);
|
||||
elm_win_resize_object_add(win, bg);
|
||||
evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_color_set(bg, 255, 255, 255, 255);
|
||||
evas_object_show(bg);
|
||||
|
||||
bx = elm_box_add(win);
|
||||
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
elm_win_resize_object_add(win, bx);
|
||||
evas_object_show(bx);
|
||||
|
||||
fr = elm_frame_add(win);
|
||||
evas_object_size_hint_weight_set(fr, 1.0, 0.5);
|
||||
evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_frame_label_set(fr, "Color View");
|
||||
elm_box_pack_end(bx, fr);
|
||||
evas_object_show(fr);
|
||||
|
||||
ly = elm_layout_add(win);
|
||||
snprintf(buf, sizeof(buf), "%s/objects/colorpreview.edj", PACKAGE_DATA_DIR);
|
||||
elm_layout_file_set(ly, buf, "main");
|
||||
evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
elm_frame_content_set(fr, ly);
|
||||
evas_object_show(ly);
|
||||
|
||||
re = evas_object_rectangle_add(evas_object_evas_get(win));
|
||||
evas_object_show(re);
|
||||
elm_layout_content_set(ly, "ColorPreview", re);
|
||||
|
||||
fr = elm_frame_add(win);
|
||||
evas_object_size_hint_weight_set(fr, 1.0, 0.5);
|
||||
evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_frame_label_set(fr, "Color Picker");
|
||||
elm_box_pack_end(bx, fr);
|
||||
evas_object_show(fr);
|
||||
|
||||
cp = elm_colorpicker_add(win);
|
||||
|
||||
a = 180;
|
||||
r = 255;
|
||||
g = 160;
|
||||
b = 132;
|
||||
|
||||
elm_colorpicker_color_set(cp, r, g, b, a);
|
||||
evas_object_size_hint_weight_set(cp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(cp, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_frame_content_set(fr, cp);
|
||||
evas_object_show(cp);
|
||||
evas_object_smart_callback_add(cp, "changed", _colorpicker_clicked_cb, re);
|
||||
|
||||
elm_colorpicker_color_get(cp, &r, &g, &b, &a);
|
||||
/* Fix Alpha pre multiplication by edje */
|
||||
r = (r * a) / 255;
|
||||
g = (g * a) / 255;
|
||||
b = (b * a) / 255;
|
||||
evas_object_color_set(re, r, g, b, a);
|
||||
|
||||
evas_object_resize(win, 320, 480);
|
||||
evas_object_show(win);
|
||||
|
||||
}
|
||||
#endif
|
|
@ -1940,6 +1940,14 @@ extern "C" {
|
|||
* "selected" - when item is selected (scroller stops)
|
||||
*/
|
||||
|
||||
/* colorpicker */
|
||||
EAPI Evas_Object *elm_colorpicker_add(Evas_Object *parent);
|
||||
EAPI void elm_colorpicker_color_set(Evas_Object *obj, int r, int g , int b, int a);
|
||||
EAPI void elm_colorpicker_color_get(Evas_Object *obj, int *r, int *g , int *b, int *a);
|
||||
/* smart callbacks called:
|
||||
* "clicked" - when bar or button is clicked
|
||||
*/
|
||||
|
||||
/* debug
|
||||
* don't use it unless you are sure
|
||||
*/
|
||||
|
|
|
@ -84,6 +84,7 @@ elm_animator.c \
|
|||
elm_calendar.c \
|
||||
elm_flippicker.c \
|
||||
elm_diskpicker.c \
|
||||
elm_colorpicker.c \
|
||||
\
|
||||
elc_anchorblock.c \
|
||||
elc_anchorview.c \
|
||||
|
|
|
@ -0,0 +1,892 @@
|
|||
#include <Elementary.h>
|
||||
#include "elm_priv.h"
|
||||
#include <Ecore.h>
|
||||
|
||||
/**
|
||||
* @addtogroup Colorpicker Colorpicker
|
||||
*
|
||||
* By using colorpicker, you can select a color.
|
||||
* Colorpicker made a color using HSV/HSB mode.
|
||||
*/
|
||||
|
||||
#define BASE_STEP 360
|
||||
#define HUE_STEP 360
|
||||
#define SAT_STEP 128
|
||||
#define LIG_STEP 256
|
||||
#define ALP_STEP 256
|
||||
|
||||
typedef struct _Colorpicker_Data Colorpicker_Data;
|
||||
|
||||
struct _Colorpicker_Data
|
||||
{
|
||||
Evas_Object *parent;
|
||||
Evas_Object *colorbar;
|
||||
Evas_Object *bar;
|
||||
Evas_Object *lbt;
|
||||
Evas_Object *rbt;
|
||||
Evas_Object *bg_rect;
|
||||
Evas_Object *arrow;
|
||||
Evas_Object *touch_area;
|
||||
int colorpicker_num;
|
||||
int button_state;
|
||||
};
|
||||
|
||||
typedef struct _Widget_Data Widget_Data;
|
||||
|
||||
struct _Widget_Data
|
||||
{
|
||||
Evas_Object *base;
|
||||
Colorpicker_Data *cp[4];
|
||||
Evas_Coord _x, _y, _w, _h;
|
||||
int r, g, b, a;
|
||||
int er, eg, eb;
|
||||
int sr, sg, sb;
|
||||
int lr, lg, lb;
|
||||
double h, s, l;
|
||||
Ecore_Timer *lp_timer;
|
||||
Ecore_Timer *mv_timer;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_RELEASED,
|
||||
L_BUTTON_PRESSED,
|
||||
R_BUTTON_PRESSED
|
||||
} Button_State;
|
||||
|
||||
static const char *widtype = NULL;
|
||||
static void _del_hook(Evas_Object *obj);
|
||||
static void _theme_hook(Evas_Object *obj);
|
||||
static void _sizing_eval(Evas_Object *obj);
|
||||
static void _rgb_to_hsl(void *data);
|
||||
static void _hsl_to_rgb(void *data);
|
||||
static void _color_with_saturation(void *data);
|
||||
static void _color_with_lightness(void *data);
|
||||
static void _draw_rects(void *data, double x);
|
||||
static void _arrow_cb(void *data, Evas_Object *obj, const char *emission, const char *source);
|
||||
static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _arrow_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static Eina_Bool _mv_timer(void *data);
|
||||
static Eina_Bool _long_press_timer(void *data);
|
||||
static void _left_button_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _right_button_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _left_button_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _right_button_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
static void _add_colorbar(Evas_Object *obj);
|
||||
static void _set_color(Evas_Object *obj, int r, int g, int b, int a);
|
||||
|
||||
static const char SIG_CHANGED[] = "changed";
|
||||
static const Evas_Smart_Cb_Description _signals[] = {
|
||||
{SIG_CHANGED, ""},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
int i;
|
||||
|
||||
if (!wd)
|
||||
return;
|
||||
|
||||
if (wd->lp_timer)
|
||||
ecore_timer_del(wd->lp_timer);
|
||||
if (wd->mv_timer)
|
||||
ecore_timer_del(wd->mv_timer);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
free(wd->cp[i]);
|
||||
}
|
||||
|
||||
free(wd);
|
||||
}
|
||||
|
||||
static void
|
||||
_theme_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
int i;
|
||||
|
||||
if (!wd || !wd->base)
|
||||
return;
|
||||
|
||||
_elm_theme_object_set(obj, wd->base, "colorpicker", "bg",
|
||||
elm_widget_style_get(obj));
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
evas_object_del(wd->cp[i]->colorbar);
|
||||
wd->cp[i]->colorbar = NULL;
|
||||
evas_object_del(wd->cp[i]->bar);
|
||||
wd->cp[i]->bar = NULL;
|
||||
evas_object_del(wd->cp[i]->lbt);
|
||||
wd->cp[i]->lbt = NULL;
|
||||
evas_object_del(wd->cp[i]->rbt);
|
||||
wd->cp[i]->rbt = NULL;
|
||||
if (i == 1 || i == 2)
|
||||
{
|
||||
evas_object_del(wd->cp[i]->bg_rect);
|
||||
wd->cp[i]->bg_rect = NULL;
|
||||
}
|
||||
evas_object_del(wd->cp[i]->arrow);
|
||||
wd->cp[i]->arrow = NULL;
|
||||
evas_object_del(wd->cp[i]->touch_area);
|
||||
wd->cp[i]->touch_area = NULL;
|
||||
}
|
||||
|
||||
_add_colorbar(obj);
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_sizing_eval(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
Evas_Coord minw = -1, minh = -1;
|
||||
if (!wd) return;
|
||||
elm_coords_finger_size_adjust(4, &minw, 4, &minh);
|
||||
edje_object_size_min_restricted_calc(wd->base, &minw, &minh, minw, minh);
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
evas_object_size_hint_max_set(obj, -1, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
_rgb_to_hsl(void *data)
|
||||
{
|
||||
Widget_Data *wd = data;
|
||||
double r, g, b;
|
||||
double v, m, vm;
|
||||
double r2, g2, b2;
|
||||
|
||||
r = wd->r;
|
||||
g = wd->g;
|
||||
b = wd->b;
|
||||
|
||||
r /= 255.0;
|
||||
g /= 255.0;
|
||||
b /= 255.0;
|
||||
|
||||
v = (r > g) ? r : g;
|
||||
v = (v > b) ? v : b;
|
||||
|
||||
m = (r < g) ? r : g;
|
||||
m = (m < b) ? m : b;
|
||||
|
||||
wd->h = 0.0;
|
||||
wd->s = 0.0;
|
||||
wd->l = 0.0;
|
||||
|
||||
wd->l = (m + v) / 2.0;
|
||||
|
||||
if (wd->l <= 0.0)
|
||||
return;
|
||||
|
||||
vm = v - m;
|
||||
wd->s = vm;
|
||||
|
||||
if (wd->s > 0.0)
|
||||
wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
|
||||
|
||||
else
|
||||
return;
|
||||
|
||||
r2 = (v - r) / vm;
|
||||
g2 = (v - g) / vm;
|
||||
b2 = (v - b) / vm;
|
||||
|
||||
if (r == v)
|
||||
wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
|
||||
|
||||
else if (g == v)
|
||||
wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
|
||||
|
||||
else
|
||||
wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
|
||||
|
||||
wd->h *= 60.0;
|
||||
}
|
||||
|
||||
static void
|
||||
_hsl_to_rgb(void *data)
|
||||
{
|
||||
Widget_Data *wd = data;
|
||||
double r = 0, g = 0, b = 0;
|
||||
double _h, _s, _l;
|
||||
int i;
|
||||
double sv, vsf, f, p, q, t, v;
|
||||
|
||||
_h = wd->h;
|
||||
_s = wd->s;
|
||||
_l = wd->l;
|
||||
|
||||
if (_s == 0.0)
|
||||
r = g = b = _l;
|
||||
|
||||
else
|
||||
{
|
||||
if (_h == 360.0)
|
||||
_h = 0.0;
|
||||
_h /= 60.0;
|
||||
|
||||
v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
|
||||
p = _l + _l - v;
|
||||
|
||||
if (v != 0)
|
||||
sv = (v - p) / v;
|
||||
else
|
||||
sv = 0;
|
||||
|
||||
i = (int)_h;
|
||||
f = _h - i;
|
||||
|
||||
vsf = v * sv * f;
|
||||
|
||||
t = p + vsf;
|
||||
q = v - vsf;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
case 4:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
case 5:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
i = (int)(r * 255.0);
|
||||
f = (r * 255.0) - i;
|
||||
wd->r = (f <= 0.5) ? i : (i + 1);
|
||||
|
||||
i = (int)(g * 255.0);
|
||||
f = (g * 255.0) - i;
|
||||
wd->g = (f <= 0.5) ? i : (i + 1);
|
||||
|
||||
i = (int)(b * 255.0);
|
||||
f = (b * 255.0) - i;
|
||||
wd->b = (f <= 0.5) ? i : (i + 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_color_with_saturation(void *data)
|
||||
{
|
||||
Widget_Data *wd = data;
|
||||
|
||||
if (wd->er > 127)
|
||||
wd->sr = (int)((double)127 + ((double)wd->er - (double)127) * wd->s);
|
||||
else
|
||||
wd->sr = (int)((double)127 - ((double)127 - (double)wd->er) * wd->s);
|
||||
|
||||
if (wd->eg > 127)
|
||||
wd->sg = (int)((double)127 + ((double)wd->eg - (double)127) * wd->s);
|
||||
else
|
||||
wd->sg = (int)((double)127 - ((double)127 - (double)wd->eg) * wd->s);
|
||||
|
||||
if (wd->eb > 127)
|
||||
wd->sb = (int)((double)127 + ((double)wd->eb - (double)127) * wd->s);
|
||||
else
|
||||
wd->sb = (int)((double)127 - ((double)127 - (double)wd->eb) * wd->s);
|
||||
}
|
||||
|
||||
static void
|
||||
_color_with_lightness(void *data)
|
||||
{
|
||||
Widget_Data *wd = data;
|
||||
|
||||
if (wd->l > 0.5)
|
||||
{
|
||||
wd->lr = wd->er + (int)((double)(255 - wd->er) * (double)(wd->l - 0.5) *
|
||||
(double)2);
|
||||
wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (double)(wd->l - 0.5) *
|
||||
(double)2);
|
||||
wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (double)(wd->l - 0.5) *
|
||||
(double)2);
|
||||
}
|
||||
else if (wd->l < 0.5)
|
||||
{
|
||||
wd->lr = (int)((double)wd->er * (double)wd->l * (double)2);
|
||||
wd->lg = (int)((double)wd->eg * (double)wd->l * (double)2);
|
||||
wd->lb = (int)((double)wd->eb * (double)wd->l * (double)2);
|
||||
}
|
||||
else
|
||||
{
|
||||
wd->lr = wd->er;
|
||||
wd->lg = wd->eg;
|
||||
wd->lb = wd->eb;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_draw_rects(void *data, double x)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
double one_six = (double)1 / (double)6;
|
||||
|
||||
switch (cp->colorpicker_num)
|
||||
{
|
||||
case 0:
|
||||
wd->h = 360.0 * x;
|
||||
|
||||
if (x < one_six)
|
||||
{
|
||||
wd->er = 255;
|
||||
wd->eg = (int)((double)255 * x * (double)6);
|
||||
wd->eb = 0;
|
||||
}
|
||||
else if (x < (double)2 * one_six)
|
||||
{
|
||||
wd->er = 255 - (int)((double)255 * (x - one_six) * (double)6);
|
||||
wd->eg = 255;
|
||||
wd->eb = 0;
|
||||
}
|
||||
else if (x < (double)3 * one_six)
|
||||
{
|
||||
wd->er = 0;
|
||||
wd->eg = 255;
|
||||
wd->eb = (int)((double)255 * (x - (double)2 * one_six) * (double)6);
|
||||
}
|
||||
else if (x < (double)4 * one_six)
|
||||
{
|
||||
wd->er = 0;
|
||||
wd->eg = 255 - (int)((double)255 * (x - (double)3 * one_six) * (double)6);
|
||||
wd->eb = 255;
|
||||
}
|
||||
else if (x < (double)5 * one_six)
|
||||
{
|
||||
wd->er = (int)((double)255 * (x - (double)4 * one_six) * (double)6);
|
||||
wd->eg = 0;
|
||||
wd->eb = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
wd->er = 255;
|
||||
wd->eg = 0;
|
||||
wd->eb = 255 - (int)((double)255 * (x - (double)5 * one_six) * (double)6);
|
||||
}
|
||||
|
||||
evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
|
||||
evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
|
||||
evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
|
||||
evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
|
||||
|
||||
_color_with_saturation(wd);
|
||||
evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
|
||||
|
||||
_color_with_lightness(wd);
|
||||
evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
|
||||
|
||||
evas_object_color_set(wd->cp[3]->arrow, (wd->er * wd->a) / 255,
|
||||
(wd->eg * wd->a) / 255, (wd->eb * wd->a) / 255,
|
||||
wd->a);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
wd->s = (double)1 - x;
|
||||
_color_with_saturation(wd);
|
||||
evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
wd->l = x;
|
||||
_color_with_lightness(wd);
|
||||
evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
wd->a = (int)((double)255 * x);
|
||||
evas_object_color_set(wd->cp[3]->arrow, wd->er, wd->eg, wd->eb, wd->a);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
_hsl_to_rgb(wd);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
_arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
double x, y;
|
||||
|
||||
edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
|
||||
_draw_rects(data, x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Evas_Event_Mouse_Down *ev = event_info;
|
||||
Evas_Coord x, y, w, h;
|
||||
double arrow_x, arrow_y;
|
||||
|
||||
evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
|
||||
edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
|
||||
&arrow_x, &arrow_y);
|
||||
arrow_x = ((double)ev->output.x - (double)x) / (double)w;
|
||||
if (arrow_x > 1)
|
||||
arrow_x = 1;
|
||||
if (arrow_x < 0)
|
||||
arrow_x = 0;
|
||||
edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
|
||||
_draw_rects(data, arrow_x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
evas_event_feed_mouse_cancel(e, 0, NULL);
|
||||
evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_arrow_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Evas_Coord arrow_w, arrow_h;
|
||||
|
||||
evas_object_geometry_get(cp->touch_area, NULL, NULL, NULL, &arrow_h);
|
||||
evas_object_geometry_get(cp->arrow, NULL, NULL, &arrow_w, NULL);
|
||||
|
||||
evas_object_size_hint_min_set(cp->arrow, arrow_w, arrow_h);
|
||||
evas_object_size_hint_max_set(cp->arrow, arrow_w, arrow_h);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_mv_timer(void *data)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
double x, y;
|
||||
|
||||
if (!cp || !wd)
|
||||
return 0;
|
||||
|
||||
edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
|
||||
if (cp->button_state == L_BUTTON_PRESSED)
|
||||
{
|
||||
x -= (double)1 / (double)BASE_STEP;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(data, x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
else if (cp->button_state == R_BUTTON_PRESSED)
|
||||
{
|
||||
x += (double)1 / (double)BASE_STEP;
|
||||
if (x > 1)
|
||||
x = 1;
|
||||
edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(data, x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wd->mv_timer)
|
||||
{
|
||||
ecore_timer_del(wd->mv_timer);
|
||||
wd->mv_timer = NULL;
|
||||
}
|
||||
return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_long_press_timer(void *data)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
|
||||
if (wd->lp_timer)
|
||||
{
|
||||
ecore_timer_del(wd->lp_timer);
|
||||
wd->lp_timer = NULL;
|
||||
}
|
||||
|
||||
wd->mv_timer = ecore_timer_add(0.01, _mv_timer, cp);
|
||||
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_left_button_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
double x, y;
|
||||
|
||||
edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
|
||||
"left_button");
|
||||
edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
|
||||
|
||||
if (cp->colorpicker_num == 0)
|
||||
x -= (double)1 / (double)HUE_STEP;
|
||||
else if (cp->colorpicker_num == 1)
|
||||
x -= (double)1 / (double)SAT_STEP;
|
||||
else if (cp->colorpicker_num == 2)
|
||||
x -= (double)1 / (double)LIG_STEP;
|
||||
else if (cp->colorpicker_num == 3)
|
||||
x -= (double)1 / (double)ALP_STEP;
|
||||
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
|
||||
edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(data, x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
cp->button_state = L_BUTTON_PRESSED;
|
||||
wd->lp_timer = ecore_timer_add(1.0, _long_press_timer, cp);
|
||||
}
|
||||
|
||||
static void
|
||||
_right_button_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
double x, y;
|
||||
|
||||
edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
|
||||
"right_button");
|
||||
edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
|
||||
|
||||
if (cp->colorpicker_num == 0)
|
||||
x += (double)1 / (double)HUE_STEP;
|
||||
else if (cp->colorpicker_num == 1)
|
||||
x += (double)1 / (double)SAT_STEP;
|
||||
else if (cp->colorpicker_num == 2)
|
||||
x += (double)1 / (double)LIG_STEP;
|
||||
else if (cp->colorpicker_num == 3)
|
||||
x += (double)1 / (double)ALP_STEP;
|
||||
|
||||
if (x > 1)
|
||||
x = 1;
|
||||
|
||||
edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(data, x);
|
||||
evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
|
||||
cp->button_state = R_BUTTON_PRESSED;
|
||||
wd->lp_timer = ecore_timer_add(1.0, _long_press_timer, cp);
|
||||
}
|
||||
|
||||
static void
|
||||
_left_button_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
|
||||
if (wd->lp_timer)
|
||||
{
|
||||
ecore_timer_del(wd->lp_timer);
|
||||
wd->lp_timer = NULL;
|
||||
}
|
||||
if (wd->mv_timer)
|
||||
{
|
||||
ecore_timer_del(wd->mv_timer);
|
||||
wd->mv_timer = NULL;
|
||||
}
|
||||
|
||||
cp->button_state = BUTTON_RELEASED;
|
||||
edje_object_signal_emit(cp->lbt, "elm,state,left,button,up", "left_button");
|
||||
}
|
||||
|
||||
static void
|
||||
_right_button_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
{
|
||||
Colorpicker_Data *cp = data;
|
||||
Widget_Data *wd = elm_widget_data_get(cp->parent);
|
||||
|
||||
if (wd->lp_timer)
|
||||
{
|
||||
ecore_timer_del(wd->lp_timer);
|
||||
wd->lp_timer = NULL;
|
||||
}
|
||||
if (wd->mv_timer)
|
||||
{
|
||||
ecore_timer_del(wd->mv_timer);
|
||||
wd->mv_timer = NULL;
|
||||
}
|
||||
|
||||
cp->button_state = BUTTON_RELEASED;
|
||||
edje_object_signal_emit(cp->rbt, "elm,state,right,button,up",
|
||||
"right_button");
|
||||
}
|
||||
|
||||
static void
|
||||
_add_colorbar(Evas_Object *obj)
|
||||
{
|
||||
char colorbar_name[128];
|
||||
char colorbar_s[128];
|
||||
Widget_Data *wd;
|
||||
Evas *e;
|
||||
int i;
|
||||
|
||||
wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
|
||||
e = evas_object_evas_get(obj);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
wd->cp[i] = ELM_NEW(Colorpicker_Data);
|
||||
|
||||
wd->cp[i]->parent = obj;
|
||||
wd->cp[i]->colorpicker_num = i;
|
||||
|
||||
/* load colorbar area */
|
||||
wd->cp[i]->colorbar = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorpicker", "base",
|
||||
"default");
|
||||
snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
|
||||
snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
|
||||
edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
|
||||
_arrow_cb, wd->cp[i]);
|
||||
edje_object_part_swallow(wd->base, colorbar_s, wd->cp[i]->colorbar);
|
||||
evas_object_show(wd->cp[i]->colorbar);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
|
||||
|
||||
/* load colorbar image */
|
||||
wd->cp[i]->bar = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->bar, "colorpicker", "image",
|
||||
colorbar_name);
|
||||
evas_object_show(wd->cp[i]->bar);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
|
||||
wd->cp[i]->bar);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->bar);
|
||||
|
||||
/* provide expanded touch area */
|
||||
wd->cp[i]->touch_area = evas_object_rectangle_add(e);
|
||||
evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
|
||||
wd->cp[i]->touch_area);
|
||||
evas_object_event_callback_add(wd->cp[i]->touch_area,
|
||||
EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
|
||||
wd->cp[i]);
|
||||
evas_object_event_callback_add(wd->cp[i]->touch_area,
|
||||
EVAS_CALLBACK_RESIZE, _arrow_resize_cb,
|
||||
wd->cp[i]);
|
||||
evas_object_show(wd->cp[i]->touch_area);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
|
||||
|
||||
/* load background rectangle of the colorbar. used for
|
||||
changing color of the opacity bar */
|
||||
if (i == 1 || i == 2)
|
||||
{
|
||||
wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
|
||||
evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
|
||||
255);
|
||||
evas_object_show(wd->cp[i]->bg_rect);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
|
||||
wd->cp[i]->bg_rect);
|
||||
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
|
||||
}
|
||||
if (i == 3)
|
||||
{
|
||||
wd->cp[i]->bg_rect = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorpicker",
|
||||
"bg_image", colorbar_name);
|
||||
evas_object_show(wd->cp[i]->bg_rect);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
|
||||
wd->cp[i]->bg_rect);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
|
||||
evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
|
||||
}
|
||||
/* load arrow image, pointing the colorbar */
|
||||
wd->cp[i]->arrow = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->arrow, "colorpicker", "image",
|
||||
"updown");
|
||||
evas_object_show(wd->cp[i]->arrow);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow",
|
||||
wd->cp[i]->arrow);
|
||||
evas_object_event_callback_add(wd->cp[i]->arrow, EVAS_CALLBACK_RESIZE,
|
||||
_arrow_resize_cb, wd->cp[i]);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
|
||||
if (i == 2)
|
||||
evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
|
||||
else
|
||||
evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
|
||||
|
||||
/* load left button */
|
||||
wd->cp[i]->lbt = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->lbt, "colorpicker", "button",
|
||||
"left");
|
||||
evas_object_event_callback_add(wd->cp[i]->lbt, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_left_button_down_cb, wd->cp[i]);
|
||||
evas_object_event_callback_add(wd->cp[i]->lbt, EVAS_CALLBACK_MOUSE_UP,
|
||||
_left_button_up_cb, wd->cp[i]);
|
||||
evas_object_show(wd->cp[i]->lbt);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
|
||||
wd->cp[i]->lbt);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
|
||||
|
||||
/* load right button */
|
||||
wd->cp[i]->rbt = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->cp[i]->rbt, "colorpicker", "button",
|
||||
"right");
|
||||
evas_object_event_callback_add(wd->cp[i]->rbt, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_right_button_down_cb, wd->cp[i]);
|
||||
evas_object_event_callback_add(wd->cp[i]->rbt, EVAS_CALLBACK_MOUSE_UP,
|
||||
_right_button_up_cb, wd->cp[i]);
|
||||
evas_object_show(wd->cp[i]->rbt);
|
||||
edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
|
||||
wd->cp[i]->rbt);
|
||||
elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_set_color(Evas_Object *obj, int r, int g, int b, int a)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
double x, y;
|
||||
|
||||
wd->r = r;
|
||||
wd->g = g;
|
||||
wd->b = b;
|
||||
wd->a = a;
|
||||
|
||||
_rgb_to_hsl(wd);
|
||||
|
||||
edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
|
||||
x = wd->h / 360.0;
|
||||
edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(wd->cp[0], x);
|
||||
|
||||
edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
|
||||
x = 1.0 - wd->s;
|
||||
edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(wd->cp[1], x);
|
||||
|
||||
edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
|
||||
x = wd->l;
|
||||
edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(wd->cp[2], x);
|
||||
|
||||
edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
|
||||
x = wd->a / 255.0;
|
||||
edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
|
||||
_draw_rects(wd->cp[3], x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new colorpicker to the parent
|
||||
*
|
||||
* @param parent The parent object
|
||||
* @return The new object or NULL if it cannot be created
|
||||
*
|
||||
* @ingroup Colorpicker
|
||||
*/
|
||||
EAPI Evas_Object *
|
||||
elm_colorpicker_add(Evas_Object *parent)
|
||||
{
|
||||
Evas_Object *obj = NULL;
|
||||
Widget_Data *wd = NULL;
|
||||
Evas *e;
|
||||
|
||||
wd = ELM_NEW(Widget_Data);
|
||||
e = evas_object_evas_get(parent);
|
||||
obj = elm_widget_add(e);
|
||||
ELM_SET_WIDTYPE(widtype, "colorpicker");
|
||||
elm_widget_type_set(obj, "colorpicker");
|
||||
elm_widget_sub_object_add(parent, obj);
|
||||
elm_widget_data_set(obj, wd);
|
||||
elm_widget_del_hook_set(obj, _del_hook);
|
||||
elm_widget_theme_hook_set(obj, _theme_hook);
|
||||
|
||||
/* load background edj */
|
||||
wd->base = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->base, "colorpicker", "bg", "default");
|
||||
elm_widget_resize_object_set(obj, wd->base);
|
||||
|
||||
wd->er = 255;
|
||||
wd->eg = 0;
|
||||
wd->eb = 0;
|
||||
wd->h = 0.0;
|
||||
wd->s = 1.0;
|
||||
wd->l = 0.0;
|
||||
wd->a = 255;
|
||||
|
||||
_hsl_to_rgb(wd);
|
||||
_add_colorbar(obj);
|
||||
_sizing_eval(obj);
|
||||
|
||||
evas_object_smart_callbacks_descriptions_set(obj, _signals);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a color for the colorpicker
|
||||
*
|
||||
* @param obj Colorpicker object
|
||||
* @param r r-value of color
|
||||
* @param g g-value of color
|
||||
* @param b b-value of color
|
||||
* @param a a-value of color
|
||||
*
|
||||
* @ingroup Colorpicker
|
||||
*/
|
||||
EAPI void
|
||||
elm_colorpicker_color_set(Evas_Object *obj, int r, int g, int b, int a)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
_set_color(obj, r, g, b, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a color from the colorpicker
|
||||
*
|
||||
* @param obj Colorpicker object
|
||||
* @param r integer pointer for r-value of color
|
||||
* @param g integer pointer for g-value of color
|
||||
* @param b integer pointer for b-value of color
|
||||
* @param a integer pointer for a-value of color
|
||||
*
|
||||
* @ingroup Colorpicker
|
||||
*/
|
||||
EAPI void
|
||||
elm_colorpicker_color_get(Evas_Object *obj, int *r, int *g, int *b, int*a)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
|
||||
if (r)
|
||||
*r = wd->r;
|
||||
if (g)
|
||||
*g = wd->g;
|
||||
if (b)
|
||||
*b = wd->b;
|
||||
if (a)
|
||||
*a = wd->a;
|
||||
}
|
Loading…
Reference in New Issue