Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code for checking a module being in focus #18071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/develop/blend.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ void dt_develop_blend_process(dt_iop_module_t *self,
const dt_iop_roi_t *const roi_in,
const dt_iop_roi_t *const roi_out)
{
if(piece->pipe->bypass_blendif
&& self->dev->gui_attached
&& (self == self->dev->gui_module))
if(piece->pipe->bypass_blendif && dt_iop_has_focus(self))
return;

const dt_develop_blend_params_t *const d = piece->blendop_data;
Expand Down Expand Up @@ -545,10 +543,7 @@ void dt_develop_blend_process(dt_iop_module_t *self,
return;
}

const gboolean valid_request =
self->dev->gui_attached
&& (self == self->dev->gui_module)
&& (piece->pipe == self->dev->full.pipe);
const gboolean valid_request = dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe);

// does user want us to display a specific channel?
const dt_dev_pixelpipe_display_mask_t request_mask_display =
Expand Down Expand Up @@ -934,9 +929,7 @@ gboolean dt_develop_blend_process_cl(dt_iop_module_t *self,
const dt_iop_roi_t *roi_in,
const dt_iop_roi_t *roi_out)
{
if(piece->pipe->bypass_blendif
&& self->dev->gui_attached
&& (self == self->dev->gui_module))
if(piece->pipe->bypass_blendif && dt_iop_has_focus(self))
return TRUE;

dt_develop_blend_params_t *const d = piece->blendop_data;
Expand Down Expand Up @@ -971,10 +964,7 @@ gboolean dt_develop_blend_process_cl(dt_iop_module_t *self,
// only non-zero if mask_display was set by an _earlier_ module
const dt_dev_pixelpipe_display_mask_t mask_display = piece->pipe->mask_display;

const gboolean valid_request =
self->dev->gui_attached
&& (self == self->dev->gui_module)
&& (piece->pipe == self->dev->full.pipe);
const gboolean valid_request = dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe);

// does user want us to display a specific channel?
const dt_dev_pixelpipe_display_mask_t request_mask_display =
Expand Down
12 changes: 10 additions & 2 deletions src/develop/imageop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,15 @@ static gboolean _presets_scroll_callback(GtkWidget *widget,
return TRUE;
}

gboolean dt_iop_has_focus(const dt_iop_module_t *module)
{
return module
&& module->dev
&& module->dev->gui_attached
&& module == module->dev->gui_module
&& dt_dev_modulegroups_test_activated(darktable.develop);
}

void dt_iop_request_focus(dt_iop_module_t *module)
{
dt_develop_t *dev = darktable.develop;
Expand All @@ -2320,8 +2329,7 @@ void dt_iop_request_focus(dt_iop_module_t *module)
if(!darktable.lib->proxy.colorpicker.restrict_histogram)
dt_iop_color_picker_reset(NULL, TRUE);

if(darktable.gui->reset
|| (out_focus_module == module))
if(darktable.gui->reset || (out_focus_module == module))
return;

dev->gui_module = module;
Expand Down
2 changes: 2 additions & 0 deletions src/develop/imageop.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ GtkWidget *dt_iop_gui_header_button(dt_iop_module_t *module,

/** requests the focus for this plugin (to draw overlays over the center image) */
void dt_iop_request_focus(dt_iop_module_t *module);
/** returns TRUE if tested module has focus */
gboolean dt_iop_has_focus(const dt_iop_module_t *module);
/** allocate and load default settings from introspection. */
void dt_iop_default_init(dt_iop_module_t *module);
/** loads default settings from database. */
Expand Down
13 changes: 3 additions & 10 deletions src/iop/ashift.c
Original file line number Diff line number Diff line change
Expand Up @@ -4054,13 +4054,6 @@ static gboolean _get_points(dt_iop_module_t *self,
return FALSE;
}

// does this gui have focus?
static gboolean _gui_has_focus(dt_iop_module_t *self)
{
return (self->dev->gui_module == self
&& dt_dev_modulegroups_test_activated(darktable.develop));
}

/* this function replaces this sentence, it calls distort_transform()
for this module on the pipe
if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe,
Expand Down Expand Up @@ -4154,7 +4147,7 @@ void gui_post_expose(dt_iop_module_t *self,

// we draw the cropping area; we need x_off/y_off/width/height which is only available
// after g->buf has been processed
if(g->buf && self->enabled && _gui_has_focus(self))
if(g->buf && self->enabled && dt_iop_has_focus(self))
{
// roi data of the preview pipe input buffer

Expand Down Expand Up @@ -4354,7 +4347,7 @@ void gui_post_expose(dt_iop_module_t *self,
if(g->fitting) return;

// no structural data or visibility switched off? -> stop here
if(g->lines == NULL || !_gui_has_focus(self)) return;
if(g->lines == NULL || !dt_iop_has_focus(self)) return;

// get hash value that reflects distortions from here to the end of the pixelpipe
const dt_hash_t hash = dt_dev_hash_distort_plus(dev,
Expand Down Expand Up @@ -5630,7 +5623,7 @@ void commit_params(dt_iop_module_t *self,
d->orthocorr = (p->mode == ASHIFT_MODE_GENERIC) ? 0.0f : p->orthocorr;
d->aspect = (p->mode == ASHIFT_MODE_GENERIC) ? 1.0f : p->aspect;

if(_gui_has_focus(self)
if(dt_iop_has_focus(self)
|| dt_isnan(p->cl)
|| dt_isnan(p->cr)
|| dt_isnan(p->ct)
Expand Down
8 changes: 1 addition & 7 deletions src/iop/clipping.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
return IOP_CS_RGB;
}

static int gui_has_focus(dt_iop_module_t *self)
{
return (self->dev->gui_module == self
&& dt_dev_modulegroups_test_activated(darktable.develop));
}

static void keystone_get_matrix(const dt_boundingbox_t k_space, float kxa, float kxb, float kxc, float kxd, float kya,
float kyb, float kyc, float kyd, float *a, float *b, float *d, float *e,
float *g, float *h)
Expand Down Expand Up @@ -1328,7 +1322,7 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_
d->k_apply = 0;
}

if(gui_has_focus(self))
if(dt_iop_has_focus(self))
{
d->cx = 0.0f;
d->cy = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/iop/colorequal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ static gboolean _iop_colorequalizer_draw(GtkWidget *widget,

dt_free_align(g->LUT);

if(self->enabled && (self == self->dev->gui_module) && g->picking)
if(self->enabled && dt_iop_has_focus(self) && g->picking)
_draw_color_picker(self, cr, p, g, (double)graph_width, (double)graph_height);

cairo_restore(cr);
Expand Down
5 changes: 3 additions & 2 deletions src/iop/colorzones.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,9 @@ void process(dt_iop_module_t *self,
// display selection if requested
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
&& g
&& g->display_mask && self->dev->gui_attached
&& (self == self->dev->gui_module) && (piece->pipe == self->dev->full.pipe))
&& g->display_mask
&& dt_iop_has_focus(self)
&& (piece->pipe == self->dev->full.pipe))
process_display(self, piece, ivoid, ovoid, roi_in, roi_out);
else if(d->mode == DT_IOP_COLORZONES_MODE_SMOOTH)
process_v3(self, piece, ivoid, ovoid, roi_in, roi_out);
Expand Down
8 changes: 1 addition & 7 deletions src/iop/crop.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
return IOP_CS_RGB;
}

static int _gui_has_focus(dt_iop_module_t *self)
{
return (self->dev->gui_module == self
&& dt_dev_modulegroups_test_activated(darktable.develop));
}

static void _commit_box(dt_iop_module_t *self,
dt_iop_crop_gui_data_t *g,
dt_iop_crop_params_t *p)
Expand Down Expand Up @@ -421,7 +415,7 @@ void commit_params(dt_iop_module_t *self,
dt_iop_crop_params_t *p = (dt_iop_crop_params_t *)p1;
dt_iop_crop_data_t *d = piece->data;

if(_gui_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC))
if(dt_iop_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC))
{
d->cx = 0.0f;
d->cy = 0.0f;
Expand Down
24 changes: 9 additions & 15 deletions src/iop/retouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3860,9 +3860,7 @@ void process(dt_iop_module_t *self,
retouch_user_data_t usr_data = { 0 };
dwt_params_t *dwt_p = NULL;

const int gui_active = (self->dev) ? (self == self->dev->gui_module) : 0;
const gboolean display_wavelet_scale =
(g && gui_active) ? g->display_wavelet_scale : FALSE;
const gboolean display_wavelet_scale = g && dt_iop_has_focus(self) ? g->display_wavelet_scale : FALSE;

// we will do all the clone, heal, etc on the input image,
// this way the source for one algorithm can be the destination from a previous one
Expand All @@ -3881,8 +3879,7 @@ void process(dt_iop_module_t *self,
usr_data.mask_display = FALSE;
usr_data.suppress_mask = (g
&& g->suppress_mask
&& self->dev->gui_attached
&& (self == self->dev->gui_module)
&& dt_iop_has_focus(self)
&& (piece->pipe == self->dev->full.pipe));
usr_data.display_scale = p->curr_scale;

Expand All @@ -3898,8 +3895,8 @@ void process(dt_iop_module_t *self,

// check if this module should expose mask.
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL) && g
&& (g->mask_display || display_wavelet_scale) && self->dev->gui_attached
&& (self == self->dev->gui_module) && (piece->pipe == self->dev->full.pipe))
&& (g->mask_display || display_wavelet_scale)
&& dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe))
{
for(size_t j = 0; j < (size_t)roi_rt->width * roi_rt->height * 4; j += 4)
in_retouch[j + 3] = 0.f;
Expand All @@ -3913,7 +3910,7 @@ void process(dt_iop_module_t *self,
if(piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
{
// check if the image support this number of scales
if(gui_active)
if(dt_iop_has_focus(self))
{
const int max_scales = dwt_get_max_scale(dwt_p);
if(dwt_p->scales > max_scales)
Expand Down Expand Up @@ -4671,8 +4668,7 @@ int process_cl(dt_iop_module_t *self,
retouch_user_data_t usr_data = { 0 };
dwt_params_cl_t *dwt_p = NULL;

const gboolean gui_active = (self->dev) ? (self == self->dev->gui_module) : FALSE;
const gboolean display_wavelet_scale = g && gui_active ? g->display_wavelet_scale : FALSE;
const gboolean display_wavelet_scale = g && dt_iop_has_focus(self) ? g->display_wavelet_scale : FALSE;

// we will do all the clone, heal, etc on the input image, this way
// the source for one algorithm can be the destination from a
Expand All @@ -4696,8 +4692,7 @@ int process_cl(dt_iop_module_t *self,
usr_data.mask_display = FALSE;
usr_data.suppress_mask = (g
&& g->suppress_mask
&& self->dev->gui_attached
&& (self == self->dev->gui_module)
&& dt_iop_has_focus(self)
&& (piece->pipe == self->dev->full.pipe));
usr_data.display_scale = p->curr_scale;

Expand All @@ -4718,8 +4713,7 @@ int process_cl(dt_iop_module_t *self,
// check if this module should expose mask.
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
&& g && g->mask_display
&& self->dev->gui_attached
&& (self == self->dev->gui_module)
&& dt_iop_has_focus(self)
&& (piece->pipe == self->dev->full.pipe))
{
const int kernel = gd->kernel_retouch_clear_alpha;
Expand All @@ -4738,7 +4732,7 @@ int process_cl(dt_iop_module_t *self,
if(piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
{
// check if the image support this number of scales
if(gui_active)
if(dt_iop_has_focus(self))
{
const int max_scales = dwt_get_max_scale_cl(dwt_p);
if(dwt_p->scales > max_scales)
Expand Down
Loading