Commit f38cdf12 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/brush_edit.[ch] app/brush_header.h app/gimpbrush.[ch]

2000-09-29  Michael Natterer  <mitch@gimp.org>

	* app/brush_edit.[ch]
	* app/brush_header.h
	* app/gimpbrush.[ch]
	* app/gimpbrushgenerated.[ch]
	* app/gimpbrushlist.[ch]
	* app/gimpbrushpipe.[ch]
	* app/gimpcontext.h
	* app/gimplist.[ch]
	* app/gimpobject.[ch]
	* app/gimpset.[ch]
	* app/gimpsignal.[ch]
	* app/parasitelist.h: Lotsa fixes in the brush referencing code
	and cleanups in many GtkObjects:

	- Reference brushes correctly (call gtk_object_sink() after adding
	  them to the brush list). Don't crash when renaming a brush
	  multiple times.
	- Replaced all gtk_object_destroy() with gtk_object_unref|sink().
	- Removed the "Fake Gimp object system" (gimp_object_destroy() et.al.)
	  all over the place (while it's a good idea to have a common Gimp
	  base object, it's totally useless to try to imitate Gtk's object
	  system).
	- s/sz_BrushHeader/sizeof(BrushHeader)/g
	- And of course various indentation and coding style paranoia changes
	  in all files I visited.
parent 48e3c38f
2000-09-29 Michael Natterer <mitch@gimp.org>
* app/brush_edit.[ch]
* app/brush_header.h
* app/gimpbrush.[ch]
* app/gimpbrushgenerated.[ch]
* app/gimpbrushlist.[ch]
* app/gimpbrushpipe.[ch]
* app/gimpcontext.h
* app/gimplist.[ch]
* app/gimpobject.[ch]
* app/gimpset.[ch]
* app/gimpsignal.[ch]
* app/parasitelist.h: Lotsa fixes in the brush referencing code
and cleanups in many GtkObjects:
- Reference brushes correctly (call gtk_object_sink() after adding
them to the brush list). Don't crash when renaming a brush
multiple times.
- Replaced all gtk_object_destroy() with gtk_object_unref|sink().
- Removed the "Fake Gimp object system" (gimp_object_destroy() et.al.)
all over the place (while it's a good idea to have a common Gimp
base object, it's totally useless to try to imitate Gtk's object
system).
- s/sz_BrushHeader/sizeof(BrushHeader)/g
- And of course various indentation and coding style paranoia changes
in all files I visited.
Fri Sep 29 03:10:10 CEST 2000 Daniel Egger <egger@suse.de>
* app/brightness_contrast.c:
......
......@@ -17,7 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include "config.h"
#include <string.h>
#include "appenv.h"
......@@ -25,45 +27,50 @@
#include "brush_edit.h"
#include "gimpui.h"
#include "config.h"
#include "libgimp/gimpmath.h"
#include "libgimp/gimpintl.h"
static void brush_edit_close_callback (GtkWidget *, gpointer);
static gint brush_edit_preview_resize (GtkWidget *widget, GdkEvent *event,
static void brush_edit_close_callback (GtkWidget *widget,
gpointer data);
static gint brush_edit_preview_resize (GtkWidget *widget,
GdkEvent *event,
BrushEditGeneratedWindow *begw);
static void
update_brush_callback (GtkAdjustment *adjustment,
BrushEditGeneratedWindow *begw)
{
if (begw->brush &&
((begw->radius_data->value
!= gimp_brush_generated_get_radius(begw->brush))
!= gimp_brush_generated_get_radius (begw->brush))
|| (begw->hardness_data->value
!= gimp_brush_generated_get_hardness(begw->brush))
!= gimp_brush_generated_get_hardness (begw->brush))
|| (begw->aspect_ratio_data->value
!= gimp_brush_generated_get_aspect_ratio(begw->brush))
!= gimp_brush_generated_get_aspect_ratio (begw->brush))
|| (begw->angle_data->value
!=gimp_brush_generated_get_angle(begw->brush))))
{
gimp_brush_generated_freeze (begw->brush);
gimp_brush_generated_set_radius (begw->brush,
begw->radius_data->value);
gimp_brush_generated_set_hardness (begw->brush,
begw->hardness_data->value);
gimp_brush_generated_set_aspect_ratio (begw->brush,
begw->aspect_ratio_data->value);
gimp_brush_generated_set_angle (begw->brush,
begw->angle_data->value);
gimp_brush_generated_thaw (begw->brush);
}
!= gimp_brush_generated_get_angle (begw->brush))))
{
gimp_brush_generated_freeze (begw->brush);
gimp_brush_generated_set_radius (begw->brush,
begw->radius_data->value);
gimp_brush_generated_set_hardness (begw->brush,
begw->hardness_data->value);
gimp_brush_generated_set_aspect_ratio (begw->brush,
begw->aspect_ratio_data->value);
gimp_brush_generated_set_angle (begw->brush,
begw->angle_data->value);
gimp_brush_generated_thaw (begw->brush);
}
}
static void
brush_edit_clear_preview (BrushEditGeneratedWindow *begw)
{
guchar * buf;
gint i;
guchar *buf;
gint i;
buf = g_new (guchar, begw->preview->requisition.width);
......@@ -126,7 +133,7 @@ brush_edit_brush_dirty_callback (GimpBrush *brush,
return TRUE;
}
void
static void
brush_renamed_callback (GtkWidget *widget,
BrushEditGeneratedWindow *begw)
{
......@@ -138,15 +145,20 @@ void
brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
GimpBrush *gbrush)
{
GimpBrushGenerated *brush = 0;
if (begw->brush == (GimpBrushGenerated*)gbrush)
GimpBrushGenerated *brush = NULL;
g_return_if_fail (begw != NULL);
if (begw->brush == (GimpBrushGenerated *) gbrush)
return;
if (begw && begw->brush)
if (begw->brush)
{
gtk_signal_disconnect_by_data (GTK_OBJECT (begw->brush), begw);
gtk_object_unref (GTK_OBJECT (begw->brush));
begw->brush = NULL;
}
if (!gbrush || !GIMP_IS_BRUSH_GENERATED (gbrush))
{
begw->brush = NULL;
......@@ -154,29 +166,30 @@ brush_edit_generated_set_brush (BrushEditGeneratedWindow *begw,
gtk_widget_hide (begw->shell);
return;
}
brush = GIMP_BRUSH_GENERATED (gbrush);
if (begw)
{
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
begw);
gtk_signal_connect (GTK_OBJECT (brush), "rename",
GTK_SIGNAL_FUNC (brush_renamed_callback),
begw);
begw->brush = NULL;
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
gimp_brush_generated_get_radius (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
gimp_brush_generated_get_hardness (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
gimp_brush_generated_get_angle (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
gimp_brush_generated_get_aspect_ratio (brush));
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
begw->brush = brush;
gtk_object_ref (GTK_OBJECT (begw->brush));
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
}
gtk_signal_connect (GTK_OBJECT (brush), "dirty",
GTK_SIGNAL_FUNC (brush_edit_brush_dirty_callback),
begw);
gtk_signal_connect (GTK_OBJECT (brush), "rename",
GTK_SIGNAL_FUNC (brush_renamed_callback),
begw);
begw->brush = NULL;
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->radius_data),
gimp_brush_generated_get_radius (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->hardness_data),
gimp_brush_generated_get_hardness (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->angle_data),
gimp_brush_generated_get_angle (brush));
gtk_adjustment_set_value (GTK_ADJUSTMENT (begw->aspect_ratio_data),
gimp_brush_generated_get_aspect_ratio (brush));
gtk_entry_set_text (GTK_ENTRY (begw->name), gimp_brush_get_name (gbrush));
begw->brush = brush;
gtk_object_ref (GTK_OBJECT (begw->brush));
brush_edit_brush_dirty_callback (GIMP_BRUSH (brush), begw);
}
void
......@@ -184,6 +197,7 @@ name_changed_func (GtkWidget *widget,
BrushEditGeneratedWindow *begw)
{
gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (widget));
gimp_brush_set_name (GIMP_BRUSH (begw->brush), entry_text);
}
......@@ -204,8 +218,7 @@ brush_edit_generated_new (void)
GtkWidget *slider;
GtkWidget *table;
begw = g_new (BrushEditGeneratedWindow, 1);
begw->brush = NULL;
begw = g_new0 (BrushEditGeneratedWindow, 1);
begw->shell = gimp_dialog_new (_("Brush Editor"), "generated_brush_editor",
gimp_standard_help_func,
......@@ -222,23 +235,18 @@ brush_edit_generated_new (void)
gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (begw->shell)->vbox), vbox);
/* Populate the window with some widgets */
/* table for brush controlls */
table = gtk_table_new (5, 4, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
/* Brush's name */
begw->name = gtk_entry_new();
gtk_box_pack_start (GTK_BOX (vbox), begw->name, TRUE, TRUE, 0);
begw->name = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (vbox), begw->name, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (begw->name), "activate",
(GtkSignalFunc) name_changed_func,
GTK_SIGNAL_FUNC (name_changed_func),
begw);
gtk_signal_connect (GTK_OBJECT (begw->name), "focus_out_event",
(GtkSignalFunc) focus_out_func,
GTK_SIGNAL_FUNC (focus_out_func),
begw);
gtk_widget_show(begw->name);
gtk_widget_show (begw->name);
/* brush's preview widget w/frame */
begw->frame = gtk_frame_new (NULL);
......@@ -247,21 +255,23 @@ brush_edit_generated_new (void)
begw->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
gtk_preview_size (GTK_PREVIEW (begw->preview), 125, 100);
gtk_signal_connect_after (GTK_OBJECT(begw->frame), "size_allocate",
(GtkSignalFunc) brush_edit_preview_resize,
begw);
gtk_signal_connect_after (GTK_OBJECT (begw->frame), "size_allocate",
GTK_SIGNAL_FUNC (brush_edit_preview_resize),
begw);
gtk_container_add (GTK_CONTAINER (begw->frame), begw->preview);
gtk_widget_show(begw->preview);
gtk_widget_show(begw->frame);
gtk_widget_show (begw->preview);
gtk_widget_show (begw->frame);
/* table for sliders/labels */
begw->scale_label = gtk_label_new ("-1:1");
gtk_box_pack_start (GTK_BOX (vbox), begw->scale_label, FALSE, FALSE, 0);
begw->scale = -1;
gtk_widget_show (begw->scale_label);
begw->scale = -1;
/* table for sliders/labels */
table = gtk_table_new(2, 4, FALSE);
table = gtk_table_new (4, 2, FALSE);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
/* brush radius scale */
......@@ -271,7 +281,8 @@ brush_edit_generated_new (void)
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (begw->radius_data), "value_changed",
(GtkSignalFunc) update_brush_callback, begw);
GTK_SIGNAL_FUNC (update_brush_callback),
begw);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Radius:"), 1.0, 1.0,
slider, 1, FALSE);
......@@ -283,7 +294,8 @@ brush_edit_generated_new (void)
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (begw->hardness_data), "value_changed",
(GtkSignalFunc) update_brush_callback, begw);
GTK_SIGNAL_FUNC (update_brush_callback),
begw);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Hardness:"), 1.0, 1.0,
slider, 1, FALSE);
......@@ -295,7 +307,8 @@ brush_edit_generated_new (void)
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (begw->aspect_ratio_data), "value_changed",
(GtkSignalFunc) update_brush_callback, begw);
GTK_SIGNAL_FUNC (update_brush_callback),
begw);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
_("Aspect Ratio:"), 1.0, 1.0,
slider, 1, FALSE);
......@@ -307,7 +320,8 @@ brush_edit_generated_new (void)
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (begw->angle_data), "value_changed",
(GtkSignalFunc) update_brush_callback, begw);
GTK_SIGNAL_FUNC (update_brush_callback),
begw);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Angle:"), 1.0, 1.0,
slider, 1, FALSE);
......@@ -327,14 +341,15 @@ brush_edit_preview_resize (GtkWidget *widget,
GdkEvent *event,
BrushEditGeneratedWindow *begw)
{
gtk_preview_size (GTK_PREVIEW (begw->preview),
widget->allocation.width - 4,
widget->allocation.height - 4);
/* update the display */
if (begw->brush)
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
return FALSE;
gtk_preview_size (GTK_PREVIEW (begw->preview),
widget->allocation.width - 4,
widget->allocation.height - 4);
/* update the display */
if (begw->brush)
brush_edit_brush_dirty_callback (GIMP_BRUSH (begw->brush), begw);
return FALSE;
}
static void
......
......@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __BRUSH_EDIT_H__
#define __BRUSH_EDIT_H__
......@@ -26,20 +27,21 @@ typedef struct _BrushEditGeneratedWindow BrushEditGeneratedWindow;
struct _BrushEditGeneratedWindow
{
GtkWidget *shell;
GtkWidget *frame;
GtkWidget *preview;
GtkWidget *scale_label;
GtkWidget *options_box;
GtkWidget *name;
GtkWidget *shell;
GtkWidget *frame;
GtkWidget *preview;
GtkWidget *scale_label;
GtkWidget *options_box;
GtkWidget *name;
GtkAdjustment *radius_data;
GtkAdjustment *hardness_data;
GtkAdjustment *angle_data;
GtkAdjustment *aspect_ratio_data;
/* Brush preview */
GtkWidget *brush_preview;
GtkWidget *brush_preview;
GimpBrushGenerated *brush;
gint scale;
gint scale;
};
BrushEditGeneratedWindow * brush_edit_generated_new (void);
......
......@@ -15,30 +15,30 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __BRUSH_HEADER_H__
#define __BRUSH_HEADER_H__
typedef struct _BrushHeader BrushHeader;
#define GBRUSH_FILE_VERSION 2
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
#define sz_BrushHeader (sizeof (BrushHeader))
/* All field entries are MSB */
typedef struct _BrushHeader BrushHeader;
struct _BrushHeader
{
unsigned int header_size; /* header_size = sz_BrushHeader + brush name */
unsigned int version; /* brush file version # */
unsigned int width; /* width of brush */
unsigned int height; /* height of brush */
unsigned int bytes; /* depth of brush in bytes--always 1 */
unsigned int magic_number;/* GIMP brush magic number */
unsigned int spacing; /* brush spacing */
guint header_size; /* header_size = sizeof (BrushHeader) + brush name */
guint version; /* brush file version # */
guint width; /* width of brush */
guint height; /* height of brush */
guint bytes; /* depth of brush in bytes--always 1 */
guint magic_number; /* GIMP brush magic number */
guint spacing; /* brush spacing */
};
/* In a brush file, next comes the brush name, null-terminated. After that
* comes the brush data--width * height * bytes bytes of it...
*/
#endif /* __BRUSH_HEADER_H__ */
#endif /* ! __BRUSH_HEADER_H__ */
......@@ -15,30 +15,30 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __BRUSH_HEADER_H__
#define __BRUSH_HEADER_H__
typedef struct _BrushHeader BrushHeader;
#define GBRUSH_FILE_VERSION 2
#define GBRUSH_MAGIC (('G' << 24) + ('I' << 16) + ('M' << 8) + ('P' << 0))
#define sz_BrushHeader (sizeof (BrushHeader))
/* All field entries are MSB */
typedef struct _BrushHeader BrushHeader;
struct _BrushHeader
{
unsigned int header_size; /* header_size = sz_BrushHeader + brush name */
unsigned int version; /* brush file version # */
unsigned int width; /* width of brush */
unsigned int height; /* height of brush */
unsigned int bytes; /* depth of brush in bytes--always 1 */
unsigned int magic_number;/* GIMP brush magic number */
unsigned int spacing; /* brush spacing */
guint header_size; /* header_size = sizeof (BrushHeader) + brush name */
guint version; /* brush file version # */
guint width; /* width of brush */
guint height; /* height of brush */
guint bytes; /* depth of brush in bytes--always 1 */
guint magic_number; /* GIMP brush magic number */
guint spacing; /* brush spacing */
};
/* In a brush file, next comes the brush name, null-terminated. After that
* comes the brush data--width * height * bytes bytes of it...
*/
#endif /* __BRUSH_HEADER_H__ */
#endif /* ! __BRUSH_HEADER_H__ */
......@@ -47,15 +47,14 @@ gimp_brush_destroy (GtkObject *object)
{
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->filename)
g_free (brush->filename);
if (brush->name)
g_free (brush->name);
g_free (brush->filename);
g_free (brush->name);
if (brush->mask)
temp_buf_free (brush->mask);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
......@@ -116,6 +115,7 @@ gimp_brush_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gimp_object_get_type (), &info);
}
return type;
......@@ -126,7 +126,10 @@ gimp_brush_new (gchar *filename)
{
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
return (gimp_brush_load (brush, filename)? brush : NULL);
if (gimp_brush_load (brush, filename))
return brush;
return NULL;
}
static GimpBrush *
......@@ -144,6 +147,7 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
TempBuf *
gimp_brush_get_mask (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->mask;
......@@ -152,6 +156,7 @@ gimp_brush_get_mask (GimpBrush *brush)
gchar *
gimp_brush_get_name (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->name;
......@@ -161,10 +166,12 @@ void
gimp_brush_set_name (GimpBrush *brush,
gchar *name)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH (brush));
if (strcmp (brush->name, name) == 0)
return;
if (brush->name)
g_free (brush->name);
brush->name = g_strdup (name);
......@@ -195,20 +202,23 @@ gboolean
gimp_brush_load (GimpBrush *brush,
gchar *filename)
{
FILE * fp;
FILE *fp;
brush->filename = g_strdup (filename);
/* Open the requested file */
if (! (fp = fopen (filename, "rb")))
{
gimp_object_destroy (brush);
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
if (! gimp_brush_load_brush (brush, fp, filename))
{
fclose (fp);
return FALSE;
}
if (!gimp_brush_load_brush (brush, fp, filename))
return FALSE;
/* Clean up */
fclose (fp);
......@@ -219,39 +229,37 @@ gimp_brush_load (GimpBrush *brush,
return TRUE;
}
gint
gboolean
gimp_brush_load_brush (GimpBrush *brush,
FILE *fp,
gchar *filename)
{
gint bn_size;
guchar buf [sz_BrushHeader];
guchar buf [sizeof (BrushHeader)];
BrushHeader header;
guint *hp;
gint i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
if ((fread (buf, 1, sizeof (BrushHeader), fp)) < sizeof (BrushHeader))
{
fclose (fp);
gimp_object_destroy (brush);
return 0;
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
/* rearrange the bytes in each unsigned int */
hp = (guint *) &header;
for (i = 0; i < (sz_BrushHeader / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
for (i = 0; i < (sizeof (BrushHeader) / 4); i++)
hp [i] = ((buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]));
/* Check for correct file format */
if (header.magic_number != GBRUSH_MAGIC)
{
if (header.version != 1)
{
fclose (fp);
gimp_object_destroy (brush);
return 0;
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
}
......@@ -265,19 +273,20 @@ gimp_brush_load_brush (GimpBrush *brush,
}
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = g_new (gchar, bn_size);
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
}
if ((bn_size = (header.header_size - sizeof (BrushHeader))))
{
brush->name = g_new (gchar, bn_size);
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
}
else
brush->name = g_strdup (_("Unnamed"));
{
brush->name = g_strdup (_("Unnamed"));
}
switch (header.version)
{
......@@ -293,16 +302,18 @@ gimp_brush_load_brush (GimpBrush *brush,
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
if ((fread (temp_buf_data (brush->mask),
1, header.width * header.height, fp)) <
header.width * header.height)
g_message (_("GIMP brush file appears to be truncated."));
break;
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return 0;
gtk_object_sink (GTK_OBJECT (brush));
return FALSE;
}
return 1;
return TRUE;
}
......@@ -47,15 +47,14 @@ gimp_brush_destroy (GtkObject *object)
{
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->filename)
g_free (brush->filename);
if (brush->name)
g_free (brush->name);
g_free (brush->filename);
g_free (brush->name);
if (brush->mask)
temp_buf_free (brush->mask);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
......@@ -116,6 +115,7 @@ gimp_brush_get_type (void)
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gimp_object_get_type (), &info);
}
return type;
......@@ -126,7 +126,10 @@ gimp_brush_new (gchar *filename)
{
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
return (gimp_brush_load (brush, filename)? brush : NULL);
if (gimp_brush_load (brush, filename))
return brush;
return NULL;
}
static GimpBrush *
......@@ -144,6 +147,7 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
TempBuf *
gimp_brush_get_mask (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->mask;
......@@ -152,6 +156,7 @@ gimp_brush_get_mask (GimpBrush *brush)
gchar *
gimp_brush_get_name (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->name;
......@@ -161,10 +166,12 @@ void
gimp_brush_set_name (GimpBrush *brush,