2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.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
|
|
|
|
2005-12-08 05:11:53 +08:00
|
|
|
static void gimp_airbrush_finalize (GObject *object);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2005-12-08 05:11:53 +08:00
|
|
|
static void gimp_airbrush_paint (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
|
|
|
GimpPaintOptions *paint_options,
|
2009-05-03 18:08:21 +08:00
|
|
|
const GimpCoords *coords,
|
2005-12-08 05:11:53 +08:00
|
|
|
GimpPaintState paint_state,
|
|
|
|
guint32 time);
|
|
|
|
static void gimp_airbrush_motion (GimpPaintCore *paint_core,
|
|
|
|
GimpDrawable *drawable,
|
2009-05-03 18:08:21 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
const GimpCoords *coords);
|
2005-12-08 05:11:53 +08:00
|
|
|
static gboolean gimp_airbrush_timeout (gpointer data);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpAirbrush, gimp_airbrush, GIMP_TYPE_PAINTBRUSH)
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2005-12-08 05:11:53 +08:00
|
|
|
#define parent_class gimp_airbrush_parent_class
|
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,
|
2005-12-28 02:57:01 +08:00
|
|
|
"gimp-airbrush",
|
|
|
|
_("Airbrush"),
|
|
|
|
"gimp-tool-airbrush");
|
2002-02-27 21:57:49 +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
|
|
|
|
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,
|
2009-05-03 18:08:21 +08:00
|
|
|
const GimpCoords *coords,
|
2004-07-19 22:37:40 +08:00
|
|
|
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)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
|
|
|
}
|
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,
|
2009-05-03 18:08:21 +08:00
|
|
|
coords,
|
2004-05-27 00:13:53 +08:00
|
|
|
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)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-05-03 18:08:21 +08:00
|
|
|
gimp_airbrush_motion (paint_core, drawable, paint_options, coords);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
if (options->rate != 0.0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2008-05-10 18:03:21 +08:00
|
|
|
gdouble dynamic_rate;
|
|
|
|
gint timeout;
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
airbrush->drawable = drawable;
|
2003-07-15 23:38:24 +08:00
|
|
|
airbrush->paint_options = paint_options;
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2008-05-10 18:03:21 +08:00
|
|
|
dynamic_rate = gimp_paint_options_get_dynamic_rate (paint_options,
|
2009-05-03 18:08:21 +08:00
|
|
|
coords);
|
2008-05-10 18:03:21 +08:00
|
|
|
|
|
|
|
timeout = 10000 / (options->rate * dynamic_rate);
|
2001-04-01 07:04:29 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
airbrush->timeout_id = g_timeout_add (timeout,
|
2003-07-15 23:38:24 +08:00
|
|
|
gimp_airbrush_timeout,
|
|
|
|
airbrush);
|
2006-04-12 20:49:29 +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)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
g_source_remove (airbrush->timeout_id);
|
|
|
|
airbrush->timeout_id = 0;
|
|
|
|
}
|
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,
|
2009-05-03 18:08:21 +08:00
|
|
|
coords,
|
2004-05-27 00:13:53 +08:00
|
|
|
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,
|
2009-05-03 18:08:21 +08:00
|
|
|
GimpPaintOptions *paint_options,
|
|
|
|
const GimpCoords *coords)
|
|
|
|
|
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;
|
2008-05-10 18:03:21 +08:00
|
|
|
gboolean saved_velocity;
|
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;
|
2008-05-10 18:03:21 +08:00
|
|
|
saved_velocity = paint_options->velocity_options->hardness;
|
2001-04-07 19:01:22 +08:00
|
|
|
|
2003-07-15 23:38:24 +08:00
|
|
|
if (saved_pressure)
|
2009-05-03 18:08:21 +08:00
|
|
|
opacity *= GIMP_PAINT_PRESSURE_SCALE * coords->pressure;
|
2008-05-10 18:03:21 +08:00
|
|
|
|
|
|
|
if (saved_velocity)
|
2009-05-03 18:08:21 +08:00
|
|
|
opacity *= MAX (0.0, 1 - GIMP_PAINT_VELOCITY_SCALE * coords->velocity);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-06-12 20:44:24 +08:00
|
|
|
paint_options->pressure_options->hardness = FALSE;
|
2008-05-10 18:03:21 +08:00
|
|
|
paint_options->velocity_options->hardness = FALSE;
|
|
|
|
|
2009-05-03 18:08:21 +08:00
|
|
|
_gimp_paintbrush_motion (paint_core, drawable, paint_options, coords, opacity);
|
2008-05-10 18:03:21 +08:00
|
|
|
|
2004-06-12 20:44:24 +08:00
|
|
|
paint_options->pressure_options->hardness = saved_pressure;
|
2008-05-10 18:03:21 +08:00
|
|
|
paint_options->velocity_options->hardness = saved_velocity;
|
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);
|
2009-05-03 18:08:21 +08:00
|
|
|
GimpCoords coords;
|
|
|
|
|
|
|
|
gimp_paint_core_get_current_coords (GIMP_PAINT_CORE (airbrush), &coords);
|
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,
|
2009-05-03 18:08:21 +08:00
|
|
|
&coords,
|
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
|
|
|
}
|