[gimp] libgimp: new gimp_procedure_dialog_get_spin_scale() and support of…



commit 7ca4d0ca451a2da43dffc9844608deba0971db8d
Author: Jehan <jehan girinstud io>
Date:   Sat Feb 19 01:22:48 2022 +0100

    libgimp: new gimp_procedure_dialog_get_spin_scale() and support of…
    
    … %GIMP_TYPE_SPIN_SCALE in gimp_procedure_dialog_get_widget().
    
    The dedicated function is for when a plug-in wants to use a scale range
    multiplied by a factor. Otherwise using the generic function is fine.

 libgimp/gimpproceduredialog.c | 92 ++++++++++++++++++++++++++++++++++++++++++-
 libgimp/gimpproceduredialog.h |  3 ++
 libgimp/gimpui.def            |  1 +
 3 files changed, 95 insertions(+), 1 deletion(-)
---
diff --git a/libgimp/gimpproceduredialog.c b/libgimp/gimpproceduredialog.c
index 5d502dc53c..213ee4cd36 100644
--- a/libgimp/gimpproceduredialog.c
+++ b/libgimp/gimpproceduredialog.c
@@ -549,7 +549,8 @@ gimp_procedure_dialog_new (GimpProcedure       *procedure,
  *     * %GTK_TYPE_SWITCH
  * - %G_TYPE_PARAM_INT or %G_TYPE_PARAM_DOUBLE:
  *     * %GIMP_TYPE_LABEL_SPIN (default): a spin button with a label.
- *     * %GIMP_TYPE_SCALE_ENTRY: a scale entry.
+ *     * %GIMP_TYPE_SCALE_ENTRY: a scale entry with label.
+ *     * %GIMP_TYPE_SPIN_SCALE: a spin scale with label embedded.
  *     * %GIMP_TYPE_SPIN_BUTTON: a spin button with no label.
  * - %G_TYPE_PARAM_STRING:
  *     * %GIMP_TYPE_LABEL_ENTRY (default): an entry with a label.
@@ -649,6 +650,11 @@ gimp_procedure_dialog_get_widget (GimpProcedureDialog *dialog,
                                               _(g_param_spec_get_nick (pspec)),
                                               1.0, FALSE, 0.0, 0.0);
         }
+      else if (widget_type == GIMP_TYPE_SPIN_SCALE)
+        {
+          widget = gimp_prop_spin_scale_new (G_OBJECT (dialog->priv->config),
+                                             property, step, page, digits);
+        }
       else if (widget_type == GIMP_TYPE_SPIN_BUTTON)
         {
           /* Just some spin button without label. */
@@ -926,6 +932,90 @@ gimp_procedure_dialog_get_int_combo (GimpProcedureDialog *dialog,
   return widget;
 }
 
+/**
+ * gimp_procedure_dialog_get_spin_scale:
+ * @dialog:   the associated #GimpProcedureDialog.
+ * @property: name of the int or double property to build a
+ *            #GimpSpinScale for. It must be a property of the
+ *            #GimpProcedure @dialog has been created for.
+ * @factor:   a display factor for the range shown by the widget.
+ *
+ * Creates a new #GimpSpinScale for @property which must necessarily be
+ * an integer or double property.
+ * This can be used instead of gimp_procedure_dialog_get_widget() in
+ * particular if you want to tweak the display factor. A typical example
+ * is showing a [0.0, 1.0] range as [0.0, 100.0] instead (@factor = 100.0).
+ *
+ * If a widget has already been created for this procedure, it will be
+ * returned instead (whatever its actual widget type).
+ *
+ * Returns: (transfer none): the #GtkWidget representing @property. The
+ *                           object belongs to @dialog and must not be
+ *                           freed.
+ */
+GtkWidget *
+gimp_procedure_dialog_get_spin_scale (GimpProcedureDialog *dialog,
+                                      const gchar         *property,
+                                      gdouble              factor)
+{
+  GtkWidget  *widget = NULL;
+  GParamSpec *pspec;
+  gdouble     minimum;
+  gdouble     maximum;
+  gdouble     step   = 0.0;
+  gdouble     page   = 0.0;
+  gint        digits = 0;
+
+  g_return_val_if_fail (GIMP_IS_PROCEDURE_DIALOG (dialog), NULL);
+  g_return_val_if_fail (property != NULL, NULL);
+
+  pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (dialog->priv->config),
+                                        property);
+
+  if (! pspec)
+    {
+      g_warning ("%s: parameter %s does not exist.",
+                 G_STRFUNC, property);
+      return NULL;
+    }
+
+  g_return_val_if_fail (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT ||
+                        G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_DOUBLE, NULL);
+
+  /* First check if it already exists. */
+  widget = g_hash_table_lookup (dialog->priv->widgets, property);
+
+  if (widget)
+    return widget;
+
+  if (G_PARAM_SPEC_TYPE (pspec) == G_TYPE_PARAM_INT)
+    {
+      GParamSpecInt *pspecint = (GParamSpecInt *) pspec;
+
+      minimum = (gdouble) pspecint->minimum;
+      maximum = (gdouble) pspecint->maximum;
+    }
+  else /* G_TYPE_PARAM_DOUBLE */
+    {
+      GParamSpecDouble *pspecdouble = (GParamSpecDouble *) pspec;
+
+      minimum = pspecdouble->minimum;
+      maximum = pspecdouble->maximum;
+    }
+  gimp_range_estimate_settings (minimum * factor, maximum * factor, &step, &page, &digits);
+
+  widget = gimp_prop_spin_scale_new (G_OBJECT (dialog->priv->config),
+                                     property, step, page, digits);
+  gimp_prop_widget_set_factor (widget, factor, step, page, digits);
+
+  gimp_procedure_dialog_check_mnemonic (dialog, widget, property, NULL);
+  g_hash_table_insert (dialog->priv->widgets, g_strdup (property), widget);
+  if (g_object_is_floating (widget))
+    g_object_ref_sink (widget);
+
+  return widget;
+}
+
 /**
  * gimp_procedure_dialog_get_scale_entry:
  * @dialog:   the associated #GimpProcedureDialog.
diff --git a/libgimp/gimpproceduredialog.h b/libgimp/gimpproceduredialog.h
index b3d44eafef..0107bb8ef2 100644
--- a/libgimp/gimpproceduredialog.h
+++ b/libgimp/gimpproceduredialog.h
@@ -85,6 +85,9 @@ GtkWidget * gimp_procedure_dialog_get_color_widget  (GimpProcedureDialog *dialog
 GtkWidget * gimp_procedure_dialog_get_int_combo     (GimpProcedureDialog *dialog,
                                                      const gchar         *property,
                                                      GimpIntStore        *store);
+GtkWidget * gimp_procedure_dialog_get_spin_scale    (GimpProcedureDialog *dialog,
+                                                     const gchar         *property,
+                                                     gdouble              factor);
 GtkWidget * gimp_procedure_dialog_get_scale_entry   (GimpProcedureDialog *dialog,
                                                      const gchar         *property,
                                                      gdouble              factor);
diff --git a/libgimp/gimpui.def b/libgimp/gimpui.def
index 46217b918b..7180a05f47 100644
--- a/libgimp/gimpui.def
+++ b/libgimp/gimpui.def
@@ -51,6 +51,7 @@ EXPORTS
        gimp_procedure_dialog_get_int_combo
        gimp_procedure_dialog_get_label
        gimp_procedure_dialog_get_scale_entry
+       gimp_procedure_dialog_get_spin_scale
        gimp_procedure_dialog_get_type
        gimp_procedure_dialog_get_widget
        gimp_procedure_dialog_new


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