int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, const int new_version) { if(old_version == 1 && new_version == 2) { typedef struct dt_iop_spots_v1_t { float x, y; float xc, yc; float radius; } dt_iop_spots_v1_t; typedef struct dt_iop_spots_params_v1_t { int num_spots; dt_iop_spots_v1_t spot[32]; } dt_iop_spots_params_v1_t; dt_iop_spots_params_v1_t *o = (dt_iop_spots_params_v1_t *)old_params; dt_iop_spots_params_t *n = (dt_iop_spots_params_t *)new_params; dt_iop_spots_params_t *d = (dt_iop_spots_params_t *)self->default_params; *n = *d; // start with a fresh copy of default parameters for(int i = 0; i < o->num_spots; i++) { // we have to register a new circle mask dt_masks_form_t *form = dt_masks_create(DT_MASKS_CIRCLE | DT_MASKS_CLONE); // spots v1 was before raw orientation changes form->version = 1; dt_masks_point_circle_t *circle = (dt_masks_point_circle_t *)(malloc(sizeof(dt_masks_point_circle_t))); circle->center[0] = o->spot[i].x; circle->center[1] = o->spot[i].y; circle->radius = o->spot[i].radius; circle->border = 0.0f; form->points = g_list_append(form->points, circle); form->source[0] = o->spot[i].xc; form->source[1] = o->spot[i].yc; // adapt for raw orientation changes dt_masks_legacy_params(self->dev, form, form->version, dt_masks_version()); dt_masks_gui_form_save_creation(self, form, NULL); // and add it to the module params n->clone_id[i] = form->formid; n->clone_algo[i] = 1; } return 0; } return 1; }
static gboolean _add_ellipse(GtkWidget *widget, GdkEventButton *e, dt_iop_module_t *self) { _reset_form_creation(widget, self); if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) return FALSE; // we want to be sure that the iop has focus dt_iop_request_focus(self); // we create the new form dt_masks_form_t *spot = dt_masks_create(DT_MASKS_ELLIPSE | DT_MASKS_CLONE); dt_masks_change_form_gui(spot); darktable.develop->form_gui->creation = TRUE; darktable.develop->form_gui->creation_module = self; dt_control_queue_redraw_center(); return FALSE; }
static void _add_circle(GtkWidget *widget, GdkEventButton *e, dt_iop_module_t *self) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { //we unset the creation mode dt_masks_form_t *form = darktable.develop->form_visible; if (form) dt_masks_free_form(form); dt_masks_change_form_gui(NULL); dt_masks_init_formgui(darktable.develop); GTK_TOGGLE_BUTTON(widget)->active = FALSE; return; } //we want to be sure that the iop has focus dt_iop_request_focus(self); //we create the new form dt_masks_form_t *spot = dt_masks_create(DT_MASKS_CIRCLE|DT_MASKS_CLONE); dt_masks_change_form_gui(spot); darktable.develop->form_gui->creation = TRUE; darktable.develop->form_gui->creation_module = self; dt_control_queue_redraw_center(); }
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; }