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
|
|
|
*/
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1999-04-23 17:39:51 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_DIRENT_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <dirent.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
1998-07-20 06:32:35 +08:00
|
|
|
#include <math.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "appenv.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpbrushgenerated.h"
|
1999-08-23 14:06:12 +08:00
|
|
|
#include "gimpbrushpipe.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "brush_header.h"
|
1999-12-02 21:00:18 +08:00
|
|
|
#include "brush_select.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "datafiles.h"
|
|
|
|
#include "gimprc.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpsignal.h"
|
1998-07-12 19:40:43 +08:00
|
|
|
#include "gimplist.h"
|
|
|
|
#include "gimpbrush.h"
|
|
|
|
#include "gimplistP.h"
|
|
|
|
#include "gimpbrushlistP.h"
|
1999-08-30 18:51:01 +08:00
|
|
|
#include "general.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-11-23 22:47:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* global variables */
|
1999-10-27 02:27:27 +08:00
|
|
|
GimpBrushList *brush_list = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* local variables */
|
|
|
|
static GimpBrush *standard_brush = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
static void brushes_brush_load (gchar *filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static gint brush_compare_func (gconstpointer first,
|
|
|
|
gconstpointer second);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* class functions */
|
1998-07-09 13:31:06 +08:00
|
|
|
static GimpObjectClass* parent_class;
|
|
|
|
|
1998-07-12 19:40:43 +08:00
|
|
|
static void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add_func (GimpList *list,
|
|
|
|
gpointer val)
|
1998-07-12 19:40:43 +08:00
|
|
|
{
|
|
|
|
list->list=g_slist_insert_sorted (list->list, val, brush_compare_func);
|
1999-10-27 02:27:27 +08:00
|
|
|
GIMP_BRUSH_LIST (list)->num_brushes++;
|
1998-07-12 19:40:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_remove_func (GimpList *list,
|
|
|
|
gpointer val)
|
1998-07-12 19:40:43 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
list->list=g_slist_remove (list->list, val);
|
|
|
|
GIMP_BRUSH_LIST (list)->num_brushes--;
|
1998-07-12 19:40:43 +08:00
|
|
|
}
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
static void
|
|
|
|
gimp_brush_list_class_init (GimpBrushListClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-12 19:40:43 +08:00
|
|
|
GimpListClass *gimp_list_class;
|
1998-07-09 13:31:06 +08:00
|
|
|
|
1998-07-12 19:40:43 +08:00
|
|
|
gimp_list_class = GIMP_LIST_CLASS(klass);
|
|
|
|
gimp_list_class->add = gimp_brush_list_add_func;
|
1998-07-24 16:56:18 +08:00
|
|
|
gimp_list_class->remove = gimp_brush_list_remove_func;
|
1998-07-12 19:40:43 +08:00
|
|
|
parent_class = gtk_type_class (gimp_list_get_type ());
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_init (GimpBrushList *list)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
|
|
|
list->num_brushes = 0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
GtkType
|
|
|
|
gimp_brush_list_get_type (void)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
static GtkType type = 0;
|
|
|
|
|
|
|
|
if (!type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo info =
|
|
|
|
{
|
|
|
|
"GimpBrushList",
|
|
|
|
sizeof (GimpBrushList),
|
|
|
|
sizeof (GimpBrushListClass),
|
|
|
|
(GtkClassInitFunc) gimp_brush_list_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_brush_list_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
(GtkClassInitFunc) NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
type = gtk_type_unique (gimp_list_get_type (), &info);
|
|
|
|
}
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
return type;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
GimpBrushList *
|
1999-12-02 21:00:18 +08:00
|
|
|
gimp_brush_list_new (void)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
GimpBrushList *list;
|
|
|
|
|
|
|
|
list = GIMP_BRUSH_LIST (gtk_type_new (gimp_brush_list_get_type ()));
|
|
|
|
|
|
|
|
GIMP_LIST (list)->type = GIMP_TYPE_BRUSH;
|
|
|
|
GIMP_LIST (list)->weak = FALSE;
|
1998-07-09 13:31:06 +08:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
/* function declarations */
|
|
|
|
void
|
|
|
|
brushes_init (int no_data)
|
|
|
|
{
|
|
|
|
if (brush_list)
|
1999-10-27 02:27:27 +08:00
|
|
|
brushes_free ();
|
1998-07-24 16:56:18 +08:00
|
|
|
else
|
1999-10-27 02:27:27 +08:00
|
|
|
brush_list = gimp_brush_list_new ();
|
1998-07-09 13:31:06 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
if (brush_path != NULL && !no_data)
|
1999-12-02 21:00:18 +08:00
|
|
|
{
|
|
|
|
brush_select_freeze_all ();
|
|
|
|
|
|
|
|
datafiles_read_directories (brush_path,
|
|
|
|
(datafile_loader_t) brushes_brush_load, 0);
|
|
|
|
|
|
|
|
brush_select_thaw_all ();
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
gimp_context_refresh_brushes ();
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpBrush *
|
|
|
|
brushes_get_standard_brush (void)
|
|
|
|
{
|
|
|
|
if (! standard_brush)
|
|
|
|
{
|
|
|
|
standard_brush =
|
|
|
|
GIMP_BRUSH (gimp_brush_generated_new (5.0, 0.5, 0.0, 1.0));
|
|
|
|
|
1999-11-14 18:50:19 +08:00
|
|
|
gimp_brush_set_name (standard_brush, "Standard");
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* set ref_cout to 2 --> never swap the standard brush */
|
|
|
|
gtk_object_ref (GTK_OBJECT (standard_brush));
|
|
|
|
gtk_object_ref (GTK_OBJECT (standard_brush));
|
|
|
|
}
|
|
|
|
|
|
|
|
return standard_brush;
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-16 19:44:56 +08:00
|
|
|
static void
|
1999-10-27 02:27:27 +08:00
|
|
|
brushes_brush_load (gchar *filename)
|
1998-07-16 19:44:56 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
if (strcmp (&filename[strlen (filename) - 4], ".gbr") == 0)
|
1999-08-09 14:30:31 +08:00
|
|
|
{
|
|
|
|
GimpBrush *brush;
|
1999-10-27 02:27:27 +08:00
|
|
|
brush = gimp_brush_new (filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
if (brush != NULL)
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add (brush_list, brush);
|
1999-08-09 14:30:31 +08:00
|
|
|
else
|
1999-10-27 02:27:27 +08:00
|
|
|
g_message ("Warning: failed to load brush \"%s\"", filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
else if (strcmp (&filename[strlen(filename) - 4], ".vbr") == 0)
|
1999-08-09 14:30:31 +08:00
|
|
|
{
|
|
|
|
GimpBrushGenerated *brush;
|
1999-10-27 02:27:27 +08:00
|
|
|
brush = gimp_brush_generated_load (filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
if (brush != NULL)
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
1999-08-09 14:30:31 +08:00
|
|
|
else
|
1999-10-27 02:27:27 +08:00
|
|
|
g_message ("Warning: failed to load brush \"%s\"", filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
else if (strcmp (&filename[strlen (filename) - 4], ".gpb") == 0)
|
1999-08-09 14:30:31 +08:00
|
|
|
{
|
Overhaul of pixmap brushes and pipes: No separate pixmap pipe
brush tool any longer. The paintbrush, airbrush and pencil
tools, which already knew how to handle the single-pixmap
brushes now also handle the pipes as well.
* app/pixmapbrush.{h,c}
* app/gimpbrushpixmap.{h,c}: Removed these files.
* app/Makefile.am
* app/makefile.{cygwin,msc}: Remove from here, too.
* app/gimpbrushpipe.{h,c}: Total overhaul.
* app/paint_core.h
* app/apptypes.h: Some more types moved to apptypes.h
* app/context_manager.c
* app/tool_options.c
* app/tools.c
* app/toolsF.h: Remove PIXMAPBRUSH tool.
* app/gimpbrush.h: New method: select_brush. Used to change the
brush in paint_core, for pipe brushes.
* app/gimpbrush.c: Add gimp_brush_select_brush, which is dummy for
the normal brushes (returns the same brush).
* app/paint_core.c: Call the brush's select_brush method to get a
potential new brush before calling the paint_func.
* app/gimpbrushlist.c: Various changes related to the pixmap and
pipe overhaul.
* app/airbrush.c
* app/pencil.c: Reorder code a bit in the tool motion function to
avoid executing unnecessary code in the case of a pixmap brush.
Other changes in the same commit:
* app/install.c: Make quote_spaces extern.
* app/appenv.h: Declare it.
* libgimp/gimpui.def: Add missing entry points.
* libgimp/makefile.{cygwin,msc}: Add missing objects to gimpui.
1999-08-26 08:54:30 +08:00
|
|
|
GimpBrushPipe *brush;
|
1999-10-27 02:27:27 +08:00
|
|
|
brush = gimp_brush_pixmap_load (filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
if (brush != NULL)
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
1999-08-09 14:30:31 +08:00
|
|
|
else
|
Overhaul of pixmap brushes and pipes: No separate pixmap pipe
brush tool any longer. The paintbrush, airbrush and pencil
tools, which already knew how to handle the single-pixmap
brushes now also handle the pipes as well.
* app/pixmapbrush.{h,c}
* app/gimpbrushpixmap.{h,c}: Removed these files.
* app/Makefile.am
* app/makefile.{cygwin,msc}: Remove from here, too.
* app/gimpbrushpipe.{h,c}: Total overhaul.
* app/paint_core.h
* app/apptypes.h: Some more types moved to apptypes.h
* app/context_manager.c
* app/tool_options.c
* app/tools.c
* app/toolsF.h: Remove PIXMAPBRUSH tool.
* app/gimpbrush.h: New method: select_brush. Used to change the
brush in paint_core, for pipe brushes.
* app/gimpbrush.c: Add gimp_brush_select_brush, which is dummy for
the normal brushes (returns the same brush).
* app/paint_core.c: Call the brush's select_brush method to get a
potential new brush before calling the paint_func.
* app/gimpbrushlist.c: Various changes related to the pixmap and
pipe overhaul.
* app/airbrush.c
* app/pencil.c: Reorder code a bit in the tool motion function to
avoid executing unnecessary code in the case of a pixmap brush.
Other changes in the same commit:
* app/install.c: Make quote_spaces extern.
* app/appenv.h: Declare it.
* libgimp/gimpui.def: Add missing entry points.
* libgimp/makefile.{cygwin,msc}: Add missing objects to gimpui.
1999-08-26 08:54:30 +08:00
|
|
|
g_message("Warning: failed to load pixmap brush \"%s\"", filename);
|
1999-08-09 14:30:31 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
else if (strcmp (&filename[strlen (filename) - 4], ".gih") == 0)
|
1999-08-17 08:59:07 +08:00
|
|
|
{
|
1999-08-23 14:06:12 +08:00
|
|
|
GimpBrushPipe *brush;
|
1999-10-27 02:27:27 +08:00
|
|
|
brush = gimp_brush_pipe_load (filename);
|
1999-08-17 08:59:07 +08:00
|
|
|
if (brush != NULL)
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add (brush_list, GIMP_BRUSH (brush));
|
1999-08-17 08:59:07 +08:00
|
|
|
else
|
Overhaul of pixmap brushes and pipes: No separate pixmap pipe
brush tool any longer. The paintbrush, airbrush and pencil
tools, which already knew how to handle the single-pixmap
brushes now also handle the pipes as well.
* app/pixmapbrush.{h,c}
* app/gimpbrushpixmap.{h,c}: Removed these files.
* app/Makefile.am
* app/makefile.{cygwin,msc}: Remove from here, too.
* app/gimpbrushpipe.{h,c}: Total overhaul.
* app/paint_core.h
* app/apptypes.h: Some more types moved to apptypes.h
* app/context_manager.c
* app/tool_options.c
* app/tools.c
* app/toolsF.h: Remove PIXMAPBRUSH tool.
* app/gimpbrush.h: New method: select_brush. Used to change the
brush in paint_core, for pipe brushes.
* app/gimpbrush.c: Add gimp_brush_select_brush, which is dummy for
the normal brushes (returns the same brush).
* app/paint_core.c: Call the brush's select_brush method to get a
potential new brush before calling the paint_func.
* app/gimpbrushlist.c: Various changes related to the pixmap and
pipe overhaul.
* app/airbrush.c
* app/pencil.c: Reorder code a bit in the tool motion function to
avoid executing unnecessary code in the case of a pixmap brush.
Other changes in the same commit:
* app/install.c: Make quote_spaces extern.
* app/appenv.h: Declare it.
* libgimp/gimpui.def: Add missing entry points.
* libgimp/makefile.{cygwin,msc}: Add missing objects to gimpui.
1999-08-26 08:54:30 +08:00
|
|
|
g_message("Warning: failed to load pixmap pipe \"%s\"", filename);
|
1999-08-17 08:59:07 +08:00
|
|
|
}
|
1998-07-16 19:44:56 +08:00
|
|
|
}
|
|
|
|
|
1998-01-29 16:03:27 +08:00
|
|
|
static gint
|
1999-10-27 02:27:27 +08:00
|
|
|
brush_compare_func (gconstpointer first,
|
|
|
|
gconstpointer second)
|
1998-01-29 16:03:27 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
return strcmp (((const GimpBrush *) first)->name,
|
|
|
|
((const GimpBrush *) second)->name);
|
1998-01-29 16:03:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-12-02 21:00:18 +08:00
|
|
|
brushes_free (void)
|
1998-01-29 16:03:27 +08:00
|
|
|
{
|
1998-07-24 16:56:18 +08:00
|
|
|
if (brush_list)
|
1999-08-30 18:51:01 +08:00
|
|
|
{
|
1999-12-02 21:00:18 +08:00
|
|
|
brush_select_freeze_all ();
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
while (GIMP_LIST (brush_list)->list)
|
1999-08-30 18:51:01 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
GimpBrush * b = GIMP_BRUSH (GIMP_LIST (brush_list)->list->data);
|
|
|
|
if (GIMP_IS_BRUSH_GENERATED (b))
|
|
|
|
{
|
|
|
|
gchar *filename = g_strdup (b->filename);
|
|
|
|
if (!filename)
|
1999-08-30 18:51:01 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
gchar *home;
|
|
|
|
gchar *local_path;
|
|
|
|
gchar *first_token;
|
|
|
|
gchar *token;
|
|
|
|
gchar *path;
|
|
|
|
FILE *tmp_fp;
|
|
|
|
gint unum = 0;
|
|
|
|
|
|
|
|
if (brush_vbr_path)
|
1999-08-30 18:51:01 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
/* Get the first path specified in the
|
|
|
|
* brush-vbr-path gimprc variable.
|
|
|
|
*/
|
|
|
|
home = g_get_home_dir ();
|
|
|
|
local_path = g_strdup (brush_vbr_path);
|
|
|
|
first_token = local_path;
|
|
|
|
token = xstrsep (&first_token, G_SEARCHPATH_SEPARATOR_S);
|
|
|
|
|
|
|
|
if (token)
|
|
|
|
{
|
|
|
|
if (*token == '~')
|
|
|
|
if (home != NULL)
|
|
|
|
path = g_strconcat (home, token + 1, NULL);
|
|
|
|
else
|
|
|
|
path = g_strdup (""); /* Better than nothing */
|
|
|
|
else
|
|
|
|
path = g_strdup (token);
|
1999-08-30 18:51:01 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
filename = g_strconcat (path, G_DIR_SEPARATOR_S,
|
|
|
|
b->name, ".vbr", NULL);
|
|
|
|
while ((tmp_fp = fopen (filename, "r")))
|
|
|
|
{ /* make sure we don't overite an existing brush */
|
|
|
|
fclose (tmp_fp);
|
|
|
|
g_free (filename);
|
|
|
|
filename = g_strdup_printf ("%s%s%s_%d.vbr", path,
|
|
|
|
G_DIR_SEPARATOR_S,
|
|
|
|
b->name, unum);
|
|
|
|
unum++;
|
|
|
|
}
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
g_free (local_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcmp (&filename[strlen (filename) - 4], ".vbr"))
|
|
|
|
{
|
|
|
|
g_free (filename);
|
|
|
|
filename = NULL;
|
1999-08-30 18:51:01 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* okay we are ready to try to save the generated file */
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
gimp_brush_generated_save (GIMP_BRUSH_GENERATED (b), filename);
|
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_remove (brush_list, b);
|
|
|
|
}
|
1999-12-02 21:00:18 +08:00
|
|
|
|
|
|
|
brush_select_thaw_all ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-07 04:05:06 +08:00
|
|
|
#if 0
|
1998-01-29 16:03:27 +08:00
|
|
|
static GSList *
|
1999-10-27 02:27:27 +08:00
|
|
|
insert_brush_in_list (GSList *list,
|
|
|
|
GimpBrush *brush)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-01-29 16:03:27 +08:00
|
|
|
return g_slist_insert_sorted (list, brush, brush_compare_func);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-09-07 04:05:06 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gint
|
1998-07-20 22:05:33 +08:00
|
|
|
gimp_brush_list_get_brush_index (GimpBrushList *brush_list,
|
1999-10-27 02:27:27 +08:00
|
|
|
GimpBrush *brush)
|
1998-07-20 22:05:33 +08:00
|
|
|
{
|
|
|
|
/* fix me: make a gimp_list function that does this? */
|
1998-07-24 16:56:18 +08:00
|
|
|
return g_slist_index (GIMP_LIST(brush_list)->list, brush);
|
1998-07-20 22:05:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-12 19:40:43 +08:00
|
|
|
GimpBrush *
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_get_brush_by_index (GimpBrushList *brush_list,
|
|
|
|
gint index)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
GimpBrush *brush = NULL;
|
1998-01-29 16:03:27 +08:00
|
|
|
GSList *list;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
1998-07-12 19:40:43 +08:00
|
|
|
/* fix me: make a gimp_list function that does this? */
|
1999-10-27 02:27:27 +08:00
|
|
|
list = g_slist_nth (GIMP_LIST (brush_list)->list, index);
|
1998-01-29 16:03:27 +08:00
|
|
|
if (list)
|
1998-07-12 19:40:43 +08:00
|
|
|
brush = (GimpBrush *) list->data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-01-29 16:03:27 +08:00
|
|
|
return brush;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-07-20 06:32:35 +08:00
|
|
|
static void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_uniquefy_brush_name (GimpBrushList *brush_list,
|
|
|
|
GimpBrush *brush)
|
1998-07-20 06:32:35 +08:00
|
|
|
{
|
1998-07-20 22:05:33 +08:00
|
|
|
GSList *list, *listb;
|
1998-07-20 06:32:35 +08:00
|
|
|
GimpBrush *brushb;
|
|
|
|
int number = 1;
|
|
|
|
char *newname;
|
|
|
|
char *oldname;
|
|
|
|
char *ext;
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BRUSH_LIST (brush_list));
|
|
|
|
g_return_if_fail (GIMP_IS_BRUSH (brush));
|
|
|
|
list = GIMP_LIST (brush_list)->list;
|
1998-07-20 06:32:35 +08:00
|
|
|
while (list)
|
1999-10-27 02:27:27 +08:00
|
|
|
{
|
|
|
|
brushb = GIMP_BRUSH (list->data);
|
|
|
|
if (brush != brushb &&
|
|
|
|
strcmp (gimp_brush_get_name (brush),
|
|
|
|
gimp_brush_get_name (brushb)) == 0)
|
|
|
|
{ /* names conflict */
|
|
|
|
oldname = gimp_brush_get_name (brush);
|
|
|
|
newname = g_malloc (strlen (oldname) + 10); /* if this aint enough
|
|
|
|
yer screwed */
|
|
|
|
strcpy (newname, oldname);
|
|
|
|
if ((ext = strrchr(newname, '#')))
|
|
|
|
{
|
|
|
|
number = atoi (ext+1);
|
|
|
|
if (&ext[(int)(log10 (number) + 1)] !=
|
|
|
|
&newname[strlen (newname) - 1])
|
|
|
|
{
|
|
|
|
number = 1;
|
|
|
|
ext = &newname[strlen (newname)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
number = 1;
|
|
|
|
ext = &newname[strlen (newname)];
|
|
|
|
}
|
|
|
|
sprintf (ext, "#%d", number+1);
|
|
|
|
listb = GIMP_LIST (brush_list)->list;
|
|
|
|
while (listb) /* make sure the new name is unique */
|
|
|
|
{
|
|
|
|
brushb = GIMP_BRUSH (listb->data);
|
|
|
|
if (brush != brushb &&
|
|
|
|
strcmp (newname, gimp_brush_get_name (brushb)) == 0)
|
|
|
|
{
|
|
|
|
number++;
|
|
|
|
sprintf (ext, "#%d", number+1);
|
|
|
|
listb = GIMP_LIST (brush_list)->list;
|
|
|
|
}
|
|
|
|
listb = listb->next;
|
|
|
|
}
|
|
|
|
gimp_brush_set_name (brush, newname);
|
|
|
|
g_free (newname);
|
|
|
|
if (gimp_list_have (GIMP_LIST (brush_list), brush))
|
|
|
|
{ /* ought to have a better way than this to resort the brush */
|
|
|
|
gtk_object_ref (GTK_OBJECT (brush));
|
|
|
|
gimp_brush_list_remove (brush_list, brush);
|
|
|
|
gimp_brush_list_add (brush_list, brush);
|
|
|
|
gtk_object_unref (GTK_OBJECT (brush));
|
|
|
|
}
|
|
|
|
return;
|
1998-07-20 22:05:33 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
list = list->next;
|
1998-07-20 06:32:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
static void
|
|
|
|
brush_renamed (GimpBrush *brush,
|
|
|
|
GimpBrushList *brush_list)
|
1998-07-20 06:32:35 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_uniquefy_brush_name (brush_list, brush);
|
1998-07-20 06:32:35 +08:00
|
|
|
}
|
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_add (GimpBrushList *brush_list,
|
|
|
|
GimpBrush *brush)
|
1998-07-09 13:31:06 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_uniquefy_brush_name (brush_list, brush);
|
|
|
|
gimp_list_add (GIMP_LIST (brush_list), brush);
|
|
|
|
gtk_object_sink (GTK_OBJECT (brush));
|
|
|
|
gtk_signal_connect (GTK_OBJECT (brush), "rename",
|
|
|
|
GTK_SIGNAL_FUNC (brush_renamed),
|
|
|
|
brush_list);
|
1998-07-09 13:31:06 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
void
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_remove (GimpBrushList *brush_list,
|
|
|
|
GimpBrush *brush)
|
1998-07-12 19:40:43 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
gtk_signal_disconnect_by_data (GTK_OBJECT (brush), brush_list);
|
|
|
|
|
|
|
|
gimp_list_remove (GIMP_LIST (brush_list), brush);
|
1998-07-12 19:40:43 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
gint
|
1998-07-12 19:40:43 +08:00
|
|
|
gimp_brush_list_length (GimpBrushList *brush_list)
|
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_BRUSH_LIST (brush_list), 0);
|
|
|
|
|
|
|
|
return brush_list->num_brushes;
|
1998-07-12 19:40:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpBrush *
|
1999-10-27 02:27:27 +08:00
|
|
|
gimp_brush_list_get_brush (GimpBrushList *blist,
|
|
|
|
gchar *name)
|
1998-07-12 19:40:43 +08:00
|
|
|
{
|
|
|
|
GimpBrush *brushp;
|
|
|
|
GSList *list;
|
1999-10-27 02:27:27 +08:00
|
|
|
|
1998-07-12 19:40:43 +08:00
|
|
|
if (blist == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
for (list = GIMP_LIST (brush_list)->list; list; list = g_slist_next (list))
|
1998-07-12 19:40:43 +08:00
|
|
|
{
|
1999-10-27 02:27:27 +08:00
|
|
|
brushp = (GimpBrush *) list->data;
|
|
|
|
|
|
|
|
if (!strcmp (brushp->name, name))
|
|
|
|
return brushp;
|
1998-07-12 19:40:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|