Gimp/app/paint/gimppaintcore-stroke.c
Michael Natterer 9c13b724d4 app/core/gimpimage-mask-select.c (gimp_image_mask_select_vectors)
2003-09-12  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage-mask-select.c (gimp_image_mask_select_vectors)
	* app/paint/gimppaintcore-stroke.c (gimp_paint_core_stroke_vectors)
	* app/display/gimpdisplayshell.c (gimp_display_shell_draw_vector)
	* app/tools/gimpdrawtool.c (gimp_draw_tool_real_draw)
	* app/tools/gimptransformtool.c (gimp_transform_tool_draw)
	* app/tools/gimpvectortool.c (gimp_vector_tool_vectors_visible)
	(gimp_vector_tool_draw): all callers of gimp_stroke_interpolate():
	don't leak the returned GimpCoords array and don't crash if it's
	NULL.

	* app/tools/gimpvectortool.[ch]: added VECTORS_SELECT_VECTOR state
	which enables activating any visible GimpVectors on any display.

	(gimp_vector_tool_on_handle)
	(gimp_vector_tool_on_curve): added a GimpVectors parameter so we
	can check for vectors which are not vector_tool->vectors.

	(gimp_vector_tool_oper_update): iterate gdisp->gimage->vectors
	to figure if we are hovering any visible vectors and set
	VECTORS_SELECT_VECTOR.

	(gimp_vector_tool_button_press): catch VECTORS_SELECT_VECTOR and
	start editing the selected vectors. Also make it the image's
	active_vectors.

	(gimp_vector_tool_button_release): removed unneeded call to
	gimp_viewable_invalidate_preview(vectors).

	Random cleanup all over the place.
2003-09-12 10:04:37 +00:00

274 lines
8.1 KiB
C

/* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "paint-types.h"
#include "base/boundary.h"
#include "core/gimpdrawable.h"
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
#include "gimppaintcore.h"
#include "gimppaintcore-stroke.h"
#include "gimppaintoptions.h"
gboolean
gimp_paint_core_stroke (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *strokes,
gint n_strokes)
{
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
g_return_val_if_fail (strokes != NULL, FALSE);
g_return_val_if_fail (n_strokes > 0, FALSE);
if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0]))
{
GimpBrush *current_brush;
gint i;
core->start_coords = strokes[0];
core->last_coords = strokes[0];
gimp_paint_core_paint (core, drawable, paint_options, INIT_PAINT);
current_brush = core->brush;
gimp_paint_core_paint (core, drawable, paint_options, MOTION_PAINT);
core->brush = current_brush;
for (i = 1; i < n_strokes; i++)
{
core->cur_coords = strokes[i];
gimp_paint_core_interpolate (core, drawable, paint_options);
}
gimp_paint_core_paint (core, drawable, paint_options, FINISH_PAINT);
gimp_paint_core_finish (core, drawable);
gimp_paint_core_cleanup (core);
return TRUE;
}
return FALSE;
}
gboolean
gimp_paint_core_stroke_boundary (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
const BoundSeg *bound_segs,
gint n_bound_segs,
gint offset_x,
gint offset_y)
{
GimpImage *gimage;
BoundSeg *stroke_segs;
gint n_stroke_segs;
gint off_x;
gint off_y;
GimpCoords *coords;
gint n_coords;
gint seg;
gint i;
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
g_return_val_if_fail (bound_segs != NULL && n_bound_segs > 0, FALSE);
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
stroke_segs = sort_boundary (bound_segs, n_bound_segs, &n_stroke_segs);
if (n_stroke_segs == 0)
return TRUE;
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
off_x -= offset_x;
off_y -= offset_y;
coords = g_new0 (GimpCoords, n_bound_segs + 4);
seg = 0;
n_coords = 0;
/* we offset all coordinates by 0.5 to align the brush with the path */
coords[n_coords].x = (gdouble) (stroke_segs[0].x1 - off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[0].y1 - off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
for (i = 0; i < n_stroke_segs; i++)
{
while (stroke_segs[seg].x1 != -1 ||
stroke_segs[seg].x2 != -1 ||
stroke_segs[seg].y1 != -1 ||
stroke_segs[seg].y2 != -1)
{
coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 -
off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 -
off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
seg++;
}
/* Close the stroke points up */
coords[n_coords] = coords[0];
n_coords++;
gimp_paint_core_stroke (core, drawable, paint_options,
coords, n_coords);
n_coords = 0;
seg++;
coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 - off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 - off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
}
g_free (coords);
g_free (stroke_segs);
return TRUE;
}
gboolean
gimp_paint_core_stroke_vectors (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpVectors *vectors)
{
GList *stroke;
GArray *coords = NULL;
gboolean initialized = FALSE;
gboolean closed;
gint off_x, off_y;
gint vectors_off_x, vectors_off_y;
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE);
gimp_item_offsets (GIMP_ITEM (vectors), &vectors_off_x, &vectors_off_y);
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
off_x -= vectors_off_x;
off_y -= vectors_off_y;
for (stroke = vectors->strokes; stroke; stroke = stroke->next)
{
gint i;
coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data),
1.0, &closed);
if (coords && coords->len)
{
GimpBrush *current_brush;
for (i = 0; i < coords->len; i++)
{
g_array_index (coords, GimpCoords, i).x -= off_x;
g_array_index (coords, GimpCoords, i).y -= off_y;
}
if (! initialized)
{
if (! gimp_paint_core_start (core, drawable, paint_options,
&g_array_index (coords,
GimpCoords, 0)))
{
g_array_free (coords, TRUE);
return FALSE;
}
initialized = TRUE;
}
gimp_paint_core_paint (core, drawable, paint_options, INIT_PAINT);
core->start_coords = g_array_index (coords, GimpCoords, 0);
core->last_coords = g_array_index (coords, GimpCoords, 0);
current_brush = core->brush;
gimp_paint_core_paint (core, drawable, paint_options, MOTION_PAINT);
core->brush = current_brush;
for (i = 1; i < coords->len; i++)
{
core->cur_coords = g_array_index (coords, GimpCoords, i);
gimp_paint_core_interpolate (core, drawable, paint_options);
}
if (closed)
{
core->cur_coords = g_array_index (coords, GimpCoords, 0);
gimp_paint_core_interpolate (core, drawable, paint_options);
}
gimp_paint_core_paint (core, drawable, paint_options, FINISH_PAINT);
}
if (coords)
g_array_free (coords, TRUE);
}
if (initialized)
{
gimp_paint_core_finish (core, drawable);
gimp_paint_core_cleanup (core);
}
return TRUE;
}