Commit 78a8bb4c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/Makefile.am new object.

2001-02-04  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am
	* app/gimppattern.[ch]: new object.

	* app/apptypes.h: added GimpPattern, removed GPattern.

	* app/patterns.[ch]: contains only the "patterns_()" functions for
	the global pattern list, s/pattern_list/global_pattern_list/g

	* app/brushes.[ch]: s/brush_list/global_brush_list/g

	* app/pattern_select.[ch]
	* app/gimpcontext.[ch]: connect to the Patterns' and the pattern
	list's signals.

	* app/brush_select.[ch]
	* app/devices.c
	* app/disp_callbacks.[ch]
	* app/gimpbrush.c
	* app/gimpbrushgenerated.[ch]
	* app/gimpcontextpreview.[ch]
	* app/gimpdnd.[ch]
	* app/indicator_area.c
	* app/pdb/brush_select_cmds.c
	* app/pdb/brushes_cmds.c
	* app/pdb/pattern_select_cmds.c
	* app/pdb/patterns_cmds.c
	* app/tools/bucket_fill.c
	* app/tools/clone.c
	* tools/pdbgen/pdb/brush_select.pdb
	* tools/pdbgen/pdb/brushes.pdb
	* tools/pdbgen/pdb/pattern_select.pdb
	* tools/pdbgen/pdb/patterns.pdb
	* po/POTFILES.in: changed accordingly.
parent 1994facc
2001-02-04 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
* app/gimppattern.[ch]: new object.
* app/apptypes.h: added GimpPattern, removed GPattern.
* app/patterns.[ch]: contains only the "patterns_()" functions for
the global pattern list, s/pattern_list/global_pattern_list/g
* app/brushes.[ch]: s/brush_list/global_brush_list/g
* app/pattern_select.[ch]
* app/gimpcontext.[ch]: connect to the Patterns' and the pattern
list's signals.
* app/brush_select.[ch]
* app/devices.c
* app/disp_callbacks.[ch]
* app/gimpbrush.c
* app/gimpbrushgenerated.[ch]
* app/gimpcontextpreview.[ch]
* app/gimpdnd.[ch]
* app/indicator_area.c
* app/pdb/brush_select_cmds.c
* app/pdb/brushes_cmds.c
* app/pdb/pattern_select_cmds.c
* app/pdb/patterns_cmds.c
* app/tools/bucket_fill.c
* app/tools/clone.c
* tools/pdbgen/pdb/brush_select.pdb
* tools/pdbgen/pdb/brushes.pdb
* tools/pdbgen/pdb/pattern_select.pdb
* tools/pdbgen/pdb/patterns.pdb
* po/POTFILES.in: changed accordingly.
2001-02-04 Michael Natterer <mitch@gimp.org>
* app/gimpcontainer.[ch]: renamed gimp_container_lookup() back
......@@ -13,7 +49,7 @@
* app/gimpbrushlist.[ch]: removed. It's job is done by the
GimpDataList now.
* app/brushes.[ch]: new files. Contain the "brushes_()" functions
* app/brushes.[ch]: new files. Contains the "brushes_()" functions
for the global brush list.
* app/app_procs.c
......
......@@ -142,6 +142,8 @@ gimp_SOURCES = \
gimpmarshal.h \
gimpobject.c \
gimpobject.h \
gimppattern.c \
gimppattern.h \
gimppalette.c \
gimppalette.h \
gimpparasite.c \
......
......@@ -60,6 +60,8 @@ typedef struct _GimpBrush GimpBrush;
typedef struct _GimpBrushGenerated GimpBrushGenerated;
typedef struct _GimpBrushPipe GimpBrushPipe;
typedef struct _GimpPattern GimpPattern;
typedef struct _GimpPalette GimpPalette;
......@@ -95,8 +97,6 @@ typedef struct _GimpParasite GimpParasite;
typedef struct _GimpProgress GimpProgress;
typedef struct _GPattern GPattern;
typedef struct _gradient_t gradient_t;
typedef struct _Guide Guide;
......
......@@ -310,7 +310,8 @@ brush_select_new (gchar *title,
if (title && init_name && strlen (init_name))
{
active = (GimpBrush *) gimp_list_get_child_by_name (brush_list, init_name);
active = (GimpBrush *) gimp_list_get_child_by_name (global_brush_list,
init_name);
}
else
{
......@@ -526,20 +527,20 @@ brush_select_new (gchar *title,
/* add callbacks to keep the display area current */
bsp->name_changed_handler_id =
gimp_container_add_handler
(GIMP_CONTAINER (brush_list), "name_changed",
(GIMP_CONTAINER (global_brush_list), "name_changed",
GTK_SIGNAL_FUNC (brush_select_brush_dirty_callback),
bsp);
bsp->dirty_handler_id =
gimp_container_add_handler
(GIMP_CONTAINER (brush_list), "dirty",
(GIMP_CONTAINER (global_brush_list), "dirty",
GTK_SIGNAL_FUNC (brush_select_brush_dirty_callback),
bsp);
gtk_signal_connect (GTK_OBJECT (brush_list), "add",
gtk_signal_connect (GTK_OBJECT (global_brush_list), "add",
GTK_SIGNAL_FUNC (brush_added_callback),
bsp);
gtk_signal_connect (GTK_OBJECT (brush_list), "remove",
gtk_signal_connect (GTK_OBJECT (global_brush_list), "remove",
GTK_SIGNAL_FUNC (brush_removed_callback),
bsp);
......@@ -599,12 +600,12 @@ brush_select_free (BrushSelect *bsp)
gtk_object_unref (GTK_OBJECT (bsp->context));
}
gimp_container_remove_handler (GIMP_CONTAINER (brush_list),
gimp_container_remove_handler (GIMP_CONTAINER (global_brush_list),
bsp->name_changed_handler_id);
gimp_container_remove_handler (GIMP_CONTAINER (brush_list),
gimp_container_remove_handler (GIMP_CONTAINER (global_brush_list),
bsp->dirty_handler_id);
gtk_signal_disconnect_by_data (GTK_OBJECT (brush_list), bsp);
gtk_signal_disconnect_by_data (GTK_OBJECT (global_brush_list), bsp);
g_free (bsp);
}
......@@ -613,7 +614,7 @@ void
brush_select_freeze_all (void)
{
BrushSelect *bsp;
GSList *list;
GSList *list;
for (list = brush_active_dialogs; list; list = g_slist_next (list))
{
......@@ -627,7 +628,7 @@ void
brush_select_thaw_all (void)
{
BrushSelect *bsp;
GSList *list;
GSList *list;
for (list = brush_active_dialogs; list; list = g_slist_next (list))
{
......@@ -835,7 +836,7 @@ brush_select_select (BrushSelect *bsp,
gint row, col;
gint scroll_offset = 0;
index = gimp_list_get_child_index (brush_list, GIMP_OBJECT (brush));
index = gimp_list_get_child_index (global_brush_list, GIMP_OBJECT (brush));
if (index < 0)
return;
......@@ -885,7 +886,7 @@ brush_select_brush_dirty_callback (GimpBrush *brush,
if (!bsp || bsp->freeze)
return;
index = gimp_list_get_child_index (brush_list, GIMP_OBJECT (brush));
index = gimp_list_get_child_index (global_brush_list, GIMP_OBJECT (brush));
redraw = (brush != gimp_context_get_brush (bsp->context));
clear_brush (bsp, brush,
......@@ -1351,8 +1352,8 @@ do_display_brush (GimpBrush *brush,
static void
display_brushes (BrushSelect *bsp)
{
if (brush_list == NULL ||
gimp_container_num_children (GIMP_CONTAINER (brush_list)) == 0)
if (global_brush_list == NULL ||
gimp_container_num_children (GIMP_CONTAINER (global_brush_list)) == 0)
{
gtk_widget_set_sensitive (bsp->options_box, FALSE);
return;
......@@ -1366,7 +1367,7 @@ display_brushes (BrushSelect *bsp)
display_setup (bsp);
brush_counter = 0;
gimp_container_foreach (GIMP_CONTAINER (brush_list),
gimp_container_foreach (GIMP_CONTAINER (global_brush_list),
(GFunc) do_display_brush,
bsp);
}
......@@ -1492,7 +1493,7 @@ preview_calc_scrollbar (BrushSelect *bsp)
gint max;
bsp->scroll_offset = 0;
num_rows = ((gimp_container_num_children (GIMP_CONTAINER (brush_list)) +
num_rows = ((gimp_container_num_children (GIMP_CONTAINER (global_brush_list)) +
(bsp->NUM_BRUSH_COLUMNS) - 1)
/ (bsp->NUM_BRUSH_COLUMNS));
max = num_rows * bsp->cell_width;
......@@ -1533,7 +1534,7 @@ brush_select_resize (GtkWidget *widget,
bsp->NUM_BRUSH_COLUMNS =
(gint) (wid / cell_size);
bsp->NUM_BRUSH_ROWS =
(gint) ((gimp_container_num_children (GIMP_CONTAINER (brush_list)) +
(gint) ((gimp_container_num_children (GIMP_CONTAINER (global_brush_list)) +
bsp->NUM_BRUSH_COLUMNS - 1) /
bsp->NUM_BRUSH_COLUMNS);
......@@ -1567,7 +1568,8 @@ brush_select_events (GtkWidget *widget,
index = row * bsp->NUM_BRUSH_COLUMNS + col;
/* Get the brush and check if it is editable */
brush = GIMP_BRUSH (gimp_list_get_child_by_index (brush_list, index));
brush = GIMP_BRUSH (gimp_list_get_child_by_index (global_brush_list,
index));
if (GIMP_IS_BRUSH_GENERATED (brush))
brush_select_edit_brush_callback (NULL, bsp);
break;
......@@ -1579,7 +1581,8 @@ brush_select_events (GtkWidget *widget,
row = (bevent->y + bsp->scroll_offset) / bsp->cell_height;
index = row * bsp->NUM_BRUSH_COLUMNS + col;
brush = (GimpBrush *) gimp_list_get_child_by_index (brush_list, index);
brush = (GimpBrush *) gimp_list_get_child_by_index (global_brush_list,
index);
if (brush)
bsp->dnd_brush = brush;
......@@ -1706,7 +1709,8 @@ brush_select_scroll_update (GtkAdjustment *adjustment,
if (active)
{
index = gimp_list_get_child_index (brush_list, GIMP_OBJECT (active));
index = gimp_list_get_child_index (global_brush_list,
GIMP_OBJECT (active));
if (index < 0)
return;
row = index / bsp->NUM_BRUSH_COLUMNS;
......@@ -1810,7 +1814,7 @@ brush_select_new_brush_callback (GtkWidget *widget,
brush = gimp_brush_generated_new (10, .5, 0.0, 1.0);
if (brush)
{
gimp_container_add (GIMP_CONTAINER (brush_list),
gimp_container_add (GIMP_CONTAINER (global_brush_list),
GIMP_OBJECT (brush));
gimp_context_set_brush (bsp->context, brush);
......@@ -1870,7 +1874,7 @@ brush_select_delete_brush_callback (GtkWidget *widget,
brush_select_freeze_all ();
gimp_container_remove (GIMP_CONTAINER (brush_list),
gimp_container_remove (GIMP_CONTAINER (global_brush_list),
GIMP_OBJECT (brush));
gimp_context_refresh_brushes ();
......
......@@ -84,6 +84,7 @@ extern GSList *brush_active_dialogs;
/* the main brush dialog */
extern BrushSelect *brush_select_dialog;
BrushSelect * brush_select_new (gchar *title,
/* These are the required initial vals
* If init_name == NULL then use
......
......@@ -18,21 +18,12 @@
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include "apptypes.h"
#include "appenv.h"
#include "brushes.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushpipe.h"
......@@ -51,7 +42,7 @@
/* global variables */
GimpList *brush_list = NULL;
GimpList *global_brush_list = NULL;
/* local function prototypes */
......@@ -62,10 +53,10 @@ static void brushes_brush_load (const gchar *filename);
void
brushes_init (gboolean no_data)
{
if (brush_list)
if (global_brush_list)
brushes_free ();
else
brush_list = GIMP_LIST (gimp_data_list_new (GIMP_TYPE_BRUSH));
global_brush_list = GIMP_LIST (gimp_data_list_new (GIMP_TYPE_BRUSH));
if (brush_path != NULL && !no_data)
{
......@@ -130,7 +121,7 @@ brushes_brush_load (const gchar *filename)
}
if (brush != NULL)
gimp_container_add (GIMP_CONTAINER (brush_list),
gimp_container_add (GIMP_CONTAINER (global_brush_list),
GIMP_OBJECT (brush));
}
......@@ -140,7 +131,7 @@ brushes_free (void)
GList *vbr_path;
gchar *vbr_dir;
if (!brush_list)
if (! global_brush_list)
return;
vbr_path = gimp_path_parse (brush_vbr_path, 16, TRUE, NULL);
......@@ -149,66 +140,14 @@ brushes_free (void)
brush_select_freeze_all ();
while (GIMP_LIST (brush_list)->list)
while (GIMP_LIST (global_brush_list)->list)
{
GimpBrush *brush = GIMP_BRUSH (GIMP_LIST (brush_list)->list->data);
GimpBrush *brush = GIMP_BRUSH (GIMP_LIST (global_brush_list)->list->data);
if (GIMP_IS_BRUSH_GENERATED (brush) && vbr_dir)
{
gchar *filename = NULL;
if (!brush->filename)
{
FILE *tmp_fp;
gint unum = 0;
if (vbr_dir)
{
gchar *safe_name;
gint i;
/* make sure we don't create a naughty filename */
safe_name = g_strdup (GIMP_OBJECT (brush)->name);
if (safe_name[0] == '.')
safe_name[0] = '_';
for (i = 0; safe_name[i]; i++)
if (safe_name[i] == G_DIR_SEPARATOR || isspace(safe_name[i]))
safe_name[i] = '_';
filename = g_strdup_printf ("%s%s.vbr",
vbr_dir,
safe_name);
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_%d.vbr",
vbr_dir, safe_name, unum);
unum++;
}
g_free (safe_name);
}
}
else
{
filename = g_strdup (brush->filename);
if (strlen(filename) < 4 || strcmp (&filename[strlen (filename) - 4],
".vbr"))
{ /* we only want to save .vbr files, so set filename to null
if this isn't a .vbr file */
g_free (filename);
filename = NULL;
}
}
/* we are (finaly) ready to try to save the generated brush file */
if (filename)
{
gimp_brush_generated_save (GIMP_BRUSH_GENERATED (brush),
filename);
g_free (filename);
}
}
gimp_container_remove (GIMP_CONTAINER (brush_list),
gimp_brush_generated_save (GIMP_BRUSH_GENERATED (brush), vbr_dir);
gimp_container_remove (GIMP_CONTAINER (global_brush_list),
GIMP_OBJECT (brush));
}
......
......@@ -20,11 +20,12 @@
#define __BRUSHES_H__
extern GimpList *brush_list;
extern GimpList *global_brush_list;
void brushes_init (gboolean no_data);
void brushes_free (void);
GimpBrush * brushes_get_standard_brush (void);
......
......@@ -47,8 +47,6 @@
#include "brush_header.h"
#include "gimpbrush.h"
#include "gimprc.h"
#include "patterns.h"
#include "pattern_header.h"
#include "temp_buf.h"
/* this needs to go away */
......@@ -135,7 +133,7 @@ gimp_brush_get_type (void)
{
static GtkType type = 0;
if (!type)
if (! type)
{
static const GtkTypeInfo info =
{
......@@ -149,7 +147,7 @@ gimp_brush_get_type (void)
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gimp_object_get_type (), &info);
type = gtk_type_unique (GIMP_TYPE_OBJECT, &info);
}
return type;
}
......@@ -237,7 +235,6 @@ gimp_brush_load_brush (gint fd,
const gchar *filename)
{
GimpBrush *brush;
GPattern *pattern;
gint bn_size;
BrushHeader header;
gchar *name;
......@@ -310,32 +307,6 @@ gimp_brush_load_brush (gint fd,
gtk_object_unref (GTK_OBJECT (brush));
return NULL;
}
/* For backwards-compatibility, check if a pattern follows.
The obsolete .gpb format did it this way. */
pattern = pattern_load (fd, filename);
if (pattern)
{
if (pattern->mask && pattern->mask->bytes == 3)
{
brush->pixmap = pattern->mask;
pattern->mask = NULL;
}
pattern_free (pattern);
}
else
{
/* rewind to make brush pipe loader happy */
if (lseek (fd, - ((off_t) sizeof (PatternHeader)), SEEK_CUR) < 0)
{
g_message (_("GIMP brush file appears to be corrupted: \"%s\"."),
filename);
g_free (name);
gtk_object_unref (GTK_OBJECT (brush));
return NULL;
}
}
break;
case 4:
......@@ -359,7 +330,9 @@ gimp_brush_load_brush (gint fd,
break;
default:
g_message ("Unsupported brush depth: %d\n in file \"%s\"\nGIMP Brushes must be GRAY or RGBA\n",
g_message ("Unsupported brush depth: %d\n"
"in file \"%s\"\n"
"GIMP Brushes must be GRAY or RGBA",
header.bytes, filename);
g_free (name);
return NULL;
......
......@@ -47,8 +47,6 @@
#include "brush_header.h"
#include "gimpbrush.h"
#include "gimprc.h"
#include "patterns.h"
#include "pattern_header.h"
#include "temp_buf.h"
/* this needs to go away */
......@@ -135,7 +133,7 @@ gimp_brush_get_type (void)
{
static GtkType type = 0;
if (!type)
if (! type)
{
static const GtkTypeInfo info =
{
......@@ -149,7 +147,7 @@ gimp_brush_get_type (void)
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gimp_object_get_type (), &info);
type = gtk_type_unique (GIMP_TYPE_OBJECT, &info);
}
return type;
}
......@@ -237,7 +235,6 @@ gimp_brush_load_brush (gint fd,
const gchar *filename)
{
GimpBrush *brush;
GPattern *pattern;
gint bn_size;
BrushHeader header;
gchar *name;
......@@ -310,32 +307,6 @@ gimp_brush_load_brush (gint fd,
gtk_object_unref (GTK_OBJECT (brush));
return NULL;
}
/* For backwards-compatibility, check if a pattern follows.
The obsolete .gpb format did it this way. */
pattern = pattern_load (fd, filename);
if (pattern)
{
if (pattern->mask && pattern->mask->bytes == 3)
{
brush->pixmap = pattern->mask;
pattern->mask = NULL;
}
pattern_free (pattern);
}
else
{
/* rewind to make brush pipe loader happy */
if (lseek (fd, - ((off_t) sizeof (PatternHeader)), SEEK_CUR) < 0)
{
g_message (_("GIMP brush file appears to be corrupted: \"%s\"."),
filename);
g_free (name);
gtk_object_unref (GTK_OBJECT (brush));
return NULL;
}
}
break;
case 4:
......@@ -359,7 +330,9 @@ gimp_brush_load_brush (gint fd,
break;
default:
g_message ("Unsupported brush depth: %d\n in file \"%s\"\nGIMP Brushes must be GRAY or RGBA\n",
g_message ("Unsupported brush depth: %d\n"
"in file \"%s\"\n"
"GIMP Brushes must be GRAY or RGBA",
header.bytes, filename);
g_free (name);
return NULL;
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
......@@ -201,14 +202,66 @@ gimp_brush_generated_load (const gchar *file_name)
}
void
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *file_name)
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *directory)
{
FILE *fp;
FILE *fp;
gchar *filename = NULL;
if ((fp = fopen (file_name, "wb")) == NULL)
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
g_return_if_fail (directory != NULL);
if (! GIMP_BRUSH (brush)->filename)
{
gchar *safe_name;
gint i;
gint unum = 1;
/* make sure we don't create a naughty filename */
safe_name = g_strdup (GIMP_OBJECT (brush)->name);
if (safe_name[0] == '.')
safe_name[0] = '_';
for (i = 0; safe_name[i]; i++)
if (safe_name[i] == G_DIR_SEPARATOR || isspace (safe_name[i]))
safe_name[i] = '_';
filename = g_strdup_printf ("%s%s.vbr",
directory, safe_name);
while ((fp = fopen (filename, "r")))
{
/* make sure we don't overite an existing brush */
fclose (fp);
g_free (filename);
filename = g_strdup_printf ("%s%s_%d.vbr",
directory, safe_name, unum);
unum++;
}
g_free (safe_name);
}
else
{
filename = g_strdup (GIMP_BRUSH (brush)->filename);
if (strlen(filename) < 4 || strcmp (&filename[strlen (filename) - 4],
".vbr"))
{
/* we only want to save .vbr files, so set filename to null
* if this isn't a .vbr file
*/
g_free (filename);
filename = NULL;
}
}
if (! filename)
return;
/* we are (finaly) ready to try to save the generated brush file */
if ((fp = fopen (filename, "wb")) == NULL)
{
g_warning ("Unable to save file %s", file_name);
g_warning ("Unable to save file %s", filename);
return;
}
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
......@@ -201,14 +202,66 @@ gimp_brush_generated_load (const gchar *file_name)
}
void
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *file_name)
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *directory)
{
FILE *fp;
FILE *fp;
gchar *filename = NULL;
if ((fp = fopen (file_name, "wb")) == NULL)
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
g_return_if_fail (directory != NULL);
if (! GIMP_BRUSH (brush)->filename)
{
gchar *safe_name;
gint i;
gint unum = 1;
/* make sure we don't create a naughty filename */
safe_name = g_strdup (GIMP_OBJECT (brush)->name);
if (safe_name[0] == '.')
safe_name[0] = '_';
for (i = 0; safe_name[i]; i++)
if (safe_name[i] == G_DIR_SEPARATOR || isspace (safe_name[i]))
safe_name[i] = '_';
filename = g_strdup_printf ("%s%s.vbr",
directory, safe_name);
while ((fp = fopen (filename, "r")))
{
/* make sure we don't overite an existing brush */
fclose (fp);
g_free (filename);
filename = g_strdup_printf ("%s%s_%d.vbr",
directory, safe_name, unum);
unum++;
}
g_free (safe_name);
}
else
{
filename = g_strdup (GIMP_BRUSH (brush)->filename);
if (strlen(filename) < 4 || strcmp (&filename[strlen (filename) - 4],
".vbr"))
{
/* we only want to save .vbr files, so set filename to null
* if this isn't a .vbr file
*/
g_free (filename);
filename = NULL;
}
}
if (! filename)
return;
/* we are (finaly) ready to try to save the generated brush file */
if ((fp = fopen (filename, "wb")) == NULL)
{
g_warning ("Unable to save file %s", file_name);
g_warning ("Unable to save file %s", filename);
return;
}
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
......@@ -201,14 +202,66 @@ gimp_brush_generated_load (const gchar *file_name)
}
void
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *file_name)
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *directory)
{
FILE *fp;
FILE *fp;