Skip to content
Merged
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
19 changes: 15 additions & 4 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3093,10 +3093,19 @@ _dev_mask_overlay_bounds(const dt_develop_t *dev, float *x0, float *y0, float *x
if(!gpt)
continue;

// points[], border[] and source[] are interleaved (x, y) pairs
const float *const arrays[3] = { gpt->points, gpt->border, gpt->source };
const int counts[3] = { gpt->points_count, gpt->border_count, gpt->source_count };
for(int a = 0; a < 3; a++)
// points[] (shape outline) and source[] (clone source) are interleaved
// (x, y) pairs. The feather border[] is deliberately excluded: it is not a
// drag target, so it shouldn't enlarge the pannable region, and its
// degenerate segments are flagged with DT_INVALID_COORDINATE (== -FLT_MAX)
// sentinels. Folding those (or any other stray non-finite / extreme value)
// into the box would blow it up to ~1e35 and let the viewport pan away from
// the image without bound. Reject anything outside a generous window around
// the image (32x its size — far more than any reachable handle) so a single
// bad coordinate can't defeat the clamp.
const float *const arrays[2] = { gpt->points, gpt->source };
const int counts[2] = { gpt->points_count, gpt->source_count };
const float limx = 32.0f * wd, limy = 32.0f * ht;
for(int a = 0; a < 2; a++)
{
const float *p = arrays[a];
if(!p)
Expand All @@ -3105,6 +3114,8 @@ _dev_mask_overlay_bounds(const dt_develop_t *dev, float *x0, float *y0, float *x
{
const float px = p[i * 2];
const float py = p[i * 2 + 1];
if(!isfinite(px) || !isfinite(py) || px <= -limx || px >= limx || py <= -limy || py >= limy)
continue;
minx = fminf(minx, px);
maxx = fmaxf(maxx, px);
miny = fminf(miny, py);
Expand Down
7 changes: 7 additions & 0 deletions src/develop/masks.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,13 @@ void dt_masks_gui_form_create(dt_masks_form_t *form,
void dt_masks_gui_form_remove(dt_masks_form_t *form,
dt_masks_form_gui_t *gui,
const int index);
// Constrain a drag target (in preview/processed-pipe pixel coords, wd/ht =
// processed image size) so it stays within the image expanded by
// DT_MASKS_MOVE_MARGIN. Used when translating a whole form / its anchor / clone
// source so the dragged control point stays within the image or reasonably
// close, instead of being movable to an arbitrary distance where the shape
// would be lost.
void dt_masks_clamp_move_pts(float *pts, const float wd, const float ht);
void dt_masks_gui_form_test_create(dt_masks_form_t *form,
dt_masks_form_gui_t *gui,
const struct dt_iop_module_t *module);
Expand Down
3 changes: 3 additions & 0 deletions src/develop/masks/brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@ static int _brush_events_button_released(dt_iop_module_t *module,
// we get point0 new values
dt_masks_point_brush_t *point = (form->points)->data;
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
float dx = pts[0] / iwidth - point->corner[0];
float dy = pts[1] / iheight - point->corner[1];
Expand Down Expand Up @@ -2171,6 +2172,7 @@ static int _brush_events_button_released(dt_iop_module_t *module,

// we change the source value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
form->source[0] = pts[0] / iwidth;
form->source[1] = pts[1] / iheight;
Expand Down Expand Up @@ -2546,6 +2548,7 @@ static int _brush_events_mouse_moved(struct dt_iop_module_t *module,
else if(gui->form_dragging || gui->source_dragging)
{
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

// we move all points
Expand Down
3 changes: 3 additions & 0 deletions src/develop/masks/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ static int _circle_events_button_released(dt_iop_module_t *module,

// we change the center value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
circle->center[0] = pts[0] / iwidth;
circle->center[1] = pts[1] / iheight;
Expand Down Expand Up @@ -470,6 +471,7 @@ static int _circle_events_button_released(dt_iop_module_t *module,
{
// we change the center value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);

dt_dev_distort_backtransform(darktable.develop, pts, 1);

Expand Down Expand Up @@ -523,6 +525,7 @@ static int _circle_events_mouse_moved(dt_iop_module_t *module,
float wd, ht, iwidth, iheight;
dt_masks_get_image_size(&wd, &ht, &iwidth, &iheight);
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

if(gui->form_dragging)
Expand Down
3 changes: 3 additions & 0 deletions src/develop/masks/ellipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ static int _ellipse_events_button_released(dt_iop_module_t *module,

// we change the center value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
ellipse->center[0] = pts[0] / iwidth;
ellipse->center[1] = pts[1] / iheight;
Expand Down Expand Up @@ -1012,6 +1013,7 @@ static int _ellipse_events_button_released(dt_iop_module_t *module,
{
// we change the center value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);

dt_dev_distort_backtransform(darktable.develop, pts, 1);

Expand Down Expand Up @@ -1057,6 +1059,7 @@ static int _ellipse_events_mouse_moved(dt_iop_module_t *module,
float wd, ht, iwidth, iheight;
dt_masks_get_image_size(&wd, &ht, &iwidth, &iheight);
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

if(gui->form_dragging)
Expand Down
2 changes: 2 additions & 0 deletions src/develop/masks/gradient.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ static int _gradient_events_button_released(dt_iop_module_t *module,

// we change the center value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

gradient->anchor[0] = pts[0] / iwidth;
Expand Down Expand Up @@ -558,6 +559,7 @@ static int _gradient_events_mouse_moved(dt_iop_module_t *module,
dt_masks_get_image_size(&wd, &ht, &iwidth, &iheight);

float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

gradient->anchor[0] = pts[0] / iwidth;
Expand Down
12 changes: 12 additions & 0 deletions src/develop/masks/masks.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ void dt_masks_gui_form_remove(dt_masks_form_t *form,
}
}

// Maximum fraction of the image dimension by which a dragged mask node /
// anchor / clone source may be pushed outside the image.
#define DT_MASKS_MOVE_MARGIN 0.5f

void dt_masks_clamp_move_pts(float *pts, const float wd, const float ht)
{
const float mx = DT_MASKS_MOVE_MARGIN * wd;
const float my = DT_MASKS_MOVE_MARGIN * ht;
pts[0] = fminf(fmaxf(pts[0], -mx), wd + mx);
pts[1] = fminf(fmaxf(pts[1], -my), ht + my);
}

void dt_masks_gui_form_test_create(dt_masks_form_t *form,
dt_masks_form_gui_t *gui,
const dt_iop_module_t *module)
Expand Down
3 changes: 3 additions & 0 deletions src/develop/masks/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,7 @@ static int _path_events_button_released(dt_iop_module_t *module,
// we get point0 new values
dt_masks_point_path_t *point = form->points->data;
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
const float dx = pts[0] / iwidth - point->corner[0];
const float dy = pts[1] / iheight - point->corner[1];
Expand Down Expand Up @@ -3571,6 +3572,7 @@ static int _path_events_button_released(dt_iop_module_t *module,

// we change the source value
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);
form->source[0] = pts[0] / iwidth;
form->source[1] = pts[1] / iheight;
Expand Down Expand Up @@ -3823,6 +3825,7 @@ static int _path_events_mouse_moved(dt_iop_module_t *module,
else if(gui->form_dragging || gui->source_dragging)
{
float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy };
dt_masks_clamp_move_pts(pts, wd, ht);
dt_dev_distort_backtransform(darktable.develop, pts, 1);

// we move all points
Expand Down
73 changes: 72 additions & 1 deletion src/libs/navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,68 @@ void gui_cleanup(dt_lib_module_t *self)
self->data = NULL;
}

// Draw a small arrow on the thumbnail border pointing toward the viewport
// centre when it has been panned outside the image (e.g. reaching off-image
// mask handles), where the view box would otherwise shrink to nothing and
// vanish. Expects the current transform to map the thumbnail image to
// [0,wd]x[0,ht]; scale is that transform's scale (to keep the outline 1px).
static void _draw_offview_arrow(cairo_t *cr,
const int wd,
const int ht,
const float zoom_x,
const float zoom_y,
const float scale)
{
const float cx = wd * (0.5f + zoom_x);
const float cy = ht * (0.5f + zoom_y);
if(cx >= 0.0f && cx <= wd && cy >= 0.0f && cy <= ht)
return; // view centre still inside the thumbnail: the box itself suffices

const float ox = 0.5f * wd, oy = 0.5f * ht;
float dx = cx - ox, dy = cy - oy;
const float dlen = hypotf(dx, dy);
if(dlen <= 1e-3f)
return;

dx /= dlen;
dy /= dlen;
// where the centre->view ray exits the image rectangle
float t = 1e9f;
if(dx > 0.0f)
t = fminf(t, (wd - ox) / dx);
else if(dx < 0.0f)
t = fminf(t, (0.0f - ox) / dx);
if(dy > 0.0f)
t = fminf(t, (ht - oy) / dy);
else if(dy < 0.0f)
t = fminf(t, (0.0f - oy) / dy);
t = fmaxf(0.0f, t);

// Draw a chevron ( ">" shape ) whose apex points outward along the view
// direction: an open two-armed stroke reads its direction more clearly than
// a solid triangle.
const float a = fminf(wd, ht) * 0.08f; // chevron reach in thumbnail units
const float tipx = ox + dx * t - dx * a * 0.3f; // apex just inside the border
const float tipy = oy + dy * t - dy * a * 0.3f;
const float perpx = -dy, perpy = dx;
const float spread = a * 0.85f; // half-width of the arms (~90 deg opening)
const float ax1 = tipx - dx * a + perpx * spread, ay1 = tipy - dy * a + perpy * spread;
const float ax2 = tipx - dx * a - perpx * spread, ay2 = tipy - dy * a - perpy * spread;

cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
cairo_move_to(cr, ax1, ay1);
cairo_line_to(cr, tipx, tipy);
cairo_line_to(cr, ax2, ay2);
// dark halo first, then a white core, so it reads on any background
cairo_set_source_rgba(cr, 0., 0., 0., 0.7);
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(4) / scale);
cairo_stroke_preserve(cr);
cairo_set_source_rgb(cr, 1., 1., 1.);
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(2) / scale);
cairo_stroke(cr);
}

static gboolean _lib_navigation_draw_callback(GtkWidget *widget,
cairo_t *crf,
gpointer user_data)
Expand Down Expand Up @@ -358,7 +420,10 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget,
cairo_set_source_rgba(cr, 0, 0, 0, 0.5);
cairo_fill(cr);

// Repaint the original image in the area of interest
// Repaint the original image in the area of interest. Isolate the box
// clip/translate in its own save so the off-view arrow below is drawn in
// plain thumbnail coordinates.
cairo_save(cr);
cairo_set_source_surface(cr, surface, 0, 0);
cairo_translate(cr, wd * (.5f + zoom_x), ht * (.5f + zoom_y));
boxw *= wd;
Expand All @@ -376,6 +441,12 @@ static gboolean _lib_navigation_draw_callback(GtkWidget *widget,
cairo_set_source_rgb(cr, 1., 1., 1.);
cairo_rectangle(cr, -boxw / 2, -boxh / 2, boxw, boxh);
cairo_stroke(cr);
cairo_restore(cr);

// While editing a mask the viewport can be panned outside the image; the
// view box then shrinks against the thumbnail edge and disappears, losing
// any sense of where one is looking. Point an arrow the way it has gone.
_draw_offview_arrow(cr, wd, ht, zoom_x, zoom_y, scale);
}
cairo_restore(cr);

Expand Down
45 changes: 32 additions & 13 deletions src/views/darkroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,24 +706,39 @@ void expose(dt_view_t *self,
force a resizing in next expose. So we disable in cases close
to full.

This near-fit centring is applied only to the values handed to the
scrollbar; the real zoom_x/zoom_y are kept for rendering so the mask
overlay (and guides/pickers) follow the image exactly even when the
user has deliberately panned off-canvas below the fit zoom to reach
mask handles outside the image. Zeroing them here would pin the
overlay at the image centre while the image itself (and raster mask
overlay) follow the pan, breaking alignment below fit.
The scrollbar always gets this near-fit centring (sb_zoom_*). The real
zoom_x/zoom_y feeding the overlay coordinate frame below are kept
un-centred ONLY while a mask is being edited: there the user may
deliberately pan off-canvas below the fit zoom to reach mask handles
outside the image, and zeroing them would pin the overlay at the image
centre while the image itself (and raster mask overlay) follow the pan,
breaking alignment. When no mask is being edited we centre them exactly
as darktable did before the off-canvas panning was added, so guides,
colour pickers and the crop module's dimming can't drift off the image
on a nonzero stored viewport centre -- e.g. entering the crop module
shows the uncropped image, reprojecting port->zoom_x against the larger
processed size into a nonzero centre that would otherwise shift the crop
overlay into a grey band beside the picture.
*/
// Mask editing (including creation) is the only state that relaxes the pan
// clamp to allow the viewport past the image; it is disabled while the crop
// overlay is active, so form_visible is NULL there.
const gboolean mask_editing = dev->form_visible != NULL;

float sb_zoom_x = zoom_x, sb_zoom_y = zoom_y, sb_boxw = boxw, sb_boxh = boxh;
if(boxw > 0.95f)
{
sb_zoom_x = .0f;
sb_boxw = 1.01f;
if(!mask_editing)
zoom_x = .0f;
}
if(boxh > 0.95f)
{
sb_zoom_y = .0f;
sb_boxh = 1.01f;
if(!mask_editing)
zoom_y = .0f;
}

dt_view_set_scrollbar(self,
Expand Down Expand Up @@ -1010,13 +1025,17 @@ void expose(dt_view_t *self,
"expose masks",
port->pipe, dev->gui_module, DT_DEVICE_NONE, NULL, NULL, "%dx%d, px=%d py=%d",
width, height, pointerx, pointery);
// Clip to viewport (excluding border) so mask overlays don't
// bleed into the grey border when the image is zoomed in.
// Clip the mask overlay to the full viewport. Mask control points can be
// placed outside the image, in the expanded grey canvas around it; insetting
// the clip by the grey border (tb) as we used to would hide those off-image
// handles and segments behind an invisible border a few pixels in from the
// window edge. The grey-border containment the inset provided no longer
// applies now that masks legitimately extend past the image.
cairo_save(cri);
const float vp_w = (width - 2.0f * tb) / zoom_scale;
const float vp_h = (height - 2.0f * tb) / zoom_scale;
const float vp_x = (tb - 0.5f * width) / zoom_scale + 0.5f * wd + zoom_x * wd;
const float vp_y = (tb - 0.5f * height) / zoom_scale + 0.5f * ht + zoom_y * ht;
const float vp_w = width / zoom_scale;
const float vp_h = height / zoom_scale;
const float vp_x = -0.5f * width / zoom_scale + 0.5f * wd + zoom_x * wd;
const float vp_y = -0.5f * height / zoom_scale + 0.5f * ht + zoom_y * ht;
cairo_rectangle(cri, vp_x, vp_y, vp_w, vp_h);
cairo_clip(cri);
// Mask overlay points are in preview-pipe output space; shift the
Expand Down
Loading
Loading