[gimp] app: add a modifier action for opacity change.



commit d72a42ed2018296395571f9e45398162daa9f34d
Author: Jehan <jehan girinstud io>
Date:   Wed Aug 17 16:46:26 2022 +0200

    app: add a modifier action for opacity change.
    
    Opacity and brush size are among the 2 most common tool options which
    people might want to often change, though we should likely later add all
    other common types of tool settings angle, aspect ratio, spacing, etc.
    
    I am also unsure using the enum action is the right call because what it
    does is just taking into account the distance from initial click to
    compute an opacity. Instead it might be more interesting to increase or
    decrease slowly or rapidly by going right or left from the initial
    click. We'll see. But it's a first step.

 app/display/display-enums.c                |  2 ++
 app/display/display-enums.h                |  1 +
 app/display/gimpdisplayshell-tool-events.c | 33 ++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)
---
diff --git a/app/display/display-enums.c b/app/display/display-enums.c
index 9ba4003a47..c789c52fe9 100644
--- a/app/display/display-enums.c
+++ b/app/display/display-enums.c
@@ -607,6 +607,7 @@ gimp_modifier_action_get_type (void)
     { GIMP_MODIFIER_ACTION_ACTION, "GIMP_MODIFIER_ACTION_ACTION", "action" },
     { GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE, "GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE", "brush-pixel-size" },
     { GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE, "GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE", 
"brush-radius-pixel-size" },
+    { GIMP_MODIFIER_ACTION_TOOL_OPACITY, "GIMP_MODIFIER_ACTION_TOOL_OPACITY", "tool-opacity" },
     { 0, NULL, NULL }
   };
 
@@ -622,6 +623,7 @@ gimp_modifier_action_get_type (void)
     { GIMP_MODIFIER_ACTION_ACTION, NC_("modifier-action", "Custom action"), NULL },
     { GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE, NC_("modifier-action", "Change brush size in canvas pixels"), 
NULL },
     { GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE, NC_("modifier-action", "Change brush radius' size in 
canvas pixels"), NULL },
+    { GIMP_MODIFIER_ACTION_TOOL_OPACITY, NC_("modifier-action", "Change tool opacity"), NULL },
     { 0, NULL, NULL }
   };
 
diff --git a/app/display/display-enums.h b/app/display/display-enums.h
index fb969bca0d..d032038e46 100644
--- a/app/display/display-enums.h
+++ b/app/display/display-enums.h
@@ -280,6 +280,7 @@ typedef enum
 
   GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE,        /*< desc="Change brush size in canvas pixels"         >*/
   GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE, /*< desc="Change brush radius' size in canvas pixels" >*/
+  GIMP_MODIFIER_ACTION_TOOL_OPACITY,            /*< desc="Change tool opacity"                        >*/
 } GimpModifierAction;
 
 
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index 7e82ec9395..ed62d2cf55 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -593,6 +593,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
               case GIMP_MODIFIER_ACTION_LAYER_PICKING:
               case GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE:
               case GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE:
+              case GIMP_MODIFIER_ACTION_TOOL_OPACITY:
                 gimp_display_shell_start_scrolling (shell, event, state,
                                                     bevent->x, bevent->y);
                 break;
@@ -753,6 +754,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
                 break;
               case GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE:
               case GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE:
+              case GIMP_MODIFIER_ACTION_TOOL_OPACITY:
                 gimp_display_shell_stop_scrolling (shell, event);
                 break;
               case GIMP_MODIFIER_ACTION_ACTION:
@@ -1756,6 +1758,7 @@ gimp_display_shell_start_scrolling (GimpDisplayShell *shell,
       break;
     case GIMP_MODIFIER_ACTION_BRUSH_PIXEL_SIZE:
     case GIMP_MODIFIER_ACTION_BRUSH_RADIUS_PIXEL_SIZE:
+    case GIMP_MODIFIER_ACTION_TOOL_OPACITY:
         {
           Gimp     *gimp        = gimp_display_get_gimp (shell->display);
           GimpTool *active_tool = tool_manager_get_active (gimp);
@@ -1928,6 +1931,36 @@ gimp_display_shell_handle_scrolling (GimpDisplayShell *shell,
             }
         }
       break;
+    case GIMP_MODIFIER_ACTION_TOOL_OPACITY:
+        {
+          GimpDisplay *display     = shell->display;
+          Gimp        *gimp        = gimp_display_get_gimp (display);
+          GimpTool    *active_tool = tool_manager_get_active (gimp);
+          const gchar *action;
+          gint         size;
+
+          /* Size in image pixels: distance between start and current
+           * position.
+           */
+          size = (gint) (sqrt (pow ((x - shell->scroll_start_x) / shell->scale_x, 2) +
+                               pow ((y - shell->scroll_start_y) / shell->scale_y, 2)));
+
+          action = gimp_tool_control_get_action_opacity (active_tool->control);
+
+          if (action)
+            {
+              GimpImageWindow *window  = gimp_display_shell_get_window (shell);
+              GimpUIManager   *manager = gimp_image_window_get_ui_manager (window);
+
+              /* Special trick with these enum actions. If using any
+               * positive value, we get the GIMP_ACTION_SELECT_SET behavior
+               * which sets to the given value.
+               */
+              gimp_display_shell_activate_action (manager, action,
+                                                  g_variant_new_int32 (size));
+            }
+        }
+      break;
     case GIMP_MODIFIER_ACTION_PANNING:
       gimp_display_shell_scroll (shell,
                                  shell->scroll_last_x - x,


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