static gboolean _gradient_slider_button_release(GtkWidget *widget, GdkEventButton *event) { GtkDarktableGradientSlider *gslider=DTGTK_GRADIENT_SLIDER(widget); if( event->button==1 && gslider->selected != -1 && gslider->do_reset==FALSE ) { // First get some dimention info gslider->is_changed=TRUE; gdouble newposition = roundf(_screen_to_scale(widget, event->x)/gslider->increment)*gslider->increment; newposition = CLAMP_RANGE(newposition, 0.0, 1.0); gint direction = gslider->position[gslider->selected] <= newposition ? MOVE_RIGHT : MOVE_LEFT; _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected-1]; gslider->max = gslider->selected == gslider->positions-1 ? 1.0f : gslider->position[gslider->selected+1]; gtk_widget_draw(widget,NULL); gslider->prev_x_root = event->x_root; gslider->is_dragging=FALSE; g_signal_emit_by_name(G_OBJECT(widget),"value-changed"); } return TRUE; }
static void _blendif_scale(dt_iop_colorspace_type_t cst, const float *in, float *out) { switch(cst) { case iop_cs_Lab: out[0] = CLAMP_RANGE(in[0] / 100.0f, 0.0f, 1.0f); out[1] = CLAMP_RANGE((in[1] + 128.0f)/256.0f, 0.0f, 1.0f); out[2] = CLAMP_RANGE((in[2] + 128.0f)/256.0f, 0.0f, 1.0f); out[3] = -1.0f; break; case iop_cs_rgb: out[0] = CLAMP_RANGE(0.3f*in[0] + 0.59f*in[1] + 0.11f*in[2], 0.0f, 1.0f); out[1] = CLAMP_RANGE(in[0], 0.0f, 1.0f); out[2] = CLAMP_RANGE(in[1], 0.0f, 1.0f); out[3] = CLAMP_RANGE(in[2], 0.0f, 1.0f); break; default: out[0] = out[1] = out[2] = out[3] = -1.0f; } }
static gboolean _gradient_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { GtkDarktableGradientSlider *gslider=DTGTK_GRADIENT_SLIDER(widget); if( gslider->is_dragging==TRUE && gslider->selected != -1 && gslider->do_reset==FALSE ) { assert(gslider->timeout_handle > 0); gdouble newposition = roundf(_screen_to_scale(widget, event->x)/gslider->increment)*gslider->increment; newposition = CLAMP_RANGE(newposition, 0.0, 1.0); gint direction = gslider->position[gslider->selected] <= newposition ? MOVE_RIGHT : MOVE_LEFT; _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected-1]; gslider->max = gslider->selected == gslider->positions-1 ? 1.0f : gslider->position[gslider->selected+1]; gslider->is_changed = TRUE; gtk_widget_draw(widget,NULL); } return TRUE; }
static gboolean _gradient_slider_button_press(GtkWidget *widget, GdkEventButton *event) { GtkDarktableGradientSlider *gslider=DTGTK_GRADIENT_SLIDER(widget); if(event->button == 1 && event->type == GDK_2BUTTON_PRESS && gslider->is_resettable) { gslider->is_dragging=FALSE; gslider->do_reset=TRUE; gslider->selected=-1; for(int k=0; k<gslider->positions; k++) gslider->position[k] = gslider->resetvalue[k]; gtk_widget_draw(widget,NULL); g_signal_emit_by_name(G_OBJECT(widget),"value-changed"); } else if((event->button==1 || event->button==3) && event->type == GDK_BUTTON_PRESS) { gint lselected = -1; gdouble newposition = roundf(_screen_to_scale(widget, event->x)/gslider->increment)*gslider->increment; gslider->prev_x_root=event->x_root; assert(gslider->positions > 0); if(gslider->positions == 1) { lselected = 0; } else if (newposition <= gslider->position[0]) { lselected = 0; } else if (newposition >= gslider->position[gslider->positions-1]) { lselected = gslider->positions-1; } else for(int k=0; k<=gslider->positions-2; k++) { if(newposition >= gslider->position[k] && newposition <= gslider->position[k+1]) { lselected = newposition - gslider->position[k] < gslider->position[k+1] - newposition ? k : k+1; break; } } assert(lselected >= 0); assert(lselected <= gslider->positions-1); if(event->button==1) // left mouse button : select and start dragging { gslider->selected = lselected; gslider->is_dragging=TRUE; gslider->do_reset=FALSE; newposition = CLAMP_RANGE(newposition, 0.0, 1.0); gint direction = gslider->position[gslider->selected] <= newposition ? MOVE_RIGHT : MOVE_LEFT; _slider_move(widget, gslider->selected, newposition, direction); gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected-1]; gslider->max = gslider->selected == gslider->positions-1 ? 1.0f : gslider->position[gslider->selected+1]; g_signal_emit_by_name(G_OBJECT(widget),"value-changed"); } else if (gslider->positions > 1) // right mouse button: switch on/off selection (only if we have more than one marker) { gslider->is_dragging=FALSE; gslider->do_reset=FALSE; if(gslider->selected != lselected) { gslider->selected = lselected; gslider->min = gslider->selected == 0 ? 0.0f : gslider->position[gslider->selected-1]; gslider->max = gslider->selected == gslider->positions-1 ? 1.0f : gslider->position[gslider->selected+1]; } else gslider->selected = -1; gtk_widget_draw(widget,NULL); } } return TRUE; }
static void _blendif_scale(dt_iop_colorspace_type_t cst, const float *in, float *out) { float temp[4]; switch(cst) { case iop_cs_Lab: _Lab_2_LCH(in, temp); out[0] = CLAMP_RANGE(in[0] / 100.0f, 0.0f, 1.0f); out[1] = CLAMP_RANGE((in[1] + 128.0f)/256.0f, 0.0f, 1.0f); out[2] = CLAMP_RANGE((in[2] + 128.0f)/256.0f, 0.0f, 1.0f); out[3] = CLAMP_RANGE(temp[1] / (128.0f * sqrtf(2.0f)), 0.0f, 1.0f); out[4] = CLAMP_RANGE(temp[2], 0.0f, 1.0f); out[5] = out[6] = out[7] = -1; break; case iop_cs_rgb: _RGB_2_HSL(in, temp); out[0] = CLAMP_RANGE(0.3f*in[0] + 0.59f*in[1] + 0.11f*in[2], 0.0f, 1.0f); out[1] = CLAMP_RANGE(in[0], 0.0f, 1.0f); out[2] = CLAMP_RANGE(in[1], 0.0f, 1.0f); out[3] = CLAMP_RANGE(in[2], 0.0f, 1.0f); out[4] = CLAMP_RANGE(temp[0], 0.0f, 1.0f); out[5] = CLAMP_RANGE(temp[1], 0.0f, 1.0f); out[6] = CLAMP_RANGE(temp[2], 0.0f, 1.0f); out[7] = -1; break; default: out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] = out[7] = -1.0f; } }