From e007254233c1730b7863d7be38b07805ae3b49a5 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Mon, 24 Jun 2024 18:26:08 +0200 Subject: [PATCH 1/4] Allows for editing color picker area. --- src/libs/colorpicker.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/libs/colorpicker.c b/src/libs/colorpicker.c index f829b43b9039..1bbd0444d642 100644 --- a/src/libs/colorpicker.c +++ b/src/libs/colorpicker.c @@ -64,6 +64,7 @@ typedef struct dt_lib_colorpicker_t GtkWidget *add_sample_button; GtkWidget *display_samples_check_box; dt_colorpicker_sample_t primary_sample; + dt_colorpicker_sample_t *target_sample; } dt_lib_colorpicker_t; const char *name(dt_lib_module_t *self) @@ -219,8 +220,30 @@ static gboolean _large_patch_toggle(GtkWidget *widget, static void _picker_button_toggled(GtkToggleButton *button, dt_lib_colorpicker_t *data) { - gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), - gtk_toggle_button_get_active(button)); + const gboolean is_active = gtk_toggle_button_get_active(button); + gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), is_active); + + // We leaving the color-picker active mode and we have a target_sample + // recorded. In this case we want the target sample to be replaced by + // the current primay_sample. + if(!is_active && data->target_sample) + { + // Copy only the position & style for sample + memcpy(&data->target_sample->point, + &data->primary_sample.point, + sizeof(data->primary_sample.point)); + memcpy(&data->target_sample->box, + &data->primary_sample.box, + sizeof(data->primary_sample.box)); + // Size cannot be changed at this point, but in case this is done + // in the future. + data->target_sample->size = data->primary_sample.size; + + data->target_sample = NULL; + + // And now redisplay the new samples areas + gtk_widget_queue_draw(data->samples_container); + } } static void _update_size(dt_lib_module_t *self, @@ -448,17 +471,22 @@ static gboolean _live_sample_button(GtkWidget *widget, GdkEventButton *event, dt_colorpicker_sample_t *sample) { + dt_lib_module_t *self = darktable.lib->proxy.colorpicker.module; + dt_lib_colorpicker_t *data = self->data; + if(event->button == 1) { sample->locked = !sample->locked; + data->target_sample = NULL; gtk_widget_queue_draw(widget); } else if(event->button == 3) { // copy to active picker - dt_lib_module_t *self = darktable.lib->proxy.colorpicker.module; dt_iop_color_picker_t *picker = darktable.lib->proxy.colorpicker.picker_proxy; + gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), TRUE); + // no active picker, too much iffy GTK work to activate a default if(!picker) return FALSE; @@ -469,6 +497,9 @@ static gboolean _live_sample_button(GtkWidget *widget, else return FALSE; + // Record the current sample to be the modified (copied) one + data->target_sample = sample; + if(picker->module) { picker->module->dev->preview_pipe->status = DT_DEV_PIXELPIPE_DIRTY; @@ -492,6 +523,8 @@ static void _add_sample(GtkButton *widget, dt_colorpicker_sample_t *sample = (dt_colorpicker_sample_t *)malloc(sizeof(dt_colorpicker_sample_t)); + data->target_sample = NULL; + memcpy(sample, &data->primary_sample, sizeof(dt_colorpicker_sample_t)); sample->locked = FALSE; From 6249e0f96822078b26a4d6bf1fb95906bcd1f4c2 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Mon, 24 Jun 2024 21:03:52 +0200 Subject: [PATCH 2/4] wip --- src/libs/colorpicker.c | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/libs/colorpicker.c b/src/libs/colorpicker.c index 1bbd0444d642..7d4744fcfca3 100644 --- a/src/libs/colorpicker.c +++ b/src/libs/colorpicker.c @@ -220,6 +220,7 @@ static gboolean _large_patch_toggle(GtkWidget *widget, static void _picker_button_toggled(GtkToggleButton *button, dt_lib_colorpicker_t *data) { + // If picker is active allow adding a sample const gboolean is_active = gtk_toggle_button_get_active(button); gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), is_active); @@ -488,7 +489,7 @@ static gboolean _live_sample_button(GtkWidget *widget, gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), TRUE); // no active picker, too much iffy GTK work to activate a default - if(!picker) return FALSE; + // if(!picker) return FALSE; if(sample->size == DT_LIB_COLORPICKER_SIZE_POINT) _set_sample_point(self, sample->point); @@ -497,10 +498,47 @@ static gboolean _live_sample_button(GtkWidget *widget, else return FALSE; + // We leaving the color-picker active mode and we have a target_sample + // recorded. In this case we want the target sample to be replaced by + // the current primay_sample. + const gboolean is_active = +// dt_bauhaus_widget_get_quad_active(data->picker_button); + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->picker_button)); + + printf("picker is active %d\n", is_active); + + if(0 && is_active && data->target_sample) + { + printf("===================> copy back sample\n"); + // Copy only the position & style for sample + memcpy(&data->target_sample->point, + &data->primary_sample.point, + sizeof(data->primary_sample.point)); + memcpy(&data->target_sample->box, + &data->primary_sample.box, + sizeof(data->primary_sample.box)); + // Size cannot be changed at this point, but in case this is done + // in the future. + data->target_sample->size = data->primary_sample.size; + + data->target_sample = NULL; + + // And now redisplay the new samples areas + gtk_widget_queue_draw(data->samples_container); + } + else if(!is_active) + { + printf("===================> record target sample\n"); + data->target_sample = sample; + darktable.lib->proxy.colorpicker.module = self; + } + + dt_bauhaus_widget_set_quad_active(data->picker_button, !is_active); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->picker_button), !is_active); + // Record the current sample to be the modified (copied) one - data->target_sample = sample; - if(picker->module) + if(picker && picker->module) { picker->module->dev->preview_pipe->status = DT_DEV_PIXELPIPE_DIRTY; } From 5eb84b3ecfa219441d3abc05336ad72d11427917 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Mon, 24 Jun 2024 22:44:33 +0200 Subject: [PATCH 3/4] wip --- src/libs/colorpicker.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/colorpicker.c b/src/libs/colorpicker.c index 7d4744fcfca3..13859425d480 100644 --- a/src/libs/colorpicker.c +++ b/src/libs/colorpicker.c @@ -224,11 +224,13 @@ static void _picker_button_toggled(GtkToggleButton *button, const gboolean is_active = gtk_toggle_button_get_active(button); gtk_widget_set_sensitive(GTK_WIDGET(data->add_sample_button), is_active); + printf("toggled... is button active %d\n", is_active); // We leaving the color-picker active mode and we have a target_sample // recorded. In this case we want the target sample to be replaced by // the current primay_sample. if(!is_active && data->target_sample) { + printf("... so copy back\n"); // Copy only the position & style for sample memcpy(&data->target_sample->point, &data->primary_sample.point, @@ -530,11 +532,13 @@ static gboolean _live_sample_button(GtkWidget *widget, { printf("===================> record target sample\n"); data->target_sample = sample; - darktable.lib->proxy.colorpicker.module = self; + // darktable.lib->proxy.colorpicker.module = self; } - dt_bauhaus_widget_set_quad_active(data->picker_button, !is_active); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->picker_button), !is_active); + g_signal_emit_by_name(G_OBJECT(data->picker_button), "toggled"); + // gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(data->picker_button)); + //dt_bauhaus_widget_set_quad_active(data->picker_button, !is_active); // Record the current sample to be the modified (copied) one From 7e0c2e18b9aa462b23327caf308e643898bd21cb Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Wed, 11 Sep 2024 21:57:46 +0200 Subject: [PATCH 4/4] not too bad, just the state of the picker seems buggy. we need to select it select the shape in it ctrl+click over an area and when this is done the picker MUST be active change size / position click back on the picker (= deselect it) the area should properly be recorded. --- src/libs/colorpicker.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libs/colorpicker.c b/src/libs/colorpicker.c index 13859425d480..1f3cdb8f6a97 100644 --- a/src/libs/colorpicker.c +++ b/src/libs/colorpicker.c @@ -1,6 +1,6 @@ /* This file is part of darktable, - Copyright (C) 2011-2023 darktable developers. + Copyright (C) 2011-2024 darktable developers. darktable is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -509,16 +509,22 @@ static gboolean _live_sample_button(GtkWidget *widget, printf("picker is active %d\n", is_active); - if(0 && is_active && data->target_sample) + if(is_active && data->target_sample) { printf("===================> copy back sample\n"); // Copy only the position & style for sample memcpy(&data->target_sample->point, &data->primary_sample.point, sizeof(data->primary_sample.point)); - memcpy(&data->target_sample->box, + memcpy(&darktable.lib->proxy.colorpicker.selected_sample->box, + //&data->target_sample->box, &data->primary_sample.box, sizeof(data->primary_sample.box)); + /* + memcpy(&darktable.lib->proxy.colorpicker.selected_sample->box, + &data->primary_sample.box, + sizeof(data->primary_sample.box)); + */ // Size cannot be changed at this point, but in case this is done // in the future. data->target_sample->size = data->primary_sample.size;