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
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 20:21:50 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "paint-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-04-07 23:58:26 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
#include "gimpairbrush.h"
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimpairbrushoptions.h"
|
2002-02-22 00:02:30 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-02-14 22:14:29 +08:00
|
|
|
|
2002-02-22 00:02:30 +08:00
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
static void gimp_airbrush_class_init (GimpAirbrushClass *klass);
|
|
|
|
static void gimp_airbrush_init (GimpAirbrush *airbrush);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
static void gimp_airbrush_finalize (GObject *object);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
static void gimp_airbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_airbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options);
|
|
|
|
static gboolean gimp_airbrush_timeout (gpointer data);
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
static GimpPaintbrushClass *parent_class = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
|
2002-02-27 21:57:49 +08:00
|
|
|
void
|
|
|
|
gimp_airbrush_register (Gimp *gimp,
|
|
|
|
GimpPaintRegisterCallback callback)
|
|
|
|
{
|
2003-02-14 22:14:29 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_AIRBRUSH,
|
|
|
|
GIMP_TYPE_AIRBRUSH_OPTIONS,
|
|
|
|
_("Airbrush"));
|
2002-02-27 21:57:49 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_airbrush_get_type (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static GType type = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (! type)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
static const GTypeInfo info =
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2002-02-15 03:31:16 +08:00
|
|
|
sizeof (GimpAirbrushClass),
|
2004-05-26 04:41:09 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_airbrush_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpAirbrush),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_airbrush_init,
|
2001-04-01 07:04:29 +08:00
|
|
|
};
|
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
type = g_type_register_static (GIMP_TYPE_PAINTBRUSH,
|
2002-02-15 03:31:16 +08:00
|
|
|
"GimpAirbrush",
|
|
|
|
&info, 0);
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
return type;
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_airbrush_class_init (GimpAirbrushClass *klass)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
object_class->finalize = gimp_airbrush_finalize;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
paint_core_class->paint = gimp_airbrush_paint;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-04-01 07:04:29 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_airbrush_init (GimpAirbrush *airbrush)
|
1999-04-13 01:55:06 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
airbrush->timeout_id = 0;
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
2002-02-15 03:31:16 +08:00
|
|
|
|
2001-04-01 07:04:29 +08:00
|
|
|
static void
|
2002-02-15 03:31:16 +08:00
|
|
|
gimp_airbrush_finalize (GObject *object)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
GimpAirbrush *airbrush = GIMP_AIRBRUSH (object);
|
|
|
|
|
|
|
|
if (airbrush->timeout_id)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
1999-04-13 01:55:06 +08:00
|
|
|
}
|
|
|
|
|
2001-04-01 07:04:29 +08:00
|
|
|
static void
|
2004-07-19 22:37:40 +08:00
|
|
|
gimp_airbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpAirbrush *airbrush = GIMP_AIRBRUSH (paint_core);
|
|
|
|
GimpAirbrushOptions *options = GIMP_AIRBRUSH_OPTIONS (paint_options);
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
switch (paint_state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-07-19 22:37:40 +08:00
|
|
|
case GIMP_PAINT_STATE_INIT:
|
2003-07-15 23:38:24 +08:00
|
|
|
if (airbrush->timeout_id)
|
2000-01-14 20:41:00 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
2000-01-14 20:41:00 +08:00
|
|
|
}
|
2003-07-15 23:38:24 +08:00
|
|
|
|
|
|
|
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
|
2004-05-27 00:13:53 +08:00
|
|
|
paint_options,
|
|
|
|
paint_state, time);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
case GIMP_PAINT_STATE_MOTION:
|
2003-07-15 23:38:24 +08:00
|
|
|
if (airbrush->timeout_id)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-06-09 21:56:09 +08:00
|
|
|
gimp_airbrush_motion (paint_core, drawable, paint_options);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (options->rate != 0.0)
|
1999-08-20 03:53:30 +08:00
|
|
|
{
|
2001-04-01 07:04:29 +08:00
|
|
|
gdouble timeout;
|
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
airbrush->drawable = drawable;
|
|
|
|
airbrush->paint_options = paint_options;
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2003-07-14 22:50:41 +08:00
|
|
|
timeout = (paint_options->pressure_options->rate ?
|
2004-05-24 21:11:43 +08:00
|
|
|
(10000 / (options->rate * PRESSURE_SCALE * paint_core->cur_coords.pressure)) :
|
|
|
|
(10000 / options->rate));
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
airbrush->timeout_id = g_timeout_add (timeout,
|
|
|
|
gimp_airbrush_timeout,
|
|
|
|
airbrush);
|
1999-08-20 03:53:30 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2004-07-19 22:37:40 +08:00
|
|
|
case GIMP_PAINT_STATE_FINISH:
|
2003-07-15 23:38:24 +08:00
|
|
|
if (airbrush->timeout_id)
|
2001-04-01 07:04:29 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
2001-04-01 07:04:29 +08:00
|
|
|
}
|
2003-07-15 23:38:24 +08:00
|
|
|
|
|
|
|
GIMP_PAINT_CORE_CLASS (parent_class)->paint (paint_core, drawable,
|
2004-05-27 00:13:53 +08:00
|
|
|
paint_options,
|
|
|
|
paint_state, time);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-22 00:02:30 +08:00
|
|
|
gimp_airbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-05-26 04:41:09 +08:00
|
|
|
GimpAirbrushOptions *options = GIMP_AIRBRUSH_OPTIONS (paint_options);
|
2003-07-15 23:38:24 +08:00
|
|
|
gdouble opacity;
|
|
|
|
gboolean saved_pressure;
|
2001-01-21 00:28:05 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
opacity = options->pressure / 100.0;
|
2001-04-07 19:01:22 +08:00
|
|
|
|
2004-06-12 20:44:24 +08:00
|
|
|
saved_pressure = paint_options->pressure_options->hardness;
|
2001-04-07 19:01:22 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
if (saved_pressure)
|
2004-05-24 21:11:43 +08:00
|
|
|
opacity *= PRESSURE_SCALE * paint_core->cur_coords.pressure;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-12 20:44:24 +08:00
|
|
|
paint_options->pressure_options->hardness = FALSE;
|
2003-07-15 23:38:24 +08:00
|
|
|
_gimp_paintbrush_motion (paint_core, drawable, paint_options, opacity);
|
2004-06-12 20:44:24 +08:00
|
|
|
paint_options->pressure_options->hardness = saved_pressure;
|
2002-06-09 21:56:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-07-15 23:38:24 +08:00
|
|
|
gimp_airbrush_timeout (gpointer data)
|
2002-06-09 21:56:09 +08:00
|
|
|
{
|
2003-07-15 23:38:24 +08:00
|
|
|
GimpAirbrush *airbrush = GIMP_AIRBRUSH (data);
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
gimp_airbrush_paint (GIMP_PAINT_CORE (airbrush),
|
|
|
|
airbrush->drawable,
|
|
|
|
airbrush->paint_options,
|
2004-07-19 22:37:40 +08:00
|
|
|
GIMP_PAINT_STATE_MOTION, 0);
|
2002-06-09 21:56:09 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
gimp_image_flush (gimp_item_get_image (GIMP_ITEM (airbrush->drawable)));
|
2002-06-09 21:56:09 +08:00
|
|
|
|
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|