2000-02-16 01:47:22 +00: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-16 21:37:03 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-12-16 21:37:03 +00:00
|
|
|
|
2000-12-29 15:22:01 +00:00
|
|
|
#include <gtk/gtk.h>
|
2000-02-16 01:47:22 +00:00
|
|
|
|
2001-01-23 23:56:18 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
include the new "paint-funcs/paint-funcs-types.h".
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h: include the new
"paint-funcs/paint-funcs-types.h".
* app/paint-funcs/Makefile.am
* app/paint-funcs/paint-funcs-types.h: new file. Includes
"base/base-types.h".
* app/paint-funcs/paint-funcs.[ch]: removed the enums here,
include "paint-funcs-types.h".
* app/widgets/widgets-types.h: include "display/display-types.h"
* app/display/display-types.h: include "widgets/widgets-types.h".
* app/tools/tools-types.h: include "display/display-types.h"
* app/gui/gui-types.h: include "tools/tools-types.h".
The order of namespaces/dependencies should be (but is not):
(base, paint-funcs) -> (core, file, xcf, pdb) ->
(widgets, display) -> tools -> gui
* app/path.c: include "tools/tools-types.h".
* app/core/Makefile.am
* app/core/gimpimage-guides.[ch]
* app/core/gimpimage-merge.[ch]
* app/core/gimpimage-resize.[ch]
* app/core/gimpimage-scale.[ch]: new files.
* app/core/gimpimage.[ch]: removed the stuff which is in the new
files. Reordered all functions in both the .h and .c files,
commented the groups of functions.
* app/core/gimpcontainer.c: create the handler_id using a counter,
not the address of a pointer, because the address *may* be the
same twice, added debugging output.
* app/core/gimpviewable.[ch]: added primitive support for getting
a preview GdkPixbuf.
* app/nav_window.c
* app/undo.c
* app/undo_history.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.[ch]
* app/display/gimpdisplay.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-scroll.c
* app/gui/image-commands.c
* app/gui/info-window.c
* app/gui/layers-commands.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimpmovetool.c
* app/widgets/gimpcontainerview-utils.c
* app/xcf/xcf-load.c: changed accordingly, some cleanup.
* tools/pdbgen/pdb/guides.pdb
* tools/pdbgen/pdb/image.pdb: changed accordingly, reordered functions.
* app/plug_in.c: set the labels of the "Repeat" and "Re-Show" menu
items to the name of the last plug-in (Fixes #50986).
* app/display/gimpdisplayshell.[ch]: set the labels of "Undo" and
"Redo" to the resp. undo names. Much simplified the WM icon stuff
by removing most code and using gimp_viewable_get_new_preview_pixbuf().
* app/widgets/gimpbrushfactoryview.c: forgot to assign the GQuark
returned by gimp_container_add_handler().
* app/pdb/guides_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2001-11-28 17:51:06 +00:00
|
|
|
#include "tools/tools-types.h"
|
2001-01-23 23:56:18 +00:00
|
|
|
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 12:52:30 +00:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-09-25 23:23:09 +00:00
|
|
|
|
2001-04-17 21:43:29 +00:00
|
|
|
#include "tools/gimpbezierselecttool.h"
|
|
|
|
|
|
|
|
#include "gui/paths-dialog.h"
|
|
|
|
|
2000-02-16 13:52:33 +00:00
|
|
|
#include "path.h"
|
|
|
|
#include "pathP.h"
|
2001-01-22 01:46:28 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
static gchar * unique_name (GimpImage *gimage,
|
|
|
|
gchar *cstr);
|
2000-02-16 01:47:22 +00:00
|
|
|
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
Path *
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
path->closed = closed;
|
|
|
|
path->state = state;
|
|
|
|
path->locked = locked;
|
|
|
|
path->pathtype = ptype;
|
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
if(tattoo)
|
|
|
|
path->tattoo = tattoo;
|
|
|
|
else
|
|
|
|
path->tattoo = gimp_image_get_new_tattoo (gimage);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
Path *
|
2000-02-16 01:47:22 +00:00
|
|
|
path_copy (GimpImage *gimage,
|
|
|
|
Path *path)
|
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
Path *p_copy = g_new0 (Path, 1);
|
2000-02-16 01:47:22 +00:00
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = unique_name (gimage, path->name);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
if (name)
|
|
|
|
p_copy->name = name;
|
|
|
|
else
|
|
|
|
p_copy->name = g_strdup (path->name);
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
p_copy->closed = path->closed;
|
|
|
|
p_copy->state = path->state;
|
|
|
|
p_copy->pathtype = path->pathtype;
|
2000-02-16 01:47:22 +00:00
|
|
|
p_copy->path_details = pathpoints_copy (path->path_details);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
PathPoint *
|
2000-02-16 13:52:33 +00:00
|
|
|
path_point_new (guint type,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
PathPoint *pathpoint = g_new0 (PathPoint,1);
|
2000-02-16 01:47:22 +00:00
|
|
|
|
|
|
|
pathpoint->type = type;
|
2001-01-22 20:46:50 +00:00
|
|
|
pathpoint->x = x;
|
|
|
|
pathpoint->y = y;
|
|
|
|
|
|
|
|
return pathpoint;
|
2000-02-16 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_point_free (PathPoint *pathpoint)
|
|
|
|
{
|
|
|
|
g_free (pathpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_stroke (GimpImage *gimage,
|
|
|
|
PathList *pl,
|
|
|
|
Path *bzp)
|
|
|
|
{
|
2001-03-26 05:31:47 +00:00
|
|
|
GimpBezierSelectTool *bezier_sel;
|
2001-10-29 11:47:11 +00:00
|
|
|
GimpDisplay *gdisp;
|
2000-02-16 01:47:22 +00:00
|
|
|
|
2000-02-16 13:52:33 +00:00
|
|
|
gdisp = gdisplays_check_valid (pl->gdisp, gimage);
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
gint ret;
|
2001-03-26 05:31:47 +00:00
|
|
|
GimpBezierSelectTool *bezier_sel;
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
|
|
|
|
return ret;
|
2000-02-16 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
2001-08-17 14:27:31 +00:00
|
|
|
GimpTattoo
|
2000-02-16 01:47:22 +00:00
|
|
|
path_get_tattoo (Path* p)
|
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
if (!p)
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
g_warning ("path_get_tattoo: invalid path");
|
2000-02-16 01:47:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
return p->tattoo;
|
2000-02-16 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Path*
|
2001-08-17 14:27:31 +00:00
|
|
|
path_get_path_by_tattoo (GimpImage *gimage,
|
|
|
|
GimpTattoo tattoo)
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
|
|
|
GSList *tlist;
|
|
|
|
PathList *plp;
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
if (!gimage || !tattoo)
|
2000-02-16 01:47:22 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Go around the list and check all tattoos. */
|
|
|
|
|
|
|
|
/* Get path structure */
|
|
|
|
plp = (PathList*) gimp_image_get_paths (gimage);
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
if (!plp)
|
2000-02-16 01:47:22 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
for (tlist = plp->bz_paths; tlist; tlist = g_slist_next(tlist))
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
|
|
|
Path* p = (Path*)(tlist->data);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
|
|
|
if (p->tattoo == tattoo)
|
2000-02-16 01:47:22 +00:00
|
|
|
return (p);
|
|
|
|
}
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
PathList *
|
|
|
|
path_list_new (GimpImage *gimage,
|
|
|
|
gint last_selected_row,
|
|
|
|
GSList *bz_paths)
|
|
|
|
{
|
|
|
|
PathList *pip = g_new0 (PathList, 1);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
|
|
|
pip->gimage = gimage;
|
2000-02-16 01:47:22 +00:00
|
|
|
pip->last_selected_row = last_selected_row;
|
|
|
|
|
|
|
|
/* add connector to image delete/destroy */
|
2003-01-05 22:07:10 +00:00
|
|
|
pip->sig_id = g_signal_connect (gimage, "disconnect",
|
2001-08-01 09:33:12 +00:00
|
|
|
G_CALLBACK (paths_dialog_destroy_cb),
|
|
|
|
pip);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
pip->bz_paths = bz_paths;
|
|
|
|
|
2001-01-22 20:46:50 +00:00
|
|
|
return (PathList *) pip;
|
2000-02-16 01:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
path_list_free (PathList* iml)
|
|
|
|
{
|
|
|
|
g_return_if_fail (iml != NULL);
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
if (iml->bz_paths)
|
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
g_slist_foreach (iml->bz_paths, (GFunc) path_free, NULL);
|
2000-02-16 01:47:22 +00:00
|
|
|
g_slist_free (iml->bz_paths);
|
|
|
|
}
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
gchar *tstr;
|
|
|
|
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
GSList *tlist;
|
2000-02-16 01:47:22 +00:00
|
|
|
PathList *plp;
|
2001-01-22 20:46:50 +00:00
|
|
|
gboolean unique = TRUE;
|
|
|
|
gchar *copy_cstr;
|
|
|
|
gchar *copy_test;
|
|
|
|
gchar *stripped_copy;
|
|
|
|
gint counter = 1;
|
2000-02-16 01:47:22 +00:00
|
|
|
|
|
|
|
/* Get bzpath structure */
|
|
|
|
if (!gimage || !(plp = (PathList*) gimp_image_get_paths(gimage)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
tlist = plp->bz_paths;
|
|
|
|
|
|
|
|
while (tlist)
|
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
gchar *test_str;
|
|
|
|
|
|
|
|
test_str = ((Path *) (tlist->data))->name;
|
|
|
|
|
2000-02-16 01:47:22 +00: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-22 20:46:50 +00:00
|
|
|
while (tlist)
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
|
|
|
copy_test = ((Path*)(tlist->data))->name;
|
2001-01-22 20:46:50 +00:00
|
|
|
|
|
|
|
if (strcmp (copy_cstr,copy_test) == 0)
|
2000-02-16 01:47:22 +00:00
|
|
|
{
|
2001-01-22 20:46:50 +00:00
|
|
|
g_free (copy_cstr);
|
|
|
|
copy_cstr = g_strdup_printf ("%s#%d", stripped_copy, counter++);
|
2000-02-16 01:47:22 +00:00
|
|
|
tlist = plp->bz_paths;
|
|
|
|
continue;
|
|
|
|
}
|
2001-01-22 20:46:50 +00:00
|
|
|
|
2000-02-16 01:47:22 +00:00
|
|
|
tlist = g_slist_next(tlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (stripped_copy);
|
|
|
|
|
|
|
|
return copy_cstr;
|
|
|
|
}
|