8000 Better calculation of cropped UI output dimension by jenshannoschwalm · Pull Request #18785 · darktable-org/darktable · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Better calculation of cropped UI output dimension #18785

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

Merged
merged 2 commits into from
May 10, 2025
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
11 changes: 6 additions & 5 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2475,21 +2475,21 @@ gboolean dt_dev_get_preview_size(const dt_develop_t *dev,
return *wd >= 1.f && *ht >= 1.f;
}

void dt_dev_get_processed_size(dt_dev_viewport_t *port,
int *procw,
int *proch)
gboolean dt_dev_get_processed_size(dt_dev_viewport_t *port,
int *procw,
int *proch)
{
// no processed pipes, lets return 0 size
*procw = *proch = 0;

if(!port) return;
if(!port) return FALSE;

// if pipe is processed, lets return its size
if(port->pipe && port->pipe->processed_width)
{
*procw = port->pipe->processed_width;
*proch = port->pipe->processed_height;
return;
return TRUE;
}

dt_develop_t *dev = darktable.develop;
Expand All @@ -2501,6 +2501,7 @@ void dt_dev_get_processed_size(dt_dev_viewport_t *port,
*procw = scale * dev->preview_pipe->processed_width;
*proch = scale * dev->preview_pipe->processed_height;
}
return FALSE;
}

static float _calculate_new_scroll_zoom_tscale(const int up,
Expand Down
7 changes: 4 additions & 3 deletions src/develop/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,10 @@ void dt_dev_reprocess_preview(dt_develop_t *dev);
gboolean dt_dev_get_preview_size(const dt_develop_t *dev,
float *wd,
float *ht);
void dt_dev_get_processed_size(dt_dev_viewport_t *port,
int *procw,
int *proch);
// return TRUE in case we got it from current port instead of preview
gboolean dt_dev_get_processed_size(dt_dev_viewport_t *port,
int *procw,
int *proch);
gboolean dt_dev_get_zoom_bounds(dt_dev_viewport_t *port,
float *zoom_x,
float *zoom_y,
Expand Down
38 changes: 18 additions & 20 deletions src/iop/crop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,25 +1418,26 @@ void gui_post_expose(dt_iop_module_t *self,
if(dimmed) return;

// draw cropping window dimensions if first mouse button is pressed
if(darktable.control->button_down && darktable.control->button_down_which == 1)
if(darktable.control->button_down && darktable.control->button_down_which == GDK_BUTTON_PRIMARY)
{
char dimensions[16];
char dimensions[64];
dimensions[0] = '\0';
PangoLayout *layout;
PangoRectangle ext;
PangoFontDescription *desc =
pango_font_description_copy_static(darktable.bauhaus->pango_font_desc);
pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
pango_font_description_set_absolute_size
(desc,
DT_PIXEL_APPLY_DPI(16) * PANGO_SCALE / zoom_scale);
pango_font_description_set_absolute_size(desc, DT_PIXEL_APPLY_DPI(16) * PANGO_SCALE / zoom_scale);
layout = pango_cairo_create_layout(cr);
pango_layout_set_font_description(layout, desc);

int procw, proch;
dt_dev_get_processed_size(&dev->full, &procw, &proch);
snprintf(dimensions, sizeof(dimensions),
"%i x %i", (int)(0.5f + procw * g->clip_w), (int)(0.5f + proch * g->clip_h));
const gboolean exact = dt_dev_get_processed_size(&dev->full, &procw, &proch);
const int dx = floorf(procw * g->clip_w);
const int dy = floorf(proch * g->clip_h);
snprintf(dimensions, sizeof(dimensions), "%s%d x %d", exact ? "" : "~ ", dx, dy);
dt_print(DT_DEBUG_VERBOSE, "reported crop dimension: %s%d x %d",
exact ? "" : "~ ", dx, dy);

pango_layout_set_text(layout, dimensions, -1);
pango_layout_get_pixel_extents(layout, NULL, &ext);
Expand All @@ -1454,8 +1455,7 @@ void gui_post_expose(dt_iop_module_t *self,
yp = CLAMP(yp, y1 + 2.0 * margin, y2 - text_h - 2.0 * margin);

cairo_set_source_rgba(cr, .5, .5, .5, .9);
dt_gui_draw_rounded_rectangle
(cr, text_w + 2 * margin, text_h + 2 * margin, xp - margin, yp - margin);
dt_gui_draw_rounded_rectangle(cr, text_w + 2 * margin, text_h + 2 * margin, xp - margin, yp - margin);
cairo_set_source_rgb(cr, .7, .7, .7);
cairo_move_to(cr, xp, yp);
pango_cairo_show_layout(cr, layout);
Expand Down Expand Up @@ -1537,7 +1537,7 @@ int mouse_moved(dt_iop_module_t *self,

_set_max_clip(self);

if(darktable.control->button_down && darktable.control->button_down_which == 1)
if(darktable.control->button_down && darktable.control->button_down_which == GDK_BUTTON_PRIMARY)
{
// draw a light gray frame, to show it's not stored yet:
// first mouse button, adjust cropping frame, but what do we do?
Expand All @@ -1548,14 +1548,12 @@ int mouse_moved(dt_iop_module_t *self,
{
/* moving the crop window */
if(!g->shift_hold)
g->clip_x
= fminf(g->clip_max_w + g->clip_max_x - g->clip_w,
fmaxf(g->clip_max_x, g->handle_x + pzx - bzx));
g->clip_x = MIN(g->clip_max_w + g->clip_max_x - g->clip_w,
MAX(g->clip_max_x, g->handle_x + pzx - bzx));

if(!g->ctrl_hold)
g->clip_y
= fminf(g->clip_max_h + g->clip_max_y - g->clip_h,
fmaxf(g->clip_max_y, g->handle_y + pzy - bzy));
g->clip_y = MIN(g->clip_max_h + g->clip_max_y - g->clip_h,
MAX(g->clip_max_y, g->handle_y + pzy - bzy));
}
else if(g->cropping == GRAB_NONE)
return 0;
Expand Down Expand Up @@ -1734,10 +1732,10 @@ int button_pressed(dt_iop_module_t *self,
if(!g->preview_ready) return 0;

// avoid unexpected back to lt mode:
if(type == GDK_2BUTTON_PRESS && which == 1)
if(type == GDK_2BUTTON_PRESS && which == GDK_BUTTON_PRIMARY)
return 1;

if(which == 1)
if(which == GDK_BUTTON_PRIMARY)
{
float wd, ht;
dt_dev_get_preview_size(self->dev, &wd, &ht);
Expand Down Expand Up @@ -1779,7 +1777,7 @@ int button_pressed(dt_iop_module_t *self,

return 1;
}
else if(which == 3)
else if(which == GDK_BUTTON_SECONDARY)
{
// we reset cropping
g->clip_x = 0.0f;
Expand Down
Loading
0