static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, float pzx, float pzy, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index) { if(which == 3 && parentid > 0 && gui->edit_mode == DT_MASKS_EDIT_FULL) { // we hide the form if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP)) dt_masks_change_form_gui(NULL); else if(g_list_length(darktable.develop->form_visible->points) < 2) dt_masks_change_form_gui(NULL); else { dt_masks_clear_form_gui(darktable.develop); GList *forms = g_list_first(darktable.develop->form_visible->points); while(forms) { dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } forms = g_list_next(forms); } gui->edit_mode = DT_MASKS_EDIT_FULL; } // we remove the shape dt_dev_masks_list_remove(darktable.develop, form->formid, parentid); dt_masks_form_remove(module, dt_masks_get_from_id(darktable.develop, parentid), form); return 1; } if(gui->form_dragging) { // we get the ellipse dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); // we end the form dragging gui->form_dragging = FALSE; // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy }; dt_dev_distort_backtransform(darktable.develop, pts, 1); ellipse->center[0] = pts[0] / darktable.develop->preview_pipe->iwidth; ellipse->center[1] = pts[1] / darktable.develop->preview_pipe->iheight; dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the move dt_masks_update_image(darktable.develop); return 1; } else if(gui->border_toggling) { // we get the ellipse dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); // we end the border toggling gui->border_toggling = FALSE; // toggle feathering type of border and adjust border radius accordingly if(ellipse->flags & DT_MASKS_ELLIPSE_PROPORTIONAL) { const float min_radius = fmin(ellipse->radius[0], ellipse->radius[1]); ellipse->border = ellipse->border * min_radius; ellipse->border = CLAMP(ellipse->border, 0.001f, 1.0f); ellipse->flags &= ~DT_MASKS_ELLIPSE_PROPORTIONAL; } else { const float min_radius = fmin(ellipse->radius[0], ellipse->radius[1]); ellipse->border = ellipse->border/min_radius; ellipse->border = CLAMP(ellipse->border, 0.001f/min_radius, 1.0f/min_radius); ellipse->flags |= DT_MASKS_ELLIPSE_PROPORTIONAL; } if(form->type & DT_MASKS_CLONE) { dt_conf_set_int("plugins/darkroom/spots/ellipse_flags", ellipse->flags); dt_conf_set_float("plugins/darkroom/spots/ellipse_border", ellipse->border); } else { dt_conf_set_int("plugins/darkroom/masks/ellipse/flags", ellipse->flags); dt_conf_set_float("plugins/darkroom/masks/ellipse/border", ellipse->border); } dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the new parameters dt_masks_update_image(darktable.develop); return 1; } else if(gui->form_rotating && gui->edit_mode == DT_MASKS_EDIT_FULL) { // we get the ellipse dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); // we end the form rotating gui->form_rotating = FALSE; float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float x = pzx * wd; float y = pzy * ht; // we need the reference point dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; float xref = gpt->points[0]; float yref = gpt->points[1]; float dv = atan2(y - yref, x - xref) - atan2(-gui->dy, -gui->dx); ellipse->rotation += dv / M_PI * 180.0f; ellipse->rotation = fmodf(ellipse->rotation, 360.0f); if(form->type & DT_MASKS_CLONE) dt_conf_set_float("plugins/darkroom/spots/ellipse_rotation", ellipse->rotation); else dt_conf_set_float("plugins/darkroom/masks/ellipse/rotation", ellipse->rotation); dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the rotation dt_masks_update_image(darktable.develop); return 1; } else if(gui->point_dragging >= 1 && gui->edit_mode == DT_MASKS_EDIT_FULL) { // we get the ellipse dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); const int k = gui->point_dragging; // we end the point dragging gui->point_dragging = -1; // we need the reference points dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; const float xref = gpt->points[0]; const float yref = gpt->points[1]; const float rx = gpt->points[k * 2] - xref; const float ry = gpt->points[k * 2 + 1] - yref; const float deltax = gui->posx + gui->dx - xref; const float deltay = gui->posy + gui->dy - yref; const float r = sqrtf(rx * rx + ry * ry); const float d = (rx * deltax + ry * deltay) / r; const float s = fmaxf(r > 0.0f ? (r + d) / r : 0.0f, 0.0f); // make sure we adjust the right radius: anchor points and 1 and 2 correspond to the ellipse's longer axis if(((k == 1 || k == 2) && ellipse->radius[0] > ellipse->radius[1]) || ((k == 3 || k == 4) && ellipse->radius[0] <= ellipse->radius[1])) { ellipse->radius[0] = MAX(0.002f, ellipse->radius[0] * s); if(form->type & DT_MASKS_CLONE) dt_conf_set_float("plugins/darkroom/spots/ellipse_radius_a", ellipse->radius[0]); else dt_conf_set_float("plugins/darkroom/masks/ellipse/radius_a", ellipse->radius[0]); } else { ellipse->radius[1] = MAX(0.002f, ellipse->radius[1] * s); if(form->type & DT_MASKS_CLONE) dt_conf_set_float("plugins/darkroom/spots/ellipse_radius_b", ellipse->radius[1]); else dt_conf_set_float("plugins/darkroom/masks/ellipse/radius_b", ellipse->radius[1]); } dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the rotation dt_masks_update_image(darktable.develop); return 1; } else if(gui->source_dragging) { // we end the form dragging gui->source_dragging = FALSE; if(gui->scrollx != 0.0 || gui->scrolly != 0.0) { dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(g_list_first(form->points)->data); form->source[0] = ellipse->center[0] + ellipse->radius[0]; form->source[1] = ellipse->center[1] - ellipse->radius[1]; gui->scrollx = gui->scrolly = 0.0; } else { // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy }; dt_dev_distort_backtransform(darktable.develop, pts, 1); form->source[0] = pts[0] / darktable.develop->preview_pipe->iwidth; form->source[1] = pts[1] / darktable.develop->preview_pipe->iheight; } dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the move dt_masks_update_image(darktable.develop); return 1; } return 0; }
static int dt_ellipse_events_button_pressed(struct dt_iop_module_t *module, float pzx, float pzy, double pressure, int which, int type, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index) { if(!gui) return 0; if(gui->source_selected && !gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) { dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; // we start the source dragging gui->source_dragging = TRUE; gui->posx = pzx * darktable.develop->preview_pipe->backbuf_width; gui->posy = pzy * darktable.develop->preview_pipe->backbuf_height; gui->dx = gpt->source[0] - gui->posx; gui->dy = gpt->source[1] - gui->posy; return 1; } else if(gui->point_selected >= 1 && !gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL && !((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)) { dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; gui->point_dragging = gui->point_selected; gui->posx = pzx * darktable.develop->preview_pipe->backbuf_width; gui->posy = pzy * darktable.develop->preview_pipe->backbuf_height; gui->dx = gpt->points[0] - gui->posx; gui->dy = gpt->points[1] - gui->posy; return 1; } else if(gui->form_selected && !gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) { dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *)g_list_nth_data(gui->points, index); if(!gpt) return 0; // we start the form dragging or rotating if((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK) gui->form_rotating = TRUE; else gui->form_dragging = TRUE; gui->posx = pzx * darktable.develop->preview_pipe->backbuf_width; gui->posy = pzy * darktable.develop->preview_pipe->backbuf_height; gui->dx = gpt->points[0] - gui->posx; gui->dy = gpt->points[1] - gui->posy; return 1; } else if(gui->creation && (which == 3)) { darktable.develop->form_visible = NULL; dt_masks_clear_form_gui(darktable.develop); dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL); dt_masks_iop_update(module); dt_control_queue_redraw_center(); return 1; } else if(gui->creation) { dt_iop_module_t *crea_module = gui->creation_module; // we create the ellipse dt_masks_point_ellipse_t *ellipse = (dt_masks_point_ellipse_t *)(malloc(sizeof(dt_masks_point_ellipse_t))); // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd, pzy * ht }; dt_dev_distort_backtransform(darktable.develop, pts, 1); ellipse->center[0] = pts[0] / darktable.develop->preview_pipe->iwidth; ellipse->center[1] = pts[1] / darktable.develop->preview_pipe->iheight; if(form->type & DT_MASKS_CLONE) { const float a = MIN(0.5f, dt_conf_get_float("plugins/darkroom/spots/ellipse_radius_a")); const float b = MIN(0.5f, dt_conf_get_float("plugins/darkroom/spots/ellipse_radius_b")); const float spots_border = MIN(0.5f, dt_conf_get_float("plugins/darkroom/spots/ellipse_border")); const float rotation = dt_conf_get_float("plugins/darkroom/spots/ellipse_rotation"); ellipse->radius[0] = MAX(0.01f, a); ellipse->radius[1] = MAX(0.01f, b); ellipse->border = MAX(0.005f, spots_border); ellipse->rotation = rotation; form->source[0] = ellipse->center[0] + 0.02f; form->source[1] = ellipse->center[1] + 0.02f; } else { const float a = MIN(0.5f, dt_conf_get_float("plugins/darkroom/masks/ellipse/radius_a")); const float b = MIN(0.5f, dt_conf_get_float("plugins/darkroom/masks/ellipse/radius_b")); const float ellipse_border = MIN(0.5f, dt_conf_get_float("plugins/darkroom/masks/ellipse/border")); const float rotation = dt_conf_get_float("plugins/darkroom/masks/ellipse/rotation"); ellipse->radius[0] = MAX(0.01f, a); ellipse->radius[1] = MAX(0.01f, b); ellipse->border = MAX(0.005f, ellipse_border); ellipse->rotation = rotation; // not used for masks form->source[0] = form->source[1] = 0.0f; } form->points = g_list_append(form->points, ellipse); dt_masks_gui_form_save_creation(crea_module, form, gui); if(crea_module) { // we save the move dt_dev_add_history_item(darktable.develop, crea_module, TRUE); // and we switch in edit mode to show all the forms dt_masks_set_edit_mode(crea_module, DT_MASKS_EDIT_FULL); dt_masks_iop_update(crea_module); gui->creation_module = NULL; } else { // we select the new form dt_dev_masks_selection_change(darktable.develop, form->formid, TRUE); } // if we draw a clone ellipse, we start now the source dragging if(form->type & DT_MASKS_CLONE) { dt_masks_form_t *grp = darktable.develop->form_visible; if(!grp || !(grp->type & DT_MASKS_GROUP)) return 1; int pos3 = 0, pos2 = -1; GList *fs = g_list_first(grp->points); while(fs) { dt_masks_point_group_t *pt = (dt_masks_point_group_t *)fs->data; if(pt->formid == form->formid) { pos2 = pos3; break; } pos3++; fs = g_list_next(fs); } if(pos2 < 0) return 1; dt_masks_form_gui_t *gui2 = darktable.develop->form_gui; if(!gui2) return 1; gui2->source_dragging = TRUE; gui2->group_edited = gui2->group_selected = pos2; gui2->posx = pzx * darktable.develop->preview_pipe->backbuf_width; gui2->posy = pzy * darktable.develop->preview_pipe->backbuf_height; gui2->dx = 0.0; gui2->dy = 0.0; gui2->scrollx = pzx; gui2->scrolly = pzy; } return 1; } return 0; }
static int dt_gradient_events_button_pressed(struct dt_iop_module_t *module, float pzx, float pzy, double pressure, int which, int type, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index) { if (!gui) return 0; if (!gui->creation && gui->edit_mode == DT_MASKS_EDIT_FULL) { dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *) g_list_nth_data(gui->points,index); if (!gpt) return 0; //we start the form rotating or dragging if(gui->pivot_selected) gui->form_rotating = TRUE; else gui->form_dragging = TRUE; gui->posx = pzx*darktable.develop->preview_pipe->backbuf_width; gui->posy = pzy*darktable.develop->preview_pipe->backbuf_height; gui->dx = gpt->points[0] - gui->posx; gui->dy = gpt->points[1] - gui->posy; return 1; } else if (gui->creation && (which == 3)) { darktable.develop->form_visible = NULL; dt_masks_clear_form_gui(darktable.develop); dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL); dt_masks_iop_update(module); dt_control_queue_redraw_center(); return 1; } else if (gui->creation) { dt_iop_module_t *crea_module = gui->creation_module; //we create the circle dt_masks_point_gradient_t *gradient = (dt_masks_point_gradient_t *) (malloc(sizeof(dt_masks_point_gradient_t))); //we change the offset value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = {pzx*wd,pzy*ht}; dt_dev_distort_backtransform(darktable.develop,pts,1); gradient->anchor[0] = pts[0]/darktable.develop->preview_pipe->iwidth; gradient->anchor[1] = pts[1]/darktable.develop->preview_pipe->iheight; const float compression = MIN(1.0f,dt_conf_get_float("plugins/darkroom/masks/gradient/compression")); const float steepness = 0.0f; //MIN(1.0f,dt_conf_get_float("plugins/darkroom/masks/gradient/steepness")); // currently not used const float rotation = dt_conf_get_float("plugins/darkroom/masks/gradient/rotation"); gradient->rotation = rotation; gradient->compression = MAX(0.0f, compression); gradient->steepness = MAX(0.0f, steepness); // not used for masks form->source[0] = form->source[1] = 0.0f; form->points = g_list_append(form->points,gradient); dt_masks_gui_form_save_creation(crea_module,form,gui); if (crea_module) { //we save the move dt_dev_add_history_item(darktable.develop, crea_module, TRUE); //and we switch in edit mode to show all the forms dt_masks_set_edit_mode(crea_module, DT_MASKS_EDIT_FULL); dt_masks_iop_update(crea_module); gui->creation_module = NULL; } else { //we select the new form dt_dev_masks_selection_change(darktable.develop,form->formid,TRUE); } return 1; } return 0; }
static int dt_gradient_events_button_released(struct dt_iop_module_t *module,float pzx, float pzy, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index) { if (which == 3 && parentid > 0 && gui->edit_mode == DT_MASKS_EDIT_FULL) { dt_masks_clear_form_gui(darktable.develop); //we hide the form if (!(darktable.develop->form_visible->type & DT_MASKS_GROUP)) darktable.develop->form_visible = NULL; else if (g_list_length(darktable.develop->form_visible->points) < 2) darktable.develop->form_visible = NULL; else { GList *forms = g_list_first(darktable.develop->form_visible->points); while (forms) { dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if (gpt->formid == form->formid) { darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points,gpt); break; } forms = g_list_next(forms); } } //we remove the shape dt_masks_form_remove(module,dt_masks_get_from_id(darktable.develop,parentid),form); dt_dev_masks_list_remove(darktable.develop,form->formid,parentid); return 1; } if(gui->form_dragging && gui->edit_mode == DT_MASKS_EDIT_FULL) { //we get the gradient dt_masks_point_gradient_t *gradient = (dt_masks_point_gradient_t *) (g_list_first(form->points)->data); //we end the form dragging gui->form_dragging = FALSE; //we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = {pzx*wd+gui->dx,pzy*ht+gui->dy}; dt_dev_distort_backtransform(darktable.develop,pts,1); gradient->anchor[0] = pts[0]/darktable.develop->preview_pipe->iwidth; gradient->anchor[1] = pts[1]/darktable.develop->preview_pipe->iheight; dt_masks_write_form(form,darktable.develop); //we recreate the form points dt_masks_gui_form_remove(form,gui,index); dt_masks_gui_form_create(form,gui,index); //we save the move dt_masks_update_image(darktable.develop); return 1; } else if(gui->form_rotating && gui->edit_mode == DT_MASKS_EDIT_FULL) { //we get the gradient dt_masks_point_gradient_t *gradient = (dt_masks_point_gradient_t *) (g_list_first(form->points)->data); //we end the form rotating gui->form_rotating = FALSE; float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float x = pzx*wd; float y = pzy*ht; //we need the reference point dt_masks_form_gui_points_t *gpt = (dt_masks_form_gui_points_t *) g_list_nth_data(gui->points,index); if (!gpt) return 0; float xref = gpt->points[0]; float yref = gpt->points[1]; float dv = atan2(y - yref, x - xref) - atan2(-gui->dy, -gui->dx); gradient->rotation -= dv/M_PI*180.0f; dt_masks_write_form(form,darktable.develop); //we recreate the form points dt_masks_gui_form_remove(form,gui,index); dt_masks_gui_form_create(form,gui,index); //we save the rotation dt_masks_update_image(darktable.develop); return 1; } return 0; }
static int dt_circle_events_button_released(struct dt_iop_module_t *module, float pzx, float pzy, int which, uint32_t state, dt_masks_form_t *form, int parentid, dt_masks_form_gui_t *gui, int index) { if(which == 3 && parentid > 0 && gui->edit_mode == DT_MASKS_EDIT_FULL) { // we hide the form if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP)) dt_masks_change_form_gui(NULL); else if(g_list_length(darktable.develop->form_visible->points) < 2) dt_masks_change_form_gui(NULL); else { dt_masks_clear_form_gui(darktable.develop); GList *forms = g_list_first(darktable.develop->form_visible->points); while(forms) { dt_masks_point_group_t *gpt = (dt_masks_point_group_t *)forms->data; if(gpt->formid == form->formid) { darktable.develop->form_visible->points = g_list_remove(darktable.develop->form_visible->points, gpt); free(gpt); break; } forms = g_list_next(forms); } gui->edit_mode = DT_MASKS_EDIT_FULL; } // we remove the shape dt_dev_masks_list_remove(darktable.develop, form->formid, parentid); dt_masks_form_remove(module, dt_masks_get_from_id(darktable.develop, parentid), form); return 1; } if(gui->form_dragging) { // we get the circle dt_masks_point_circle_t *circle = (dt_masks_point_circle_t *)(g_list_first(form->points)->data); // we end the form dragging gui->form_dragging = FALSE; // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy }; dt_dev_distort_backtransform(darktable.develop, pts, 1); circle->center[0] = pts[0] / darktable.develop->preview_pipe->iwidth; circle->center[1] = pts[1] / darktable.develop->preview_pipe->iheight; dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the move dt_masks_update_image(darktable.develop); if(gui->creation_continuous) { dt_masks_form_t *form_new = dt_masks_create(form->type); dt_masks_change_form_gui(form_new); darktable.develop->form_gui->creation = TRUE; darktable.develop->form_gui->creation_module = gui->creation_continuous_module; } return 1; } else if(gui->source_dragging) { // we end the form dragging gui->source_dragging = FALSE; if(gui->scrollx != 0.0 || gui->scrolly != 0.0) { // if there's no dragging the source is calculated in dt_circle_events_button_pressed() } else { // we change the center value float wd = darktable.develop->preview_pipe->backbuf_width; float ht = darktable.develop->preview_pipe->backbuf_height; float pts[2] = { pzx * wd + gui->dx, pzy * ht + gui->dy }; dt_dev_distort_backtransform(darktable.develop, pts, 1); form->source[0] = pts[0] / darktable.develop->preview_pipe->iwidth; form->source[1] = pts[1] / darktable.develop->preview_pipe->iheight; } dt_masks_write_form(form, darktable.develop); // we recreate the form points dt_masks_gui_form_remove(form, gui, index); dt_masks_gui_form_create(form, gui, index); // we save the move dt_masks_update_image(darktable.develop); if(gui->creation_continuous) { dt_masks_form_t *form_new = dt_masks_create(form->type); dt_masks_change_form_gui(form_new); darktable.develop->form_gui->creation = TRUE; darktable.develop->form_gui->creation_module = gui->creation_continuous_module; } return 1; } return 0; }