static gboolean dt_iop_levels_scroll(GtkWidget *widget, GdkEventScroll *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_levels_gui_data_t *c = (dt_iop_levels_gui_data_t *)self->gui_data; dt_iop_levels_params_t *p = (dt_iop_levels_params_t *)self->params; const float interval = 0.002; // Distance moved for each scroll event gboolean updated = FALSE; float new_position = 0; if(c->dragging) { return FALSE; } if(event->direction == GDK_SCROLL_UP) { new_position = p->levels[c->handle_move] + interval; updated = TRUE; } else if(event->direction == GDK_SCROLL_DOWN) { new_position = p->levels[c->handle_move] - interval; updated = TRUE; } if(updated) { dt_iop_levels_move_handle(self, c->handle_move, new_position, p->levels, c->drag_start_percentage); dt_dev_add_history_item(darktable.develop, self, TRUE); return TRUE; } return FALSE; }
static gboolean dt_iop_levels_scroll(GtkWidget *widget, GdkEventScroll *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_levels_gui_data_t *c = (dt_iop_levels_gui_data_t *)self->gui_data; dt_iop_levels_params_t *p = (dt_iop_levels_params_t *)self->params; dt_iop_color_picker_reset(self, TRUE); if(c->dragging) { return FALSE; } const float interval = 0.002; // Distance moved for each scroll event gdouble delta_y; if(dt_gui_get_scroll_deltas(event, NULL, &delta_y)) { float new_position = p->levels[c->handle_move] - interval * delta_y; dt_iop_levels_move_handle(self, c->handle_move, new_position, p->levels, c->drag_start_percentage); dt_dev_add_history_item(darktable.develop, self, TRUE); return TRUE; } return FALSE; }
static gboolean dt_iop_levels_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_levels_gui_data_t *c = (dt_iop_levels_gui_data_t *)self->gui_data; dt_iop_levels_params_t *p = (dt_iop_levels_params_t *)self->params; const int inset = DT_GUI_CURVE_EDITOR_INSET; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); int height = allocation.height - 2 * inset, width = allocation.width - 2 * inset; if(!c->dragging) { c->mouse_x = CLAMP(event->x - inset, 0, width); c->drag_start_percentage = (p->levels[1] - p->levels[0]) / (p->levels[2] - p->levels[0]); } c->mouse_y = CLAMP(event->y - inset, 0, height); if(c->dragging) { if(c->handle_move >= 0 && c->handle_move < 3) { const float mx = (CLAMP(event->x - inset, 0, width)) / (float)width; dt_iop_levels_move_handle(self, c->handle_move, mx, p->levels, c->drag_start_percentage); } dt_dev_add_history_item(darktable.develop, self, TRUE); } else { c->handle_move = 0; const float mx = CLAMP(event->x - inset, 0, width) / (float)width; float dist = fabsf(p->levels[0] - mx); for(int k = 1; k < 3; k++) { float d2 = fabsf(p->levels[k] - mx); if(d2 < dist) { c->handle_move = k; dist = d2; } } } gtk_widget_queue_draw(widget); gint x, y; #if GTK_CHECK_VERSION(3, 20, 0) gdk_window_get_device_position(event->window, gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(widget))), &x, &y, 0); #else gdk_window_get_device_position(event->window, gdk_device_manager_get_client_pointer( gdk_display_get_device_manager(gdk_window_get_display(event->window))), &x, &y, NULL); #endif return TRUE; }
static gboolean dt_iop_levels_motion_notify(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { dt_iop_module_t *self = (dt_iop_module_t *)user_data; dt_iop_levels_gui_data_t *c = (dt_iop_levels_gui_data_t *)self->gui_data; dt_iop_levels_params_t *p = (dt_iop_levels_params_t *)self->params; const int inset = DT_GUI_CURVE_EDITOR_INSET; int height = widget->allocation.height - 2*inset, width = widget->allocation.width - 2*inset; if(!c->dragging) { c->mouse_x = CLAMP(event->x - inset, 0, width); c->drag_start_percentage = (p->levels[1] - p->levels[0]) / (p->levels[2] - p->levels[0]); } c->mouse_y = CLAMP(event->y - inset, 0, height); if(c->dragging) { if(c->handle_move >= 0 && c->handle_move < 3) { const float mx = (CLAMP(event->x - inset, 0, width)) / (float)width; dt_iop_levels_move_handle(c->handle_move, mx, p->levels, c->drag_start_percentage); } dt_dev_add_history_item(darktable.develop, self, TRUE); } else { c->handle_move = 0; const float mx = CLAMP(event->x - inset, 0, width)/(float)width; float dist = fabsf(p->levels[0] - mx); for(int k=1; k<3; k++) { float d2 = fabsf(p->levels[k] - mx); if(d2 < dist) { c->handle_move = k; dist = d2; } } } gtk_widget_queue_draw(widget); gint x, y; gdk_window_get_pointer(event->window, &x, &y, NULL); return TRUE; }