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

app/Makefile.am app/apptypes.h new abstract base class for everything

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

	* app/Makefile.am
	* app/apptypes.h
	* app/gimpdata.[ch]: new abstract base class for everything
	(except images) which has a filename and can become dirty and must
	be saved.

	* app/gimpbrush.[ch]
	* app/gimpgradient.[ch]
	* app/gimppattern.[ch]: all derived from GimpData now.

	* app/gimpbrushgenerated.[ch]
	* app/brush_select.c
	* app/brushes.c
	* app/gimpbrushpipe.c
	* app/gradient_editor.c
	* app/gradients.c
	* app/patterns.c: removed lots of code duplication due to common
	file save magic.

	The gradient file format has changed: it now contains the
	gradient's name (no more ugly underscores). The files have the
	extension ".ggr".

	* app/gimpgradient.[ch]: save new gradients, load new and old
	gradients.

	* data/gradients/*: removed all old gradients and added the new
	ones.
parent e2db8600
2001-02-11 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
* app/apptypes.h
* app/gimpdata.[ch]: new abstract base class for everything
(except images) which has a filename and can become dirty and must
be saved.
* app/gimpbrush.[ch]
* app/gimpgradient.[ch]
* app/gimppattern.[ch]: all derived from GimpData now.
* app/gimpbrushgenerated.[ch]
* app/brush_select.c
* app/brushes.c
* app/gimpbrushpipe.c
* app/gradient_editor.c
* app/gradients.c
* app/patterns.c: removed lots of code duplication due to common
file save magic.
The gradient file format has changed: it now contains the
gradient's name (no more ugly underscores). The files have the
extension ".ggr".
* app/gimpgradient.[ch]: save new gradients, load new and old
gradients.
* data/gradients/*: removed all old gradients and added the new
ones.
2001-02-10 David Monniaux <monniaux@genievre.ens.fr>
MMX code for paint_funcs. Very partial so far.
......
......@@ -116,6 +116,8 @@ gimp_SOURCES = \
gimpcontext.h \
gimpcontextpreview.c \
gimpcontextpreview.h \
gimpdata.c \
gimpdata.h \
gimpdatalist.c \
gimpdatalist.h \
gimpdnd.c \
......@@ -267,6 +269,7 @@ gimp_SOURCES = \
\
paint_funcs.c \
paint_funcs.h \
paint_funcs_simd.S \
pixel_processor.c \
pixel_processor.h \
pixel_region.c \
......@@ -314,8 +317,7 @@ gimp_SOURCES = \
marching_ants.h \
pixmaps.h \
pixmaps2.h \
wilber.h \
paint_funcs_simd.S
wilber.h
EXTRA_DIST = \
makefile.mingw \
......
......@@ -58,6 +58,8 @@ typedef GimpImage GImage;
/* data objects */
typedef struct _GimpData GimpData;
typedef struct _GimpBrush GimpBrush;
typedef struct _GimpBrushGenerated GimpBrushGenerated;
typedef struct _GimpBrushPipe GimpBrushPipe;
......
......@@ -35,6 +35,7 @@
#include "gimpbrushgenerated.h"
#include "gimpbrushpipe.h"
#include "gimpcontext.h"
#include "gimpdata.h"
#include "gimpdnd.h"
#include "gimplist.h"
#include "gimprc.h"
......@@ -1878,7 +1879,7 @@ brush_select_delete_brush_callback (GtkWidget *widget,
if (GIMP_IS_BRUSH_GENERATED (brush))
{
gimp_brush_generated_delete (GIMP_BRUSH_GENERATED (brush));
gimp_data_delete_from_disk (GIMP_DATA (brush));
brush_select_freeze_all ();
......
......@@ -128,29 +128,28 @@ brushes_brush_load (const gchar *filename)
void
brushes_free (void)
{
GList *vbr_path;
gchar *vbr_dir;
if (! global_brush_list)
return;
vbr_path = gimp_path_parse (brush_vbr_path, 16, TRUE, NULL);
vbr_dir = gimp_path_get_user_writable_dir (vbr_path);
gimp_path_free (vbr_path);
brush_select_freeze_all ();
while (GIMP_LIST (global_brush_list)->list)
{
GimpBrush *brush = GIMP_BRUSH (GIMP_LIST (global_brush_list)->list->data);
GimpData *data;
data = GIMP_DATA (GIMP_LIST (global_brush_list)->list->data);
if (GIMP_IS_BRUSH_GENERATED (brush) && vbr_dir)
gimp_brush_generated_save (GIMP_BRUSH_GENERATED (brush), vbr_dir);
if (! GIMP_DATA (data)->filename)
gimp_data_create_filename (data,
GIMP_OBJECT (data)->name,
GIMP_BRUSH_GENERATED_FILE_EXTENSION,
brush_path);
gimp_container_remove (global_brush_list, GIMP_OBJECT (brush));
if (data->dirty)
gimp_data_save (data);
gimp_container_remove (global_brush_list, GIMP_OBJECT (data));
}
brush_select_thaw_all ();
g_free (vbr_dir);
}
......@@ -89,7 +89,7 @@ gimp_brush_get_type (void)
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (GIMP_TYPE_VIEWABLE, &info);
type = gtk_type_unique (GIMP_TYPE_DATA, &info);
}
return type;
}
......@@ -103,7 +103,7 @@ gimp_brush_class_init (GimpBrushClass *klass)
object_class = (GtkObjectClass *) klass;
viewable_class = (GimpViewableClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_VIEWABLE);
parent_class = gtk_type_class (GIMP_TYPE_DATA);
object_class->destroy = gimp_brush_destroy;
......@@ -116,16 +116,14 @@ gimp_brush_class_init (GimpBrushClass *klass)
static void
gimp_brush_init (GimpBrush *brush)
{
brush->filename = NULL;
brush->mask = NULL;
brush->pixmap = NULL;
brush->spacing = 20;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
brush->mask = NULL;
brush->pixmap = NULL;
}
static void
......@@ -135,8 +133,6 @@ gimp_brush_destroy (GtkObject *object)
brush = GIMP_BRUSH (object);
g_free (brush->filename);
if (brush->mask)
temp_buf_free (brush->mask);
......@@ -269,12 +265,16 @@ gimp_brush_load (const gchar *filename)
close (fd);
brush->filename = g_strdup (filename);
if (! brush)
return NULL;
gimp_data_set_filename (GIMP_DATA (brush), filename);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
{
temp_buf_swap (brush->mask);
if (brush->pixmap)
temp_buf_swap (brush->pixmap);
}
......@@ -429,7 +429,7 @@ gimp_brush_load_brush (gint fd,
}
}
break;
default:
g_message ("Unsupported brush depth: %d\n"
"in file \"%s\"\n"
......
......@@ -89,7 +89,7 @@ gimp_brush_get_type (void)
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (GIMP_TYPE_VIEWABLE, &info);
type = gtk_type_unique (GIMP_TYPE_DATA, &info);
}
return type;
}
......@@ -103,7 +103,7 @@ gimp_brush_class_init (GimpBrushClass *klass)
object_class = (GtkObjectClass *) klass;
viewable_class = (GimpViewableClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_VIEWABLE);
parent_class = gtk_type_class (GIMP_TYPE_DATA);
object_class->destroy = gimp_brush_destroy;
......@@ -116,16 +116,14 @@ gimp_brush_class_init (GimpBrushClass *klass)
static void
gimp_brush_init (GimpBrush *brush)
{
brush->filename = NULL;
brush->mask = NULL;
brush->pixmap = NULL;
brush->spacing = 20;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
brush->mask = NULL;
brush->pixmap = NULL;
}
static void
......@@ -135,8 +133,6 @@ gimp_brush_destroy (GtkObject *object)
brush = GIMP_BRUSH (object);
g_free (brush->filename);
if (brush->mask)
temp_buf_free (brush->mask);
......@@ -269,12 +265,16 @@ gimp_brush_load (const gchar *filename)
close (fd);
brush->filename = g_strdup (filename);
if (! brush)
return NULL;
gimp_data_set_filename (GIMP_DATA (brush), filename);
/* Swap the brush to disk (if we're being stingy with memory) */
if (stingy_memory_use)
{
temp_buf_swap (brush->mask);
if (brush->pixmap)
temp_buf_swap (brush->pixmap);
}
......@@ -429,7 +429,7 @@ gimp_brush_load_brush (gint fd,
}
}
break;
default:
g_message ("Unsupported brush depth: %d\n"
"in file \"%s\"\n"
......
......@@ -20,7 +20,7 @@
#define __GIMP_BRUSH_H__
#include "gimpviewable.h"
#include "gimpdata.h"
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
......@@ -34,19 +34,19 @@ typedef struct _GimpBrushClass GimpBrushClass;
struct _GimpBrush
{
GimpViewable parent_instance;
gchar *filename; /* actual filename--brush's location on disk */
gint spacing; /* brush's spacing */
GimpVector2 x_axis; /* for calculating brush spacing */
GimpVector2 y_axis; /* for calculating brush spacing */
TempBuf *mask; /* the actual mask */
TempBuf *pixmap; /* optional pixmap data */
GimpData parent_instance;
TempBuf *mask; /* the actual mask */
TempBuf *pixmap; /* optional pixmap data */
gint spacing; /* brush's spacing */
GimpVector2 x_axis; /* for calculating brush spacing */
GimpVector2 y_axis; /* for calculating brush spacing */
};
struct _GimpBrushClass
{
GimpViewableClass parent_class;
GimpDataClass parent_class;
/* FIXME: these are no virtual function pointers but bad hacks: */
GimpBrush * (* select_brush) (PaintCore *paint_core);
......
......@@ -47,42 +47,18 @@
#define OVERSAMPLING 5
static void gimp_brush_generated_generate (GimpBrushGenerated *brush);
/* local function prototypes */
static void gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass);
static void gimp_brush_generated_init (GimpBrushGenerated *brush);
static void gimp_brush_generated_destroy (GtkObject *object);
static gboolean gimp_brush_generated_save (GimpData *data);
static void gimp_brush_generated_dirty (GimpData *data);
static GimpBrushClass *parent_class = NULL;
static void
gimp_brush_generated_destroy (GtkObject *object)
{
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) klass;
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
object_class->destroy = gimp_brush_generated_destroy;
}
static void
gimp_brush_generated_init (GimpBrushGenerated *brush)
{
brush->radius = 5.0;
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
guint
GtkType
gimp_brush_generated_get_type (void)
{
static GtkType type = 0;
......@@ -107,162 +83,56 @@ gimp_brush_generated_get_type (void)
return type;
}
GimpBrush *
gimp_brush_generated_new (gfloat radius,
gfloat hardness,
gfloat angle,
gfloat aspect_ratio)
static void
gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
{
GimpBrushGenerated *brush;
/* set up normal brush data */
brush = GIMP_BRUSH_GENERATED (gtk_type_new (GIMP_TYPE_BRUSH_GENERATED));
gimp_object_set_name (GIMP_OBJECT (brush), "Untitled");
GtkObjectClass *object_class;
GimpDataClass *data_class;
GIMP_BRUSH (brush)->spacing = 20;
object_class = (GtkObjectClass *) klass;
data_class = (GimpDataClass *) klass;
/* set up gimp_brush_generated data */
brush->radius = radius;
brush->hardness = hardness;
brush->angle = angle;
brush->aspect_ratio = aspect_ratio;
parent_class = gtk_type_class (GIMP_TYPE_BRUSH);
/* render brush mask */
gimp_brush_generated_generate (brush);
object_class->destroy = gimp_brush_generated_destroy;
return GIMP_BRUSH (brush);
data_class->save = gimp_brush_generated_save;
data_class->dirty = gimp_brush_generated_dirty;
}
GimpBrush *
gimp_brush_generated_load (const gchar *file_name)
static void
gimp_brush_generated_init (GimpBrushGenerated *brush)
{
GimpBrushGenerated *brush;
FILE *fp;
gchar string[256];
gfloat fl;
gfloat version;
if ((fp = fopen (file_name, "rb")) == NULL)
return NULL;
/* make sure the file we are reading is the right type */
fgets (string, 255, fp);
if (strncmp (string, "GIMP-VBR", 8) != 0)
return NULL;
/* make sure we are reading a compatible version */
fgets (string, 255, fp);
sscanf (string, "%f", &version);
g_return_val_if_fail (version < 2.0, NULL);
/* create new brush */
brush =
GIMP_BRUSH_GENERATED (gtk_type_new (gimp_brush_generated_get_type ()));
GIMP_BRUSH (brush)->filename = g_strdup (file_name);
gimp_brush_generated_freeze (brush);
/* read name */
fgets (string, 255, fp);
if (string[strlen (string) - 1] == '\n')
string[strlen (string) - 1] = 0;
gimp_object_set_name (GIMP_OBJECT (brush), string);
/* read brush spacing */
fscanf (fp, "%f", &fl);
GIMP_BRUSH (brush)->spacing = fl;
/* read brush radius */
fscanf (fp, "%f", &fl);
gimp_brush_generated_set_radius (brush, fl);
/* read brush hardness */
fscanf (fp, "%f", &fl);
gimp_brush_generated_set_hardness (brush, fl);
/* read brush aspect_ratio */
fscanf (fp, "%f", &fl);
gimp_brush_generated_set_aspect_ratio (brush, fl);
/* read brush angle */
fscanf (fp, "%f", &fl);
gimp_brush_generated_set_angle (brush, fl);
fclose (fp);
gimp_brush_generated_thaw (brush);
if (stingy_memory_use)
temp_buf_swap (GIMP_BRUSH (brush)->mask);
return GIMP_BRUSH (brush);
brush->radius = 5.0;
brush->hardness = 0.0;
brush->angle = 0.0;
brush->aspect_ratio = 1.0;
brush->freeze = 0;
}
void
gimp_brush_generated_save (GimpBrushGenerated *brush,
const gchar *directory)
static void
gimp_brush_generated_destroy (GtkObject *object)
{
FILE *fp;
gchar *filename = NULL;
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
g_return_if_fail (directory != NULL);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
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);
static gboolean
gimp_brush_generated_save (GimpData *data)
{
GimpBrushGenerated *brush;
FILE *fp;
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;
}
}
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (data), FALSE);
if (! filename)
return;
brush = GIMP_BRUSH_GENERATED (data);
/* we are (finaly) ready to try to save the generated brush file */
if ((fp = fopen (filename, "wb")) == NULL)
if ((fp = fopen (data->filename, "wb")) == NULL)
{
g_warning ("Unable to save file %s", filename);
return;
g_warning ("Unable to save file %s", data->filename);
return FALSE;
}
/* write magic header */
......@@ -290,37 +160,8 @@ gimp_brush_generated_save (GimpBrushGenerated *brush,
fprintf (fp, "%f\n", brush->angle);
fclose (fp);
}
void
gimp_brush_generated_delete (GimpBrushGenerated *brush)
{
if (GIMP_BRUSH (brush)->filename)
{
unlink (GIMP_BRUSH (brush)->filename);
}
}
void
gimp_brush_generated_freeze (GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush->freeze++;
}
void
gimp_brush_generated_thaw (GimpBrushGenerated *brush)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
if (brush->freeze > 0)
brush->freeze--;
if (brush->freeze == 0)
gimp_brush_generated_generate (brush);
return TRUE;
}
static double
......@@ -340,9 +181,10 @@ gauss (gdouble f)
return (2.0 * f*f);
}
void
gimp_brush_generated_generate (GimpBrushGenerated *brush)
static void
gimp_brush_generated_dirty (GimpData *data)
{
GimpBrushGenerated *brush;
register GimpBrush *gbrush = NULL;
register gint x, y;
register guchar *centerp;
......@@ -355,9 +197,8 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
gdouble buffer[OVERSAMPLING];
gint width, height;
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH_GENERATED (brush));
brush = GIMP_BRUSH_GENERATED (data);
if (brush->freeze) /* if we are frozen defer rerendering till later */
return;
......@@ -368,7 +209,7 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
if (gbrush->mask)
{
temp_buf_free(gbrush->mask);
temp_buf_free (gbrush->mask);
}
/* compute the range of the brush. should do a better job than this? */
......@@ -462,9 +303,129 @@ gimp_brush_generated_generate (GimpBrushGenerated *brush)
g_free (lookup);
if (GIMP_DATA_CLASS (parent_class)->dirty)
GIMP_DATA_CLASS (parent_class)->dirty (data);
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (brush));
}
GimpBrush *
gimp_brush_generated_new (gfloat radius,
gfloat hardness,
gfloat angle,
gfloat aspect_ratio)
{
GimpBrushGenerated *brush;
/* set up normal brush data */
brush = GIMP_BRUSH_GENERATED (gtk_type_new (GIMP_TYPE_BRUSH_GENERATED));
gimp_object_set_name (GIMP_OBJECT (brush), "Untitled");
GIMP_BRUSH (brush)->spacing = 20;
/* set up gimp_brush_generated data */
brush->radius = radius;
brush->hardness = hardness;
brush->angle = angle;
brush->aspect_ratio = aspect_ratio;
/* render brush mask */
gimp_data_dirty (GIMP_DATA (brush));
return GIMP_BRUSH (brush);
}
GimpBrush *
gimp_brush_generated_load (const gchar *filename)
{
GimpBrushGenerated *brush;
FILE *fp;
gchar string[256];
gfloat fl;
gfloat version;
if ((fp = fopen (filename, "rb")) == NULL)
return NULL;
/* make sure the file we are reading is the right type */
fgets (string, 255, fp);
if (strncmp (string, "GIMP-VBR", 8) != 0)
return NULL;
/* make sure we are reading a compatible version */
fgets (string, 255, fp);
sscanf (string, "%f", &version);
g_return_val_if_fail (version < 2.0, NULL);
/* create new brush */
brush = GIMP_BRUSH_GENERATED (gtk_type_new (GIMP_TYPE_BRUSH_GENERATED));
gimp_data_set_filename (GIMP_DATA (brush), filename);
gimp_brush_generated_freeze (brush);
/* read name */
fgets (string, 255, fp);