1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 #include "config.h"
19 
20 #include <gegl.h>
21 #include <gtk/gtk.h>
22 
23 #include "libgimpwidgets/gimpwidgets.h"
24 
25 #include "tools-types.h"
26 
27 #include "operations/layer-modes/gimp-layer-modes.h"
28 
29 #include "paint/gimppaintoptions.h"
30 
31 #include "widgets/gimphelp-ids.h"
32 
33 #include "gimppaintbrushtool.h"
34 #include "gimppaintoptions-gui.h"
35 #include "gimptoolcontrol.h"
36 
37 #include "gimp-intl.h"
38 
39 
40 static gboolean   gimp_paintbrush_tool_is_alpha_only (GimpPaintTool *paint_tool,
41                                                       GimpDrawable  *drawable);
42 
43 
G_DEFINE_TYPE(GimpPaintbrushTool,gimp_paintbrush_tool,GIMP_TYPE_BRUSH_TOOL)44 G_DEFINE_TYPE (GimpPaintbrushTool, gimp_paintbrush_tool, GIMP_TYPE_BRUSH_TOOL)
45 
46 
47 void
48 gimp_paintbrush_tool_register (GimpToolRegisterCallback  callback,
49                                gpointer                  data)
50 {
51   (* callback) (GIMP_TYPE_PAINTBRUSH_TOOL,
52                 GIMP_TYPE_PAINT_OPTIONS,
53                 gimp_paint_options_gui,
54                 GIMP_PAINT_OPTIONS_CONTEXT_MASK |
55                 GIMP_CONTEXT_PROP_MASK_GRADIENT,
56                 "gimp-paintbrush-tool",
57                 _("Paintbrush"),
58                 _("Paintbrush Tool: Paint smooth strokes using a brush"),
59                 N_("_Paintbrush"), "P",
60                 NULL, GIMP_HELP_TOOL_PAINTBRUSH,
61                 GIMP_ICON_TOOL_PAINTBRUSH,
62                 data);
63 }
64 
65 static void
gimp_paintbrush_tool_class_init(GimpPaintbrushToolClass * klass)66 gimp_paintbrush_tool_class_init (GimpPaintbrushToolClass *klass)
67 {
68   GimpPaintToolClass *paint_tool_class = GIMP_PAINT_TOOL_CLASS (klass);
69 
70   paint_tool_class->is_alpha_only = gimp_paintbrush_tool_is_alpha_only;
71 }
72 
73 static void
gimp_paintbrush_tool_init(GimpPaintbrushTool * paintbrush)74 gimp_paintbrush_tool_init (GimpPaintbrushTool *paintbrush)
75 {
76   GimpTool *tool = GIMP_TOOL (paintbrush);
77 
78   gimp_tool_control_set_tool_cursor (tool->control,
79                                      GIMP_TOOL_CURSOR_PAINTBRUSH);
80 
81   gimp_paint_tool_enable_color_picker (GIMP_PAINT_TOOL (paintbrush),
82                                        GIMP_COLOR_PICK_TARGET_FOREGROUND);
83 }
84 
85 static gboolean
gimp_paintbrush_tool_is_alpha_only(GimpPaintTool * paint_tool,GimpDrawable * drawable)86 gimp_paintbrush_tool_is_alpha_only (GimpPaintTool *paint_tool,
87                                     GimpDrawable  *drawable)
88 {
89   GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (paint_tool);
90   GimpContext      *context       = GIMP_CONTEXT (paint_options);
91   GimpLayerMode     paint_mode    = gimp_context_get_paint_mode (context);
92 
93   return gimp_layer_mode_is_alpha_only (paint_mode);
94 }
95