Skip to content

Commit 6fe9931

Browse files
Minor crop maintenance and a UI bugfix
We must call gui_changed() at the end of gui_update() to ensure a new history if parameters changed, UI symptoms possible were subtly wrong slider soft min/max. While checking some minor cleanup - g->cropping should be _grab_region_t instead of int and be initialized as that - deduplicate updating sliders in _update_sliders_and_limit()
1 parent a2bea12 commit 6fe9931

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

src/iop/crop.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ typedef struct dt_iop_crop_gui_data_t
102102
float clip_max_x, clip_max_y, clip_max_w, clip_max_h;
103103
dt_hash_t clip_max_pipe_hash;
104104

105-
int cropping;
105+
_grab_region_t cropping;
106106
gboolean shift_hold;
107107
gboolean ctrl_hold;
108108
gboolean preview_ready;
@@ -179,7 +179,7 @@ static void _commit_box(dt_iop_module_t *self,
179179
if(darktable.gui->reset) return;
180180
if(self->dev->preview_pipe->status != DT_DEV_PIXELPIPE_VALID) return;
181181

182-
g->cropping = 0;
182+
g->cropping = GRAB_CENTER;
183183
const dt_boundingbox_t old = { p->cx, p->cy, p->cw, p->ch };
184184
const float eps = 1e-6f; // threshold to avoid rounding errors
185185
if(!self->enabled)
@@ -952,6 +952,18 @@ static void _event_aspect_presets_changed(GtkWidget *combo, dt_iop_module_t *sel
952952
--darktable.gui->reset;
953953
}
954954

955+
static void _update_sliders_and_limit(dt_iop_crop_gui_data_t *g)
956+
{
957+
dt_bauhaus_slider_set(g->cx, g->clip_x);
958+
dt_bauhaus_slider_set(g->cy, g->clip_y);
959+
dt_bauhaus_slider_set(g->cw, g->clip_x + g->clip_w);
960+
dt_bauhaus_slider_set(g->ch, g->clip_y + g->clip_h);
961+
dt_bauhaus_slider_set_soft_max(g->cx, g->clip_x + g->clip_w - 0.1f);
962+
dt_bauhaus_slider_set_soft_max(g->cy, g->clip_y + g->clip_h - 0.1f);
963+
dt_bauhaus_slider_set_soft_min(g->ch, g->clip_y + 0.1f);
964+
dt_bauhaus_slider_set_soft_min(g->cw, g->clip_x + 0.1f);
965+
}
966+
955967
void gui_changed(dt_iop_module_t *self, GtkWidget *w, void *previous)
956968
{
957969
dt_iop_crop_gui_data_t *g = self->gui_data;
@@ -983,14 +995,7 @@ void gui_changed(dt_iop_module_t *self, GtkWidget *w, void *previous)
983995
}
984996

985997
// update all sliders, as their values may have change to keep aspect ratio
986-
dt_bauhaus_slider_set(g->cx, g->clip_x);
987-
dt_bauhaus_slider_set_soft_min(g->cw, g->clip_x + 0.10);
988-
dt_bauhaus_slider_set(g->cy, g->clip_y);
989-
dt_bauhaus_slider_set_soft_min(g->ch, g->clip_y + 0.10);
990-
dt_bauhaus_slider_set(g->cw, g->clip_x + g->clip_w);
991-
dt_bauhaus_slider_set_soft_max(g->cx, g->clip_x + g->clip_w - 0.10);
992-
dt_bauhaus_slider_set(g->ch, g->clip_y + g->clip_h);
993-
dt_bauhaus_slider_set_soft_max(g->cy, g->clip_y + g->clip_h - 0.10);
998+
_update_sliders_and_limit(g);
994999

9951000
--darktable.gui->reset;
9961001

@@ -1058,6 +1063,7 @@ void gui_update(dt_iop_module_t *self)
10581063
g->clip_h = p->ch - p->cy;
10591064

10601065
dt_gui_update_collapsible_section(&g->cs);
1066+
gui_changed(self, NULL, NULL);
10611067
}
10621068

10631069
static void _event_key_swap(dt_iop_module_t *self)
@@ -1454,8 +1460,7 @@ void gui_post_expose(dt_iop_module_t *self,
14541460
}
14551461

14561462
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2.0) / zoom_scale);
1457-
const double alpha =
1458-
CLAMP(1.0 - (g_get_monotonic_time() - g->focus_time) / 2e6f, 0.0, 1.0);
1463+
const double alpha = CLIP(1.0 - (g_get_monotonic_time() - g->focus_time) / 2e6f);
14591464
dt_draw_set_color_overlay(cr, TRUE, alpha);
14601465
const double border = DT_PIXEL_APPLY_DPI(MIN(30.0, MIN(wd, ht) / 3.0)) / zoom_scale;
14611466

@@ -1640,16 +1645,7 @@ int mouse_moved(dt_iop_module_t *self,
16401645
// clipping parameters get set from the sliders when the iop loses
16411646
// focus, at which time the final selected crop is applied.
16421647
++darktable.gui->reset;
1643-
1644-
dt_bauhaus_slider_set(g->cx, g->clip_x);
1645-
dt_bauhaus_slider_set_soft_min(g->cw, g->clip_x + 0.10);
1646-
dt_bauhaus_slider_set(g->cy, g->clip_y);
1647-
dt_bauhaus_slider_set_soft_min(g->ch, g->clip_y + 0.10);
1648-
dt_bauhaus_slider_set(g->cw, g->clip_x + g->clip_w);
1649-
dt_bauhaus_slider_set_soft_max(g->cx, g->clip_x + g->clip_w - 0.10);
1650-
dt_bauhaus_slider_set(g->ch, g->clip_y + g->clip_h);
1651-
dt_bauhaus_slider_set_soft_max(g->cy, g->clip_y + g->clip_h - 0.10);
1652-
1648+
_update_sliders_and_limit(g);
16531649
--darktable.gui->reset;
16541650

16551651
dt_control_queue_redraw_center();

0 commit comments

Comments
 (0)