diff --git a/app/tools/gimpnpointdeformationoptions.c b/app/tools/gimpnpointdeformationoptions.c index de189a0cf4..60fccd5402 100644 --- a/app/tools/gimpnpointdeformationoptions.c +++ b/app/tools/gimpnpointdeformationoptions.c @@ -140,9 +140,17 @@ gimp_n_point_deformation_options_set_property (GObject *object, break; case PROP_MESH_VISIBLE: options->mesh_visible = g_value_get_boolean (value); + + if (options->check_mesh_visible) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->check_mesh_visible), + options->mesh_visible); break; case PROP_PAUSE_DEFORMATION: options->deformation_is_paused = g_value_get_boolean (value); + + if (options->check_pause_deformation) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->check_pause_deformation), + options->deformation_is_paused); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -190,41 +198,47 @@ gimp_n_point_deformation_options_get_property (GObject *object, GtkWidget * gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options) { + GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (tool_options); GObject *config = G_OBJECT (tool_options); GtkWidget *vbox = gimp_tool_options_gui (tool_options); - GtkWidget *combo, *scale, *check; + GtkWidget *widget; - check = gimp_prop_check_button_new (config, "mesh-visible", _("Show Mesh")); - gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0); - gtk_widget_show (check); + widget = gtk_label_new ("Note: These options are temporary."); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - scale = gimp_prop_spin_scale_new (config, "square-size", _("Square Size"), 1.0, 10.0, 0); - gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 5.0, 1000.0); - gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); - gtk_widget_show (scale); + widget = gimp_prop_check_button_new (config, "mesh-visible", _("Show Mesh")); + npd_options->check_mesh_visible = widget; + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - scale = gimp_prop_spin_scale_new (config, "rigidity", _("Rigidity"), 1.0, 10.0, 0); - gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 1.0, 10000.0); - gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); - gtk_widget_show (scale); + widget = gimp_prop_spin_scale_new (config, "square-size", _("Square Size"), 1.0, 10.0, 0); + gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 5.0, 1000.0); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - combo = gimp_prop_boolean_combo_box_new (config, "ASAP-deformation", _("ASAP"), _("ARAP")); - gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0); - gtk_widget_show (combo); + widget = gimp_prop_spin_scale_new (config, "rigidity", _("Rigidity"), 1.0, 10.0, 0); + gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 1.0, 10000.0); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - combo = gimp_prop_boolean_combo_box_new (config, "MLS-weights", _("Enabled"), _("Disabled")); - gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0); - gtk_widget_show (combo); + widget = gimp_prop_boolean_combo_box_new (config, "ASAP-deformation", _("ASAP"), _("ARAP")); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - scale = gimp_prop_spin_scale_new (config, "MLS-weights-alpha", _("MLS Weights Alpha"), 0.1, 0.1, 1); - gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), 0.1, 2.0); - gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); - gtk_widget_show (scale); + widget = gimp_prop_boolean_combo_box_new (config, "MLS-weights", _("Enabled"), _("Disabled")); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); - check = gimp_prop_check_button_new (config, "pause-deformation", _("Pause Deformation")); - GIMP_N_POINT_DEFORMATION_OPTIONS (tool_options)->check_pause_deformation = check; - gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0); - gtk_widget_show (check); + widget = gimp_prop_spin_scale_new (config, "MLS-weights-alpha", _("MLS Weights Alpha"), 0.1, 0.1, 1); + gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 0.1, 2.0); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + widget = gimp_prop_check_button_new (config, "pause-deformation", _("Pause Deformation")); + npd_options->check_pause_deformation = widget; + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); return vbox; } @@ -239,9 +253,7 @@ void gimp_n_point_deformation_options_set_pause_deformation (GimpNPointDeformationOptions *npd_options, gboolean is_active) { - GtkToggleButton *check = GTK_TOGGLE_BUTTON (npd_options->check_pause_deformation); - gtk_toggle_button_set_active (check, is_active); - npd_options->deformation_is_paused = is_active; + g_object_set (G_OBJECT (npd_options), "pause-deformation", is_active, NULL); } void diff --git a/app/tools/gimpnpointdeformationoptions.h b/app/tools/gimpnpointdeformationoptions.h index 2cd857bae3..0af2cae088 100644 --- a/app/tools/gimpnpointdeformationoptions.h +++ b/app/tools/gimpnpointdeformationoptions.h @@ -48,6 +48,7 @@ struct _GimpNPointDeformationOptions gboolean deformation_is_paused; GtkWidget *check_pause_deformation; + GtkWidget *check_mesh_visible; }; struct _GimpNPointDeformationOptionsClass diff --git a/app/tools/gimpnpointdeformationtool.c b/app/tools/gimpnpointdeformationtool.c index d9ed9d93b9..8aa3ce0666 100644 --- a/app/tools/gimpnpointdeformationtool.c +++ b/app/tools/gimpnpointdeformationtool.c @@ -20,6 +20,7 @@ #include "config.h" #include +#include #include #include #include @@ -29,6 +30,7 @@ #include "tools-types.h" #include "gegl/gimp-gegl-utils.h" +#include "gegl/gimp-gegl-apply-operation.h" #include "display/gimpdisplay.h" @@ -58,7 +60,7 @@ #include -#define GIMP_NPD_DEBUG +//#define GIMP_NPD_DEBUG #define GIMP_NPD_MAXIMUM_DEFORMATION_DELAY 100000 /* 100000 microseconds == 10 FPS */ #define GIMP_NPD_DRAW_INTERVAL 50 /* 50 milliseconds == 20 FPS */ #define GIMP_NPD_STRING "N-Point Deformation" @@ -129,7 +131,7 @@ gboolean gimp_n_point_deformation_tool_canvas_update_thread_func (GimpNPointDeformationTool *npd_tool); static void gimp_n_point_deformation_tool_perform_deformation (GimpNPointDeformationTool *npd_tool); static void gimp_n_point_deformation_tool_halt_threads (GimpNPointDeformationTool *npd_tool); -GimpCanvasItem *gimp_n_point_deformation_tool_add_preview (GimpNPointDeformationTool *npd_tool); +static void gimp_n_point_deformation_tool_add_preview (GimpNPointDeformationTool *npd_tool); static void gimp_n_point_deformation_tool_apply_deformation (GimpNPointDeformationTool *npd_tool); #ifdef GIMP_NPD_DEBUG @@ -271,12 +273,6 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool, gegl_node_link_many (source, node, sink, NULL); - /* initialize some options */ - npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool); - npd_options->mesh_visible = TRUE; - gimp_n_point_deformation_options_set_pause_deformation (npd_options, FALSE); - gimp_n_point_deformation_tool_set_options (node, npd_options); - /* compute and get model */ gegl_node_process (node); gegl_node_get (node, "model", &model, NULL); @@ -294,6 +290,12 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool, npd_tool->selected_cps = NULL; npd_tool->previous_cps_positions = NULL; npd_tool->rubber_band = FALSE; + npd_tool->apply_deformation = FALSE; + + /* initialize some options */ + npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool); + g_object_set (G_OBJECT (npd_options), "mesh-visible", TRUE, NULL); + gimp_n_point_deformation_options_set_pause_deformation (npd_options, FALSE); /* get drawable's offset */ gimp_item_get_offset (GIMP_ITEM (drawable), @@ -305,6 +307,11 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool, /* start draw tool */ gimp_draw_tool_start (draw_tool, display); + /* hide original image */ + gimp_n_point_deformation_tool_perform_deformation (npd_tool); + gimp_item_set_visible (GIMP_ITEM (drawable), FALSE, FALSE); + gimp_image_flush (image); + /* create and start a deformation thread */ npd_tool->deform_thread = g_thread_new ("deform thread", @@ -328,6 +335,18 @@ gimp_n_point_deformation_tool_halt (GimpNPointDeformationTool *npd_tool) gimp_n_point_deformation_tool_halt_threads (npd_tool); + /* apply the deformation? */ + if (npd_tool->apply_deformation) + { + gimp_tool_control_push_preserve (tool->control, TRUE); + gimp_n_point_deformation_tool_apply_deformation (npd_tool); + gimp_tool_control_pop_preserve (tool->control); + } + + /* show original/deformed image */ + gimp_item_set_visible (GIMP_ITEM (npd_tool->drawable), TRUE, FALSE); + gimp_image_flush (gimp_display_get_image (npd_tool->display)); + npd_tool->active = FALSE; if (gimp_draw_tool_is_active (draw_tool)) @@ -420,12 +439,7 @@ gimp_n_point_deformation_tool_key_press (GimpTool *tool, case GDK_KEY_Return: case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: - gimp_n_point_deformation_tool_halt_threads (npd_tool); - - gimp_tool_control_push_preserve (tool->control, TRUE); - gimp_n_point_deformation_tool_apply_deformation (npd_tool); - gimp_tool_control_pop_preserve (tool->control); - + npd_tool->apply_deformation = TRUE; gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display); break; @@ -893,8 +907,13 @@ gimp_n_point_deformation_tool_deform_thread_func (gpointer data) static void gimp_n_point_deformation_tool_perform_deformation (GimpNPointDeformationTool *npd_tool) { - gimp_npd_debug (("gegl_node_invalidated\n")); - gegl_node_invalidated (npd_tool->npd_node, NULL, FALSE); + GObject *operation = NULL; + g_object_get (npd_tool->npd_node, + "gegl-operation", &operation, + NULL); + gimp_npd_debug (("gegl_operation_invalidate\n")); + gegl_operation_invalidate (GEGL_OPERATION (operation), NULL, FALSE); +// gegl_node_invalidated (npd_tool->npd_node, NULL, FALSE); gimp_npd_debug (("gegl_node_process\n")); gegl_node_process (npd_tool->sink); @@ -916,7 +935,7 @@ gimp_n_point_deformation_tool_halt_threads (GimpNPointDeformationTool *npd_tool) gimp_npd_debug (("finished\n")); } -GimpCanvasItem * +static void gimp_n_point_deformation_tool_add_preview (GimpNPointDeformationTool *npd_tool) { GimpCanvasItem *item; @@ -929,8 +948,6 @@ gimp_n_point_deformation_tool_add_preview (GimpNPointDeformationTool *npd_tool) gimp_draw_tool_add_preview (draw_tool, item); g_object_unref (item); - - return item; } static void diff --git a/app/tools/gimpnpointdeformationtool.h b/app/tools/gimpnpointdeformationtool.h index 5633651028..992f895f2f 100644 --- a/app/tools/gimpnpointdeformationtool.h +++ b/app/tools/gimpnpointdeformationtool.h @@ -79,6 +79,7 @@ struct _GimpNPointDeformationTool gboolean active; volatile gboolean deformation_active; gboolean rubber_band; + gboolean apply_deformation; }; struct _GimpNPointDeformationToolClass