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

Removing max height of histogram #17045

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
68 changes: 53 additions & 15 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3870,19 +3870,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")) {
johnlb marked this conversation as resolved.
Show resolved Hide resolved
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) {
johnlb marked this conversation as resolved.
Show resolved Hide resolved
//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;
}
Expand Down Expand Up @@ -3918,14 +3937,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) {
johnlb marked this conversation as resolved.
Show resolved Hide resolved
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
{
Expand Down Expand Up @@ -3991,19 +4018,30 @@ 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),
G_CALLBACK(_scroll_wrap),
config_str);
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/gui/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,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);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,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);
Expand Down