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>
|
1998-12-16 19:23:30 +08:00
|
|
|
#include <stdio.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <math.h>
|
|
|
|
#include "appenv.h"
|
1999-07-07 02:13:59 +08:00
|
|
|
#include "buildmenu.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "drawable.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "gdisplay.h"
|
1999-08-14 04:50:30 +08:00
|
|
|
#include "gimpbrushlist.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"
|
1999-03-17 13:40:16 +08:00
|
|
|
#include "gradient.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paint_funcs.h"
|
|
|
|
#include "paint_core.h"
|
|
|
|
#include "palette.h"
|
1999-04-22 22:34:00 +08:00
|
|
|
#include "paint_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "paintbrush.h"
|
|
|
|
#include "selection.h"
|
1999-04-13 01:55:06 +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"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* defines */
|
|
|
|
#define PAINT_LEFT_THRESHOLD 0.05
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
/* defaults for the tool options */
|
|
|
|
#define PAINTBRUSH_DEFAULT_FADE_OUT 0.0
|
|
|
|
#define PAINTBRUSH_DEFAULT_INCREMENTAL FALSE
|
|
|
|
#define PAINTBRUSH_DEFAULT_USE_GRADIENT FALSE
|
|
|
|
#define PAINTBRUSH_DEFAULT_GRADIENT_LENGTH 10.0
|
|
|
|
#define PAINTBRUSH_DEFAULT_GRADIENT_TYPE LOOP_TRIANGLE
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the paintbrush structures */
|
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
typedef struct _PaintbrushOptions PaintbrushOptions;
|
|
|
|
struct _PaintbrushOptions
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintOptions paint_options;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
double fade_out;
|
|
|
|
double fade_out_d;
|
|
|
|
GtkObject *fade_out_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
int use_gradient;
|
|
|
|
int use_gradient_d;
|
|
|
|
GtkWidget *use_gradient_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
double gradient_length;
|
|
|
|
double gradient_length_d;
|
|
|
|
GtkObject *gradient_length_w;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
int gradient_type;
|
|
|
|
int gradient_type_d;
|
1999-07-07 02:13:59 +08:00
|
|
|
GtkWidget *gradient_type_w;
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the paint brush tool options */
|
1999-06-22 06:12:07 +08:00
|
|
|
static PaintbrushOptions * paintbrush_options = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* local variables */
|
1999-06-22 06:12:07 +08:00
|
|
|
static double non_gui_fade_out;
|
|
|
|
static double non_gui_gradient_length;
|
|
|
|
static int non_gui_gradient_type;
|
|
|
|
static double non_gui_incremental;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* forward function declarations */
|
1999-06-22 06:12:07 +08:00
|
|
|
static void paintbrush_motion (PaintCore *, GimpDrawable *,
|
1999-08-19 11:51:33 +08:00
|
|
|
double, double, PaintApplicationMode, GradientPaintMode);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-03-01 09:18:45 +08:00
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
paintbrush_gradient_toggle_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintbrushOptions *options = paintbrush_options;
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
static int incremental_save = FALSE;
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
tool_options_toggle_update (widget, data);
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
if (paintbrush_options->use_gradient)
|
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
incremental_save = options->paint_options.incremental;
|
|
|
|
gtk_toggle_button_set_active
|
|
|
|
(GTK_TOGGLE_BUTTON (options->paint_options.incremental_w), TRUE);
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
1999-03-28 13:27:34 +08:00
|
|
|
else
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
gtk_toggle_button_set_active
|
|
|
|
(GTK_TOGGLE_BUTTON (options->paint_options.incremental_w),
|
|
|
|
incremental_save);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-03-22 12:10:58 +08:00
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
paintbrush_gradient_type_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1999-03-22 12:10:58 +08:00
|
|
|
{
|
1999-04-13 01:55:06 +08:00
|
|
|
if (paintbrush_options)
|
1999-07-07 02:13:59 +08:00
|
|
|
paintbrush_options->gradient_type = (GradientPaintMode) data;
|
1999-03-28 13:27:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
1999-04-13 01:55:06 +08:00
|
|
|
paintbrush_options_reset (void)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintbrushOptions *options = paintbrush_options;
|
|
|
|
|
|
|
|
paint_options_reset ((PaintOptions *) options);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->fade_out_w),
|
|
|
|
options->fade_out_d);
|
1999-04-13 01:55:06 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->use_gradient_w),
|
|
|
|
options->use_gradient_d);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->gradient_length_w),
|
|
|
|
options->gradient_length_d);
|
1999-07-07 02:13:59 +08:00
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (options->gradient_type_w),
|
|
|
|
options->gradient_type_d);
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
1999-03-28 13:27:34 +08:00
|
|
|
|
1999-04-22 22:34:00 +08:00
|
|
|
static PaintbrushOptions *
|
1999-04-13 01:55:06 +08:00
|
|
|
paintbrush_options_new (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-04-22 22:34:00 +08:00
|
|
|
PaintbrushOptions *options;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *vbox;
|
1999-04-09 06:25:54 +08:00
|
|
|
GtkWidget *abox;
|
|
|
|
GtkWidget *table;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *label;
|
1999-07-07 02:13:59 +08:00
|
|
|
GtkWidget *length_label;
|
|
|
|
GtkWidget *type_label;
|
1999-04-09 06:25:54 +08:00
|
|
|
GtkWidget *scale;
|
1999-07-07 02:13:59 +08:00
|
|
|
GtkWidget *menu;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
1999-07-07 02:13:59 +08:00
|
|
|
static MenuItem gradient_type_items[] =
|
1999-03-28 13:27:34 +08:00
|
|
|
{
|
1999-07-07 02:13:59 +08:00
|
|
|
{ N_("Once Forward"), 0, 0, paintbrush_gradient_type_callback,
|
|
|
|
(gpointer) ONCE_FORWARD, NULL, NULL },
|
|
|
|
{ N_("Once Backward"), 0, 0, paintbrush_gradient_type_callback,
|
|
|
|
(gpointer) ONCE_BACKWARDS, NULL, NULL },
|
|
|
|
{ N_("Loop Sawtooth"), 0, 0, paintbrush_gradient_type_callback,
|
|
|
|
(gpointer) LOOP_SAWTOOTH, NULL, NULL },
|
|
|
|
{ N_("Loop Triangle"), 0, 0, paintbrush_gradient_type_callback,
|
|
|
|
(gpointer) LOOP_TRIANGLE, NULL, NULL },
|
|
|
|
{ NULL, 0, 0, NULL, NULL, NULL, NULL }
|
1999-03-28 13:27:34 +08:00
|
|
|
};
|
1999-03-19 08:42:27 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the new paint tool options structure */
|
1999-04-22 22:34:00 +08:00
|
|
|
options = (PaintbrushOptions *) g_malloc (sizeof (PaintbrushOptions));
|
|
|
|
paint_options_init ((PaintOptions *) options,
|
|
|
|
PAINTBRUSH,
|
|
|
|
paintbrush_options_reset);
|
1999-07-20 06:42:49 +08:00
|
|
|
options->fade_out =
|
|
|
|
options->fade_out_d = PAINTBRUSH_DEFAULT_FADE_OUT;
|
|
|
|
options->use_gradient =
|
|
|
|
options->use_gradient_d = PAINTBRUSH_DEFAULT_USE_GRADIENT;
|
|
|
|
options->gradient_length =
|
|
|
|
options->gradient_length_d = PAINTBRUSH_DEFAULT_GRADIENT_LENGTH;
|
|
|
|
options->gradient_type =
|
|
|
|
options->gradient_type_d = PAINTBRUSH_DEFAULT_GRADIENT_TYPE;
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* the main vbox */
|
1999-04-22 22:34:00 +08:00
|
|
|
vbox = ((ToolOptions *) options)->main_vbox;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the fade-out scale */
|
1999-04-09 06:25:54 +08:00
|
|
|
table = gtk_table_new (4, 2, FALSE);
|
1999-04-22 22:34:00 +08:00
|
|
|
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 4);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
|
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 2, 3);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
label = gtk_label_new (_("Fade Out:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (label), 1.0, 1.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
|
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
options->fade_out_w =
|
|
|
|
gtk_adjustment_new (options->fade_out_d, 0.0, 50.0, 1.0, 0.1, 0.0);
|
1999-04-09 06:25:54 +08:00
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->fade_out_w));
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), scale, 1, 2, 0, 1);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->fade_out_w), "value_changed",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_double_adjustment_update,
|
1999-04-13 02:09:55 +08:00
|
|
|
&options->fade_out);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_widget_show (scale);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the use gradient toggle */
|
|
|
|
options->use_gradient_w =
|
|
|
|
gtk_check_button_new_with_label (_("Gradient"));
|
|
|
|
gtk_table_attach (GTK_TABLE (table), options->use_gradient_w, 0, 1, 1, 2,
|
1999-04-09 06:25:54 +08:00
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
|
1999-04-13 01:55:06 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (options->use_gradient_w), "toggled",
|
|
|
|
(GtkSignalFunc) paintbrush_gradient_toggle_callback,
|
|
|
|
&options->use_gradient);
|
|
|
|
gtk_widget_show (options->use_gradient_w);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-07-07 02:13:59 +08:00
|
|
|
length_label = gtk_label_new (_("Length:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (length_label), 1.0, 1.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), length_label, 0, 1, 2, 3,
|
1999-04-13 01:55:06 +08:00
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
1999-07-07 02:13:59 +08:00
|
|
|
gtk_widget_show (length_label);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the gradient length scale */
|
1999-04-09 06:25:54 +08:00
|
|
|
abox = gtk_alignment_new (0.5, 1.0, 1.0, 0.0);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), abox, 1, 2, 1, 3,
|
|
|
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (abox);
|
|
|
|
|
|
|
|
options->gradient_length_w =
|
1999-04-13 01:55:06 +08:00
|
|
|
gtk_adjustment_new (options->gradient_length_d, 1.0, 50.0, 1.1, 0.1, 0.0);
|
1999-04-09 06:25:54 +08:00
|
|
|
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->gradient_length_w));
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), scale);
|
|
|
|
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
|
|
|
|
gtk_range_set_update_policy (GTK_RANGE (scale), GTK_UPDATE_DELAYED);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (options->gradient_length_w), "value_changed",
|
1999-04-13 01:55:06 +08:00
|
|
|
(GtkSignalFunc) tool_options_double_adjustment_update,
|
|
|
|
&options->gradient_length);
|
1999-04-09 06:25:54 +08:00
|
|
|
gtk_widget_show (scale);
|
|
|
|
gtk_widget_show (table);
|
1998-03-01 09:18:45 +08:00
|
|
|
|
1999-07-07 02:13:59 +08:00
|
|
|
/* the gradient type */
|
|
|
|
type_label = gtk_label_new (_("Type:"));
|
|
|
|
gtk_misc_set_alignment (GTK_MISC (type_label), 1.0, 0.5);
|
|
|
|
gtk_table_attach (GTK_TABLE (table), type_label, 0, 1, 3, 4,
|
|
|
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
|
|
|
gtk_widget_show (type_label);
|
|
|
|
|
|
|
|
abox = gtk_alignment_new (0.0, 0.5, 0.0, 0.0);
|
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), abox, 1, 2, 3, 4);
|
|
|
|
gtk_widget_show (abox);
|
|
|
|
|
|
|
|
options->gradient_type_w = gtk_option_menu_new ();
|
|
|
|
gtk_container_add (GTK_CONTAINER (abox), options->gradient_type_w);
|
|
|
|
gtk_widget_show (options->gradient_type_w);
|
|
|
|
|
|
|
|
menu = build_menu (gradient_type_items, NULL);
|
|
|
|
gtk_option_menu_set_menu (GTK_OPTION_MENU (options->gradient_type_w), menu);
|
|
|
|
gtk_option_menu_set_history (GTK_OPTION_MENU (options->gradient_type_w),
|
|
|
|
options->gradient_type_d);
|
|
|
|
|
1999-04-19 02:55:49 +08:00
|
|
|
/* automatically set the sensitive state of the gradient stuff */
|
|
|
|
gtk_widget_set_sensitive (scale, options->use_gradient_d);
|
1999-07-07 02:13:59 +08:00
|
|
|
gtk_widget_set_sensitive (length_label, options->use_gradient_d);
|
|
|
|
gtk_widget_set_sensitive (options->gradient_type_w, options->use_gradient_d);
|
|
|
|
gtk_widget_set_sensitive (type_label, options->use_gradient_d);
|
1999-08-20 03:53:30 +08:00
|
|
|
gtk_widget_set_sensitive (options->paint_options.incremental_w,
|
|
|
|
! options->use_gradient_d);
|
1999-04-19 02:55:49 +08:00
|
|
|
gtk_object_set_data (GTK_OBJECT (options->use_gradient_w), "set_sensitive",
|
|
|
|
scale);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (scale), "set_sensitive",
|
1999-07-07 02:13:59 +08:00
|
|
|
length_label);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (length_label), "set_sensitive",
|
|
|
|
options->gradient_type_w);
|
|
|
|
gtk_object_set_data (GTK_OBJECT (options->gradient_type_w), "set_sensitive",
|
|
|
|
type_label);
|
1999-04-19 02:55:49 +08:00
|
|
|
gtk_object_set_data (GTK_OBJECT (options->use_gradient_w), "inverse_sensitive",
|
1999-08-20 03:53:30 +08:00
|
|
|
options->paint_options.incremental_w);
|
1999-04-19 02:55:49 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
1998-12-16 19:23:30 +08:00
|
|
|
#define TIMED_BRUSH 0
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void *
|
1999-07-07 02:13:59 +08:00
|
|
|
paintbrush_paint_func (PaintCore *paint_core,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable,
|
1999-07-07 02:13:59 +08:00
|
|
|
int state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-12-16 19:23:30 +08:00
|
|
|
#if TIMED_BRUSH
|
1999-04-23 14:07:09 +08:00
|
|
|
static GTimer *timer = NULL;
|
1998-12-16 19:23:30 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case INIT_PAINT :
|
1998-12-16 19:23:30 +08:00
|
|
|
#if TIMED_BRUSH
|
|
|
|
timer = g_timer_new();
|
|
|
|
g_timer_start(timer);
|
|
|
|
#endif /* TIMED_BRUSH */
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTION_PAINT :
|
1999-05-13 19:12:32 +08:00
|
|
|
paintbrush_motion (paint_core, drawable,
|
|
|
|
paintbrush_options->fade_out,
|
|
|
|
paintbrush_options->use_gradient ?
|
|
|
|
exp(paintbrush_options->gradient_length/10) : 0,
|
1999-08-20 03:53:30 +08:00
|
|
|
paintbrush_options->paint_options.incremental,
|
1999-05-13 19:12:32 +08:00
|
|
|
paintbrush_options->gradient_type);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FINISH_PAINT :
|
1998-12-16 19:23:30 +08:00
|
|
|
#if TIMED_BRUSH
|
1999-04-23 14:07:09 +08:00
|
|
|
if (timer)
|
|
|
|
{
|
|
|
|
g_timer_stop(timer);
|
|
|
|
printf("painting took %f:\n", g_timer_elapsed(timer, NULL));
|
|
|
|
g_timer_destroy(timer);
|
|
|
|
timer = NULL;
|
|
|
|
}
|
1998-12-16 19:23:30 +08:00
|
|
|
#endif /* TIMED_BRUSH */
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Tool *
|
|
|
|
tools_new_paintbrush ()
|
|
|
|
{
|
|
|
|
Tool * tool;
|
|
|
|
PaintCore * private;
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* The tool options */
|
|
|
|
if (! paintbrush_options)
|
|
|
|
{
|
|
|
|
paintbrush_options = paintbrush_options_new ();
|
|
|
|
tools_register (PAINTBRUSH, (ToolOptions *) paintbrush_options);
|
1999-04-18 07:18:43 +08:00
|
|
|
|
|
|
|
/* press all default buttons */
|
|
|
|
paintbrush_options_reset ();
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool = paint_core_new (PAINTBRUSH);
|
|
|
|
|
|
|
|
private = (PaintCore *) tool->private;
|
|
|
|
private->paint_func = paintbrush_paint_func;
|
1999-05-13 19:12:32 +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
|
|
|
|
1999-09-01 14:02:08 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tools_free_paintbrush (Tool *tool)
|
|
|
|
{
|
|
|
|
paint_core_free (tool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
1999-08-20 03:53:30 +08:00
|
|
|
paintbrush_motion (PaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
double fade_out,
|
|
|
|
double gradient_length,
|
|
|
|
PaintApplicationMode incremental,
|
|
|
|
GradientPaintMode gradient_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GImage *gimage;
|
|
|
|
TempBuf * area;
|
|
|
|
double x, paint_left;
|
1999-03-19 08:42:27 +08:00
|
|
|
double position;
|
|
|
|
unsigned char local_blend = OPAQUE_OPACITY;
|
1999-03-17 13:40:16 +08:00
|
|
|
unsigned char temp_blend = OPAQUE_OPACITY;
|
1997-11-25 06:05:25 +08:00
|
|
|
unsigned char col[MAX_CHANNELS];
|
1999-03-17 13:40:16 +08:00
|
|
|
double r,g,b,a;
|
1999-03-19 08:42:27 +08:00
|
|
|
int mode;
|
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 = incremental ? INCREMENTAL : CONSTANT;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-03-17 13:40:16 +08:00
|
|
|
position = 0.0;
|
1998-01-22 15:02:57 +08:00
|
|
|
if (! (gimage = drawable_gimage (drawable)))
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
gimage_get_foreground (gimage, drawable, col);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-08-14 04:50:30 +08:00
|
|
|
/* silly hack to be removed later */
|
|
|
|
/* paint_core->brush = gimp_brush_list_get_brush_by_index(brush_list,(rand()% gimp_brush_list_length(brush_list))); */
|
1999-08-17 09:05:59 +08:00
|
|
|
|
|
|
|
|
1999-05-15 08:02:47 +08:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* factor in the fade out value */
|
|
|
|
if (fade_out)
|
|
|
|
{
|
|
|
|
/* Model the amount of paint left as a gaussian curve */
|
|
|
|
x = ((double) paint_core->distance / fade_out);
|
|
|
|
paint_left = exp (- x * x * 0.5);
|
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
local_blend = (int) (255 * paint_left);
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
if (local_blend)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* set the alpha channel */
|
1998-01-25 09:24:46 +08:00
|
|
|
col[area->bytes - 1] = OPAQUE_OPACITY;
|
1999-03-19 08:42:27 +08:00
|
|
|
temp_blend = local_blend;
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-03-19 08:42:27 +08:00
|
|
|
/* hard core to mode LOOP_TRIANGLE */
|
1999-05-15 08:02:47 +08:00
|
|
|
/* need to make a gui to handle this */
|
1999-03-28 13:27:34 +08:00
|
|
|
mode = gradient_type;
|
1999-03-19 08:42:27 +08:00
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
if (gradient_length)
|
1999-03-17 13:40:16 +08:00
|
|
|
{
|
1999-03-19 08:42:27 +08:00
|
|
|
paint_core_get_color_from_gradient (paint_core, gradient_length, &r,&g,&b,&a,mode);
|
1999-03-17 13:40:16 +08:00
|
|
|
r = r * 255.0;
|
|
|
|
g = g * 255.0;
|
|
|
|
b = b * 255.0;
|
1999-08-19 11:51:33 +08:00
|
|
|
a = a * 255.0;
|
1999-03-19 08:42:27 +08:00
|
|
|
temp_blend = (gint)((a * local_blend)/255);
|
1999-03-17 13:40:16 +08:00
|
|
|
col[0] = (gint)r;
|
|
|
|
col[1] = (gint)g;
|
|
|
|
col[2] = (gint)b;
|
1999-03-19 08:42:27 +08:00
|
|
|
/* always use incremental mode with gradients */
|
|
|
|
/* make the gui cool later */
|
1999-08-20 03:53:30 +08:00
|
|
|
paint_appl_mode = INCREMENTAL;
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
1999-08-14 04:50:30 +08:00
|
|
|
/* just leave this because I know as soon as i delete it i'll find a bug */
|
1999-03-19 08:42:27 +08:00
|
|
|
/* printf("temp_blend: %u grad_len: %f distance: %f \n",temp_blend, gradient_length, distance); */
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* color the pixels */
|
1999-08-14 04:50:30 +08:00
|
|
|
|
|
|
|
|
1999-08-17 09:05:59 +08:00
|
|
|
/* we check to see if this is a pixmap, if so composite the
|
|
|
|
pixmap image into the are instead of the color */
|
1999-08-20 03:53:30 +08:00
|
|
|
if (GIMP_IS_BRUSH_PIXMAP (paint_core->brush) && !gradient_length)
|
1999-08-14 04:50:30 +08:00
|
|
|
{
|
1999-09-01 14:02:08 +08:00
|
|
|
color_area_with_pixmap (paint_core, gimage, drawable, area, SOFT);
|
1999-08-20 03:53:30 +08:00
|
|
|
paint_appl_mode = INCREMENTAL;
|
1999-08-14 04:50:30 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* color the pixels */
|
|
|
|
color_pixels (temp_buf_data (area), col,
|
|
|
|
area->width * area->height, area->bytes);
|
|
|
|
}
|
1999-08-23 14:06:12 +08:00
|
|
|
|
1999-03-17 13:40:16 +08:00
|
|
|
paint_core_paste_canvas (paint_core, drawable, temp_blend,
|
1999-07-06 23:18:25 +08:00
|
|
|
(int) (gimp_context_get_opacity (NULL) * 255),
|
|
|
|
gimp_context_get_paint_mode (NULL),
|
|
|
|
PRESSURE,
|
1999-08-20 03:53:30 +08:00
|
|
|
paint_appl_mode);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
1999-07-07 02:13:59 +08:00
|
|
|
paintbrush_non_gui_paint_func (PaintCore *paint_core,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable,
|
1999-07-07 02:13:59 +08:00
|
|
|
int state)
|
1998-03-01 09:18:45 +08:00
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
paintbrush_motion (paint_core,drawable,
|
|
|
|
non_gui_fade_out,
|
|
|
|
(non_gui_gradient_length)?exp(non_gui_gradient_length/10):0,
|
|
|
|
non_gui_incremental,
|
|
|
|
non_gui_gradient_type);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
gboolean
|
|
|
|
paintbrush_non_gui_default (GimpDrawable *drawable,
|
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array)
|
|
|
|
{
|
|
|
|
PaintbrushOptions *options = paintbrush_options;
|
1999-08-20 03:53:30 +08:00
|
|
|
double fade_out = PAINTBRUSH_DEFAULT_FADE_OUT;
|
|
|
|
gboolean incremental = PAINTBRUSH_DEFAULT_INCREMENTAL;
|
|
|
|
int use_gradient = PAINTBRUSH_DEFAULT_USE_GRADIENT;
|
1999-07-20 06:42:49 +08:00
|
|
|
double gradient_length = PAINTBRUSH_DEFAULT_GRADIENT_LENGTH;
|
1999-08-20 03:53:30 +08:00
|
|
|
int gradient_type = PAINTBRUSH_DEFAULT_GRADIENT_TYPE;
|
1999-07-20 06:42:49 +08:00
|
|
|
int i;
|
1999-08-20 03:53:30 +08:00
|
|
|
|
|
|
|
if (options)
|
1999-07-20 06:42:49 +08:00
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
fade_out = options->fade_out;
|
|
|
|
incremental = options->paint_options.incremental;
|
|
|
|
use_gradient = options->use_gradient;
|
1999-07-20 06:42:49 +08:00
|
|
|
gradient_length = options->gradient_length;
|
1999-08-20 03:53:30 +08:00
|
|
|
gradient_type = options->gradient_type;
|
1999-07-20 06:42:49 +08:00
|
|
|
}
|
|
|
|
|
1999-08-20 03:53:30 +08:00
|
|
|
if (use_gradient == 0)
|
|
|
|
gradient_length = 0.0;
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
/* Hmmm... PDB paintbrush should have gradient type added to it!*/
|
|
|
|
/* thats why the code below is duplicated.
|
|
|
|
*/
|
|
|
|
if (paint_core_init (&non_gui_paint_core, drawable,
|
1999-08-20 03:53:30 +08:00
|
|
|
stroke_array[0], stroke_array[1]))
|
1999-07-20 06:42:49 +08:00
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
non_gui_fade_out = fade_out;
|
1999-07-20 06:42:49 +08:00
|
|
|
non_gui_gradient_length = gradient_length;
|
1999-08-20 03:53:30 +08:00
|
|
|
non_gui_gradient_type = gradient_type;
|
|
|
|
non_gui_incremental = incremental;
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
/* Set the paint core's paint func */
|
|
|
|
non_gui_paint_core.paint_func = paintbrush_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
|
|
|
paintbrush_non_gui_paint_func (&non_gui_paint_core, drawable, 0);
|
1999-07-20 06:42:49 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
|
|
|
{
|
|
|
|
non_gui_paint_core.curx = stroke_array[i * 2 + 0];
|
|
|
|
non_gui_paint_core.cury = stroke_array[i * 2 + 1];
|
|
|
|
|
|
|
|
paint_core_interpolate (&non_gui_paint_core, drawable);
|
|
|
|
|
|
|
|
non_gui_paint_core.lastx = non_gui_paint_core.curx;
|
|
|
|
non_gui_paint_core.lasty = non_gui_paint_core.cury;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish the painting */
|
|
|
|
paint_core_finish (&non_gui_paint_core, drawable, -1);
|
|
|
|
|
|
|
|
/* Cleanup */
|
|
|
|
paint_core_cleanup ();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
gboolean
|
|
|
|
paintbrush_non_gui (GimpDrawable *drawable,
|
1999-07-07 02:13:59 +08:00
|
|
|
int num_strokes,
|
|
|
|
double *stroke_array,
|
|
|
|
double fade_out,
|
|
|
|
int method,
|
|
|
|
double gradient_length)
|
1999-03-17 13:40:16 +08:00
|
|
|
{
|
1997-11-25 06:05:25 +08:00
|
|
|
int i;
|
|
|
|
|
1999-07-20 06:42:49 +08:00
|
|
|
/* Code duplicated above */
|
1999-04-19 05:22:41 +08:00
|
|
|
if (paint_core_init (&non_gui_paint_core, drawable,
|
1999-04-23 14:07:09 +08:00
|
|
|
stroke_array[0], stroke_array[1]))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-08-20 03:53:30 +08:00
|
|
|
non_gui_fade_out = fade_out;
|
1999-04-19 05:22:41 +08:00
|
|
|
non_gui_gradient_length = gradient_length;
|
1999-08-20 03:53:30 +08:00
|
|
|
non_gui_gradient_type = LOOP_TRIANGLE;
|
|
|
|
non_gui_incremental = method;
|
1999-04-21 07:03:31 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Set the paint core's paint func */
|
1999-03-17 13:40:16 +08:00
|
|
|
non_gui_paint_core.paint_func = paintbrush_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];
|
|
|
|
|
|
|
|
if (num_strokes == 1)
|
1999-04-23 14:07:09 +08:00
|
|
|
paintbrush_non_gui_paint_func (&non_gui_paint_core, drawable, 0);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
|
|
|
for (i = 1; i < num_strokes; i++)
|
1999-04-23 14:07:09 +08:00
|
|
|
{
|
|
|
|
non_gui_paint_core.curx = stroke_array[i * 2 + 0];
|
|
|
|
non_gui_paint_core.cury = stroke_array[i * 2 + 1];
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-23 14:07:09 +08:00
|
|
|
paint_core_interpolate (&non_gui_paint_core, drawable);
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-23 14:07:09 +08:00
|
|
|
non_gui_paint_core.lastx = non_gui_paint_core.curx;
|
|
|
|
non_gui_paint_core.lasty = non_gui_paint_core.cury;
|
|
|
|
}
|
1999-03-17 13:40:16 +08:00
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Finish the painting */
|
1999-03-17 13:40:16 +08:00
|
|
|
paint_core_finish (&non_gui_paint_core, drawable, -1);
|
|
|
|
|
1999-04-19 05:22:41 +08:00
|
|
|
/* Cleanup */
|
1999-03-17 13:40:16 +08:00
|
|
|
paint_core_cleanup ();
|
1999-04-19 05:22:41 +08:00
|
|
|
return TRUE;
|
1999-03-17 13:40:16 +08:00
|
|
|
}
|
1999-04-19 05:22:41 +08:00
|
|
|
else
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|