From 2b5130f08acedb4f42464892f2bd1541e6e8db5b Mon Sep 17 00:00:00 2001 From: jaycox Date: Thu, 2 Sep 1999 09:20:48 +0000 Subject: [PATCH] free the brush dialog before freeing the brushes. * app/app_procs.c: free the brush dialog before freeing the brushes. * app/blend.c, app/bucket_fill.c: don't include brush_select.h * app/brush_select.[ch]: add the ability to delete generated brushes. * app/gimpbrushgenerated.c: save the brush parameters on seperate lines. * app/gimpbrushlist.c: make sure we don't overwrite other brush files when saving newly created brushes. --- ChangeLog | 13 ++++ app/app_procs.c | 2 +- app/blend.c | 1 - app/brush_select.c | 95 ++++++++++++++++++++++++++---- app/brush_select.h | 4 ++ app/bucket_fill.c | 1 - app/core/gimpbrushgenerated-load.c | 16 ++--- app/core/gimpbrushgenerated-save.c | 16 ++--- app/core/gimpbrushgenerated.c | 16 ++--- app/core/gimpdrawable-blend.c | 1 - app/gimpbrushgenerated.c | 16 ++--- app/gimpbrushlist.c | 18 ++++++ app/gui/brush-select.c | 95 ++++++++++++++++++++++++++---- app/gui/brush-select.h | 4 ++ app/tools/blend.c | 1 - app/tools/bucket_fill.c | 1 - app/tools/gimpblendtool.c | 1 - app/tools/gimpbucketfilltool.c | 1 - 18 files changed, 242 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6781318eb8..f6242019ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Thu Sep 2 02:12:20 1999 Jay Cox (jaycox@earthlink.net) + + * app/app_procs.c: free the brush dialog before freeing the brushes. + + * app/blend.c, app/bucket_fill.c: don't include brush_select.h + + * app/brush_select.[ch]: add the ability to delete generated brushes. + + * app/gimpbrushgenerated.c: save the brush parameters on seperate lines. + + * app/gimpbrushlist.c: make sure we don't overwrite other brush + files when saving newly created brushes. + Wed Sep 1 14:50:29 PDT 1999 Manish Singh * libgimp/Makefile.am: add gimpmath.h diff --git a/app/app_procs.c b/app/app_procs.c index da1cd20144..766f9ed7f8 100644 --- a/app/app_procs.c +++ b/app/app_procs.c @@ -640,6 +640,7 @@ app_exit_finish (void) named_buffers_free (); swapping_free (); context_manager_free (); + brush_select_dialog_free (); brushes_free (); patterns_free (); palettes_free (); @@ -648,7 +649,6 @@ app_exit_finish (void) hue_saturation_free (); curves_free (); levels_free (); - brush_select_dialog_free (); pattern_select_dialog_free (); palette_free (); paint_funcs_free (); diff --git a/app/blend.c b/app/blend.c index cea60c01dc..b2386e3c98 100644 --- a/app/blend.c +++ b/app/blend.c @@ -22,7 +22,6 @@ #include "appenv.h" #include "asupsample.h" #include "blend.h" -#include "brush_select.h" #include "cursorutil.h" #include "draw_core.h" #include "drawable.h" diff --git a/app/brush_select.c b/app/brush_select.c index 3d7ffdd4fd..c7074d4a40 100644 --- a/app/brush_select.c +++ b/app/brush_select.c @@ -17,6 +17,7 @@ */ #include +#include #include "appenv.h" #include "actionarea.h" #include "brush_scale.h" @@ -66,8 +67,11 @@ static void preview_calc_scrollbar (BrushSelectP); static void brush_select_show_selected (BrushSelectP, int, int); static void update_active_brush_field (BrushSelectP); static void edit_active_brush (); +static void delete_active_brush (); static gint edit_brush_callback (GtkWidget *w, GdkEvent *e, gpointer data); +static gint delete_brush_callback (GtkWidget *w, GdkEvent *e, + gpointer data); static gint new_brush_callback (GtkWidget *w, GdkEvent *e, gpointer data); static gint brush_select_brush_dirty_callback (GimpBrushP brush, @@ -150,6 +154,8 @@ brush_select_new (gchar *title, bsp->NUM_BRUSH_COLUMNS = STD_BRUSH_COLUMNS; bsp->NUM_BRUSH_ROWS = STD_BRUSH_ROWS; + bsp->freeze = FALSE; + /* The shell and main vbox */ bsp->shell = gtk_dialog_new (); gtk_window_set_wmclass (GTK_WINDOW (bsp->shell), "brushselection", "Gimp"); @@ -316,11 +322,6 @@ brush_select_new (gchar *title, /* Create the edit/new buttons */ util_box = gtk_hbox_new (FALSE, 0); gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4); - bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); - gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", - (GtkSignalFunc) edit_brush_callback, - NULL); - gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); button2 = gtk_button_new_with_label (_("New Brush")); gtk_signal_connect (GTK_OBJECT (button2), "clicked", @@ -328,14 +329,28 @@ brush_select_new (gchar *title, NULL); gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6); + bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); + gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", + (GtkSignalFunc) edit_brush_callback, + NULL); + gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); + + bsp->delete_button = gtk_button_new_with_label (_("Delete Brush")); + gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked", + (GtkSignalFunc) delete_brush_callback, + bsp); + gtk_box_pack_start (GTK_BOX (util_box), bsp->delete_button, TRUE, TRUE, 5); + gtk_widget_show (bsp->edit_button); gtk_widget_show (button2); + gtk_widget_show (bsp->delete_button); gtk_widget_show (util_box); /* We can only edit in the main window! (for now) */ if (title) { gtk_widget_set_sensitive (bsp->edit_button, FALSE); + gtk_widget_set_sensitive (bsp->delete_button, FALSE); gtk_widget_set_sensitive (button2, FALSE); } @@ -445,9 +460,15 @@ brush_select_new (gchar *title, } bsp->redraw = old_value; if (GIMP_IS_BRUSH_GENERATED (active)) + { gtk_widget_set_sensitive (bsp->edit_button, 1); + gtk_widget_set_sensitive (bsp->delete_button, 1); + } else + { gtk_widget_set_sensitive (bsp->edit_button, 0); + gtk_widget_set_sensitive (bsp->delete_button, 0); + } } /* Finally, show the dialog */ @@ -462,8 +483,11 @@ brush_select_select (BrushSelectP bsp, int index) { int row, col; - if (index < 0) + if (index >= gimp_brush_list_length(brush_list)) + index = gimp_brush_list_length(brush_list) - 1; + if (index < 0 || index >= gimp_brush_list_length(brush_list)) return; + update_active_brush_field (bsp); row = index / bsp->NUM_BRUSH_COLUMNS; col = index - row * (bsp->NUM_BRUSH_COLUMNS); @@ -494,6 +518,12 @@ brush_select_free (BrushSelectP bsp) /* remove from active list */ brush_active_dialogs = g_slist_remove (brush_active_dialogs, bsp); + gimp_list_foreach (GIMP_LIST (brush_list), + (GFunc) disconnect_signals_from_brush, + bsp); + gtk_signal_disconnect_by_data (GTK_OBJECT (brush_list), + bsp); + g_free (bsp); } } @@ -626,7 +656,6 @@ brush_select_brush_dirty_callback (GimpBrushP brush, BrushSelectP bsp) { brush_select_brush_changed (bsp, brush); - update_active_brush_field (bsp); return TRUE; } @@ -656,8 +685,11 @@ brush_added_callback (GimpBrushList *list, BrushSelectP bsp) { connect_signals_to_brush (brush, bsp); + if (bsp->freeze) + return; preview_calc_scrollbar (bsp); brush_select_brush_changed (bsp, brush); + display_brushes (bsp); } static void @@ -666,7 +698,12 @@ brush_removed_callback (GimpBrushList *list, BrushSelectP bsp) { disconnect_signals_from_brush (brush, bsp); + if (bsp->freeze) + return; +/* This doesn't all seem right, but it does keep the display synchronized */ preview_calc_scrollbar (bsp); + brush_select_brush_changed (bsp, brush); + display_brushes (bsp); } @@ -1182,6 +1219,25 @@ edit_active_brush() "please write your own or try back tomorrow\n")); } +static void +delete_active_brush(BrushSelectP bsp) +{ + if (GIMP_IS_BRUSH_GENERATED (get_active_brush ())) + { + GimpBrush *brush = get_active_brush (); + int index; + if (brush->filename) + { + unlink(brush->filename); + } + index = gimp_brush_list_get_brush_index(brush_list, brush); + gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush)); + select_brush (gimp_brush_list_get_brush_by_index(brush_list, index)); + } + else + g_message ("Wilber says: \"I don\'t know how to delete that brush.\""); +} + static gint brush_select_events (GtkWidget *widget, GdkEvent *event, @@ -1236,9 +1292,15 @@ brush_select_events (GtkWidget *widget, if (GIMP_IS_BRUSH_GENERATED (brush) && bsp == brush_select_dialog) + { gtk_widget_set_sensitive (bsp->edit_button, 1); + gtk_widget_set_sensitive (bsp->delete_button, 1); + } else + { gtk_widget_set_sensitive (bsp->edit_button, 0); + gtk_widget_set_sensitive (bsp->delete_button, 0); + } if (brush_edit_generated_dialog) brush_edit_generated_set_brush (brush_edit_generated_dialog, @@ -1306,6 +1368,15 @@ edit_brush_callback (GtkWidget *w, return TRUE; } +static gint +delete_brush_callback (GtkWidget *w, + GdkEvent *e, + gpointer data) +{ + delete_active_brush(data); + return TRUE; +} + static gint new_brush_callback (GtkWidget *w, GdkEvent *e, @@ -1364,7 +1435,9 @@ brush_select_refresh_callback (GtkWidget *w, bsp = (BrushSelectP) client_data; /* re-init the brush list */ + bsp->freeze = TRUE; brushes_init (FALSE); + bsp->freeze = FALSE; /* recalculate scrollbar extents */ preview_calc_scrollbar (bsp); @@ -1374,9 +1447,11 @@ brush_select_refresh_callback (GtkWidget *w, /* update the active selection */ active = get_active_brush (); - if (active) - brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, - active)); +/* if (active) + select_brush (bsp, active); */ +/* brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, + active)); */ + select_brush(gimp_brush_list_get_brush_by_index (brush_list, 0)); /* update the display */ if (bsp->redraw) diff --git a/app/brush_select.h b/app/brush_select.h index 7cf78bedcd..71debe3281 100644 --- a/app/brush_select.h +++ b/app/brush_select.h @@ -44,6 +44,7 @@ struct _BrushSelect { GtkAdjustment *opacity_data; GtkAdjustment *spacing_data; GtkWidget *edit_button; + GtkWidget *delete_button; GtkWidget *option_menu; /* Brush preview */ @@ -71,6 +72,9 @@ struct _BrushSelect { int old_col; gint NUM_BRUSH_COLUMNS; gint NUM_BRUSH_ROWS; + + int freeze; /* so we don't waste so much time during refresh */ + }; BrushSelectP brush_select_new (gchar *title, diff --git a/app/bucket_fill.c b/app/bucket_fill.c index 64e1de9d32..6e9c6ba005 100644 --- a/app/bucket_fill.c +++ b/app/bucket_fill.c @@ -18,7 +18,6 @@ #include #include "gdk/gdkkeysyms.h" #include "appenv.h" -#include "brush_select.h" #include "bucket_fill.h" #include "cursorutil.h" #include "drawable.h" diff --git a/app/core/gimpbrushgenerated-load.c b/app/core/gimpbrushgenerated-load.c index 6168989398..26ff401b9d 100644 --- a/app/core/gimpbrushgenerated-load.c +++ b/app/core/gimpbrushgenerated-load.c @@ -91,7 +91,7 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness, /* set up normal brush data */ brush = GIMP_BRUSH_GENERATED(gimp_type_new(gimp_brush_generated_get_type ())); - GIMP_BRUSH(brush)->name = g_strdup ("AAAGenerated"); + GIMP_BRUSH(brush)->name = g_strdup ("Untitled"); GIMP_BRUSH(brush)->spacing = 20; /* set up gimp_brush_generated data */ @@ -178,15 +178,15 @@ gimp_brush_generated_save (GimpBrushGenerated *brush, /* write name */ fprintf(fp, "%.255s\n", GIMP_BRUSH(brush)->name); /* write brush spacing */ - fprintf(fp, "%f ", (float)GIMP_BRUSH(brush)->spacing); + fprintf(fp, "%f\n", (float)GIMP_BRUSH(brush)->spacing); /* write brush radius */ - fprintf(fp, "%f ", brush->radius); + fprintf(fp, "%f\n", brush->radius); /* write brush hardness */ - fprintf(fp, "%f ", brush->hardness); + fprintf(fp, "%f\n", brush->hardness); /* write brush aspect_ratio */ - fprintf(fp, "%f ", brush->aspect_ratio); + fprintf(fp, "%f\n", brush->aspect_ratio); /* write brush angle */ - fprintf(fp, "%f", brush->angle); + fprintf(fp, "%f\n", brush->angle); fclose(fp); } @@ -214,7 +214,8 @@ gimp_brush_generated_thaw(GimpBrushGenerated *brush) static double gauss(double f) -{ /* this aint' a real gauss function */ +{ + /* this aint' a real gauss function */ if (f < -.5) { f = -1.0-f; @@ -337,7 +338,6 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush) } g_free (lookup); gtk_signal_emit_by_name(GTK_OBJECT(brush), "dirty"); -/* brush_changed_notify(GIMP_BRUSH(brush)); */ } float diff --git a/app/core/gimpbrushgenerated-save.c b/app/core/gimpbrushgenerated-save.c index 6168989398..26ff401b9d 100644 --- a/app/core/gimpbrushgenerated-save.c +++ b/app/core/gimpbrushgenerated-save.c @@ -91,7 +91,7 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness, /* set up normal brush data */ brush = GIMP_BRUSH_GENERATED(gimp_type_new(gimp_brush_generated_get_type ())); - GIMP_BRUSH(brush)->name = g_strdup ("AAAGenerated"); + GIMP_BRUSH(brush)->name = g_strdup ("Untitled"); GIMP_BRUSH(brush)->spacing = 20; /* set up gimp_brush_generated data */ @@ -178,15 +178,15 @@ gimp_brush_generated_save (GimpBrushGenerated *brush, /* write name */ fprintf(fp, "%.255s\n", GIMP_BRUSH(brush)->name); /* write brush spacing */ - fprintf(fp, "%f ", (float)GIMP_BRUSH(brush)->spacing); + fprintf(fp, "%f\n", (float)GIMP_BRUSH(brush)->spacing); /* write brush radius */ - fprintf(fp, "%f ", brush->radius); + fprintf(fp, "%f\n", brush->radius); /* write brush hardness */ - fprintf(fp, "%f ", brush->hardness); + fprintf(fp, "%f\n", brush->hardness); /* write brush aspect_ratio */ - fprintf(fp, "%f ", brush->aspect_ratio); + fprintf(fp, "%f\n", brush->aspect_ratio); /* write brush angle */ - fprintf(fp, "%f", brush->angle); + fprintf(fp, "%f\n", brush->angle); fclose(fp); } @@ -214,7 +214,8 @@ gimp_brush_generated_thaw(GimpBrushGenerated *brush) static double gauss(double f) -{ /* this aint' a real gauss function */ +{ + /* this aint' a real gauss function */ if (f < -.5) { f = -1.0-f; @@ -337,7 +338,6 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush) } g_free (lookup); gtk_signal_emit_by_name(GTK_OBJECT(brush), "dirty"); -/* brush_changed_notify(GIMP_BRUSH(brush)); */ } float diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c index 6168989398..26ff401b9d 100644 --- a/app/core/gimpbrushgenerated.c +++ b/app/core/gimpbrushgenerated.c @@ -91,7 +91,7 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness, /* set up normal brush data */ brush = GIMP_BRUSH_GENERATED(gimp_type_new(gimp_brush_generated_get_type ())); - GIMP_BRUSH(brush)->name = g_strdup ("AAAGenerated"); + GIMP_BRUSH(brush)->name = g_strdup ("Untitled"); GIMP_BRUSH(brush)->spacing = 20; /* set up gimp_brush_generated data */ @@ -178,15 +178,15 @@ gimp_brush_generated_save (GimpBrushGenerated *brush, /* write name */ fprintf(fp, "%.255s\n", GIMP_BRUSH(brush)->name); /* write brush spacing */ - fprintf(fp, "%f ", (float)GIMP_BRUSH(brush)->spacing); + fprintf(fp, "%f\n", (float)GIMP_BRUSH(brush)->spacing); /* write brush radius */ - fprintf(fp, "%f ", brush->radius); + fprintf(fp, "%f\n", brush->radius); /* write brush hardness */ - fprintf(fp, "%f ", brush->hardness); + fprintf(fp, "%f\n", brush->hardness); /* write brush aspect_ratio */ - fprintf(fp, "%f ", brush->aspect_ratio); + fprintf(fp, "%f\n", brush->aspect_ratio); /* write brush angle */ - fprintf(fp, "%f", brush->angle); + fprintf(fp, "%f\n", brush->angle); fclose(fp); } @@ -214,7 +214,8 @@ gimp_brush_generated_thaw(GimpBrushGenerated *brush) static double gauss(double f) -{ /* this aint' a real gauss function */ +{ + /* this aint' a real gauss function */ if (f < -.5) { f = -1.0-f; @@ -337,7 +338,6 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush) } g_free (lookup); gtk_signal_emit_by_name(GTK_OBJECT(brush), "dirty"); -/* brush_changed_notify(GIMP_BRUSH(brush)); */ } float diff --git a/app/core/gimpdrawable-blend.c b/app/core/gimpdrawable-blend.c index cea60c01dc..b2386e3c98 100644 --- a/app/core/gimpdrawable-blend.c +++ b/app/core/gimpdrawable-blend.c @@ -22,7 +22,6 @@ #include "appenv.h" #include "asupsample.h" #include "blend.h" -#include "brush_select.h" #include "cursorutil.h" #include "draw_core.h" #include "drawable.h" diff --git a/app/gimpbrushgenerated.c b/app/gimpbrushgenerated.c index 6168989398..26ff401b9d 100644 --- a/app/gimpbrushgenerated.c +++ b/app/gimpbrushgenerated.c @@ -91,7 +91,7 @@ GimpBrushGenerated *gimp_brush_generated_new(float radius, float hardness, /* set up normal brush data */ brush = GIMP_BRUSH_GENERATED(gimp_type_new(gimp_brush_generated_get_type ())); - GIMP_BRUSH(brush)->name = g_strdup ("AAAGenerated"); + GIMP_BRUSH(brush)->name = g_strdup ("Untitled"); GIMP_BRUSH(brush)->spacing = 20; /* set up gimp_brush_generated data */ @@ -178,15 +178,15 @@ gimp_brush_generated_save (GimpBrushGenerated *brush, /* write name */ fprintf(fp, "%.255s\n", GIMP_BRUSH(brush)->name); /* write brush spacing */ - fprintf(fp, "%f ", (float)GIMP_BRUSH(brush)->spacing); + fprintf(fp, "%f\n", (float)GIMP_BRUSH(brush)->spacing); /* write brush radius */ - fprintf(fp, "%f ", brush->radius); + fprintf(fp, "%f\n", brush->radius); /* write brush hardness */ - fprintf(fp, "%f ", brush->hardness); + fprintf(fp, "%f\n", brush->hardness); /* write brush aspect_ratio */ - fprintf(fp, "%f ", brush->aspect_ratio); + fprintf(fp, "%f\n", brush->aspect_ratio); /* write brush angle */ - fprintf(fp, "%f", brush->angle); + fprintf(fp, "%f\n", brush->angle); fclose(fp); } @@ -214,7 +214,8 @@ gimp_brush_generated_thaw(GimpBrushGenerated *brush) static double gauss(double f) -{ /* this aint' a real gauss function */ +{ + /* this aint' a real gauss function */ if (f < -.5) { f = -1.0-f; @@ -337,7 +338,6 @@ gimp_brush_generated_generate(GimpBrushGenerated *brush) } g_free (lookup); gtk_signal_emit_by_name(GTK_OBJECT(brush), "dirty"); -/* brush_changed_notify(GIMP_BRUSH(brush)); */ } float diff --git a/app/gimpbrushlist.c b/app/gimpbrushlist.c index 0cb93f980c..ae88f14c50 100644 --- a/app/gimpbrushlist.c +++ b/app/gimpbrushlist.c @@ -217,6 +217,8 @@ brushes_free () char *first_token; char *token; char *path; + FILE *tmp_fp; + int unum = 0; if (brush_vbr_path) { @@ -239,6 +241,15 @@ brushes_free () path = g_strdup (token); 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); @@ -427,7 +438,14 @@ gimp_brush_list_add (GimpBrushList *brush_list, GimpBrush * brush) void gimp_brush_list_remove (GimpBrushList *brush_list, GimpBrush * brush) { +/* if (active_brush == brush) + { + select_brush(gimp_brush_list_get_brush_by_index( + brush_list, gimp_brush_list_get_brush_get_index(brush_list, brush) - 1)); + } + */ gtk_signal_disconnect_by_data(GTK_OBJECT(brush), brush_list); + gimp_list_remove(GIMP_LIST(brush_list), brush); } diff --git a/app/gui/brush-select.c b/app/gui/brush-select.c index 3d7ffdd4fd..c7074d4a40 100644 --- a/app/gui/brush-select.c +++ b/app/gui/brush-select.c @@ -17,6 +17,7 @@ */ #include +#include #include "appenv.h" #include "actionarea.h" #include "brush_scale.h" @@ -66,8 +67,11 @@ static void preview_calc_scrollbar (BrushSelectP); static void brush_select_show_selected (BrushSelectP, int, int); static void update_active_brush_field (BrushSelectP); static void edit_active_brush (); +static void delete_active_brush (); static gint edit_brush_callback (GtkWidget *w, GdkEvent *e, gpointer data); +static gint delete_brush_callback (GtkWidget *w, GdkEvent *e, + gpointer data); static gint new_brush_callback (GtkWidget *w, GdkEvent *e, gpointer data); static gint brush_select_brush_dirty_callback (GimpBrushP brush, @@ -150,6 +154,8 @@ brush_select_new (gchar *title, bsp->NUM_BRUSH_COLUMNS = STD_BRUSH_COLUMNS; bsp->NUM_BRUSH_ROWS = STD_BRUSH_ROWS; + bsp->freeze = FALSE; + /* The shell and main vbox */ bsp->shell = gtk_dialog_new (); gtk_window_set_wmclass (GTK_WINDOW (bsp->shell), "brushselection", "Gimp"); @@ -316,11 +322,6 @@ brush_select_new (gchar *title, /* Create the edit/new buttons */ util_box = gtk_hbox_new (FALSE, 0); gtk_box_pack_end (GTK_BOX (bsp->options_box), util_box, FALSE, FALSE, 4); - bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); - gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", - (GtkSignalFunc) edit_brush_callback, - NULL); - gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); button2 = gtk_button_new_with_label (_("New Brush")); gtk_signal_connect (GTK_OBJECT (button2), "clicked", @@ -328,14 +329,28 @@ brush_select_new (gchar *title, NULL); gtk_box_pack_start (GTK_BOX (util_box), button2, TRUE, TRUE, 6); + bsp->edit_button = gtk_button_new_with_label (_("Edit Brush")); + gtk_signal_connect (GTK_OBJECT (bsp->edit_button), "clicked", + (GtkSignalFunc) edit_brush_callback, + NULL); + gtk_box_pack_start (GTK_BOX (util_box), bsp->edit_button, TRUE, TRUE, 5); + + bsp->delete_button = gtk_button_new_with_label (_("Delete Brush")); + gtk_signal_connect (GTK_OBJECT (bsp->delete_button), "clicked", + (GtkSignalFunc) delete_brush_callback, + bsp); + gtk_box_pack_start (GTK_BOX (util_box), bsp->delete_button, TRUE, TRUE, 5); + gtk_widget_show (bsp->edit_button); gtk_widget_show (button2); + gtk_widget_show (bsp->delete_button); gtk_widget_show (util_box); /* We can only edit in the main window! (for now) */ if (title) { gtk_widget_set_sensitive (bsp->edit_button, FALSE); + gtk_widget_set_sensitive (bsp->delete_button, FALSE); gtk_widget_set_sensitive (button2, FALSE); } @@ -445,9 +460,15 @@ brush_select_new (gchar *title, } bsp->redraw = old_value; if (GIMP_IS_BRUSH_GENERATED (active)) + { gtk_widget_set_sensitive (bsp->edit_button, 1); + gtk_widget_set_sensitive (bsp->delete_button, 1); + } else + { gtk_widget_set_sensitive (bsp->edit_button, 0); + gtk_widget_set_sensitive (bsp->delete_button, 0); + } } /* Finally, show the dialog */ @@ -462,8 +483,11 @@ brush_select_select (BrushSelectP bsp, int index) { int row, col; - if (index < 0) + if (index >= gimp_brush_list_length(brush_list)) + index = gimp_brush_list_length(brush_list) - 1; + if (index < 0 || index >= gimp_brush_list_length(brush_list)) return; + update_active_brush_field (bsp); row = index / bsp->NUM_BRUSH_COLUMNS; col = index - row * (bsp->NUM_BRUSH_COLUMNS); @@ -494,6 +518,12 @@ brush_select_free (BrushSelectP bsp) /* remove from active list */ brush_active_dialogs = g_slist_remove (brush_active_dialogs, bsp); + gimp_list_foreach (GIMP_LIST (brush_list), + (GFunc) disconnect_signals_from_brush, + bsp); + gtk_signal_disconnect_by_data (GTK_OBJECT (brush_list), + bsp); + g_free (bsp); } } @@ -626,7 +656,6 @@ brush_select_brush_dirty_callback (GimpBrushP brush, BrushSelectP bsp) { brush_select_brush_changed (bsp, brush); - update_active_brush_field (bsp); return TRUE; } @@ -656,8 +685,11 @@ brush_added_callback (GimpBrushList *list, BrushSelectP bsp) { connect_signals_to_brush (brush, bsp); + if (bsp->freeze) + return; preview_calc_scrollbar (bsp); brush_select_brush_changed (bsp, brush); + display_brushes (bsp); } static void @@ -666,7 +698,12 @@ brush_removed_callback (GimpBrushList *list, BrushSelectP bsp) { disconnect_signals_from_brush (brush, bsp); + if (bsp->freeze) + return; +/* This doesn't all seem right, but it does keep the display synchronized */ preview_calc_scrollbar (bsp); + brush_select_brush_changed (bsp, brush); + display_brushes (bsp); } @@ -1182,6 +1219,25 @@ edit_active_brush() "please write your own or try back tomorrow\n")); } +static void +delete_active_brush(BrushSelectP bsp) +{ + if (GIMP_IS_BRUSH_GENERATED (get_active_brush ())) + { + GimpBrush *brush = get_active_brush (); + int index; + if (brush->filename) + { + unlink(brush->filename); + } + index = gimp_brush_list_get_brush_index(brush_list, brush); + gimp_brush_list_remove(brush_list, GIMP_BRUSH (brush)); + select_brush (gimp_brush_list_get_brush_by_index(brush_list, index)); + } + else + g_message ("Wilber says: \"I don\'t know how to delete that brush.\""); +} + static gint brush_select_events (GtkWidget *widget, GdkEvent *event, @@ -1236,9 +1292,15 @@ brush_select_events (GtkWidget *widget, if (GIMP_IS_BRUSH_GENERATED (brush) && bsp == brush_select_dialog) + { gtk_widget_set_sensitive (bsp->edit_button, 1); + gtk_widget_set_sensitive (bsp->delete_button, 1); + } else + { gtk_widget_set_sensitive (bsp->edit_button, 0); + gtk_widget_set_sensitive (bsp->delete_button, 0); + } if (brush_edit_generated_dialog) brush_edit_generated_set_brush (brush_edit_generated_dialog, @@ -1306,6 +1368,15 @@ edit_brush_callback (GtkWidget *w, return TRUE; } +static gint +delete_brush_callback (GtkWidget *w, + GdkEvent *e, + gpointer data) +{ + delete_active_brush(data); + return TRUE; +} + static gint new_brush_callback (GtkWidget *w, GdkEvent *e, @@ -1364,7 +1435,9 @@ brush_select_refresh_callback (GtkWidget *w, bsp = (BrushSelectP) client_data; /* re-init the brush list */ + bsp->freeze = TRUE; brushes_init (FALSE); + bsp->freeze = FALSE; /* recalculate scrollbar extents */ preview_calc_scrollbar (bsp); @@ -1374,9 +1447,11 @@ brush_select_refresh_callback (GtkWidget *w, /* update the active selection */ active = get_active_brush (); - if (active) - brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, - active)); +/* if (active) + select_brush (bsp, active); */ +/* brush_select_select (bsp, gimp_brush_list_get_brush_index (brush_list, + active)); */ + select_brush(gimp_brush_list_get_brush_by_index (brush_list, 0)); /* update the display */ if (bsp->redraw) diff --git a/app/gui/brush-select.h b/app/gui/brush-select.h index 7cf78bedcd..71debe3281 100644 --- a/app/gui/brush-select.h +++ b/app/gui/brush-select.h @@ -44,6 +44,7 @@ struct _BrushSelect { GtkAdjustment *opacity_data; GtkAdjustment *spacing_data; GtkWidget *edit_button; + GtkWidget *delete_button; GtkWidget *option_menu; /* Brush preview */ @@ -71,6 +72,9 @@ struct _BrushSelect { int old_col; gint NUM_BRUSH_COLUMNS; gint NUM_BRUSH_ROWS; + + int freeze; /* so we don't waste so much time during refresh */ + }; BrushSelectP brush_select_new (gchar *title, diff --git a/app/tools/blend.c b/app/tools/blend.c index cea60c01dc..b2386e3c98 100644 --- a/app/tools/blend.c +++ b/app/tools/blend.c @@ -22,7 +22,6 @@ #include "appenv.h" #include "asupsample.h" #include "blend.h" -#include "brush_select.h" #include "cursorutil.h" #include "draw_core.h" #include "drawable.h" diff --git a/app/tools/bucket_fill.c b/app/tools/bucket_fill.c index 64e1de9d32..6e9c6ba005 100644 --- a/app/tools/bucket_fill.c +++ b/app/tools/bucket_fill.c @@ -18,7 +18,6 @@ #include #include "gdk/gdkkeysyms.h" #include "appenv.h" -#include "brush_select.h" #include "bucket_fill.h" #include "cursorutil.h" #include "drawable.h" diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c index cea60c01dc..b2386e3c98 100644 --- a/app/tools/gimpblendtool.c +++ b/app/tools/gimpblendtool.c @@ -22,7 +22,6 @@ #include "appenv.h" #include "asupsample.h" #include "blend.h" -#include "brush_select.h" #include "cursorutil.h" #include "draw_core.h" #include "drawable.h" diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c index 64e1de9d32..6e9c6ba005 100644 --- a/app/tools/gimpbucketfilltool.c +++ b/app/tools/gimpbucketfilltool.c @@ -18,7 +18,6 @@ #include #include "gdk/gdkkeysyms.h" #include "appenv.h" -#include "brush_select.h" #include "bucket_fill.h" #include "cursorutil.h" #include "drawable.h"