1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
1 |
/* GIMP - The GNU Image Manipulation Program
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
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 2 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, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 |
*/
|
|
18 |
||
19 |
#include "config.h" |
|
20 |
||
21 |
#include <glib-object.h> |
|
22 |
||
23 |
#include "libgimpcolor/gimpcolor.h" |
|
24 |
#include "libgimpmath/gimpmath.h" |
|
25 |
#include "libgimpbase/gimpbase.h" |
|
26 |
||
27 |
#include "paint-types.h" |
|
28 |
||
29 |
#include "base/temp-buf.h" |
|
30 |
||
31 |
#include "paint-funcs/paint-funcs.h" |
|
32 |
||
33 |
#include "core/gimp.h" |
|
34 |
#include "core/gimpbrush.h" |
|
35 |
#include "core/gimpdrawable.h" |
|
36 |
#include "core/gimpgradient.h" |
|
37 |
#include "core/gimpimage.h" |
|
38 |
||
39 |
#include "gimppaintbrush.h" |
|
40 |
#include "gimppaintoptions.h" |
|
41 |
||
42 |
#include "gimp-intl.h" |
|
43 |
||
44 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
45 |
static void gimp_paintbrush_paint (GimpPaintCore *paint_core, |
46 |
GimpDrawable *drawable, |
|
47 |
GimpPaintOptions *paint_options, |
|
48 |
GimpPaintState paint_state, |
|
49 |
guint32 time); |
|
50 |
||
51 |
||
52 |
G_DEFINE_TYPE (GimpPaintbrush, gimp_paintbrush, GIMP_TYPE_BRUSH_CORE) |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
53 |
|
54 |
||
55 |
void
|
|
56 |
gimp_paintbrush_register (Gimp *gimp, |
|
57 |
GimpPaintRegisterCallback callback) |
|
58 |
{
|
|
59 |
(* callback) (gimp, |
|
60 |
GIMP_TYPE_PAINTBRUSH, |
|
61 |
GIMP_TYPE_PAINT_OPTIONS, |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
62 |
"gimp-paintbrush", |
63 |
_("Paintbrush"), |
|
64 |
"gimp-tool-paintbrush"); |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
65 |
}
|
66 |
||
67 |
static void |
|
68 |
gimp_paintbrush_class_init (GimpPaintbrushClass *klass) |
|
69 |
{
|
|
70 |
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass); |
|
71 |
GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_CLASS (klass); |
|
72 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
73 |
paint_core_class->paint = gimp_paintbrush_paint; |
1
by Daniel Holbach
Import upstream version 2.2.9 |
74 |
|
75 |
brush_core_class->handles_changing_brush = TRUE; |
|
76 |
}
|
|
77 |
||
78 |
static void |
|
79 |
gimp_paintbrush_init (GimpPaintbrush *paintbrush) |
|
80 |
{
|
|
81 |
}
|
|
82 |
||
83 |
static void |
|
84 |
gimp_paintbrush_paint (GimpPaintCore *paint_core, |
|
85 |
GimpDrawable *drawable, |
|
86 |
GimpPaintOptions *paint_options, |
|
87 |
GimpPaintState paint_state, |
|
88 |
guint32 time) |
|
89 |
{
|
|
90 |
switch (paint_state) |
|
91 |
{
|
|
92 |
case GIMP_PAINT_STATE_MOTION: |
|
93 |
_gimp_paintbrush_motion (paint_core, drawable, paint_options, |
|
94 |
GIMP_OPACITY_OPAQUE); |
|
95 |
break; |
|
96 |
||
97 |
default: |
|
98 |
break; |
|
99 |
}
|
|
100 |
}
|
|
101 |
||
102 |
void
|
|
103 |
_gimp_paintbrush_motion (GimpPaintCore *paint_core, |
|
104 |
GimpDrawable *drawable, |
|
105 |
GimpPaintOptions *paint_options, |
|
106 |
gdouble opacity) |
|
107 |
{
|
|
108 |
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core); |
|
109 |
GimpContext *context = GIMP_CONTEXT (paint_options); |
|
110 |
GimpPressureOptions *pressure_options = paint_options->pressure_options; |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
111 |
GimpImage *image; |
1
by Daniel Holbach
Import upstream version 2.2.9 |
112 |
GimpRGB gradient_color; |
113 |
TempBuf *area; |
|
114 |
guchar col[MAX_CHANNELS]; |
|
115 |
GimpPaintApplicationMode paint_appl_mode; |
|
116 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
117 |
image = gimp_item_get_image (GIMP_ITEM (drawable)); |
1
by Daniel Holbach
Import upstream version 2.2.9 |
118 |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
119 |
opacity *= gimp_paint_options_get_fade (paint_options, image, |
1
by Daniel Holbach
Import upstream version 2.2.9 |
120 |
paint_core->pixel_dist); |
121 |
if (opacity == 0.0) |
|
122 |
return; |
|
123 |
||
124 |
paint_appl_mode = paint_options->application_mode; |
|
125 |
||
126 |
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options); |
|
127 |
if (! area) |
|
128 |
return; |
|
129 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
130 |
/* optionally take the color from the current gradient */
|
131 |
if (gimp_paint_options_get_gradient_color (paint_options, image, |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
132 |
paint_core->cur_coords.pressure, |
133 |
paint_core->pixel_dist, |
|
134 |
&gradient_color)) |
|
135 |
{
|
|
136 |
opacity *= gradient_color.a; |
|
137 |
||
138 |
gimp_rgb_get_uchar (&gradient_color, |
|
139 |
&col[RED_PIX], |
|
140 |
&col[GREEN_PIX], |
|
141 |
&col[BLUE_PIX]); |
|
142 |
col[ALPHA_PIX] = OPAQUE_OPACITY; |
|
143 |
||
144 |
color_pixels (temp_buf_data (area), col, |
|
145 |
area->width * area->height, |
|
146 |
area->bytes); |
|
147 |
||
148 |
paint_appl_mode = GIMP_PAINT_INCREMENTAL; |
|
149 |
}
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
150 |
/* otherwise check if the brush has a pixmap and use that to color the area */
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
151 |
else if (brush_core->brush && brush_core->brush->pixmap) |
152 |
{
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
153 |
gimp_brush_core_color_area_with_pixmap (brush_core, drawable, |
1
by Daniel Holbach
Import upstream version 2.2.9 |
154 |
area, |
155 |
gimp_paint_options_get_brush_mode (paint_options)); |
|
156 |
||
157 |
paint_appl_mode = GIMP_PAINT_INCREMENTAL; |
|
158 |
}
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
159 |
/* otherwise fill the area with the foreground color */
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
160 |
else
|
161 |
{
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
162 |
gimp_image_get_foreground (image, context, gimp_drawable_type (drawable), |
163 |
col); |
|
164 |
||
1
by Daniel Holbach
Import upstream version 2.2.9 |
165 |
col[area->bytes - 1] = OPAQUE_OPACITY; |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
166 |
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
167 |
color_pixels (temp_buf_data (area), col, |
168 |
area->width * area->height, |
|
169 |
area->bytes); |
|
170 |
}
|
|
171 |
||
1.1.8
by Steve Kowalik
Import upstream version 2.4.1 |
172 |
if (paint_core->use_pressure && pressure_options->opacity) |
1
by Daniel Holbach
Import upstream version 2.2.9 |
173 |
opacity *= PRESSURE_SCALE * paint_core->cur_coords.pressure; |
174 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
175 |
/* finally, let the brush core paste the colored area on the canvas */
|
1
by Daniel Holbach
Import upstream version 2.2.9 |
176 |
gimp_brush_core_paste_canvas (brush_core, drawable, |
177 |
MIN (opacity, GIMP_OPACITY_OPAQUE), |
|
178 |
gimp_context_get_opacity (context), |
|
179 |
gimp_context_get_paint_mode (context), |
|
180 |
gimp_paint_options_get_brush_mode (paint_options), |
|
181 |
paint_appl_mode); |
|
182 |
}
|