[gimp/wip/Jehan/issue-498-quick-brush-edit: 515/523] app: new "tools-paint-select-pixel-size-set" action.




commit 1d4a3d80f56a395ca3e471b800921206905e3d6a
Author: Jehan <jehan girinstud io>
Date:   Sun Apr 3 14:16:17 2022 +0200

    app: new "tools-paint-select-pixel-size-set" action.
    
    Also ensure that the outline circle is redrawn while changing the
    outline size.

 app/actions/tools-actions.c     | 12 ++++++++++++
 app/actions/tools-commands.c    | 30 ++++++++++++++++++++++++++++++
 app/actions/tools-commands.h    |  4 ++++
 app/tools/gimppaintselecttool.c | 16 ++++++++++++++--
 4 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/app/actions/tools-actions.c b/app/actions/tools-actions.c
index 5745e11624..c845a25476 100644
--- a/app/actions/tools-actions.c
+++ b/app/actions/tools-actions.c
@@ -601,6 +601,13 @@ static const GimpEnumActionEntry tools_force_actions[] =
     NULL },
 };
 
+static const GimpDoubleActionEntry tools_paint_select_pixel_size_actions[] =
+{
+  { "tools-paint-select-pixel-size-set", GIMP_ICON_TOOL_PAINT_SELECT,
+    "Set Paint Select Brush Size in Pixel", NULL, NULL,
+    1.0, NULL }
+};
+
 static const GimpEnumActionEntry tools_object_1_actions[] =
 {
   { "tools-object-1-set", GIMP_ICON_DIALOG_TOOL_OPTIONS,
@@ -794,6 +801,11 @@ tools_actions_setup (GimpActionGroup *group)
                                       G_N_ELEMENTS (tools_force_actions),
                                       tools_force_cmd_callback);
 
+  gimp_action_group_add_double_actions (group, NULL,
+                                        tools_paint_select_pixel_size_actions,
+                                        G_N_ELEMENTS (tools_paint_select_pixel_size_actions),
+                                        tools_paint_select_pixel_size_cmd_callback);
+
   gimp_action_group_add_enum_actions (group, NULL,
                                       tools_object_1_actions,
                                       G_N_ELEMENTS (tools_object_1_actions),
diff --git a/app/actions/tools-commands.c b/app/actions/tools-commands.c
index 8ff3b681e5..4fd3586a13 100644
--- a/app/actions/tools-commands.c
+++ b/app/actions/tools-commands.c
@@ -44,6 +44,7 @@
 #include "tools/gimp-tools.h"
 #include "tools/gimpcoloroptions.h"
 #include "tools/gimpforegroundselectoptions.h"
+#include "tools/gimppaintselectoptions.h"
 #include "tools/gimprectangleoptions.h"
 #include "tools/gimptool.h"
 #include "tools/gimptoolcontrol.h"
@@ -863,6 +864,35 @@ tools_force_cmd_callback (GimpAction *action,
     }
 }
 
+void
+tools_paint_select_pixel_size_cmd_callback (GimpAction *action,
+                                            GVariant   *value,
+                                            gpointer    data)
+{
+  GimpContext          *context;
+  GimpToolInfo         *tool_info;
+  gdouble               dvalue;
+  return_if_no_context (context, data);
+
+  dvalue = g_variant_get_double (value);
+  tool_info = gimp_context_get_tool (context);
+
+  if (tool_info && GIMP_IS_PAINT_SELECT_OPTIONS (tool_info->tool_options))
+    {
+      GParamSpec *pspec;
+
+      pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (tool_info->tool_options),
+                                            "stroke-width");
+      dvalue = CLAMP (dvalue,
+                      G_PARAM_SPEC_INT (pspec)->minimum,
+                      G_PARAM_SPEC_INT (pspec)->maximum);
+
+      g_object_set (G_OBJECT (tool_info->tool_options),
+                    "stroke-width", (gint) dvalue,
+                    NULL);
+    }
+}
+
 void
 tools_object_1_cmd_callback (GimpAction *action,
                              GVariant   *value,
diff --git a/app/actions/tools-commands.h b/app/actions/tools-commands.h
index b9e93ec983..0ea178a1cb 100644
--- a/app/actions/tools-commands.h
+++ b/app/actions/tools-commands.h
@@ -121,6 +121,10 @@ void   tools_force_cmd_callback                     (GimpAction *action,
                                                      GVariant   *value,
                                                      gpointer    data);
 
+void   tools_paint_select_pixel_size_cmd_callback   (GimpAction *action,
+                                                     GVariant   *value,
+                                                     gpointer    data);
+
 void   tools_object_1_cmd_callback                  (GimpAction *action,
                                                      GVariant   *value,
                                                      gpointer    data);
diff --git a/app/tools/gimppaintselecttool.c b/app/tools/gimppaintselecttool.c
index 10bad87431..bc680b9d0a 100644
--- a/app/tools/gimppaintselecttool.c
+++ b/app/tools/gimppaintselecttool.c
@@ -210,8 +210,11 @@ gimp_paint_select_tool_init (GimpPaintSelectTool *ps_tool)
                                      GIMP_TOOL_CURSOR_PAINTBRUSH);
   gimp_tool_control_set_cursor_modifier (tool->control,
                                          GIMP_CURSOR_MODIFIER_PLUS);
-  gimp_tool_control_set_action_size (tool->control,
-                                     "tools/tools-paint-select-brush-size-set");
+  gimp_tool_control_set_action_pixel_size (tool->control,
+                                           "tools/tools-paint-select-pixel-size-set");
+  /* TODO: the size-set action is not implemented. */
+  gimp_tool_control_set_action_size       (tool->control,
+                                           "tools/tools-paint-select-size-set");
   ps_tool->image_mask  = NULL;
   ps_tool->trimap      = NULL;
   ps_tool->drawable    = NULL;
@@ -577,6 +580,15 @@ gimp_paint_select_tool_options_notify (GimpTool         *tool,
 {
   GimpPaintSelectTool  *ps_tool = GIMP_PAINT_SELECT_TOOL (tool);
 
+  if (g_strcmp0 (pspec->name, "stroke-width") == 0)
+    {
+      /* This triggers a redraw of the tool pointer, especially useful
+       * here when we change the pen size with on-canvas interaction.
+       */
+      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
+      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
+    }
+
   if (! tool->display)
     return;
 


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