2000-02-16 09:47:22 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1999 Andy Thomas alt@picnic.demon.co.uk
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* Some of this code is based on the layers_dialog box code.
|
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-02-16 09:47:22 +08:00
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core/core-types.h"
|
|
|
|
#include "tools/tools-types.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "tools/gimpbezierselecttool.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "gdisplay.h"
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "gui/paths-dialog.h"
|
|
|
|
|
2000-02-16 21:52:33 +08:00
|
|
|
#include "path.h"
|
|
|
|
#include "pathP.h"
|
2001-01-22 09:46:28 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
static gchar * unique_name (GimpImage *gimage,
|
|
|
|
gchar *cstr);
|
2000-02-16 09:47:22 +08:00
|
|
|
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
Path *
|
2000-02-16 09:47:22 +08:00
|
|
|
path_new (GimpImage *gimage,
|
|
|
|
PathType ptype,
|
|
|
|
GSList *path_details,
|
|
|
|
gint closed,
|
|
|
|
gint state,
|
|
|
|
gint locked,
|
|
|
|
gint tattoo,
|
|
|
|
gchar *name)
|
|
|
|
{
|
|
|
|
gchar *suniq;
|
|
|
|
Path *path = g_new0 (Path, 1);
|
|
|
|
|
|
|
|
suniq = unique_name (gimage, name);
|
|
|
|
if (suniq)
|
|
|
|
path->name = suniq;
|
|
|
|
else
|
|
|
|
path->name = g_strdup (name);
|
|
|
|
|
|
|
|
path->path_details = path_details;
|
2001-01-23 04:46:50 +08:00
|
|
|
path->closed = closed;
|
|
|
|
path->state = state;
|
|
|
|
path->locked = locked;
|
|
|
|
path->pathtype = ptype;
|
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
if(tattoo)
|
|
|
|
path->tattoo = tattoo;
|
|
|
|
else
|
|
|
|
path->tattoo = gimp_image_get_new_tattoo (gimage);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
Path *
|
2000-02-16 09:47:22 +08:00
|
|
|
path_copy (GimpImage *gimage,
|
|
|
|
Path *path)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
Path *p_copy = g_new0 (Path, 1);
|
2000-02-16 09:47:22 +08:00
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = unique_name (gimage, path->name);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
if (name)
|
|
|
|
p_copy->name = name;
|
|
|
|
else
|
|
|
|
p_copy->name = g_strdup (path->name);
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
p_copy->closed = path->closed;
|
|
|
|
p_copy->state = path->state;
|
|
|
|
p_copy->pathtype = path->pathtype;
|
2000-02-16 09:47:22 +08:00
|
|
|
p_copy->path_details = pathpoints_copy (path->path_details);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
if (gimage)
|
|
|
|
p_copy->tattoo = gimp_image_get_new_tattoo (gimage);
|
|
|
|
else
|
|
|
|
p_copy->tattoo = path->tattoo;
|
|
|
|
|
|
|
|
return p_copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_free (Path *path)
|
|
|
|
{
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
|
|
g_free (path->name);
|
|
|
|
pathpoints_free (path->path_details);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
PathPoint *
|
2000-02-16 21:52:33 +08:00
|
|
|
path_point_new (guint type,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2000-02-16 09:47:22 +08:00
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
PathPoint *pathpoint = g_new0 (PathPoint,1);
|
2000-02-16 09:47:22 +08:00
|
|
|
|
|
|
|
pathpoint->type = type;
|
2001-01-23 04:46:50 +08:00
|
|
|
pathpoint->x = x;
|
|
|
|
pathpoint->y = y;
|
|
|
|
|
|
|
|
return pathpoint;
|
2000-02-16 09:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_point_free (PathPoint *pathpoint)
|
|
|
|
{
|
|
|
|
g_free (pathpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_stroke (GimpImage *gimage,
|
|
|
|
PathList *pl,
|
|
|
|
Path *bzp)
|
|
|
|
{
|
2001-03-26 13:31:47 +08:00
|
|
|
GimpBezierSelectTool *bezier_sel;
|
2001-01-23 04:46:50 +08:00
|
|
|
GDisplay *gdisp;
|
2000-02-16 09:47:22 +08:00
|
|
|
|
2000-02-16 21:52:33 +08:00
|
|
|
gdisp = gdisplays_check_valid (pl->gdisp, gimage);
|
2000-02-16 09:47:22 +08:00
|
|
|
bezier_sel = path_to_beziersel (bzp);
|
|
|
|
bezier_stroke (bezier_sel, gdisp, SUBDIVIDE, !bzp->closed);
|
|
|
|
bezier_select_free (bezier_sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
path_distance (Path *bzp,
|
|
|
|
gdouble dist,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gdouble *grad)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
gint ret;
|
2001-03-26 13:31:47 +08:00
|
|
|
GimpBezierSelectTool *bezier_sel;
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
bezier_sel = path_to_beziersel (bzp);
|
|
|
|
ret = bezier_distance_along (bezier_sel, !bzp->closed, dist, x, y, grad);
|
|
|
|
bezier_select_free (bezier_sel);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
|
|
|
return ret;
|
2000-02-16 09:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tattoo
|
|
|
|
path_get_tattoo (Path* p)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
if (!p)
|
2000-02-16 09:47:22 +08:00
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
g_warning ("path_get_tattoo: invalid path");
|
2000-02-16 09:47:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
return p->tattoo;
|
2000-02-16 09:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Path*
|
|
|
|
path_get_path_by_tattoo (GimpImage *gimage,
|
|
|
|
Tattoo tattoo)
|
|
|
|
{
|
|
|
|
GSList *tlist;
|
|
|
|
PathList *plp;
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
if (!gimage || !tattoo)
|
2000-02-16 09:47:22 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Go around the list and check all tattoos. */
|
|
|
|
|
|
|
|
/* Get path structure */
|
|
|
|
plp = (PathList*) gimp_image_get_paths (gimage);
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
if (!plp)
|
2000-02-16 09:47:22 +08:00
|
|
|
return (NULL);
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
for (tlist = plp->bz_paths; tlist; tlist = g_slist_next(tlist))
|
2000-02-16 09:47:22 +08:00
|
|
|
{
|
|
|
|
Path* p = (Path*)(tlist->data);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
|
|
|
if (p->tattoo == tattoo)
|
2000-02-16 09:47:22 +08:00
|
|
|
return (p);
|
|
|
|
}
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
PathList *
|
|
|
|
path_list_new (GimpImage *gimage,
|
|
|
|
gint last_selected_row,
|
|
|
|
GSList *bz_paths)
|
|
|
|
{
|
|
|
|
PathList *pip = g_new0 (PathList, 1);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
|
|
|
pip->gimage = gimage;
|
2000-02-16 09:47:22 +08:00
|
|
|
pip->last_selected_row = last_selected_row;
|
|
|
|
|
|
|
|
/* add connector to image delete/destroy */
|
2001-08-01 17:33:12 +08:00
|
|
|
pip->sig_id = g_signal_connect (G_OBJECT (gimage), "destroy",
|
|
|
|
G_CALLBACK (paths_dialog_destroy_cb),
|
|
|
|
pip);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
pip->bz_paths = bz_paths;
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
return (PathList *) pip;
|
2000-02-16 09:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_list_free (PathList* iml)
|
|
|
|
{
|
|
|
|
g_return_if_fail (iml != NULL);
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
if (iml->bz_paths)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
g_slist_foreach (iml->bz_paths, (GFunc) path_free, NULL);
|
2000-02-16 09:47:22 +08:00
|
|
|
g_slist_free (iml->bz_paths);
|
|
|
|
}
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
g_free (iml);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Always return a copy that must be freed later */
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
strip_off_cnumber (gchar *str)
|
|
|
|
{
|
|
|
|
gchar *hashptr;
|
|
|
|
gint num;
|
|
|
|
gchar *copy;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return str;
|
|
|
|
|
|
|
|
copy = g_strdup (str);
|
|
|
|
|
|
|
|
if ((hashptr = strrchr (copy,'#')) && /* have a hash */
|
|
|
|
strlen(hashptr) > 0 && /* followed by something */
|
|
|
|
(num = atoi(hashptr+1)) > 0 && /* which is a number */
|
|
|
|
((int) log10 (num) + 1) == strlen (hashptr+1)) /* which is at the end */
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
gchar *tstr;
|
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
/* Has a #<number> */
|
|
|
|
*hashptr = '\0';
|
|
|
|
tstr = g_strdup (copy);
|
|
|
|
g_free (copy);
|
|
|
|
copy = tstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return NULL if already unique else a unique string */
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
unique_name (GimpImage *gimage,
|
|
|
|
gchar *cstr)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
GSList *tlist;
|
2000-02-16 09:47:22 +08:00
|
|
|
PathList *plp;
|
2001-01-23 04:46:50 +08:00
|
|
|
gboolean unique = TRUE;
|
|
|
|
gchar *copy_cstr;
|
|
|
|
gchar *copy_test;
|
|
|
|
gchar *stripped_copy;
|
|
|
|
gint counter = 1;
|
2000-02-16 09:47:22 +08:00
|
|
|
|
|
|
|
/* Get bzpath structure */
|
|
|
|
if (!gimage || !(plp = (PathList*) gimp_image_get_paths(gimage)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tlist = plp->bz_paths;
|
|
|
|
|
|
|
|
while (tlist)
|
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
gchar *test_str;
|
|
|
|
|
|
|
|
test_str = ((Path *) (tlist->data))->name;
|
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
if (strcmp (cstr, test_str) == 0)
|
|
|
|
{
|
|
|
|
unique = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tlist = g_slist_next(tlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unique)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* OK Clashes with something */
|
|
|
|
/* restart scan to find unique name */
|
|
|
|
|
|
|
|
stripped_copy = strip_off_cnumber (cstr);
|
|
|
|
copy_cstr = g_strdup_printf ("%s#%d", stripped_copy, counter++);
|
|
|
|
|
|
|
|
tlist = plp->bz_paths;
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
while (tlist)
|
2000-02-16 09:47:22 +08:00
|
|
|
{
|
|
|
|
copy_test = ((Path*)(tlist->data))->name;
|
2001-01-23 04:46:50 +08:00
|
|
|
|
|
|
|
if (strcmp (copy_cstr,copy_test) == 0)
|
2000-02-16 09:47:22 +08:00
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
g_free (copy_cstr);
|
|
|
|
copy_cstr = g_strdup_printf ("%s#%d", stripped_copy, counter++);
|
2000-02-16 09:47:22 +08:00
|
|
|
tlist = plp->bz_paths;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-23 04:46:50 +08:00
|
|
|
|
2000-02-16 09:47:22 +08:00
|
|
|
tlist = g_slist_next(tlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (stripped_copy);
|
|
|
|
|
|
|
|
return copy_cstr;
|
|
|
|
}
|