1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "appenv.h"
|
|
|
|
#include "drawable.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "gdisplay.h"
|
Overhaul of pixmap brushes and pipes: No separate pixmap pipe
brush tool any longer. The paintbrush, airbrush and pencil
tools, which already knew how to handle the single-pixmap
brushes now also handle the pipes as well.
* app/pixmapbrush.{h,c}
* app/gimpbrushpixmap.{h,c}: Removed these files.
* app/Makefile.am
* app/makefile.{cygwin,msc}: Remove from here, too.
* app/gimpbrushpipe.{h,c}: Total overhaul.
* app/paint_core.h
* app/apptypes.h: Some more types moved to apptypes.h
* app/context_manager.c
* app/tool_options.c
* app/tools.c
* app/toolsF.h: Remove PIXMAPBRUSH tool.
* app/gimpbrush.h: New method: select_brush. Used to change the
brush in paint_core, for pipe brushes.
* app/gimpbrush.c: Add gimp_brush_select_brush, which is dummy for
the normal brushes (returns the same brush).
* app/paint_core.c: Call the brush's select_brush method to get a
potential new brush before calling the paint_func.
* app/gimpbrushlist.c: Various changes related to the pixmap and
pipe overhaul.
* app/airbrush.c
* app/pencil.c: Reorder code a bit in the tool motion function to
avoid executing unnecessary code in the case of a pixmap brush.
Other changes in the same commit:
* app/install.c: Make quote_spaces extern.
* app/appenv.h: Declare it.
* libgimp/gimpui.def: Add missing entry points.
* libgimp/makefile.{cygwin,msc}: Add missing objects to gimpui.
1999-08-26 08:54:30 +08:00
|
|
|
#include "gimpbrushpipe.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paint_funcs.h"
|
|
|
|
#include "paint_core.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "paint_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paintbrush.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "palette.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "pencil.h"
|
|
|
|
#include "selection.h"
|
1999-08-31 14:13:30 +08:00
|
|
|
#include "tool_options_ui.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tools.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
|
|
|
/* the pencil tool options */
|
1999-08-31 14:13:30 +08:00
|
|
|
typedef struct _PencilOptions PencilOptions;
|
|
|
|
struct _PencilOptions
|
|
|
|
{
|
|
|
|
PaintOptions paint_options;
|
|
|
|
|
|
|
|
int use_pressure;
|
|
|
|
int use_pressure_d;
|
|
|
|
GtkWidget *use_pressure_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
};
|
|
|
|
static PencilOptions *pencil_options = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* forward function declarations */
|
1999-08-31 14:13:30 +08:00
|
|
|
static void pencil_motion (PaintCore *, GimpDrawable *, gboolean, gboolean);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
static gboolean non_gui_incremental = FALSE;
|
1999-08-31 14:13:30 +08:00
|
|
|
static gboolean non_gui_pressure = TRUE;
|
|
|
|
static void pencil_options_reset (void);
|
1999-08-14 04:50:30 +08:00
|
|
|
|
|
|
|
#define PENCIL_INCREMENTAL_DEFAULT FALSE
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void *
|
1999-04-09 06:25:54 +08:00
|
|
|
pencil_paint_func (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case INIT_PAINT :
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTION_PAINT :
|
1999-08-31 14:13:30 +08:00
|
|
|
pencil_motion (paint_core, drawable, pencil_options->paint_options.incremental,
|
|
|
|
pencil_options->use_pressure);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FINISH_PAINT :
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
static void
|
|
|
|
pencil_pressure_toggle_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
tool_options_toggle_update (widget, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PencilOptions *
|
|
|
|
pencil_options_new (void)
|
|
|
|
{
|
|
|
|
PencilOptions *options;
|
|
|
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
|
|
|
|
options = (PencilOptions *) g_malloc (sizeof (PencilOptions));
|
|
|
|
|
|
|
|
paint_options_init ((PaintOptions *) options,
|
|
|
|
PENCIL,
|
|
|
|
pencil_options_reset);
|
|
|
|
options->use_pressure =
|
|
|
|
options->use_pressure_d = TRUE;
|
|
|
|
|
|
|
|
vbox = ((ToolOptions *) options)->main_vbox;
|
|
|
|
|
|
|
|
|
|
|
|
options->use_pressure_w =
|
|
|
|
gtk_check_button_new_with_label (_("Use Pressure"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), options->use_pressure_w, FALSE, FALSE, 0);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->use_pressure_w), "toggled",
|
|
|
|
(GtkSignalFunc) pencil_pressure_toggle_callback,
|
|
|
|
&options->use_pressure);
|
|
|
|
gtk_widget_show (options->use_pressure_w);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-04-22 22:34:00 +08:00
|
|
|
pencil_options_reset (void)
|
|
|
|
{
|
1999-08-31 14:13:30 +08:00
|
|
|
PencilOptions *options = pencil_options;
|
|
|
|
paint_options_reset ((PaintOptions *) pencil_options);
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->use_pressure_w),
|
|
|
|
options->use_pressure_d);
|
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
Tool *
|
1999-04-19 05:22:41 +08:00
|
|
|
tools_new_pencil (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
PaintCore * private;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!pencil_options)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
1999-08-31 14:13:30 +08:00
|
|
|
pencil_options = pencil_options_new ();
|
1999-04-22 22:34:00 +08:00
|
|
|
tools_register (PENCIL, (ToolOptions *) pencil_options);
|
1999-08-31 14:13:30 +08:00
|
|
|
pencil_options_reset();
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool = paint_core_new (PENCIL);
|
|
|
|
|
|
|
|
private = (PaintCore *) tool->private;
|
|
|
|
private->paint_func = pencil_paint_func;
|
1999-05-14 08:37:58 +08:00
|
|
|
private->pick_colors = TRUE;
|
1999-08-27 05:33:58 +08:00
|
|
|
private->flags |= TOOL_CAN_HANDLE_CHANGING_BRUSH;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-04-09 06:25:54 +08:00
|
|
|
tools_free_pencil (Tool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
paint_core_free (tool);
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1999-04-09 06:25:54 +08:00
|
|
|
pencil_motion (PaintCore *paint_core,
|
1999-08-14 04:50:30 +08:00
|
|
|
GimpDrawable *drawable,
|
1999-08-31 14:13:30 +08:00
|
|
|
gboolean increment,
|
|
|
|
gboolean pressure)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
TempBuf * area;
|
|
|
|
unsigned char col[MAX_CHANNELS];
|
1999-07-10 00:41:58 +08:00
|
|
|
gint opacity;
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
PaintApplicationMode paint_appl_mode = increment ? INCREMENTAL : CONSTANT;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (gimage = drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get a region which can be used to paint to */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (area = paint_core_get_paint_area (paint_core, drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
if (GIMP_IS_BRUSH_PIXMAP (paint_core->brush))
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
|
|
|
/* if its a pixmap, do pixmap stuff */
|
1999-09-01 14:02:08 +08:00
|
|
|
|
|
|
|
color_area_with_pixmap (paint_core, gimage, drawable, area,HARD );
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
paint_appl_mode = INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* color the pixels */
|
Overhaul of pixmap brushes and pipes: No separate pixmap pipe
brush tool any longer. The paintbrush, airbrush and pencil
tools, which already knew how to handle the single-pixmap
brushes now also handle the pipes as well.
* app/pixmapbrush.{h,c}
* app/gimpbrushpixmap.{h,c}: Removed these files.
* app/Makefile.am
* app/makefile.{cygwin,msc}: Remove from here, too.
* app/gimpbrushpipe.{h,c}: Total overhaul.
* app/paint_core.h
* app/apptypes.h: Some more types moved to apptypes.h
* app/context_manager.c
* app/tool_options.c
* app/tools.c
* app/toolsF.h: Remove PIXMAPBRUSH tool.
* app/gimpbrush.h: New method: select_brush. Used to change the
brush in paint_core, for pipe brushes.
* app/gimpbrush.c: Add gimp_brush_select_brush, which is dummy for
the normal brushes (returns the same brush).
* app/paint_core.c: Call the brush's select_brush method to get a
potential new brush before calling the paint_func.
* app/gimpbrushlist.c: Various changes related to the pixmap and
pipe overhaul.
* app/airbrush.c
* app/pencil.c: Reorder code a bit in the tool motion function to
avoid executing unnecessary code in the case of a pixmap brush.
Other changes in the same commit:
* app/install.c: Make quote_spaces extern.
* app/appenv.h: Declare it.
* libgimp/gimpui.def: Add missing entry points.
* libgimp/makefile.{cygwin,msc}: Add missing objects to gimpui.
1999-08-26 08:54:30 +08:00
|
|
|
gimage_get_foreground (gimage, drawable, col);
|
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
1999-08-14 04:50:30 +08:00
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-07-10 00:41:58 +08:00
|
|
|
/*Make the opacity dependent on the current pressure
|
|
|
|
This makes a more natural pencil since light pressure
|
|
|
|
on a graphite pen will give transparent line */
|
|
|
|
|
1999-08-31 14:13:30 +08:00
|
|
|
if(pressure)
|
|
|
|
{
|
|
|
|
opacity = 255 * gimp_context_get_opacity (NULL) * (paint_core->curpressure / 0.5);
|
|
|
|
if (opacity > 255)
|
|
|
|
opacity = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
opacity = 255 * gimp_context_get_opacity (NULL);
|
|
|
|
if (opacity > 255)
|
|
|
|
opacity = 255;
|
|
|
|
}
|
1999-07-10 00:41:58 +08:00
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* paste the newly painted canvas to the gimage which is being worked on */
|
1999-07-10 00:41:58 +08:00
|
|
|
paint_core_paste_canvas (paint_core, drawable, opacity,
|
1999-07-06 23:18:25 +08:00
|
|
|
(int) (gimp_context_get_opacity (NULL) * 255),
|
|
|
|
gimp_context_get_paint_mode (NULL),
|
Actually use the enum types GimpImageType, GimpImageBaseType,
* app/*.[ch]: Actually use the enum types GimpImageType,
GimpImageBaseType, LayerModeEffects, PaintApplicationMode,
BrushApplicationMode, GimpFillType and ConvertPaletteType, instead
of just int or gint. Hopefully I catched most of the places
where these should be used.
Add an enum ConvolutionType, suffix the too general constants
NORMAL, ABSOLUTE and NEGATIVE with _CONVOL. Use NORMAL_MODE
instead of NORMAL in some places (this was what was intended). Fix
some minor gccisms.
* app/apptypes.h: New file. This file contains the above
enumeration types, and some opaque struct typedefs. It was
necessary to collect these in one header that doesn't include
other headers, because when we started using the above mentioned
types in the headers, all hell broke loose because of the
spaghetti-like cross-inclusion mess between headers.
(An example: Header A includes header B, which includes header C
which includes A. B uses a type defined in A. This is not defined,
because A hasn't defined it yet at the point where it includes B,
and A included from B of course is skipped as we already are
reading A.)
1999-08-19 07:41:39 +08:00
|
|
|
HARD, paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
1999-04-09 06:25:54 +08:00
|
|
|
pencil_non_gui_paint_func (PaintCore *paint_core,
|
1999-08-20 03:53:30 +08:00
|
|
|
GimpDrawable *drawable,
|
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-31 14:13:30 +08:00
|
|
|
pencil_motion (paint_core, drawable, non_gui_incremental, non_gui_pressure);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
pencil_non_gui (GimpDrawable *drawable,
|
1999-08-20 03:53:30 +08:00
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
if (paint_core_init (&non_gui_paint_core, drawable,
|
1999-07-06 23:18:25 +08:00
|
|
|
stroke_array[0], stroke_array[1]))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Set the paint core's paint func */
|
1997-11-25 06:05:25 +08:00
|
|
|
non_gui_paint_core.paint_func = pencil_non_gui_paint_func;
|
|
|
|
|
|
|
|
non_gui_paint_core.startx = non_gui_paint_core.lastx = stroke_array[0];
|
|
|
|
non_gui_paint_core.starty = non_gui_paint_core.lasty = stroke_array[1];
|
|
|
|
|
1999-07-23 07:11:46 +08:00
|
|
|
pencil_non_gui_paint_func (&non_gui_paint_core, drawable, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
1999-05-14 08:37:58 +08:00
|
|
|
{
|
|
|
|
non_gui_paint_core.curx = stroke_array[i * 2 + 0];
|
|
|
|
non_gui_paint_core.cury = stroke_array[i * 2 + 1];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-14 08:37:58 +08:00
|
|
|
paint_core_interpolate (&non_gui_paint_core, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-14 08:37:58 +08:00
|
|
|
non_gui_paint_core.lastx = non_gui_paint_core.curx;
|
|
|
|
non_gui_paint_core.lasty = non_gui_paint_core.cury;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
1998-01-22 15:02:57 +08:00
|
|
|
paint_core_finish (&non_gui_paint_core, drawable, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Cleanup */
|
1997-11-25 06:05:25 +08:00
|
|
|
paint_core_cleanup ();
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|