[gimp/soc-2013-n-point-deformation-tool: 6/25] app: npd-tool: add provisional tool's options



commit 36f2e8aa11bacd17039a2057e7b82d202eca2121
Author: Marek Dvoroznak <dvoromar gmail com>
Date:   Tue Aug 13 22:55:57 2013 +0200

    app: npd-tool: add provisional tool's options

 app/tools/gimpnpointdeformationoptions.c |  114 ++++++++++++++++++++++++++++--
 app/tools/gimpnpointdeformationoptions.h |    6 ++
 app/tools/gimpnpointdeformationtool.c    |   36 +++++++++-
 3 files changed, 149 insertions(+), 7 deletions(-)
---
diff --git a/app/tools/gimpnpointdeformationoptions.c b/app/tools/gimpnpointdeformationoptions.c
index c7408c5..05c87b8 100644
--- a/app/tools/gimpnpointdeformationoptions.c
+++ b/app/tools/gimpnpointdeformationoptions.c
@@ -27,11 +27,24 @@
 
 #include "tools-types.h"
 
+#include "widgets/gimppropwidgets.h"
+#include "widgets/gimpspinscale.h"
+
 #include "gimpnpointdeformationoptions.h"
 #include "gimptooloptions-gui.h"
 
 #include "gimp-intl.h"
 
+enum
+{
+    PROP_0,
+    PROP_SQUARE_SIZE,
+    PROP_RIGIDITY,
+    PROP_ASAP_DEFORMATION,
+    PROP_MLS_WEIGHTS,
+    PROP_MLS_WEIGHTS_ALPHA
+};
+
 
 static void   gimp_n_point_deformation_options_set_property (GObject      *object,
                                                              guint         property_id,
@@ -57,6 +70,30 @@ gimp_n_point_deformation_options_class_init (GimpNPointDeformationOptionsClass *
   object_class->set_property = gimp_n_point_deformation_options_set_property;
   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"),
+                                    5.0, 1000.0, 20.0,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE  (object_class, PROP_RIGIDITY,
+                                    "rigidity", _("Rigidity"),
+                                    1.0, 10000.0, 100.0,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_ASAP_DEFORMATION,
+                                    "ASAP-deformation", _("Deformation Type"),
+                                    FALSE,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_MLS_WEIGHTS,
+                                    "MLS-weights", _("MLS Weights"),
+                                    FALSE,
+                                    GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE  (object_class, PROP_MLS_WEIGHTS_ALPHA,
+                                    "MLS-weights-alpha", _("MLS Weights Alpha"),
+                                    0.1, 2.0, 1.0,
+                                    GIMP_PARAM_STATIC_STRINGS);
 }
 
 static void
@@ -70,8 +107,29 @@ gimp_n_point_deformation_options_set_property (GObject      *object,
                                                const GValue *value,
                                                GParamSpec   *pspec)
 {
-//  GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
-
+  GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
+
+  switch (property_id)
+    {
+      case PROP_SQUARE_SIZE:
+        options->square_size = g_value_get_double (value);
+        break;
+      case PROP_RIGIDITY:
+        options->rigidity = g_value_get_double (value);
+        break;
+      case PROP_ASAP_DEFORMATION:
+        options->ASAP_deformation = g_value_get_boolean (value);
+        break;
+      case PROP_MLS_WEIGHTS:
+        options->MLS_weights = g_value_get_boolean (value);
+        break;
+      case PROP_MLS_WEIGHTS_ALPHA:
+        options->square_size = g_value_get_double (value);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
 }
 
 static void
@@ -80,15 +138,61 @@ gimp_n_point_deformation_options_get_property (GObject    *object,
                                                GValue     *value,
                                                GParamSpec *pspec)
 {
-//  GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
+  GimpNPointDeformationOptions *options = GIMP_N_POINT_DEFORMATION_OPTIONS (object);
+
+  switch (property_id)
+    {
+      case PROP_SQUARE_SIZE:
+        g_value_set_double (value, options->square_size);
+        break;
+      case PROP_RIGIDITY:
+        g_value_set_double (value, options->rigidity);
+        break;
+      case PROP_ASAP_DEFORMATION:
+        g_value_set_boolean (value, options->ASAP_deformation);
+        break;
+      case PROP_MLS_WEIGHTS:
+        g_value_set_boolean (value, options->MLS_weights);
+        break;
+      case PROP_MLS_WEIGHTS_ALPHA:
+        g_value_set_double (value, options->square_size);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
 }
 
 GtkWidget *
 gimp_n_point_deformation_options_gui (GimpToolOptions *tool_options)
 {
-//  GObject   *config = G_OBJECT (tool_options);
+  GObject   *config = G_OBJECT (tool_options);
   GtkWidget *vbox   = gimp_tool_options_gui (tool_options);
+  GtkWidget *combo;
+  GtkWidget *scale;
+
+  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);
+
+  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);
+
+  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);
+
+  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);
+
+  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);
 
   return vbox;
 }
-
diff --git a/app/tools/gimpnpointdeformationoptions.h b/app/tools/gimpnpointdeformationoptions.h
index 3e7ef45..3b6b668 100644
--- a/app/tools/gimpnpointdeformationoptions.h
+++ b/app/tools/gimpnpointdeformationoptions.h
@@ -38,6 +38,12 @@ typedef struct _GimpNPointDeformationOptionsClass GimpNPointDeformationOptionsCl
 struct _GimpNPointDeformationOptions
 {
   GimpToolOptions  parent_instance;
+
+  gdouble          square_size;
+  gdouble          rigidity;
+  gboolean         ASAP_deformation;
+  gboolean         MLS_weights;
+  gdouble          MLS_weights_alpha;
 };
 
 struct _GimpNPointDeformationOptionsClass
diff --git a/app/tools/gimpnpointdeformationtool.c b/app/tools/gimpnpointdeformationtool.c
index 462c528..fe31d7a 100644
--- a/app/tools/gimpnpointdeformationtool.c
+++ b/app/tools/gimpnpointdeformationtool.c
@@ -57,6 +57,8 @@
 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,
+                                                                       GimpNPointDeformationOptions 
*npd_options);
 static void     gimp_n_point_deformation_tool_options_notify          (GimpTool                  *tool,
                                                                        GimpToolOptions           *options,
                                                                        const GParamSpec          *pspec);
@@ -234,9 +236,12 @@ gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool,
   sink     = gegl_node_new_child (graph, "operation", "gegl:write-buffer",
                                       "buffer", shadow,
                                       NULL);
-
-  gegl_node_link_many (source, node, sink, NULL);
   
+  gegl_node_link_many (source, node, sink, NULL);
+
+  gimp_n_point_deformation_tool_set_options (node,
+                                             GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool));
+
   gegl_node_process (sink);
   
   gegl_node_get (node, "model", &model, NULL);
@@ -268,10 +273,37 @@ gimp_n_point_deformation_tool_halt (GimpNPointDeformationTool *npd_tool)
 }
 
 static void
+gimp_n_point_deformation_tool_set_options (GeglNode                     *npd_node,
+                                           GimpNPointDeformationOptions *npd_options)
+{
+  gegl_node_set (npd_node,
+                 "square size",       (int) npd_options->square_size,
+                 "rigidity",          (int) npd_options->rigidity,
+                 "ASAP deformation",  npd_options->ASAP_deformation,
+                 "MLS weights",       npd_options->MLS_weights,
+                 "MLS weights alpha", npd_options->MLS_weights_alpha,
+                 NULL);
+}
+
+static void
 gimp_n_point_deformation_tool_options_notify (GimpTool         *tool,
                                               GimpToolOptions  *options,
                                               const GParamSpec *pspec)
 {
+  GimpNPointDeformationTool    *npd_tool    = GIMP_N_POINT_DEFORMATION_TOOL (tool);
+  GimpDrawTool                 *draw_tool   = GIMP_DRAW_TOOL (tool);
+  GimpNPointDeformationOptions *npd_options = GIMP_N_POINT_DEFORMATION_OPTIONS (options);
+
+  GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
+
+  if (!npd_tool->active) return;
+
+  gimp_draw_tool_pause (draw_tool);
+
+  gimp_npd_debug (("npd options notify\n"));
+  gimp_n_point_deformation_tool_set_options (npd_tool->node, npd_options);
+
+  gimp_draw_tool_resume (draw_tool);
 }
 
 static gboolean


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