[gimp/wip/Jehan/issue-498-quick-brush-edit: 511/523] app: adding GimpDoubleAction types of actions.




commit dcd0962ca420375d233f70902a84fd22add756f5
Author: Jehan <jehan girinstud io>
Date:   Tue Mar 15 15:28:20 2022 +0100

    app: adding GimpDoubleAction types of actions.
    
    These actions can be activated with a double value. These will be useful
    to create new types of size action, which are based on accurate pixel
    values instead of an enum hacked to set per-mille values between a
    min/max.

 app/widgets/Makefile.am        |   2 +
 app/widgets/gimpactiongroup.c  |  53 ++++++++++++++
 app/widgets/gimpactiongroup.h  |  17 +++++
 app/widgets/gimpdoubleaction.c | 152 +++++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpdoubleaction.h |  61 +++++++++++++++++
 app/widgets/meson.build        |   1 +
 app/widgets/widgets-types.h    |   2 +
 7 files changed, 288 insertions(+)
---
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index 26a7adf516..196ddfddaa 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -189,6 +189,8 @@ libappwidgets_a_sources = \
        gimpdockwindow.h                \
        gimpdocumentview.c              \
        gimpdocumentview.h              \
+       gimpdoubleaction.c              \
+       gimpdoubleaction.h              \
        gimpdrawabletreeview.c          \
        gimpdrawabletreeview.h          \
        gimpdynamicseditor.c            \
diff --git a/app/widgets/gimpactiongroup.c b/app/widgets/gimpactiongroup.c
index 1cb485b5fd..e13fe257e9 100644
--- a/app/widgets/gimpactiongroup.c
+++ b/app/widgets/gimpactiongroup.c
@@ -37,6 +37,7 @@
 #include "gimpaction.h"
 #include "gimpactiongroup.h"
 #include "gimpactionimpl.h"
+#include "gimpdoubleaction.h"
 #include "gimpenumaction.h"
 #include "gimpprocedureaction.h"
 #include "gimpradioaction.h"
@@ -653,6 +654,58 @@ gimp_action_group_add_string_actions (GimpActionGroup             *group,
     }
 }
 
+void
+gimp_action_group_add_double_actions (GimpActionGroup             *group,
+                                      const gchar                 *msg_context,
+                                      const GimpDoubleActionEntry *entries,
+                                      guint                        n_entries,
+                                      GimpActionCallback           callback)
+{
+  gint i;
+
+  g_return_if_fail (GIMP_IS_ACTION_GROUP (group));
+
+  for (i = 0; i < n_entries; i++)
+    {
+      GimpDoubleAction *action;
+      const gchar      *label;
+      const gchar      *tooltip = NULL;
+
+      if (! gimp_action_group_check_unique_action (group, entries[i].name))
+        continue;
+
+      if (msg_context)
+        {
+          label = g_dpgettext2 (NULL, msg_context, entries[i].label);
+
+          if (entries[i].tooltip)
+            tooltip = g_dpgettext2 (NULL, msg_context, entries[i].tooltip);
+        }
+      else
+        {
+          label = gettext (entries[i].label);
+          if (entries[i].tooltip)
+            tooltip = gettext (entries[i].tooltip);
+        }
+
+      action = gimp_double_action_new (entries[i].name, label, tooltip,
+                                       entries[i].icon_name,
+                                       entries[i].help_id,
+                                       entries[i].value);
+
+      if (callback)
+        g_signal_connect (action, "gimp-activate",
+                          G_CALLBACK (callback),
+                          group->user_data);
+
+      gimp_action_group_add_action_with_accel (group, GIMP_ACTION (action),
+                                               entries[i].accelerator);
+      g_signal_emit (group, signals[ACTION_ADDED], 0, action);
+
+      g_object_unref (action);
+    }
+}
+
 void
 gimp_action_group_add_procedure_actions (GimpActionGroup                *group,
                                          const GimpProcedureActionEntry *entries,
diff --git a/app/widgets/gimpactiongroup.h b/app/widgets/gimpactiongroup.h
index f3bd72c487..ad0bfcea17 100644
--- a/app/widgets/gimpactiongroup.h
+++ b/app/widgets/gimpactiongroup.h
@@ -123,6 +123,18 @@ struct _GimpStringActionEntry
   const gchar *help_id;
 };
 
+struct _GimpDoubleActionEntry
+{
+  const gchar   *name;
+  const gchar   *icon_name;
+  const gchar   *label;
+  const gchar   *accelerator;
+  const gchar   *tooltip;
+  const gdouble  value;
+
+  const gchar   *help_id;
+};
+
 struct _GimpProcedureActionEntry
 {
   const gchar   *name;
@@ -189,6 +201,11 @@ void   gimp_action_group_add_string_actions   (GimpActionGroup             *grou
                                                const GimpStringActionEntry *entries,
                                                guint                        n_entries,
                                                GimpActionCallback           callback);
+void   gimp_action_group_add_double_actions   (GimpActionGroup             *group,
+                                               const gchar                 *msg_context,
+                                               const GimpDoubleActionEntry *entries,
+                                               guint                        n_entries,
+                                               GimpActionCallback           callback);
 void   gimp_action_group_add_procedure_actions(GimpActionGroup             *group,
                                                const GimpProcedureActionEntry *entries,
                                                guint                        n_entries,
diff --git a/app/widgets/gimpdoubleaction.c b/app/widgets/gimpdoubleaction.c
new file mode 100644
index 0000000000..9bb5a33c75
--- /dev/null
+++ b/app/widgets/gimpdoubleaction.c
@@ -0,0 +1,152 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdoubleaction.c
+ * Copyright (C) 2022 Jehan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "libgimpbase/gimpbase.h"
+
+#include "widgets-types.h"
+
+#include "gimpaction.h"
+#include "gimpaction-history.h"
+#include "gimpdoubleaction.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_VALUE
+};
+
+
+static void   gimp_double_action_set_property (GObject      *object,
+                                               guint         prop_id,
+                                               const GValue *value,
+                                               GParamSpec   *pspec);
+static void   gimp_double_action_get_property (GObject      *object,
+                                               guint         prop_id,
+                                               GValue       *value,
+                                               GParamSpec   *pspec);
+
+static void   gimp_double_action_activate     (GtkAction    *action);
+
+
+G_DEFINE_TYPE (GimpDoubleAction, gimp_double_action, GIMP_TYPE_ACTION_IMPL)
+
+#define parent_class gimp_double_action_parent_class
+
+
+static void
+gimp_double_action_class_init (GimpDoubleActionClass *klass)
+{
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+  GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
+
+  object_class->set_property = gimp_double_action_set_property;
+  object_class->get_property = gimp_double_action_get_property;
+
+  action_class->activate = gimp_double_action_activate;
+
+  g_object_class_install_property (object_class, PROP_VALUE,
+                                   g_param_spec_double ("value",
+                                                        NULL, NULL,
+                                                        -G_MAXDOUBLE, G_MAXDOUBLE,
+                                                        0.0,
+                                                        GIMP_PARAM_READWRITE));
+}
+
+static void
+gimp_double_action_init (GimpDoubleAction *action)
+{
+}
+
+static void
+gimp_double_action_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GimpDoubleAction *action = GIMP_DOUBLE_ACTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_VALUE:
+      g_value_set_double (value, action->value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_double_action_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GimpDoubleAction *action = GIMP_DOUBLE_ACTION (object);
+
+  switch (prop_id)
+    {
+    case PROP_VALUE:
+      action->value = g_value_get_double (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+GimpDoubleAction *
+gimp_double_action_new (const gchar *name,
+                        const gchar *label,
+                        const gchar *tooltip,
+                        const gchar *icon_name,
+                        const gchar *help_id,
+                        gdouble      value)
+{
+  GimpDoubleAction *action;
+
+  action = g_object_new (GIMP_TYPE_DOUBLE_ACTION,
+                         "name",      name,
+                         "label",     label,
+                         "tooltip",   tooltip,
+                         "icon-name", icon_name,
+                         "value",     value,
+                         NULL);
+
+  gimp_action_set_help_id (GIMP_ACTION (action), help_id);
+
+  return action;
+}
+
+static void
+gimp_double_action_activate (GtkAction *action)
+{
+  GimpDoubleAction *double_action = GIMP_DOUBLE_ACTION (action);
+
+  gimp_action_emit_activate (GIMP_ACTION (action),
+                             g_variant_new_double (double_action->value));
+
+  gimp_action_history_action_activated (GIMP_ACTION (action));
+}
diff --git a/app/widgets/gimpdoubleaction.h b/app/widgets/gimpdoubleaction.h
new file mode 100644
index 0000000000..6a825a3cfd
--- /dev/null
+++ b/app/widgets/gimpdoubleaction.h
@@ -0,0 +1,61 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdoubleaction.h
+ * Copyright (C) 2022 Jehan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_DOUBLE_ACTION_H__
+#define __GIMP_DOUBLE_ACTION_H__
+
+
+#include "gimpactionimpl.h"
+
+
+#define GIMP_TYPE_DOUBLE_ACTION            (gimp_double_action_get_type ())
+#define GIMP_DOUBLE_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DOUBLE_ACTION, 
GimpDoubleAction))
+#define GIMP_DOUBLE_ACTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DOUBLE_ACTION, 
GimpDoubleActionClass))
+#define GIMP_IS_DOUBLE_ACTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_DOUBLE_ACTION))
+#define GIMP_IS_DOUBLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GIMP_TYPE_DOUBLE_ACTION))
+#define GIMP_DOUBLE_ACTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GIMP_TYPE_DOUBLE_ACTION, 
GimpDoubleActionClass))
+
+
+typedef struct _GimpDoubleActionClass GimpDoubleActionClass;
+
+struct _GimpDoubleAction
+{
+  GimpActionImpl  parent_instance;
+
+  gdouble         value;
+};
+
+struct _GimpDoubleActionClass
+{
+  GimpActionImplClass parent_class;
+};
+
+
+GType              gimp_double_action_get_type (void) G_GNUC_CONST;
+
+GimpDoubleAction * gimp_double_action_new      (const gchar *name,
+                                                const gchar *label,
+                                                const gchar *tooltip,
+                                                const gchar *icon_name,
+                                                const gchar *help_id,
+                                                gdouble      value);
+
+
+#endif  /* __GIMP_DOUBLE_ACTION_H__ */
diff --git a/app/widgets/meson.build b/app/widgets/meson.build
index e1b1d2d08a..ff67a0336c 100644
--- a/app/widgets/meson.build
+++ b/app/widgets/meson.build
@@ -96,6 +96,7 @@ libappwidgets_sources = [
   'gimpdocked.c',
   'gimpdockwindow.c',
   'gimpdocumentview.c',
+  'gimpdoubleaction.c',
   'gimpdrawabletreeview.c',
   'gimpdynamicseditor.c',
   'gimpdynamicsfactoryview.c',
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index e7272cc97f..98a8c45720 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -127,6 +127,7 @@ typedef struct _GimpToolPresetFactoryView    GimpToolPresetFactoryView;
 typedef struct _GimpAction                   GimpAction;
 typedef struct _GimpActionFactory            GimpActionFactory;
 typedef struct _GimpActionGroup              GimpActionGroup;
+typedef struct _GimpDoubleAction             GimpDoubleAction;
 typedef struct _GimpEnumAction               GimpEnumAction;
 typedef struct _GimpMenuFactory              GimpMenuFactory;
 typedef struct _GimpProcedureAction          GimpProcedureAction;
@@ -284,6 +285,7 @@ typedef struct _GimpSessionManaged           GimpSessionManaged;
 /*  structs  */
 
 typedef struct _GimpActionEntry              GimpActionEntry;
+typedef struct _GimpDoubleActionEntry        GimpDoubleActionEntry;
 typedef struct _GimpEnumActionEntry          GimpEnumActionEntry;
 typedef struct _GimpProcedureActionEntry     GimpProcedureActionEntry;
 typedef struct _GimpRadioActionEntry         GimpRadioActionEntry;


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