From 0fbdff32e0c72bd907ba50dc1a31c42140be58ef Mon Sep 17 00:00:00 2001 From: John Bell Date: Sun, 23 Jun 2024 09:32:30 -0700 Subject: [PATCH] When implementing height limits on modules, the histogram container was also limited. This is not desirable, though, since screens with high resolution make the histogram small and hard to read, particularly when using the scope. This commit fixes this by doing two things: 1) Making functions auto-detect whether they should use height or aspect ratio to manage the container size by checking whether the passed "config_str" variable refers to height or aspect ratio -- Note: this is actually safer anyway, since it was perfectly possible before to pass an AR request to a height function 2) Changing the histogram back to using aspect ratio instead of height --- src/gui/gtk.c | 72 +++++++++++++++++++++++++++++++++----------- src/gui/gtk.h | 3 ++ src/libs/histogram.c | 2 +- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/gui/gtk.c b/src/gui/gtk.c index 6808a1c41201..25fce7c7e9a0 100644 --- a/src/gui/gtk.c +++ b/src/gui/gtk.c @@ -3739,19 +3739,38 @@ static gboolean _resize_wrap_scroll(GtkScrolledWindow *sw, return TRUE; } -static gboolean _scroll_wrap_height(GtkWidget *w, - GdkEventScroll *event, - const char *config_str) +gboolean _config_uses_height(const char *config_str) { + // Determine whether to use height or aspect ratio based on config_str + if(g_str_has_suffix(config_str, "graphheight")) { + return TRUE; + } + + return FALSE; +} + +static gboolean _scroll_wrap(GtkWidget *w, + GdkEventScroll *event, + const char *config_str) +{ + const gboolean use_height = _config_uses_height(config_str); + if(dt_modifier_is(event->state, GDK_SHIFT_MASK | GDK_MOD1_MASK)) { int delta_y; if(dt_gui_get_scroll_unit_delta(event, &delta_y)) { - //adjust height - const int height = dt_conf_get_int(config_str) + delta_y; - dt_conf_set_int(config_str, height); - dtgtk_drawing_area_set_height(w, height); + if(use_height) { + //adjust height + const int height = dt_conf_get_int(config_str) + delta_y; + dt_conf_set_int(config_str, height); + dtgtk_drawing_area_set_height(w, height); + } else { + //adjust aspect + const int aspect = dt_conf_get_int(config_str); + dt_conf_set_int(config_str, aspect + delta_y); + dtgtk_drawing_area_set_aspect_ratio(w, aspect / 100.0); + } } return TRUE; } @@ -3787,14 +3806,22 @@ static gboolean _resize_wrap_motion(GtkWidget *widget, GdkEventMotion *event, const char *config_str) { + const gboolean use_height = _config_uses_height(config_str); + if(_resize_wrap_dragging) { if(DTGTK_IS_DRAWING_AREA(widget)) { // enforce configuration limits - dt_conf_set_int(config_str, event->y); - const int height = dt_conf_get_int(config_str); - dtgtk_drawing_area_set_height(widget, height); + if(use_height) { + dt_conf_set_int(config_str, event->y); + dtgtk_drawing_area_set_height(widget, event->y); + } else { + dt_conf_set_int(config_str, + 100.0 * event->y / gtk_widget_get_allocated_width(widget)); + const float aspect = dt_conf_get_int(config_str); + dtgtk_drawing_area_set_aspect_ratio(widget, aspect / 100.0); + } } else { @@ -3860,20 +3887,31 @@ GtkWidget *dt_ui_resize_wrap(GtkWidget *w, const gint min_size, char *config_str) { - if(!w) - w = dtgtk_drawing_area_new_with_height(min_size); + const gboolean use_height = _config_uses_height(config_str); + + if(!w) { + if(use_height) + w = dtgtk_drawing_area_new_with_height(min_size); + else + w = dtgtk_drawing_area_new_with_aspect_ratio(1.0); + } gtk_widget_set_has_tooltip(w, TRUE); g_object_set_data(G_OBJECT(w), "scroll-resize-tooltip", GINT_TO_POINTER(TRUE)); if(DTGTK_IS_DRAWING_AREA(w)) { - const float height = dt_conf_get_int(config_str); - dtgtk_drawing_area_set_height(w, height); + if(use_height) { + const int height = dt_conf_get_int(config_str); + dtgtk_drawing_area_set_height(w, height); + } else { + const float aspect = dt_conf_get_int(config_str); + dtgtk_drawing_area_set_aspect_ratio(w, aspect / 100.0); + } g_signal_connect(G_OBJECT(w), - "scroll-event", - G_CALLBACK(_scroll_wrap_height), - config_str); + "scroll-event", + G_CALLBACK(_scroll_wrap), + config_str); } else { diff --git a/src/gui/gtk.h b/src/gui/gtk.h index 08b9179f5d4d..86ca554344bc 100644 --- a/src/gui/gtk.h +++ b/src/gui/gtk.h @@ -461,6 +461,9 @@ guint dt_gui_translated_key_state(GdkEventKey *event); // return modifier keys currently pressed, independent of any key event GdkModifierType dt_key_modifier_state(); +// check if the given config_str is asking for height or aspect ratio configuration +gboolean _config_uses_height(const char *config_str); + GtkWidget *dt_ui_resize_wrap(GtkWidget *w, const gint min_size, char *config_str); diff --git a/src/libs/histogram.c b/src/libs/histogram.c index 13715f689bdc..a833805ccc6b 100644 --- a/src/libs/histogram.c +++ b/src/libs/histogram.c @@ -2605,7 +2605,7 @@ void gui_init(dt_lib_module_t *self) // shows the scope, scale, and has draggable areas d->scope_draw = dt_ui_resize_wrap(NULL, 0, - "plugins/darkroom/histogram/graphheight"); + "plugins/darkroom/histogram/aspect_percent"); ac = dt_action_define(dark, NULL, N_("hide histogram"), d->scope_draw, NULL); dt_action_register(ac, NULL, _lib_histogram_collapse_callback, GDK_KEY_H, GDK_CONTROL_MASK | GDK_SHIFT_MASK);