[gimp/soc-2013-n-point-deformation-tool: 22/22] app: npd-tool: fix tool's options



commit 210e8e77dce73a7319e8aa0994ba09dd3478467a
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Thu Sep 19 23:18:14 2013 +0200

    app: npd-tool: fix tool's options

 app/tools/gimpnpointdeformationoptions.c |   65 ++++++++++++++++++++---------
 app/tools/gimpnpointdeformationoptions.h |    6 ++-
 app/tools/gimpnpointdeformationtool.c    |   66 +++++++++++++++--------------
 3 files changed, 83 insertions(+), 54 deletions(-)
---
diff --git a/app/tools/gimpnpointdeformationoptions.c b/app/tools/gimpnpointdeformationoptions.c
index 60fccd5..ae17515 100644
--- a/app/tools/gimpnpointdeformationoptions.c
+++ b/app/tools/gimpnpointdeformationoptions.c
@@ -73,7 +73,7 @@ gimp_n_point_deformation_options_class_init (GimpNPointDeformationOptionsClass *
   object_class->get_property = gimp_n_point_deformation_options_get_property;
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE  (object_class, PROP_SQUARE_SIZE,
-                                    "square-size", _("Square Size"),
+                                    "square-size", _("Density"),
                                     5.0, 1000.0, 20.0,
                                     GIMP_PARAM_STATIC_STRINGS);
 
@@ -83,27 +83,27 @@ gimp_n_point_deformation_options_class_init (GimpNPointDeformationOptionsClass *
                                     GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_ASAP_DEFORMATION,
-                                    "ASAP-deformation", _("Deformation Type"),
+                                    "ASAP-deformation", _("Deformation mode"),
                                     FALSE,
                                     GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_MLS_WEIGHTS,
-                                    "MLS-weights", _("MLS Weights"),
+                                    "MLS-weights", _("Use weights"),
                                     FALSE,
                                     GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE  (object_class, PROP_MLS_WEIGHTS_ALPHA,
-                                    "MLS-weights-alpha", _("MLS Weights Alpha"),
+                                    "MLS-weights-alpha", _("Amount of control points' influence"),
                                     0.1, 2.0, 1.0,
                                     GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_MESH_VISIBLE,
-                                    "mesh-visible", _("Mesh Visible"),
+                                    "mesh-visible", _("Show lattice"),
                                     TRUE,
                                     GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_PAUSE_DEFORMATION,
-                                    "pause-deformation", _("Pause Deformation"),
+                                    "pause-deformation", _("Pause deformation"),
                                     FALSE,
                                     GIMP_PARAM_STATIC_STRINGS);
 }
@@ -134,9 +134,13 @@ gimp_n_point_deformation_options_set_property (GObject      *object,
         break;
       case PROP_MLS_WEIGHTS:
         options->MLS_weights = g_value_get_boolean (value);
+
+        if (options->scale_MLS_weights_alpha)
+          gtk_widget_set_sensitive (options->scale_MLS_weights_alpha,
+                                    options->MLS_weights);
         break;
       case PROP_MLS_WEIGHTS_ALPHA:
-        options->square_size = g_value_get_double (value);
+        options->MLS_weights_alpha = g_value_get_double (value);
         break;
       case PROP_MESH_VISIBLE:
         options->mesh_visible = g_value_get_boolean (value);
@@ -181,7 +185,7 @@ gimp_n_point_deformation_options_get_property (GObject    *object,
         g_value_set_boolean (value, options->MLS_weights);
         break;
       case PROP_MLS_WEIGHTS_ALPHA:
-        g_value_set_double (value, options->square_size);
+        g_value_set_double (value, options->MLS_weights_alpha);
         break;
       case PROP_MESH_VISIBLE:
         g_value_set_boolean (value, options->mesh_visible);
@@ -203,43 +207,53 @@ gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options)
   GtkWidget *vbox   = gimp_tool_options_gui (tool_options);
   GtkWidget *widget;
 
-  widget = gtk_label_new ("Note: These options are temporary.");
-  gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
-  gtk_widget_show (widget);
-
-  widget = gimp_prop_check_button_new (config, "mesh-visible", _("Show Mesh"));
+  widget = gimp_prop_check_button_new (config, "mesh-visible", _("Show lattice"));
   npd_options->check_mesh_visible = widget;
   gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+  gtk_widget_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
-  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);
+  widget = gimp_prop_spin_scale_new (config, "square-size", _("Density"), 1.0, 10.0, 0);
+  npd_options->scale_square_size = widget;
+  gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 10.0, 100.0);
   gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+  gtk_widget_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
   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);
+  gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (widget), 1.0, 2000.0);
   gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+  gtk_widget_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
-  widget = gimp_prop_boolean_combo_box_new (config, "ASAP-deformation", _("ASAP"), _("ARAP"));
+  /*widget = gimp_prop_boolean_combo_box_new (config, "ASAP-deformation", _("ASAP"), _("ARAP"));*/
+  widget = gimp_prop_boolean_radio_frame_new (config, "ASAP-deformation", _("Deformation mode"), _("scale"), 
_("rigid (rubber)"));
   gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+  gtk_widget_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
-  widget = gimp_prop_boolean_combo_box_new (config, "MLS-weights", _("Enabled"), _("Disabled"));
+  /*widget = gimp_prop_boolean_combo_box_new (config, "MLS-weights", _("Enabled"), _("Disabled"));*/
+  widget = gimp_prop_check_button_new (config, "MLS-weights", _("Use weights"));
   gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+  gtk_widget_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
-  widget = gimp_prop_spin_scale_new (config, "MLS-weights-alpha", _("MLS Weights Alpha"), 0.1, 0.1, 1);
+  widget = gimp_prop_spin_scale_new (config, "MLS-weights-alpha", _("Amount of control points' influence"), 
0.1, 0.1, 1);
+  npd_options->scale_MLS_weights_alpha = widget;
   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_set_can_focus (widget, FALSE);
+  gtk_widget_set_sensitive (widget, npd_options->MLS_weights);
   gtk_widget_show (widget);
 
-  widget = gimp_prop_check_button_new (config, "pause-deformation", _("Pause Deformation"));
+  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_set_can_focus (widget, FALSE);
   gtk_widget_show (widget);
 
+  gimp_n_point_deformation_options_init_some_widgets (npd_options, FALSE);
+
   return vbox;
 }
 
@@ -260,5 +274,14 @@ void
 gimp_n_point_deformation_options_toggle_pause_deformation (GimpNPointDeformationOptions *npd_options)
 {
   gimp_n_point_deformation_options_set_pause_deformation (npd_options,
-                                                          !npd_options->deformation_is_paused);
+                                                         !npd_options->deformation_is_paused);
+}
+
+void
+gimp_n_point_deformation_options_init_some_widgets (GimpNPointDeformationOptions *npd_options,
+                                                    gboolean                      is_tool_active)
+{
+  gtk_widget_set_sensitive (npd_options->scale_square_size, !is_tool_active);
+  gtk_widget_set_sensitive (npd_options->check_mesh_visible, is_tool_active);
+  gtk_widget_set_sensitive (npd_options->check_pause_deformation, is_tool_active);
 }
diff --git a/app/tools/gimpnpointdeformationoptions.h b/app/tools/gimpnpointdeformationoptions.h
index 0af2cae..15e4694 100644
--- a/app/tools/gimpnpointdeformationoptions.h
+++ b/app/tools/gimpnpointdeformationoptions.h
@@ -47,8 +47,10 @@ struct _GimpNPointDeformationOptions
   gboolean         mesh_visible;
   gboolean         deformation_is_paused;
 
-  GtkWidget       *check_pause_deformation;
+  GtkWidget       *scale_square_size;
+  GtkWidget       *scale_MLS_weights_alpha;
   GtkWidget       *check_mesh_visible;
+  GtkWidget       *check_pause_deformation;
 };
 
 struct _GimpNPointDeformationOptionsClass
@@ -65,5 +67,7 @@ gboolean    gimp_n_point_deformation_options_is_deformation_paused    (GimpNPoin
 void        gimp_n_point_deformation_options_set_pause_deformation    (GimpNPointDeformationOptions 
*npd_options,
                                                                        gboolean                      
is_active);
 void        gimp_n_point_deformation_options_toggle_pause_deformation (GimpNPointDeformationOptions 
*npd_options);
+void        gimp_n_point_deformation_options_init_some_widgets        (GimpNPointDeformationOptions 
*npd_options,
+                                                                       gboolean                      
is_tool_active);
 
 #endif  /*  __GIMP_N_POINT_DEFORMATION_OPTIONS_H__  */
diff --git a/app/tools/gimpnpointdeformationtool.c b/app/tools/gimpnpointdeformationtool.c
index 8aa3ce0..1caa61f 100644
--- a/app/tools/gimpnpointdeformationtool.c
+++ b/app/tools/gimpnpointdeformationtool.c
@@ -68,7 +68,7 @@
 void            gimp_n_point_deformation_tool_start                   (GimpNPointDeformationTool *npd_tool,
                                                                        GimpDisplay               *display);
 void            gimp_n_point_deformation_tool_halt                    (GimpNPointDeformationTool *npd_tool);
-static void     gimp_n_point_deformation_tool_set_options             (GeglNode                  *npd_node,
+static void     gimp_n_point_deformation_tool_set_options             (GimpNPointDeformationTool *npd_tool,
                                                                        GimpNPointDeformationOptions 
*npd_options);
 static void     gimp_n_point_deformation_tool_options_notify          (GimpTool                  *tool,
                                                                        GimpToolOptions           *options,
@@ -233,7 +233,6 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
 {
   GimpTool      *tool       = GIMP_TOOL (npd_tool);
   GimpDrawTool  *draw_tool  = GIMP_DRAW_TOOL (npd_tool);
-  GeglNode      *graph, *node, *source, *sink;
   GimpImage     *image;
   GimpDrawable  *drawable;
   GeglBuffer    *source_buffer, *preview_buffer;
@@ -257,32 +256,37 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
   preview_buffer = gegl_buffer_new (gegl_buffer_get_extent (source_buffer),
                                     babl_format ("cairo-ARGB32"));
 
-  graph    = gegl_node_new ();
+  npd_tool->graph    = gegl_node_new ();
+
+  npd_tool->source   = gegl_node_new_child (npd_tool->graph,
+                                            "operation", "gegl:buffer-source",
+                                            "buffer", source_buffer,
+                                            NULL);
+  npd_tool->npd_node = gegl_node_new_child (npd_tool->graph,
+                                            "operation", "gegl:npd",
+                                            NULL);
+  npd_tool->sink     = gegl_node_new_child (npd_tool->graph,
+                                            "operation", "gegl:write-buffer",
+                                            "buffer", preview_buffer,
+                                            NULL);
+
+  gegl_node_link_many (npd_tool->source,
+                       npd_tool->npd_node,
+                       npd_tool->sink,
+                       NULL);
 
-  source   = gegl_node_new_child (graph,
-                                  "operation", "gegl:buffer-source",
-                                  "buffer", source_buffer,
-                                  NULL);
-  node     = gegl_node_new_child (graph,
-                                  "operation", "gegl:npd",
-                                  NULL);
-  sink     = gegl_node_new_child (graph,
-                                  "operation", "gegl:write-buffer",
-                                  "buffer", preview_buffer,
-                                  NULL);
-
-  gegl_node_link_many (source, node, sink, NULL);
+  /* 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);
+  gimp_n_point_deformation_options_init_some_widgets (npd_options, TRUE);
 
   /* compute and get model */
-  gegl_node_process (node);
-  gegl_node_get (node, "model", &model, NULL);
+  gegl_node_process (npd_tool->npd_node);
+  gegl_node_get (npd_tool->npd_node, "model", &model, NULL);
 
   npd_tool->drawable               = drawable;
-  npd_tool->graph                  = graph;
   npd_tool->model                  = model;
-  npd_tool->source                 = source;
-  npd_tool->npd_node               = node;
-  npd_tool->sink                   = sink;
   npd_tool->source_buffer          = source_buffer;
   npd_tool->preview_buffer         = preview_buffer;
   npd_tool->selected_cp            = NULL;
@@ -292,11 +296,6 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
   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),
                         &offset_x, &offset_y);
@@ -332,6 +331,7 @@ gimp_n_point_deformation_tool_halt (GimpNPointDeformationTool *npd_tool)
 {
   GimpTool     *tool      = GIMP_TOOL (npd_tool);
   GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (npd_tool);
+  GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);
 
   gimp_n_point_deformation_tool_halt_threads (npd_tool);
 
@@ -347,6 +347,9 @@ gimp_n_point_deformation_tool_halt (GimpNPointDeformationTool *npd_tool)
   gimp_item_set_visible (GIMP_ITEM (npd_tool->drawable), TRUE, FALSE);
   gimp_image_flush (gimp_display_get_image (npd_tool->display));
 
+  /* disable some options */
+  gimp_n_point_deformation_options_init_some_widgets (npd_options, FALSE);
+
   npd_tool->active = FALSE;
 
   if (gimp_draw_tool_is_active (draw_tool))
@@ -369,10 +372,10 @@ gimp_n_point_deformation_tool_halt (GimpNPointDeformationTool *npd_tool)
 }
 
 static void
-gimp_n_point_deformation_tool_set_options (GeglNode                     *npd_node,
+gimp_n_point_deformation_tool_set_options (GimpNPointDeformationTool    *npd_tool,
                                            GimpNPointDeformationOptions *npd_options)
 {
-  gegl_node_set (npd_node,
+  gegl_node_set (npd_tool->npd_node,
                  "square size",       (gint) npd_options->square_size,
                  "rigidity",          (gint) npd_options->rigidity,
                  "ASAP deformation",  npd_options->ASAP_deformation,
@@ -398,7 +401,7 @@ gimp_n_point_deformation_tool_options_notify (GimpTool         *tool,
   gimp_draw_tool_pause (draw_tool);
 
   gimp_npd_debug (("npd options notify\n"));
-  gimp_n_point_deformation_tool_set_options (npd_tool->npd_node, npd_options);
+  gimp_n_point_deformation_tool_set_options (npd_tool, npd_options);
 
   gimp_draw_tool_resume (draw_tool);
 }
@@ -962,8 +965,7 @@ gimp_n_point_deformation_tool_apply_deformation (GimpNPointDeformationTool *npd_
   height = gegl_buffer_get_height (buffer);
 
   npd_options->mesh_visible = FALSE;
-  gimp_n_point_deformation_tool_set_options (npd_tool->npd_node,
-                                             npd_options);
+  gimp_n_point_deformation_tool_set_options (npd_tool, npd_options);
 
   gimp_drawable_push_undo (npd_tool->drawable, _(GIMP_NPD_STRING), NULL,
                            0, 0, width, height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]