From e9dfef704816b7efde2eba04dbfc82e8f0497548 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Wed, 19 Oct 2016 22:57:40 -0200 Subject: [PATCH] Show color on hexa / rgb when it's enabled / disabled No need to wait for cursor position changes to update it. --- src/bin/main.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/bin/main.c b/src/bin/main.c index 781ae11..eeff1d8 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -82,6 +82,7 @@ struct _Zone { struct { int x, y; } last_mouse; + unsigned int color; Eina_Bool last_ruler_used : 1; Eina_Bool keyboard_move : 1; }; @@ -162,6 +163,23 @@ theme_apply(Evas_Object *edje, const char *group) return EINA_FALSE; } +static void +set_color(const Zone *zone) +{ + char buf[64]; + + if (hex_colors) + snprintf(buf, sizeof(buf), "#%06x", zone->color); + else + { + snprintf(buf, sizeof(buf), "%d %d %d", + (zone->color >> 16) & 0xff, + (zone->color >> 8) & 0xff, + (zone->color & 0xff)); + } + edje_object_part_text_set(zone->zoom.frame, "color", buf); +} + static void show_hexa_apply(void) { @@ -171,6 +189,7 @@ show_hexa_apply(void) EINA_LIST_FOREACH(zones, l, zone) { elm_check_state_set(zone->gui.hex_colors, hex_colors); + set_color(zone); } } @@ -451,7 +470,7 @@ _event_mouse_tracker(void *data) if (zone->zoom.ready) { int fx, fy, fw, fh, zx, zy, zw, zh, stride, iw, ih; - unsigned int *pixels, color; + unsigned int *pixels; zw = zone->zoom.ideal_size.w < zone->w / 4 ? zone->zoom.ideal_size.w : zone->w / 4; @@ -487,18 +506,9 @@ _event_mouse_tracker(void *data) EINA_SAFETY_ON_FALSE_GOTO(x < iw, position_invalid); EINA_SAFETY_ON_FALSE_GOTO(y < ih, position_invalid); - color = pixels[y * (stride / sizeof(unsigned int)) + x]; - color = color & 0xffffff; - if (hex_colors) - snprintf(buf, sizeof(buf), "#%06x", color); - else - { - snprintf(buf, sizeof(buf), "%d %d %d", - (color >> 16) & 0xff, - (color >> 8) & 0xff, - (color & 0xff)); - } - edje_object_part_text_set(zone->zoom.frame, "color", buf); + zone->color = pixels[y * (stride / sizeof(unsigned int)) + x]; + zone->color = zone->color & 0xffffff; + set_color(zone); position_invalid: evas_object_image_data_set(zone->zoom.image, pixels);