[gimp] app, libgimp, pdb: new PDB API to enable/disable dynamics.



commit d9387811f427f1f22dc838808a68d655f93df9d8
Author: Jehan <jehan girinstud io>
Date:   Fri Feb 4 13:54:59 2022 +0100

    app, libgimp, pdb: new PDB API to enable/disable dynamics.
    
    New libgimp C functions:
    - gimp_context_are_dynamics_enabled()
    - gimp_context_enable_dynamics()

 app/paint/gimpbrushcore.c    |   2 +-
 app/paint/gimppaintoptions.c |  24 +++++++---
 app/paint/gimppaintoptions.h |   5 +-
 app/pdb/context-cmds.c       | 110 ++++++++++++++++++++++++++++++++++++++++++-
 app/pdb/internal-procs.c     |   2 +-
 libgimp/gimpcontext_pdb.c    |  83 ++++++++++++++++++++++++++++++--
 libgimp/gimpcontext_pdb.h    |   2 +
 pdb/groups/context.pdb       |  74 +++++++++++++++++++++++++++--
 8 files changed, 285 insertions(+), 17 deletions(-)
---
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 7a6a9578fb..1013ae1a3c 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -365,7 +365,7 @@ gimp_brush_core_start (GimpPaintCore     *paint_core,
 
   gimp_brush_core_set_brush (core, gimp_context_get_brush (context));
 
-  if (gimp_paint_options_get_dynamics_enabled (paint_options))
+  if (gimp_paint_options_are_dynamics_enabled (paint_options))
     {
       gimp_brush_core_set_dynamics (core, gimp_context_get_dynamics (context));
     }
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index f402640d52..484039fbbc 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -983,12 +983,6 @@ gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
   return 0.0;
 }
 
-gboolean
-gimp_paint_options_get_dynamics_enabled (GimpPaintOptions *paint_options)
-{
-  return paint_options->dynamics_enabled;
-}
-
 gboolean
 gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
                                        GimpImage        *image,
@@ -1169,6 +1163,24 @@ gimp_paint_options_set_default_brush_hardness (GimpPaintOptions *paint_options,
     }
 }
 
+gboolean
+gimp_paint_options_are_dynamics_enabled (GimpPaintOptions *paint_options)
+{
+  return paint_options->dynamics_enabled;
+}
+
+void
+gimp_paint_options_enable_dynamics (GimpPaintOptions *paint_options,
+                                    gboolean          enable)
+{
+  if (paint_options->dynamics_enabled != enable)
+    {
+      g_object_set (paint_options,
+                    "dynamics-enabled", enable,
+                    NULL);
+    }
+}
+
 static const gchar *brush_props[] =
 {
   "brush-size",
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index e5803a9b0c..19b7d0a935 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -166,12 +166,15 @@ void     gimp_paint_options_set_default_brush_hardness
                                                (GimpPaintOptions    *options,
                                                 GimpBrush           *brush);
 
+gboolean gimp_paint_options_are_dynamics_enabled (GimpPaintOptions *paint_options);
+void     gimp_paint_options_enable_dynamics      (GimpPaintOptions *paint_options,
+                                                  gboolean          enable);
+
 gboolean gimp_paint_options_is_prop            (const gchar         *prop_name,
                                                 GimpContextPropMask  prop_mask);
 void     gimp_paint_options_copy_props         (GimpPaintOptions    *src,
                                                 GimpPaintOptions    *dest,
                                                 GimpContextPropMask  prop_mask);
 
-gboolean gimp_paint_options_get_dynamics_enabled (GimpPaintOptions *paint_options);
 
 #endif  /*  __GIMP_PAINT_OPTIONS_H__  */
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index 2878b75c05..6105a4ec89 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -1398,6 +1398,65 @@ context_set_dynamics_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
+static GimpValueArray *
+context_are_dynamics_enabled_invoker (GimpProcedure         *procedure,
+                                      Gimp                  *gimp,
+                                      GimpContext           *context,
+                                      GimpProgress          *progress,
+                                      const GimpValueArray  *args,
+                                      GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  gboolean enabled = FALSE;
+
+  GimpPaintOptions *options =
+    gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                        "gimp-paintbrush");
+
+  if (options)
+    enabled = gimp_paint_options_are_dynamics_enabled (options);
+  else
+    success = FALSE;
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_set_boolean (gimp_value_array_index (return_vals, 1), enabled);
+
+  return return_vals;
+}
+
+static GimpValueArray *
+context_enable_dynamics_invoker (GimpProcedure         *procedure,
+                                 Gimp                  *gimp,
+                                 GimpContext           *context,
+                                 GimpProgress          *progress,
+                                 const GimpValueArray  *args,
+                                 GError               **error)
+{
+  gboolean success = TRUE;
+  gboolean enable;
+
+  enable = g_value_get_boolean (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      GimpPaintOptions *options =
+        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                            "gimp-paintbrush");
+
+      if (options)
+        gimp_paint_options_enable_dynamics (options, enable);
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 context_get_mypaint_brush_invoker (GimpProcedure         *procedure,
                                    Gimp                  *gimp,
@@ -4165,7 +4224,8 @@ register_context_procs (GimpPDB *pdb)
                                "gimp-context-get-dynamics");
   gimp_procedure_set_static_help (procedure,
                                   "Retrieve the currently active paint dynamics.",
-                                  "This procedure returns the name of the currently active paint dynamics. 
All paint operations and stroke operations use this paint dynamics to control the application of paint to the 
image.",
+                                  "This procedure returns the name of the currently active paint dynamics. 
If enabled, all paint operations and stroke operations use this paint dynamics to control the application of 
paint to the image. If disabled, the dynamics will be ignored during paint actions.\n"
+                                     "See 'gimp-context-are-dynamics-enabled' to enquire whether dynamics 
are used or ignored.",
                                   NULL);
   gimp_procedure_set_static_attribution (procedure,
                                          "Michael Natterer <mitch gimp org>",
@@ -4189,7 +4249,7 @@ register_context_procs (GimpPDB *pdb)
                                "gimp-context-set-dynamics");
   gimp_procedure_set_static_help (procedure,
                                   "Set the specified paint dynamics as the active paint dynamics.",
-                                  "This procedure allows the active paint dynamics to be set by specifying 
its name. The name is simply a string which corresponds to one of the names of the installed paint dynamics. 
If there is no matching paint dynamics found, this procedure will return an error. Otherwise, the specified 
paint dynamics becomes active and will be used in all subsequent paint operations.",
+                                  "This procedure allows the active paint dynamics to be set by specifying 
its name. The name is simply a string which corresponds to one of the names of the installed paint dynamics. 
If there is no matching paint dynamics found, this procedure will return an error. Otherwise, the specified 
paint dynamics becomes active and will be used in all subsequent paint operations as long as dynamics are 
enabled.",
                                   NULL);
   gimp_procedure_set_static_attribution (procedure,
                                          "Michael Natterer <mitch gimp org>",
@@ -4205,6 +4265,52 @@ register_context_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-context-are-dynamics-enabled
+   */
+  procedure = gimp_procedure_new (context_are_dynamics_enabled_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-are-dynamics-enabled");
+  gimp_procedure_set_static_help (procedure,
+                                  "Inform whether the currently active paint dynamics will be applied to 
painting.",
+                                  "This procedure returns whether the currently active paint dynamics (as 
returned by 'gimp-context-get-dynamics') is enabled.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Jehan",
+                                         "Jehan",
+                                         "2022");
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_boolean ("enabled",
+                                                         "enabled",
+                                                         "Whether dynamics enabled or disabled",
+                                                         FALSE,
+                                                         GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-enable-dynamics
+   */
+  procedure = gimp_procedure_new (context_enable_dynamics_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-enable-dynamics");
+  gimp_procedure_set_static_help (procedure,
+                                  "Set the specified paint dynamics as the active paint dynamics.",
+                                  "This procedure enables the active paint dynamics to be used in all 
subsequent paint operations.",
+                                  NULL);
+  gimp_procedure_set_static_attribution (procedure,
+                                         "Jehan",
+                                         "Jehan",
+                                         "2022");
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_boolean ("enable",
+                                                     "enable",
+                                                     "Whether to enable or disable dynamics",
+                                                     FALSE,
+                                                     GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-context-get-mypaint-brush
    */
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 25446a4097..08410e66eb 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 759 procedures registered total */
+/* 761 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c
index b5673b927a..2720747346 100644
--- a/libgimp/gimpcontext_pdb.c
+++ b/libgimp/gimpcontext_pdb.c
@@ -1839,8 +1839,12 @@ gimp_context_set_brush_force (gdouble force)
  * Retrieve the currently active paint dynamics.
  *
  * This procedure returns the name of the currently active paint
- * dynamics. All paint operations and stroke operations use this paint
- * dynamics to control the application of paint to the image.
+ * dynamics. If enabled, all paint operations and stroke operations use
+ * this paint dynamics to control the application of paint to the
+ * image. If disabled, the dynamics will be ignored during paint
+ * actions.
+ * See gimp_context_are_dynamics_enabled() to enquire whether dynamics
+ * are used or ignored.
  *
  * Returns: (transfer full): The name of the active paint dynamics.
  *          The returned value must be freed with g_free().
@@ -1881,7 +1885,8 @@ gimp_context_get_dynamics (void)
  * to one of the names of the installed paint dynamics. If there is no
  * matching paint dynamics found, this procedure will return an error.
  * Otherwise, the specified paint dynamics becomes active and will be
- * used in all subsequent paint operations.
+ * used in all subsequent paint operations as long as dynamics are
+ * enabled.
  *
  * Returns: TRUE on success.
  *
@@ -1910,6 +1915,78 @@ gimp_context_set_dynamics (const gchar *name)
   return success;
 }
 
+/**
+ * gimp_context_are_dynamics_enabled:
+ *
+ * Inform whether the currently active paint dynamics will be applied
+ * to painting.
+ *
+ * This procedure returns whether the currently active paint dynamics
+ * (as returned by gimp_context_get_dynamics()) is enabled.
+ *
+ * Returns: Whether dynamics enabled or disabled.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_context_are_dynamics_enabled (void)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean enabled = FALSE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-context-are-dynamics-enabled",
+                                              args);
+  gimp_value_array_unref (args);
+
+  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+    enabled = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
+
+  gimp_value_array_unref (return_vals);
+
+  return enabled;
+}
+
+/**
+ * gimp_context_enable_dynamics:
+ * @enable: Whether to enable or disable dynamics.
+ *
+ * Set the specified paint dynamics as the active paint dynamics.
+ *
+ * This procedure enables the active paint dynamics to be used in all
+ * subsequent paint operations.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_context_enable_dynamics (gboolean enable)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          G_TYPE_BOOLEAN, enable,
+                                          G_TYPE_NONE);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-context-enable-dynamics",
+                                              args);
+  gimp_value_array_unref (args);
+
+  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+  gimp_value_array_unref (return_vals);
+
+  return success;
+}
+
 /**
  * gimp_context_get_mypaint_brush:
  *
diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h
index 743037e309..5f4434b45a 100644
--- a/libgimp/gimpcontext_pdb.h
+++ b/libgimp/gimpcontext_pdb.h
@@ -86,6 +86,8 @@ gdouble                     gimp_context_get_brush_force                (void);
 gboolean                    gimp_context_set_brush_force                (gdouble                        
force);
 gchar*                      gimp_context_get_dynamics                   (void);
 gboolean                    gimp_context_set_dynamics                   (const gchar                   
*name);
+gboolean                    gimp_context_are_dynamics_enabled           (void);
+gboolean                    gimp_context_enable_dynamics                (gboolean                       
enable);
 gchar*                      gimp_context_get_mypaint_brush              (void);
 gboolean                    gimp_context_set_mypaint_brush              (const gchar                   
*name);
 gchar*                      gimp_context_get_pattern                    (void);
diff --git a/pdb/groups/context.pdb b/pdb/groups/context.pdb
index 352520dd5e..6ac2d44a68 100644
--- a/pdb/groups/context.pdb
+++ b/pdb/groups/context.pdb
@@ -1459,8 +1459,12 @@ sub context_get_dynamics {
 
     $help = <<'HELP';
 This procedure returns the name of the currently active paint
-dynamics.  All paint operations and stroke operations use this paint
-dynamics to control the application of paint to the image.
+dynamics. If enabled, all paint operations and stroke operations use
+this paint dynamics to control the application of paint to the image.
+If disabled, the dynamics will be ignored during paint actions.
+
+See gimp_context_are_dynamics_enabled() to enquire whether dynamics are
+used or ignored.
 HELP
 
     &mitch_pdb_misc('2011', '2.8');
@@ -1493,7 +1497,7 @@ specifying its name.  The name is simply a string which corresponds to
 one of the names of the installed paint dynamics. If there is no
 matching paint dynamics found, this procedure will return an error.
 Otherwise, the specified paint dynamics becomes active and will be
-used in all subsequent paint operations.
+used in all subsequent paint operations as long as dynamics are enabled.
 HELP
 
     &mitch_pdb_misc('2011', '2.8');
@@ -1517,6 +1521,69 @@ CODE
     );
 }
 
+sub context_are_dynamics_enabled {
+    $blurb = 'Inform whether the currently active paint dynamics will be applied to painting.';
+
+    $help = <<'HELP';
+This procedure returns whether the currently active paint dynamics (as
+returned by gimp_context_get_dynamics()) is enabled.
+HELP
+
+    &jehan_pdb_misc('2022', '3.0');
+
+    @outargs = (
+       { name => "enabled", type => 'boolean',
+         desc => "Whether dynamics enabled or disabled" }
+    );
+
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpPaintOptions *options =
+    gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                        "gimp-paintbrush");
+
+  if (options)
+    enabled = gimp_paint_options_are_dynamics_enabled (options);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
+sub context_enable_dynamics {
+    $blurb = 'Set the specified paint dynamics as the active paint dynamics.';
+
+    $help = <<'HELP';
+This procedure enables the active paint dynamics to be used in all
+subsequent paint operations.
+HELP
+
+    &jehan_pdb_misc('2022', '3.0');
+
+    @inargs = (
+       { name => "enable", type => 'boolean',
+         desc => "Whether to enable or disable dynamics" }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpPaintOptions *options =
+    gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context),
+                                        "gimp-paintbrush");
+
+  if (options)
+    gimp_paint_options_enable_dynamics (options, enable);
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub context_get_mypaint_brush {
     $blurb = 'Retrieve the currently active MyPaint brush.';
 
@@ -3380,6 +3447,7 @@ CODE
             context_get_brush_force
             context_set_brush_force
             context_get_dynamics context_set_dynamics
+            context_are_dynamics_enabled context_enable_dynamics
             context_get_mypaint_brush context_set_mypaint_brush
             context_get_pattern context_set_pattern
             context_get_gradient context_set_gradient


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