diff --git a/ChangeLog b/ChangeLog index 99fe6f875f..961fb47269 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-04-01 Michael Natterer + + * plug-ins/flame/Makefile.am + * plug-ins/flame/megawidget.[ch]: removed + + * plug-ins/flame/flame.c: general ui cleanup, added some sanity + checks when opening a flame file, indentation. + 2000-04-01 Jay Cox * app/paint_funcs.c: Fixed the off by one error that was the cause diff --git a/plug-ins/flame/Makefile.am b/plug-ins/flame/Makefile.am index 2b8ce4d896..6f202f4923 100644 --- a/plug-ins/flame/Makefile.am +++ b/plug-ins/flame/Makefile.am @@ -13,8 +13,6 @@ flame_SOURCES = \ flame.h \ libifs.c \ libifs.h \ - megawidget.c \ - megawidget.h \ rect.c \ rect.h diff --git a/plug-ins/flame/flame.c b/plug-ins/flame/flame.c index c5538bfe13..db3ca1c526 100644 --- a/plug-ins/flame/flame.c +++ b/plug-ins/flame/flame.c @@ -24,90 +24,97 @@ #include #include +#include +#include #ifdef HAVE_UNISTD_H #include #endif #include #include #include -#include "gtk/gtk.h" -#include "libgimp/gimp.h" -#include "libgimp/gimpui.h" + +#include +#include +#include + #include "libgimp/stdplugins-intl.h" -#include "megawidget.h" +#include "flame.h" -#include "libifs.h" -#include "rect.h" -#include "cmap.h" - -#define variation_same (-2) +#define VARIATION_SAME (-2) /* Declare local functions. */ static void query (void); -static void run (char *name, - int nparams, +static void run (gchar *name, + gint nparams, GParam *param, - int *nreturn_vals, + gint *nreturn_vals, GParam **return_vals); static void doit (GDrawable *drawable); static gint dialog (void); static void set_flame_preview (void); -static void load_callback (GtkWidget *widget, gpointer data); -static void save_callback (GtkWidget *widget, gpointer data); +static void load_callback (GtkWidget *widget, + gpointer data); +static void save_callback (GtkWidget *widget, + gpointer data); static void set_edit_preview (void); -static void menu_cb (GtkWidget *widget, gpointer data); -static void my_mw_update_cb (gpointer data); +static void menu_cb (GtkWidget *widget, + gpointer data); static void init_mutants (void); -char buffer[10000]; -GtkWidget *cmap_preview; -GtkWidget *flame_preview; -int preview_width, preview_height; -GtkWidget *dlg; -static GtkWidget *file_dlg = 0; -static int load_save; +#define BUFFER_SIZE 10000 -GtkWidget *edit_dlg = 0; +static gchar buffer[BUFFER_SIZE]; +static GtkWidget *cmap_preview; +static GtkWidget *flame_preview; +static gint preview_width, preview_height; +static GtkWidget *dlg; +static GtkWidget *load_button = NULL; +static GtkWidget *save_button = NULL; +static GtkWidget *file_dlg = NULL; +static gint load_save; -#define preview_size 150 -#define edit_preview_size 85 -#define nmutants 9 +static GtkWidget *edit_dlg = NULL; -control_point edit_cp; -control_point mutants[nmutants]; -GtkWidget *edit_previews[nmutants]; -double pick_speed = 0.2; +#define SCALE_WIDTH 150 +#define PREVIEW_SIZE 150 +#define EDIT_PREVIEW_SIZE 85 +#define NMUTANTS 9 + +static control_point edit_cp; +static control_point mutants[NMUTANTS]; +static GtkWidget *edit_previews[NMUTANTS]; +static gdouble pick_speed = 0.2; GPlugInInfo PLUG_IN_INFO = { - NULL, /* init_proc */ - NULL, /* quit_proc */ + NULL, /* init_proc */ + NULL, /* quit_proc */ query, /* query_proc */ - run, /* run_proc */ + run, /* run_proc */ }; -int run_flag = 0; +static gint run_flag = FALSE; -#define black_drawable (-2) -#define gradient_drawable (-3) -#define table_drawable (-4) +#define BLACK_DRAWABLE (-2) +#define GRADIENT_DRAWABLE (-3) +#define TABLE_DRAWABLE (-4) - -struct { - int randomize; /* superseded */ - int variation; - gint32 cmap_drawable; +struct +{ + gint randomize; /* superseded */ + gint variation; + gint32 cmap_drawable; control_point cp; } config; -frame_spec f = {0.0, &config.cp, 1, 0.0}; +static frame_spec f = { 0.0, &config.cp, 1, 0.0 }; -MAIN() +MAIN () static void @@ -115,60 +122,58 @@ query (void) { static GParamDef args[] = { - {PARAM_INT32, "run_mode", "Interactive, non-interactive"}, - {PARAM_IMAGE, "image", "Input image (unused)"}, - {PARAM_DRAWABLE, "drawable", "Input drawable"}, + { PARAM_INT32, "run_mode", "Interactive, non-interactive" }, + { PARAM_IMAGE, "image", "Input image (unused)" }, + { PARAM_DRAWABLE, "drawable", "Input drawable" }, }; - static GParamDef *return_vals = NULL; - static int nargs = sizeof(args) / sizeof(args[0]); - static int nreturn_vals = 0; + static gint nargs = sizeof(args) / sizeof(args[0]); - INIT_I18N(); - gimp_install_procedure("plug_in_flame", - "Creates cosmic recursive fractal flames", - "Creates cosmic recursive fractal flames", - "Scott Draves", - "Scott Draves", - "1997", - N_("/Filters/Render/Nature/Flame..."), - "RGB*", - PROC_PLUG_IN, - nargs, nreturn_vals, - args, return_vals); + gimp_install_procedure ("plug_in_flame", + "Creates cosmic recursive fractal flames", + "Creates cosmic recursive fractal flames", + "Scott Draves", + "Scott Draves", + "1997", + N_("/Filters/Render/Nature/Flame..."), + "RGB*", + PROC_PLUG_IN, + nargs, 0, + args, NULL); } static void maybe_init_cp (void) { - if (0 == config.cp.spatial_oversample) { - config.randomize = 0; - config.variation = variation_same; - config.cmap_drawable = gradient_drawable; - random_control_point(&config.cp, variation_random); - config.cp.center[0] = 0.0; - config.cp.center[1] = 0.0; - config.cp.pixels_per_unit = 100; - config.cp.spatial_oversample = 2; - config.cp.gamma = 2.0; - config.cp.contrast = 1.0; - config.cp.brightness = 1.0; - config.cp.spatial_filter_radius = 0.75; - config.cp.sample_density = 5.0; - config.cp.zoom = 0.0; - config.cp.nbatches = 1; - config.cp.white_level = 200; - config.cp.cmap_index = 72; - /* cheating */ - config.cp.width = 256; - config.cp.height = 256; - } + if (0 == config.cp.spatial_oversample) + { + config.randomize = 0; + config.variation = VARIATION_SAME; + config.cmap_drawable = GRADIENT_DRAWABLE; + random_control_point(&config.cp, variation_random); + config.cp.center[0] = 0.0; + config.cp.center[1] = 0.0; + config.cp.pixels_per_unit = 100; + config.cp.spatial_oversample = 2; + config.cp.gamma = 2.0; + config.cp.contrast = 1.0; + config.cp.brightness = 1.0; + config.cp.spatial_filter_radius = 0.75; + config.cp.sample_density = 5.0; + config.cp.zoom = 0.0; + config.cp.nbatches = 1; + config.cp.white_level = 200; + config.cp.cmap_index = 72; + /* cheating */ + config.cp.width = 256; + config.cp.height = 256; + } } static void -run (char *name, - int n_params, +run (gchar *name, + gint n_params, GParam *param, - int *nreturn_vals, + gint *nreturn_vals, GParam **return_vals) { static GParam values[1]; @@ -179,48 +184,53 @@ run (char *name, *nreturn_vals = 1; *return_vals = values; - SRAND_FUNC (time(NULL)); + SRAND_FUNC (time (NULL)); run_mode = param[0].data.d_int32; - if (run_mode == RUN_NONINTERACTIVE) { - status = STATUS_CALLING_ERROR; - } else { - INIT_I18N_UI(); - gimp_get_data("plug_in_flame", &config); - /* XXX i tried using the init routine, but it didn't work. */ - mw_update_cb = my_mw_update_cb; - maybe_init_cp(); - - drawable = gimp_drawable_get(param[2].data.d_drawable); - config.cp.width = drawable->width; - config.cp.height = drawable->height; - - if (run_mode == RUN_INTERACTIVE) { - if (!dialog()) { - status = STATUS_EXECUTION_ERROR; - } + if (run_mode == RUN_NONINTERACTIVE) + { + status = STATUS_CALLING_ERROR; } - } + else + { + INIT_I18N_UI(); + gimp_get_data ("plug_in_flame", &config); + maybe_init_cp (); + drawable = gimp_drawable_get (param[2].data.d_drawable); + config.cp.width = drawable->width; + config.cp.height = drawable->height; - if (status == STATUS_SUCCESS) { - - if (gimp_drawable_is_rgb(drawable->id)) { - gimp_progress_init( _("Drawing Flame...")); - gimp_tile_cache_ntiles(2 * (drawable->width / gimp_tile_width() + 1)); - - doit(drawable); - - if (run_mode != RUN_NONINTERACTIVE) - gimp_displays_flush(); - gimp_set_data("plug_in_flame", &config, sizeof(config)); - } else { - status = STATUS_EXECUTION_ERROR; + if (run_mode == RUN_INTERACTIVE) + { + if (!dialog ()) + { + status = STATUS_EXECUTION_ERROR; + } + } } - gimp_drawable_detach(drawable); - } + if (status == STATUS_SUCCESS) + { + if (gimp_drawable_is_rgb (drawable->id)) + { + gimp_progress_init (_("Drawing Flame...")); + gimp_tile_cache_ntiles (2 * (drawable->width / + gimp_tile_width () + 1)); + + doit (drawable); + + if (run_mode != RUN_NONINTERACTIVE) + gimp_displays_flush (); + gimp_set_data ("plug_in_flame", &config, sizeof (config)); + } + else + { + status = STATUS_EXECUTION_ERROR; + } + gimp_drawable_detach (drawable); + } values[0].type = PARAM_STATUS; values[0].data.d_status = status; @@ -229,125 +239,152 @@ run (char *name, static void drawable_to_cmap (control_point *cp) { - int i, j; - GPixelRgn pr; + gint i, j; + GPixelRgn pr; GDrawable *d; - guchar *p; - int indexed; + guchar *p; + gint indexed; - if (table_drawable >= config.cmap_drawable) { - i = table_drawable - config.cmap_drawable; - get_cmap(i, cp->cmap, 256); - } else if (black_drawable == config.cmap_drawable) { - for (i = 0; i < 256; i++) - for (j = 0; j < 3; j++) - cp->cmap[i][j] = 0.0; - } else if (gradient_drawable == config.cmap_drawable) { - gdouble *g = gimp_gradients_sample_uniform(256); - for (i = 0; i < 256; i++) - for (j = 0; j < 3; j++) - cp->cmap[i][j] = g[i*4 + j]; - g_free(g); - } else { - d = gimp_drawable_get(config.cmap_drawable); - indexed = gimp_drawable_is_indexed(config.cmap_drawable); - p = (guchar *) g_malloc(d->bpp); - gimp_pixel_rgn_init(&pr, d, 0, 0, - d->width, d->height, FALSE, FALSE); - for (i = 0; i < 256; i++) { - gimp_pixel_rgn_get_pixel(&pr, p, i % d->width, - (i / d->width) % d->height); - for (j = 0; j < 3; j++) - cp->cmap[i][j] = - (d->bpp >= 3) ? (p[j] / 255.0) : (p[0]/255.0); + if (TABLE_DRAWABLE >= config.cmap_drawable) + { + i = TABLE_DRAWABLE - config.cmap_drawable; + get_cmap (i, cp->cmap, 256); + } + else if (BLACK_DRAWABLE == config.cmap_drawable) + { + for (i = 0; i < 256; i++) + for (j = 0; j < 3; j++) + cp->cmap[i][j] = 0.0; + } + else if (GRADIENT_DRAWABLE == config.cmap_drawable) + { + gdouble *g = gimp_gradients_sample_uniform (256); + for (i = 0; i < 256; i++) + for (j = 0; j < 3; j++) + cp->cmap[i][j] = g[i*4 + j]; + g_free (g); + } + else + { + d = gimp_drawable_get (config.cmap_drawable); + indexed = gimp_drawable_is_indexed (config.cmap_drawable); + p = g_new (guchar, d->bpp); + gimp_pixel_rgn_init (&pr, d, 0, 0, + d->width, d->height, FALSE, FALSE); + for (i = 0; i < 256; i++) + { + gimp_pixel_rgn_get_pixel (&pr, p, i % d->width, + (i / d->width) % d->height); + for (j = 0; j < 3; j++) + cp->cmap[i][j] = + (d->bpp >= 3) ? (p[j] / 255.0) : (p[0]/255.0); + } + g_free (p); } - g_free(p); - } } static void -doit (GDrawable * drawable) +doit (GDrawable *drawable) { - gint width, height; + gint width, height; guchar *tmp; - gint bytes; + gint bytes; - width = drawable->width; + width = drawable->width; height = drawable->height; - bytes = drawable->bpp; + bytes = drawable->bpp; - if (3 != bytes && 4 != bytes) { - fprintf(stderr, "only works with three or four channels, not %d.\n", bytes); - return; - } + if (3 != bytes && 4 != bytes) + { + g_message (_("Flame works only on RGB drawables.")); + return; + } - tmp = (guchar *) g_malloc(width * height * 4); + tmp = g_new (guchar, width * height * 4); /* render */ config.cp.width = width; config.cp.height = height; if (config.randomize) - random_control_point(&config.cp, config.variation); - drawable_to_cmap(&config.cp); - render_rectangle(&f, tmp, width, field_both, 4, - gimp_progress_update); + random_control_point (&config.cp, config.variation); + drawable_to_cmap (&config.cp); + render_rectangle (&f, tmp, width, field_both, 4, + gimp_progress_update); /* update destination */ - if (4 == bytes) { - GPixelRgn pr; - gimp_pixel_rgn_init(&pr, drawable, 0, 0, width, height, - TRUE, TRUE); - gimp_pixel_rgn_set_rect(&pr, tmp, 0, 0, width, height); - } else if (3 == bytes) { - int i, j; - GPixelRgn src_pr, dst_pr; - guchar *sl = (guchar *) g_malloc(3 * width); - - gimp_pixel_rgn_init(&src_pr, drawable, - 0, 0, width, height, FALSE, FALSE); - gimp_pixel_rgn_init(&dst_pr, drawable, - 0, 0, width, height, TRUE, TRUE); - for (i = 0; i < height; i++) { - guchar *rr = tmp + 4 * i * width; - guchar *sld = sl; - gimp_pixel_rgn_get_rect(&src_pr, sl, 0, i, width, 1); - for (j = 0; j < width; j++) { - int k, alpha = rr[3]; - for (k = 0; k < 3; k++) { - int t = (rr[k] + ((sld[k] * (256-alpha)) >> 8)); - if (t > 255) t = 255; - sld[k] = t; - } - rr += 4; - sld += 3; - } - gimp_pixel_rgn_set_rect(&dst_pr, sl, 0, i, width, 1); + if (4 == bytes) + { + GPixelRgn pr; + gimp_pixel_rgn_init (&pr, drawable, 0, 0, width, height, + TRUE, TRUE); + gimp_pixel_rgn_set_rect (&pr, tmp, 0, 0, width, height); } - g_free(sl); - } else - printf("oops\n"); - g_free(tmp); - gimp_drawable_flush(drawable); - gimp_drawable_merge_shadow(drawable->id, TRUE); - gimp_drawable_update(drawable->id, 0, 0, width, height); + else if (3 == bytes) + { + gint i, j; + GPixelRgn src_pr, dst_pr; + guchar *sl; + + sl = g_new (guchar, 3 * width); + + gimp_pixel_rgn_init (&src_pr, drawable, + 0, 0, width, height, FALSE, FALSE); + gimp_pixel_rgn_init (&dst_pr, drawable, + 0, 0, width, height, TRUE, TRUE); + for (i = 0; i < height; i++) + { + guchar *rr = tmp + 4 * i * width; + guchar *sld = sl; + + gimp_pixel_rgn_get_rect (&src_pr, sl, 0, i, width, 1); + for (j = 0; j < width; j++) + { + gint k, alpha = rr[3]; + + for (k = 0; k < 3; k++) + { + gint t = (rr[k] + ((sld[k] * (256-alpha)) >> 8)); + + if (t > 255) t = 255; + sld[k] = t; + } + rr += 4; + sld += 3; + } + gimp_pixel_rgn_set_rect (&dst_pr, sl, 0, i, width, 1); + } + g_free (sl); + } + + g_free (tmp); + gimp_drawable_flush (drawable); + gimp_drawable_merge_shadow (drawable->id, TRUE); + gimp_drawable_update (drawable->id, 0, 0, width, height); } -static void -close_callback (GtkWidget *widget, - gpointer data) -{ - gtk_main_quit(); -} - static void ok_callback (GtkWidget *widget, gpointer data) { - run_flag = 1; - gtk_widget_destroy(GTK_WIDGET(data)); + run_flag = TRUE; + if (edit_dlg) - gtk_widget_destroy(edit_dlg); + gtk_widget_destroy (edit_dlg); + gtk_widget_destroy (GTK_WIDGET (data)); +} + +static void +file_cancel_callback (GtkWidget *widget, + gpointer data) +{ + gtk_widget_hide (widget); + + if (! GTK_WIDGET_SENSITIVE (load_button)) + gtk_widget_set_sensitive (load_button, TRUE); + + if (! GTK_WIDGET_SENSITIVE (save_button)) + gtk_widget_set_sensitive (save_button, TRUE); } static void @@ -355,198 +392,210 @@ file_ok_callback (GtkWidget *widget, gpointer data) { GtkFileSelection *fs; - char* filename; + gchar *filename; + struct stat filestat; + fs = GTK_FILE_SELECTION (data); filename = gtk_file_selection_get_filename (fs); - if (load_save) { - FILE *f = fopen(filename, "r"); - int i, c; - char *ss; - if (NULL == f) { - perror(filename); - return; - } - i = 0; - ss = buffer; - do { - c = getc(f); - if (EOF == c) - break; - ss[i++] = c; - } while (';' != c); - parse_control_point(&ss, &config.cp); - fclose(f); - /* i want to update the existing dialogue, but it's - too painful */ - gimp_set_data("plug_in_flame", &config, sizeof(config)); - /* gtk_widget_destroy(dlg); */ - set_flame_preview(); - set_edit_preview(); - } else { - FILE *f = fopen(filename, "w"); - if (NULL == f) { - perror(filename); - return; - } - print_control_point(f, &config.cp, 0); - fclose(f); - } - gtk_widget_hide (file_dlg); -} + if (load_save) + { + FILE *f; + gint i, c; + gchar *ss; -static void -file_cancel_callback (GtkWidget *widget, - gpointer data) -{ - gtk_widget_hide (file_dlg); + if (stat (filename, &filestat)) + { + g_message ("%s: %s", filename, g_strerror (errno)); + return; + } + + if (! S_ISREG (filestat.st_mode)) + { + g_message (_("%s: Is not a regular file"), filename); + return; + } + + f = fopen (filename, "r"); + + if (f == NULL) + { + g_message ("%s: %s", filename, g_strerror (errno)); + return; + } + + i = 0; + ss = buffer; + do + { + c = getc (f); + if (EOF == c) + break; + ss[i++] = c; + } + while (i < BUFFER_SIZE && ';' != c); + parse_control_point (&ss, &config.cp); + fclose (f); + /* i want to update the existing dialogue, but it's + too painful */ + gimp_set_data ("plug_in_flame", &config, sizeof (config)); + /* gtk_widget_destroy(dlg); */ + set_flame_preview (); + set_edit_preview (); + } + else + { + FILE *f = fopen (filename, "w"); + + if (NULL == f) + { + g_message ("%s: %s", filename, g_strerror (errno)); + return; + } + + print_control_point (f, &config.cp, 0); + fclose (f); + } + + file_cancel_callback (GTK_WIDGET (data), NULL); } static void make_file_dlg (void) { - file_dlg = gtk_file_selection_new ( _("Load/Save Flame")); - gtk_window_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE); - gtk_signal_connect(GTK_OBJECT (file_dlg), - "delete_event", - (GtkSignalFunc) gtk_widget_hide_on_delete, - NULL); + file_dlg = gtk_file_selection_new (NULL); gtk_quit_add_destroy (1, GTK_OBJECT (file_dlg)); - gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION (file_dlg)->cancel_button), - "clicked", (GtkSignalFunc) file_cancel_callback, file_dlg); - gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION (file_dlg)->ok_button), - "clicked", (GtkSignalFunc) file_ok_callback, file_dlg); + + gtk_window_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE); + gtk_signal_connect_object (GTK_OBJECT (file_dlg), "delete_event", + GTK_SIGNAL_FUNC (file_cancel_callback), + GTK_OBJECT (file_dlg)); + gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_dlg)->ok_button), + "clicked", + GTK_SIGNAL_FUNC (file_ok_callback), + file_dlg); + gtk_signal_connect_object + (GTK_OBJECT (GTK_FILE_SELECTION (file_dlg)->cancel_button), + "clicked", + GTK_SIGNAL_FUNC (file_cancel_callback), + GTK_OBJECT (file_dlg)); + + gimp_help_connect_help_accel (file_dlg, + gimp_plugin_help_func, "filters/flame.html"); } static void randomize_callback (GtkWidget *widget, - gpointer data) + gpointer data) { - random_control_point(&edit_cp, config.variation); - init_mutants(); - set_edit_preview(); + random_control_point (&edit_cp, config.variation); + init_mutants (); + set_edit_preview (); } -static void -edit_close_callback (GtkWidget *widget, - gpointer data) -{ - gtk_widget_hide(edit_dlg); -} - static void edit_ok_callback (GtkWidget *widget, - gpointer data) + gpointer data) { - gtk_widget_hide(edit_dlg); + gtk_widget_hide (edit_dlg); config.cp = edit_cp; - set_flame_preview(); + set_flame_preview (); } static void -edit_cancel_callback (GtkWidget *widget, - gpointer data) +init_mutants (void) { - gtk_widget_hide(edit_dlg); -} + gint i; -static void -init_mutants (void) -{ - int i; - for (i = 0; i < nmutants; i++) { - mutants[i] = edit_cp; - random_control_point(mutants + i, config.variation); - if (variation_same == config.variation) - copy_variation(mutants + i, &edit_cp); - } + for (i = 0; i < NMUTANTS; i++) + { + mutants[i] = edit_cp; + random_control_point (mutants + i, config.variation); + if (VARIATION_SAME == config.variation) + copy_variation (mutants + i, &edit_cp); + } } -static void -my_mw_update_cb (gpointer data) -{ - double *fd = (double *) data; - if (fd == &pick_speed) - set_edit_preview(); - else if (&config.cp.brightness == fd || - &config.cp.contrast == fd || - &config.cp.gamma == fd || - &config.cp.zoom == fd || - &config.cp.center[0] == fd || - &config.cp.center[1] == fd) - set_flame_preview(); -} - static void set_edit_preview (void) { - int y, i, j; - guchar *b; - control_point pcp; - static frame_spec pf = {0.0, 0, 1, 0.0}; - int nbytes = edit_preview_size * edit_preview_size * 3; + gint y, i, j; + guchar *b; + control_point pcp; + gint nbytes = EDIT_PREVIEW_SIZE * EDIT_PREVIEW_SIZE * 3; - if (NULL == edit_previews[0]) return; + static frame_spec pf = { 0.0, 0, 1, 0.0 }; - b = g_malloc(nbytes); - maybe_init_cp(); - drawable_to_cmap(&edit_cp); + if (NULL == edit_previews[0]) + return; + + b = g_new (guchar, nbytes); + maybe_init_cp (); + drawable_to_cmap (&edit_cp); for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) { - int mut = i*3 + j; - pf.cps = &pcp; - if (1 == i && 1 == j) { - pcp = edit_cp; - } else { - control_point ends[2]; - ends[0] = edit_cp; - ends[1] = mutants[mut]; - ends[0].time = 0.0; - ends[1].time = 1.0; - interpolate(ends, 2, pick_speed, &pcp); + for (j = 0; j < 3; j++) + { + gint mut = i*3 + j; + + pf.cps = &pcp; + if (1 == i && 1 == j) + { + pcp = edit_cp; + } + else + { + control_point ends[2]; + ends[0] = edit_cp; + ends[1] = mutants[mut]; + ends[0].time = 0.0; + ends[1].time = 1.0; + interpolate (ends, 2, pick_speed, &pcp); + } + pcp.pixels_per_unit = + (pcp.pixels_per_unit * EDIT_PREVIEW_SIZE) / pcp.width; + pcp.width = EDIT_PREVIEW_SIZE; + pcp.height = EDIT_PREVIEW_SIZE; + + pcp.sample_density = 1; + pcp.spatial_oversample = 1; + pcp.spatial_filter_radius = 0.5; + + drawable_to_cmap (&pcp); + + render_rectangle (&pf, b, EDIT_PREVIEW_SIZE, field_both, 3, NULL); + + for (y = 0; y < EDIT_PREVIEW_SIZE; y++) + gtk_preview_draw_row (GTK_PREVIEW (edit_previews[mut]), + b + y * EDIT_PREVIEW_SIZE * 3, + 0, y, EDIT_PREVIEW_SIZE); + gtk_widget_draw (edit_previews[mut], NULL); } - pcp.pixels_per_unit = - (pcp.pixels_per_unit * edit_preview_size) / pcp.width; - pcp.width = edit_preview_size; - pcp.height = edit_preview_size; - - pcp.sample_density = 1; - pcp.spatial_oversample = 1; - pcp.spatial_filter_radius = 0.5; - - drawable_to_cmap(&pcp); - - render_rectangle(&pf, b, edit_preview_size, field_both, 3, NULL); - - for (y = 0; y < edit_preview_size; y++) - gtk_preview_draw_row(GTK_PREVIEW (edit_previews[mut]), - b + y * edit_preview_size * 3, - 0, y, edit_preview_size); - gtk_widget_draw (edit_previews[mut], NULL); - } - g_free(b); + g_free (b); } static void preview_clicked (GtkWidget *widget, - gpointer data) + gpointer data) { - int mut = (int) data; - if (mut == 4) { - control_point t = edit_cp; - init_mutants(); - edit_cp = t; - } else { - control_point ends[2]; - ends[0] = edit_cp; - ends[1] = mutants[mut]; - ends[0].time = 0.0; - ends[1].time = 1.0; - interpolate(ends, 2, pick_speed, &edit_cp); - } - set_edit_preview(); -} + gint mut = (gint) data; + if (mut == 4) + { + control_point t = edit_cp; + init_mutants (); + edit_cp = t; + } + else + { + control_point ends[2]; + ends[0] = edit_cp; + ends[1] = mutants[mut]; + ends[0].time = 0.0; + ends[1].time = 1.0; + interpolate (ends, 2, pick_speed, &edit_cp); + } + set_edit_preview (); +} static void edit_callback (GtkWidget *widget, @@ -554,177 +603,162 @@ edit_callback (GtkWidget *widget, { edit_cp = config.cp; - if (edit_dlg == 0) { - GtkWidget *table; - GtkWidget *hbbox; - GtkWidget *button; - GtkWidget *box, *frame, *vbox; - int i, j; - - edit_dlg = gtk_dialog_new (); - - gtk_window_set_title(GTK_WINDOW(edit_dlg), _("Edit Flame")); - gtk_window_position(GTK_WINDOW(edit_dlg), GTK_WIN_POS_MOUSE); - gtk_signal_connect(GTK_OBJECT(edit_dlg), "destroy", - (GtkSignalFunc) edit_close_callback, NULL); - gtk_quit_add_destroy (1, GTK_OBJECT (edit_dlg)); - gtk_signal_connect(GTK_OBJECT(edit_dlg), "delete_event", - (GtkSignalFunc) gtk_widget_hide_on_delete, NULL); - - /* Action area */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (edit_dlg)->action_area), 2); - gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (edit_dlg)->action_area), FALSE); - hbbox = gtk_hbutton_box_new (); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4); - gtk_box_pack_end (GTK_BOX (GTK_DIALOG (edit_dlg)->action_area), hbbox, FALSE, FALSE, 0); - gtk_widget_show (hbbox); - - button = gtk_button_new_with_label ( _("OK")); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - (GtkSignalFunc) edit_ok_callback, 0); - gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0); - gtk_widget_grab_default (button); - gtk_widget_show (button); - - button = gtk_button_new_with_label ( _("Cancel")); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - (GtkSignalFunc) edit_cancel_callback, 0); - gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0); - gtk_widget_show (button); - - frame = gtk_frame_new( _("Directions")); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width(GTK_CONTAINER(frame), 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(edit_dlg)->vbox), - frame, TRUE, TRUE, 0); - gtk_widget_show(frame); - - table = gtk_table_new(3, 3, FALSE); - gtk_container_add(GTK_CONTAINER(frame), table); - gtk_container_border_width(GTK_CONTAINER(table), 4); - gtk_table_set_row_spacings(GTK_TABLE(table), 4); - gtk_table_set_col_spacings(GTK_TABLE(table), 4); - gtk_widget_show(table); - - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) { - int mut = i*3 + j; - edit_previews[mut] = gtk_preview_new (GTK_PREVIEW_COLOR); - gtk_preview_size (GTK_PREVIEW (edit_previews[mut]), - edit_preview_size, edit_preview_size); - button = gtk_button_new(); - gtk_container_add (GTK_CONTAINER(button), edit_previews[mut]); - gtk_signal_connect(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) preview_clicked, - (gpointer) mut); - gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1, - GTK_EXPAND, GTK_EXPAND, 0, 0); - gtk_widget_show (edit_previews[mut]); - gtk_widget_show (button); - } - - frame = gtk_frame_new( _("Controls")); - gtk_frame_set_shadow_type (GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width (GTK_CONTAINER(frame), 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(edit_dlg)->vbox), - frame, TRUE, TRUE, 0); - gtk_widget_show(frame); - - vbox = gtk_vbox_new (FALSE, 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show(vbox); - - table = gtk_table_new(2, 2, FALSE); - gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); - gtk_container_border_width(GTK_CONTAINER(table), 4); - gtk_table_set_col_spacings(GTK_TABLE(table), 8); - gtk_widget_show(table); - - mw_fscale_entry_new(table, _("Speed"), 0.05, 0.5, 0.01, 0.1, - 0.0, 0, 1, 1, 2, &pick_speed); - - box = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 4); - gtk_widget_show(box); - - button = gtk_button_new_with_label( _("Randomize")); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect_object(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) randomize_callback, - (gpointer) 0); - gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); - gtk_widget_show(button); - + if (edit_dlg == NULL) { - static struct { - char *name; - int value; - } menu_items[] = { - { N_("Same"), variation_same }, - { N_("Random"), variation_random }, - { N_("Linear"), 0}, - { N_("Sinusoidal"), 1}, - { N_("Spherical"), 2}, - { N_("Swirl"), 3}, - { N_("Horseshoe"), 4}, - { N_("Polar"), 5}, - { N_("Bent"), 6}, - { NULL, 0}, - }; + GtkWidget *main_vbox; + GtkWidget *frame; + GtkWidget *table; + GtkWidget *vbox; GtkWidget *hbox; - GtkWidget *option_menu; - GtkWidget *menu, *w; - int i; + GtkWidget *button; + GtkWidget *optionmenu; + GtkWidget *label; + GtkObject *adj; + gint i, j; + + edit_dlg = gimp_dialog_new (_("Edit Flame"), "flame", + gimp_plugin_help_func, "filters/flame.html", + GTK_WIN_POS_MOUSE, + FALSE, FALSE, FALSE, + + _("OK"), edit_ok_callback, + NULL, NULL, NULL, TRUE, FALSE, + _("Cancel"), gtk_widget_hide, + NULL, 1, NULL, FALSE, TRUE, + + NULL); + + gtk_quit_add_destroy (1, GTK_OBJECT (edit_dlg)); + + main_vbox = gtk_vbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_dlg)->vbox), main_vbox, + FALSE, FALSE, 0); + + frame = gtk_frame_new (_("Directions")); + gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + table = gtk_table_new (3, 3, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 4); + gtk_table_set_row_spacings (GTK_TABLE (table), 4); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_container_add (GTK_CONTAINER (frame), table); + gtk_widget_show (table); + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + { + gint mut = i * 3 + j; + + edit_previews[mut] = gtk_preview_new (GTK_PREVIEW_COLOR); + gtk_preview_size (GTK_PREVIEW (edit_previews[mut]), + EDIT_PREVIEW_SIZE, EDIT_PREVIEW_SIZE); + button = gtk_button_new (); + gtk_container_add (GTK_CONTAINER(button), edit_previews[mut]); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (preview_clicked), + (gpointer) mut); + gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1, + GTK_EXPAND, GTK_EXPAND, 0, 0); + gtk_widget_show (edit_previews[mut]); + gtk_widget_show (button); + } + + frame = gtk_frame_new( _("Controls")); + gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + vbox = gtk_vbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); + gtk_container_add (GTK_CONTAINER (frame), vbox); + gtk_widget_show (vbox); + + table = gtk_table_new (1, 3, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); + gtk_widget_show(table); + + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, + _("Speed:"), SCALE_WIDTH, 0, + pick_speed, + 0.05, 0.5, 0.01, 0.1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &pick_speed); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_edit_preview), + NULL); hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_end (GTK_BOX(box), hbox, FALSE, FALSE, 4); - gtk_widget_show(hbox); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); - w = gtk_label_new( _("Variation:")); - gtk_misc_set_alignment(GTK_MISC(w), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), w, FALSE, FALSE, 0); - gtk_widget_show(w); + button = gtk_button_new_with_label( _("Randomize")); + gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (randomize_callback), + NULL); + gtk_widget_show (button); - option_menu = gtk_option_menu_new (); - gtk_box_pack_start(GTK_BOX(hbox), option_menu, FALSE, FALSE, 0); - i = 0; - menu = gtk_menu_new (); - while (menu_items[i].name) { - GtkWidget *menu_item; - menu_item = gtk_menu_item_new_with_label( gettext(menu_items[i].name)); - gtk_container_add (GTK_CONTAINER (menu), menu_item); - gtk_signal_connect (GTK_OBJECT (menu_item), "activate", - (GtkSignalFunc) menu_cb, - (gpointer) menu_items[i].value); - gtk_widget_show (menu_item); - i++; - } - gtk_menu_set_active (GTK_MENU (menu), config.variation + 2); - gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); - gtk_widget_show (option_menu); + optionmenu = + gimp_option_menu_new2 (FALSE, menu_cb, + &config.variation, + (gpointer) VARIATION_SAME, + + _("Same"), (gpointer) VARIATION_SAME, NULL, + _("Random"), (gpointer) variation_random, NULL, + _("Linear"), (gpointer) 0, NULL, + _("Sinusoidal"), (gpointer) 1, NULL, + _("Spherical"), (gpointer) 2, NULL, + _("Swirl"), (gpointer) 3, NULL, + _("Horseshoe"), (gpointer) 4, NULL, + _("Polar"), (gpointer) 5, NULL, + _("Bent"), (gpointer) 6, NULL, + + NULL); + gtk_box_pack_end (GTK_BOX (hbox), optionmenu, FALSE, FALSE, 0); + gtk_widget_show (optionmenu); + + label = gtk_label_new (_("Variation:")); + gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + gtk_widget_show (main_vbox); + + init_mutants (); } - init_mutants(); - } - set_edit_preview(); - if (!GTK_WIDGET_VISIBLE(edit_dlg)) - gtk_widget_show(edit_dlg); + set_edit_preview (); + + if (!GTK_WIDGET_VISIBLE (edit_dlg)) + gtk_widget_show (edit_dlg); + else + gdk_window_raise (edit_dlg->window); } static void load_callback (GtkWidget *widget, gpointer data) { - if (!file_dlg) { - make_file_dlg(); - } else { - if (GTK_WIDGET_VISIBLE(file_dlg)) - return; - } - gtk_window_set_title(GTK_WINDOW (file_dlg), _("Load Flame")); + if (!file_dlg) + { + make_file_dlg (); + } + else + { + if (GTK_WIDGET_VISIBLE (file_dlg)) + { + gdk_window_raise (file_dlg->window); + return; + } + } + gtk_window_set_title (GTK_WINDOW (file_dlg), _("Load Flame")); load_save = 1; + gtk_widget_set_sensitive (save_button, FALSE); gtk_widget_show (file_dlg); } @@ -732,43 +766,52 @@ static void save_callback (GtkWidget *widget, gpointer data) { - if (!file_dlg) { - make_file_dlg(); - } else { - if (GTK_WIDGET_VISIBLE(file_dlg)) - return; - } - gtk_window_set_title(GTK_WINDOW (file_dlg), _("Save Flame")); + if (!file_dlg) + { + make_file_dlg (); + } + else + { + if (GTK_WIDGET_VISIBLE (file_dlg)) + { + gdk_window_raise (file_dlg->window); + return; + } + } + gtk_window_set_title (GTK_WINDOW (file_dlg), _("Save Flame")); load_save = 0; + gtk_widget_set_sensitive (load_button, FALSE); gtk_widget_show (file_dlg); } static void menu_cb (GtkWidget *widget, - gpointer data) + gpointer data) { - config.variation = (int) data; - if (variation_same != config.variation) - random_control_point(&edit_cp, config.variation); - init_mutants(); - set_edit_preview(); + gimp_menu_item_update (widget, data); + + if (VARIATION_SAME != config.variation) + random_control_point (&edit_cp, config.variation); + init_mutants (); + set_edit_preview (); } static void set_flame_preview (void) { - int y; + gint y; guchar *b; control_point pcp; + static frame_spec pf = {0.0, 0, 1, 0.0}; if (NULL == flame_preview) return; - b = g_malloc(preview_width * preview_height * 3); + b = g_new (guchar, preview_width * preview_height * 3); - maybe_init_cp(); - drawable_to_cmap(&config.cp); + maybe_init_cp (); + drawable_to_cmap (&config.cp); pf.cps = &pcp; pcp = config.cp; @@ -779,12 +822,12 @@ set_flame_preview (void) pcp.sample_density = 1; pcp.spatial_oversample = 1; pcp.spatial_filter_radius = 0.1; - render_rectangle(&pf, b, preview_width, field_both, 3, NULL); + render_rectangle (&pf, b, preview_width, field_both, 3, NULL); - for (y = 0; y < preview_size; y++) - gtk_preview_draw_row(GTK_PREVIEW (flame_preview), - b+y*preview_width*3, 0, y, preview_width); - g_free(b); + for (y = 0; y < PREVIEW_SIZE; y++) + gtk_preview_draw_row (GTK_PREVIEW (flame_preview), + b+y*preview_width*3, 0, y, preview_width); + g_free (b); gtk_widget_draw (flame_preview, NULL); } @@ -792,21 +835,24 @@ set_flame_preview (void) static void set_cmap_preview (void) { - int i, x, y; + gint i, x, y; guchar b[96]; if (NULL == cmap_preview) return; - drawable_to_cmap(&config.cp); + drawable_to_cmap (&config.cp); - for (y = 0; y < 32; y+=4) { - for (x = 0; x < 32; x++) { - int j; - i = x + (y/4)*32; - for (j = 0; j < 3; j++) - b[x*3+j] = config.cp.cmap[i][j]*255.0; - } + for (y = 0; y < 32; y += 4) + { + for (x = 0; x < 32; x++) + { + gint j; + + i = x + (y/4) * 32; + for (j = 0; j < 3; j++) + b[x*3+j] = config.cp.cmap[i][j]*255.0; + } gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y, 32); gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y+1, 32); gtk_preview_draw_row (GTK_PREVIEW (cmap_preview), b, 0, y+2, 32); @@ -820,10 +866,10 @@ static void gradient_cb (GtkWidget *widget, gpointer data) { - config.cmap_drawable = (int)data; + config.cmap_drawable = (gint) data; set_cmap_preview(); set_flame_preview(); - /* set_edit_preview(); */ + /* set_edit_preview(); */ } static void @@ -836,7 +882,6 @@ cmap_callback (gint32 id, /* set_edit_preview(); */ } - static gint cmap_constrain (gint32 image_id, gint32 drawable_id, @@ -849,160 +894,270 @@ cmap_constrain (gint32 image_id, static gint dialog (void) { - GtkWidget *hbbox; + GtkWidget *main_vbox; + GtkWidget *frame; + GtkWidget *abox; + GtkWidget *pframe; GtkWidget *button; GtkWidget *table; GtkWidget *box; - GtkWidget *w; - GtkWidget *frame; - gchar **argv; - gint argc; - int row; - guchar *color_cube; + GtkObject *adj; + gchar **argv; + gint argc; + guchar *color_cube; - argc = 1; - argv = g_new(gchar *, 1); - argv[0] = g_strdup("flame"); + argc = 1; + argv = g_new (gchar *, 1); + argv[0] = g_strdup ("flame"); - gtk_init(&argc, &argv); + gtk_init (&argc, &argv); gtk_rc_parse (gimp_gtkrc ()); - gtk_preview_set_gamma (gimp_gamma ()); gtk_preview_set_install_cmap (gimp_install_cmap ()); color_cube = gimp_color_cube (); gtk_preview_set_color_cube (color_cube[0], color_cube[1], color_cube[2], color_cube[3]); - gtk_widget_set_default_visual (gtk_preview_get_visual ()); gtk_widget_set_default_colormap (gtk_preview_get_cmap ()); - dlg = gtk_dialog_new(); - gtk_window_set_title(GTK_WINDOW(dlg), _("Flame")); - gtk_window_position(GTK_WINDOW(dlg), GTK_WIN_POS_MOUSE); - gtk_signal_connect(GTK_OBJECT(dlg), "destroy", - (GtkSignalFunc) close_callback, NULL); + dlg = gimp_dialog_new (_("Flame"), "flame", + gimp_plugin_help_func, "filters/flame.html", + GTK_WIN_POS_MOUSE, + FALSE, TRUE, FALSE, - /* Action area */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dlg)->action_area), 2); - gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dlg)->action_area), FALSE); - hbbox = gtk_hbutton_box_new (); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbbox), 4); - gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dlg)->action_area), hbbox, FALSE, FALSE, 0); - gtk_widget_show (hbbox); - - button = gtk_button_new_with_label ( _("OK")); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - (GtkSignalFunc) ok_callback, - dlg); - gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0); - gtk_widget_grab_default (button); - gtk_widget_show (button); + _("OK"), ok_callback, + NULL, NULL, NULL, TRUE, FALSE, + _("Cancel"), gtk_widget_destroy, + NULL, 1, NULL, FALSE, TRUE, - button = gtk_button_new_with_label ( _("Cancel")); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_signal_connect_object (GTK_OBJECT (button), "clicked", - (GtkSignalFunc) gtk_widget_destroy, - GTK_OBJECT (dlg)); - gtk_box_pack_start (GTK_BOX (hbbox), button, FALSE, FALSE, 0); - gtk_widget_show (button); + NULL); + gtk_signal_connect (GTK_OBJECT (dlg), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), + NULL); - frame = gtk_frame_new( _("Rendering")); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width(GTK_CONTAINER(frame), 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, TRUE, TRUE, 0); - gtk_widget_show(frame); + main_vbox = gtk_vbox_new (FALSE, 4); + gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), main_vbox, + FALSE, FALSE, 0); + gtk_widget_show (main_vbox); + + box = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (main_vbox), box, FALSE, FALSE, 0); + gtk_widget_show (box); + + frame = gtk_frame_new (_("Preview")); + gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 0); + gtk_widget_show (frame); + + abox = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_set_border_width (GTK_CONTAINER (abox), 4); + gtk_container_add (GTK_CONTAINER (frame), abox); + gtk_widget_show (abox); + + pframe = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (pframe), GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (abox), pframe); + gtk_widget_show (pframe); + + frame = gtk_frame_new (_("Flame")); + gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); + + { + GtkWidget *vbbox; + + box = gtk_vbox_new (FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (box), 4); + gtk_container_add (GTK_CONTAINER (frame), box); + gtk_widget_show (box); + + vbbox= gtk_vbutton_box_new (); + gtk_box_set_homogeneous (GTK_BOX (vbbox), FALSE); + gtk_button_box_set_spacing (GTK_BUTTON_BOX (vbbox), 4); + gtk_box_pack_start (GTK_BOX (box), vbbox, FALSE, FALSE, 0); + gtk_widget_show (vbbox); + + button = gtk_button_new_with_label (_("Edit Flame")); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (edit_callback), + NULL); + gtk_box_pack_start (GTK_BOX (vbbox), button, FALSE, FALSE, 0); + gtk_widget_show (button); + + load_button = button = gtk_button_new_with_label (_("Load Flame")); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (load_callback), + NULL); + gtk_box_pack_start (GTK_BOX (vbbox), button, FALSE, FALSE, 0); + gtk_widget_show (button); + + save_button = button = gtk_button_new_with_label (_("Save Flame")); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (save_callback), + NULL); + gtk_box_pack_start (GTK_BOX (vbbox), button, FALSE, FALSE, 0); + gtk_widget_show (button); + } + + frame = gtk_frame_new (_("Rendering")); + gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); box = gtk_vbox_new (FALSE, 4); - gtk_container_add(GTK_CONTAINER(frame), box); - gtk_widget_show(box); + gtk_container_set_border_width (GTK_CONTAINER (box), 4); + gtk_container_add (GTK_CONTAINER (frame), box); + gtk_widget_show (box); - table = gtk_table_new(7, 2, FALSE); - gtk_box_pack_start(GTK_BOX(box), table, FALSE, FALSE, 0); + table = gtk_table_new (6, 3, FALSE); + gtk_table_set_row_spacings (GTK_TABLE (table), 2); + gtk_table_set_row_spacing (GTK_TABLE (table), 2, 6); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_box_pack_start (GTK_BOX (box), table, FALSE, FALSE, 0); + gtk_widget_show (table); - gtk_container_border_width(GTK_CONTAINER(table), 4); - gtk_widget_show(table); + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, + _("Brightness:"), SCALE_WIDTH, 0, + config.cp.brightness, + 0, 5, 0.1, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.brightness); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); - gtk_table_set_row_spacings(GTK_TABLE(table), 8); - gtk_table_set_col_spacings(GTK_TABLE(table), 8); + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, + _("Contrast:"), SCALE_WIDTH, 0, + config.cp.contrast, + 0, 5, 0.1, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.contrast); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); - row = 1; + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 2, + _("Gamma:"), SCALE_WIDTH, 0, + config.cp.gamma, + 1, 5, 0.1, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.gamma); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); - /* this zoom - gamma should redraw flame preview */ - mw_fscale_entry_new(table, _("Brightness"), 0, 5, 1, 1, 0, - 0, 1, row, row+1, &config.cp.brightness); row++; - mw_fscale_entry_new(table, _("Contrast"), 0, 5, 1, 1, 0, - 0, 1, row, row+1, &config.cp.contrast); row++; - mw_fscale_entry_new(table, _("Gamma"), 1, 5, 1, 1, 0, - 0, 1, row, row+1, &config.cp.gamma); row++; - mw_fscale_entry_new(table, _("Sample Density"), 0.1, 20, 1, 5, 0, - 0, 1, row, row+1, &config.cp.sample_density); row++; - mw_iscale_entry_new(table, _("Spatial Oversample"), 1, 4, 1, 1, 0, - 0, 1, row, row+1, &config.cp.spatial_oversample); row++; - mw_fscale_entry_new(table, _("Spatial Filter Radius"), 0, 4, 1, 1, 0, - 0, 1, row, row+1, &config.cp.spatial_filter_radius); row++; + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 3, + _("Sample Density:"), SCALE_WIDTH, 0, + config.cp.sample_density, + 0.1, 20, 1, 5, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.sample_density); -{ + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 4, + _("Spatial Oversample:"), SCALE_WIDTH, 0, + config.cp.spatial_oversample, + 0, 1, 0.01, 0.1, 0, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_int_adjustment_update), + &config.cp.spatial_oversample); + + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 5, + _("Spatial Filter Radius:"), SCALE_WIDTH, 0, + config.cp.spatial_filter_radius, + 0, 4, 0.2, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.spatial_filter_radius); + + { + GtkWidget *sep; GtkWidget *menu; GtkWidget *hbox; + GtkWidget *label; GtkWidget *menuitem; - GtkWidget *option_menu = gtk_option_menu_new (); + GtkWidget *option_menu; gint32 save_drawable = config.cmap_drawable; + sep = gtk_hseparator_new (); + gtk_box_pack_start (GTK_BOX (box), sep, FALSE, FALSE, 0); + gtk_widget_show (sep); + hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 10); - gtk_widget_show(hbox); + gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); - w = gtk_label_new( _("Colormap")); - gtk_misc_set_alignment(GTK_MISC(w), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), w, TRUE, TRUE, 4); - gtk_widget_show(w); + label = gtk_label_new (_("Colormap:")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); - gtk_box_pack_start(GTK_BOX(hbox), option_menu, TRUE, TRUE, 4); - menu = gimp_drawable_menu_new(cmap_constrain, cmap_callback, - 0, config.cmap_drawable); + option_menu = gtk_option_menu_new (); + gtk_box_pack_start (GTK_BOX (hbox), option_menu, FALSE, FALSE, 0); + menu = gimp_drawable_menu_new (cmap_constrain, cmap_callback, + 0, config.cmap_drawable); config.cmap_drawable = save_drawable; #if 0 - menuitem = gtk_menu_item_new_with_label( _("Black")); - gtk_signal_connect(GTK_OBJECT (menuitem), "activate", - (GtkSignalFunc) gradient_cb, - (gpointer) black_drawable); - gtk_menu_prepend(GTK_MENU (menu), menuitem); - if (black_drawable == save_drawable) - gtk_menu_set_active(GTK_MENU(menu), 0); - gtk_widget_show(menuitem); + menuitem = gtk_menu_item_new_with_label (_("Black")); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gradient_cb), + (gpointer) BLACK_DRAWABLE); + gtk_menu_prepend (GTK_MENU (menu), menuitem); + if (BLACK_DRAWABLE == save_drawable) + gtk_menu_set_active (GTK_MENU (menu), 0); + gtk_widget_show (menuitem); #endif { - static char *names[] = - {"sunny harvest", "rose", "calcoast09", - "klee insula-dulcamara", - "ernst anti-pope", "gris josette"}; - static int good[] = {10, 20, 68, 79, 70, 75}; - int i, n = (sizeof good) / (sizeof *good); - for (i = 0; i < n; i++) { - int d = table_drawable - good[i]; - menuitem = gtk_menu_item_new_with_label(names[i]); - gtk_signal_connect(GTK_OBJECT (menuitem), "activate", - (GtkSignalFunc) gradient_cb, - (gpointer) d); - gtk_menu_prepend(GTK_MENU (menu), menuitem); - if (d == save_drawable) - gtk_menu_set_active(GTK_MENU(menu), 0); - gtk_widget_show(menuitem); - } + static gchar *names[] = + { + "sunny harvest", + "rose", + "calcoast09", + "klee insula-dulcamara", + "ernst anti-pope", + "gris josette" + }; + static gint good[] = { 10, 20, 68, 79, 70, 75 }; + gint i, n = (sizeof good) / (sizeof good[0]); + + for (i = 0; i < n; i++) + { + gint d = TABLE_DRAWABLE - good[i]; + + menuitem = gtk_menu_item_new_with_label (names[i]); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gradient_cb), + (gpointer) d); + gtk_menu_prepend (GTK_MENU (menu), menuitem); + if (d == save_drawable) + gtk_menu_set_active (GTK_MENU (menu), 0); + gtk_widget_show (menuitem); + } } - - menuitem = gtk_menu_item_new_with_label( _("Custom Gradient")); - gtk_signal_connect(GTK_OBJECT (menuitem), "activate", - (GtkSignalFunc) gradient_cb, - (gpointer) gradient_drawable); - gtk_menu_prepend(GTK_MENU (menu), menuitem); - if (gradient_drawable == save_drawable) - gtk_menu_set_active(GTK_MENU(menu), 0); - gtk_widget_show(menuitem); + menuitem = gtk_menu_item_new_with_label (_("Custom Gradient")); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gradient_cb), + (gpointer) GRADIENT_DRAWABLE); + gtk_menu_prepend (GTK_MENU (menu), menuitem); + if (GRADIENT_DRAWABLE == save_drawable) + gtk_menu_set_active (GTK_MENU (menu), 0); + gtk_widget_show (menuitem); gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); gtk_widget_show (option_menu); @@ -1010,104 +1165,85 @@ dialog (void) cmap_preview = gtk_preview_new (GTK_PREVIEW_COLOR); gtk_preview_size (GTK_PREVIEW (cmap_preview), 32, 32); - gtk_box_pack_start(GTK_BOX(hbox), cmap_preview, TRUE, TRUE, 4); + gtk_box_pack_end (GTK_BOX (hbox), cmap_preview, FALSE, FALSE, 0); gtk_widget_show (cmap_preview); - set_cmap_preview(); + set_cmap_preview (); } - frame = gtk_frame_new( _("Camera")); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width(GTK_CONTAINER(frame), 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, TRUE, TRUE, 0); - gtk_widget_show(frame); + frame = gtk_frame_new (_("Camera")); + gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0); + gtk_widget_show (frame); - table = gtk_table_new(4, 2, FALSE); - gtk_container_border_width(GTK_CONTAINER(table), 4); - gtk_container_add(GTK_CONTAINER(frame), table); - gtk_widget_show(table); + table = gtk_table_new (3, 3, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 4); + gtk_table_set_row_spacings (GTK_TABLE (table), 2); + gtk_table_set_col_spacings (GTK_TABLE (table), 4); + gtk_container_add (GTK_CONTAINER (frame), table); + gtk_widget_show (table); - gtk_table_set_row_spacings(GTK_TABLE(table), 8); - gtk_table_set_col_spacings(GTK_TABLE(table), 8); + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0, + _("Zoom:"), SCALE_WIDTH, 0, + config.cp.zoom, + -4, 4, 0.5, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.zoom); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); - row = 1; - - mw_fscale_entry_new(table, _("Zoom"), -4, 4, 1, 1, 0, - 0, 1, row, row+1, &config.cp.zoom); row++; - mw_fscale_entry_new(table, _("X"), -2, 2, 0.5, 0.5, 0, - 0, 1, row, row+1, &config.cp.center[0]); row++; - mw_fscale_entry_new(table, _("Y"), -2, 2, 0.5, 0.5, 0, - 0, 1, row, row+1, &config.cp.center[1]); row++; - + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1, + _("X:"), SCALE_WIDTH, 0, + config.cp.center[0], + -2, 2, 0.5, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.center[0]); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); + + adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 2, + _("X:"), SCALE_WIDTH, 0, + config.cp.center[1], + -2, 2, 0.5, 1, 2, + TRUE, 0, 0, + NULL, NULL); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (gimp_double_adjustment_update), + &config.cp.center[1]); + gtk_signal_connect (GTK_OBJECT (adj), "value_changed", + GTK_SIGNAL_FUNC (set_flame_preview), + NULL); flame_preview = gtk_preview_new (GTK_PREVIEW_COLOR); { - double aspect = config.cp.width / (double) config.cp.height; - if (aspect > 1.0) { - preview_width = preview_size; - preview_height = preview_size/aspect; - } else { - preview_width = preview_size*aspect; - preview_height = preview_size; - } + gdouble aspect = config.cp.width / (double) config.cp.height; + + if (aspect > 1.0) + { + preview_width = PREVIEW_SIZE; + preview_height = PREVIEW_SIZE / aspect; + } + else + { + preview_width = PREVIEW_SIZE * aspect; + preview_height = PREVIEW_SIZE; + } } gtk_preview_size (GTK_PREVIEW (flame_preview), preview_width, preview_height); - - box = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), - box, FALSE, FALSE, 0); - gtk_widget_show(box); - - frame = gtk_frame_new( _("Preview")); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width(GTK_CONTAINER(frame), 4); - gtk_container_add(GTK_CONTAINER(frame), flame_preview); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, FALSE, 0); - gtk_widget_show(frame); - + gtk_container_add (GTK_CONTAINER (pframe), flame_preview); gtk_widget_show (flame_preview); - set_flame_preview(); + set_flame_preview (); - { - GtkWidget *vbox; - GtkWidget *vbbox; + gtk_widget_show (dlg); - vbox = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, FALSE, 4); - vbbox= gtk_vbutton_box_new (); - gtk_box_set_homogeneous (GTK_BOX (vbbox), FALSE); - gtk_button_box_set_spacing (GTK_BUTTON_BOX (vbbox), 4); - gtk_box_pack_start (GTK_BOX (vbox), vbbox, FALSE, FALSE, 0); - gtk_widget_show (vbbox); - gtk_widget_show (vbox); - - button = gtk_button_new_with_label( _("Edit Flame")); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect_object(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) edit_callback, - (gpointer) 0); - gtk_box_pack_start(GTK_BOX(vbbox), button, FALSE, FALSE, 0); - gtk_widget_show(button); - - button = gtk_button_new_with_label( _("Load Flame")); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect_object(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) load_callback, - (gpointer) 0); - gtk_box_pack_start(GTK_BOX(vbbox), button, FALSE, FALSE, 0); - gtk_widget_show(button); - - button = gtk_button_new_with_label( _("Save Flame")); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect_object(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) save_callback, - (gpointer) 0); - gtk_box_pack_start(GTK_BOX(vbbox), button, FALSE, FALSE, 0); - gtk_widget_show(button); - } - - gtk_widget_show(dlg); - gtk_main(); - gdk_flush(); + gtk_main (); + gdk_flush (); return run_flag; } diff --git a/plug-ins/flame/megawidget.c b/plug-ins/flame/megawidget.c deleted file mode 100644 index 0dfb01e6b5..0000000000 --- a/plug-ins/flame/megawidget.c +++ /dev/null @@ -1,424 +0,0 @@ -/************************************************** - * file: megawidget/megawidget.c - * - * Copyright (c) 1997 Eric L. Hernes (erich@rrnet.com) - * All rights reserved. - * - * !! - * !! This file has been hacked to work with the flame plug-in - * !! - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software withough specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Id$ */ - -/* Functions added by Xavier Bouchoux (Xavier.Bouchoux@ensimag.imag.fr) - * mw_value_radio_group_new() - * --> it modifies a user variable to a value associated with the current - * button - * mw_ientry_button_new() - * mw_fentry_button_new() - * ---> Guess... - * mw_color_select_button_create() - * --> Creates a colored button, wich creates a colorselection window - * (just like ifs compose) - */ - - -#include -#include -#include -#include - -#include "megawidget.h" - - -static void mw_scale_entry_new(GtkWidget *table, gchar *name, - gfloat defval, gfloat lorange, - gfloat hirange, gfloat st_inc, - gfloat pg_inc, gfloat pgsiz, - gpointer variablep, gchar *fmtvar, - gint left_a, gint right_a, gint top_a, - gint bottom_a, GtkCallback scale_cb, - GtkCallback entry_cb); -static void ui_ok_callback(GtkWidget *widget, gpointer data); -static void ui_close_callback(GtkWidget *widget, gpointer data); -static void ui_fscale_callback(GtkAdjustment *adj, gpointer data); -static void ui_fentry_callback(GtkWidget *widget, gpointer data); -static void ui_iscale_callback(GtkAdjustment *adj, gpointer data); -static void ui_ientry_callback(GtkWidget *widget, gpointer data); - - -mw_callback mw_update_cb; - -#ifndef NO_PREVIEW -static mw_preview_t *mw_do_preview = NULL; -static gint do_preview = 1; -#endif - -GtkWidget * -mw_app_new(gchar *resname, gchar *appname, gint *runpp){ - gchar **argv; - gint argc; - GtkWidget *dlg; - GtkWidget *button; - - argc = 1; - argv = g_new(gchar *, 1); - *runpp = 0; - - argv[0] = g_strdup(resname); - gtk_init(&argc, &argv); - - dlg = gtk_dialog_new(); - gtk_object_set_data(GTK_OBJECT(dlg), "runp", runpp); - - gtk_window_set_title(GTK_WINDOW(dlg), appname); - gtk_window_position(GTK_WINDOW(dlg), GTK_WIN_POS_MOUSE); - gtk_signal_connect(GTK_OBJECT(dlg), "destroy", - (GtkSignalFunc) ui_close_callback, - NULL); - - button = gtk_button_new_with_label("OK"); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect(GTK_OBJECT (button), "clicked", - (GtkSignalFunc) ui_ok_callback, - dlg); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, - TRUE, TRUE, 0); - gtk_widget_grab_default(button); - gtk_widget_show(button); - - button = gtk_button_new_with_label("Cancel"); - GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); - gtk_signal_connect_object(GTK_OBJECT(button), "clicked", - (GtkSignalFunc) gtk_widget_destroy, - GTK_OBJECT(dlg)); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), button, - TRUE, TRUE, 0); - gtk_widget_show(button); - - return dlg; -} - -void -mw_fscale_entry_new(GtkWidget *table, gchar *name, - gfloat lorange, gfloat hirange, - gfloat st_inc, gfloat pg_inc, gfloat pgsiz, - gint left_a, gint right_a, gint top_a, gint bottom_a, - gdouble *var) { - gchar buffer[40]; - - sprintf(buffer, "%0.3f", *var); - mw_scale_entry_new(table, name, *var, lorange, hirange, - st_inc, pg_inc, pgsiz, var, buffer, - left_a, right_a, top_a, bottom_a, - (GtkCallback)ui_fscale_callback, - (GtkCallback)ui_fentry_callback); -} - -void -mw_iscale_entry_new(GtkWidget *table, gchar *name, - gint lorange, gint hirange, - gint st_inc, gint pg_inc, gint pgsiz, - gint left_a, gint right_a, gint top_a, gint bottom_a, - gint *varp) { - gchar buffer[40]; - - sprintf(buffer, "%d", *varp); - - mw_scale_entry_new(table, name, (gfloat)*varp, (gfloat)lorange, - (gfloat)hirange, (gfloat)st_inc, (gfloat)pg_inc, - (gfloat)pgsiz, varp, buffer, - left_a, right_a, top_a, bottom_a, - (GtkCallback)ui_iscale_callback, - (GtkCallback)ui_ientry_callback); -} - -#ifndef NO_PREVIEW -struct mwPreview * -mw_preview_build_virgin(GDrawable *drw) { - struct mwPreview *mwp; - - mwp = (struct mwPreview *)malloc(sizeof(struct mwPreview)); - if (drw->width > drw->height) { - mwp->scale = (gdouble)drw->width/(gdouble)PREVIEW_SIZE; - mwp->width = PREVIEW_SIZE; - mwp->height = (drw->height)/(mwp->scale); - } else { - mwp->scale = (gdouble)drw->height/(gdouble)PREVIEW_SIZE; - mwp->height = PREVIEW_SIZE; - mwp->width = (drw->width)/(mwp->scale); - } - - mwp->bpp = 3; - mwp->bits = NULL; - return(mwp); -} - -struct mwPreview * -mw_preview_build(GDrawable *drw) { - struct mwPreview *mwp; - gint x, y, b; - guchar *bc, *drwBits; - GPixelRgn pr; - - mwp= mw_preview_build_virgin(drw); - - gimp_pixel_rgn_init(&pr, drw, 0, 0, drw->width, drw->height, FALSE, FALSE); - drwBits = (guchar *)g_malloc(drw->width * drw->bpp); - - mwp->bpp = 3; - bc = mwp->bits = (guchar *)malloc(mwp->width*mwp->height*mwp->bpp); - for(y=0;yheight;y++) { - gimp_pixel_rgn_get_row(&pr, drwBits, 0, (int)(y*mwp->scale), drw->width); - for(x=0;xwidth;x++) { - for(b=0;bbpp;b++) - *bc++=*(drwBits+((gint)(x*mwp->scale)*drw->bpp)+b); - } - } - g_free(drwBits); - return(mwp); -} - - -GtkWidget * -mw_preview_new(GtkWidget *parent, struct mwPreview *mwp, mw_preview_t *fcn){ - GtkWidget *preview; - GtkWidget *frame; - GtkWidget *pframe; - GtkWidget *vbox; - GtkWidget *button; - guchar *color_cube; - - gtk_preview_set_gamma (gimp_gamma ()); - gtk_preview_set_install_cmap (gimp_install_cmap ()); - color_cube = gimp_color_cube (); - gtk_preview_set_color_cube (color_cube[0], color_cube[1], - color_cube[2], color_cube[3]); - - gtk_widget_set_default_visual (gtk_preview_get_visual ()); - gtk_widget_set_default_colormap (gtk_preview_get_cmap ()); - - frame = gtk_frame_new("Preview"); - gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); - gtk_container_border_width(GTK_CONTAINER(frame), 10); - gtk_box_pack_start(GTK_BOX(parent), frame, FALSE, FALSE, 0); - gtk_widget_show(frame); - - vbox = gtk_vbox_new(FALSE, 2); - gtk_container_border_width(GTK_CONTAINER(vbox), 2); - gtk_container_add(GTK_CONTAINER(frame), vbox); - gtk_widget_show(vbox); - - pframe = gtk_frame_new(NULL); - gtk_frame_set_shadow_type(GTK_FRAME(pframe), GTK_SHADOW_IN); - gtk_container_border_width(GTK_CONTAINER(pframe), 3); - gtk_box_pack_start(GTK_BOX(vbox), pframe, FALSE, FALSE, 0); - gtk_widget_show(pframe); - - preview = gtk_preview_new(GTK_PREVIEW_COLOR); - gtk_preview_size(GTK_PREVIEW(preview), mwp->width, mwp->height); - gtk_container_add(GTK_CONTAINER(pframe), preview); - gtk_widget_show(preview); - mw_do_preview = fcn; - - button=gtk_check_button_new_with_label("Do Preview"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), do_preview); - gtk_signal_connect(GTK_OBJECT(button), "toggled", - (GtkSignalFunc) ui_toggle_callback, - &do_preview); - gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - gtk_widget_show(button); - - return preview; -} -#endif /* NO_PREVIEW */ - -/* internals */ -static void -mw_scale_entry_new(GtkWidget *table, gchar *name, - gfloat defval, gfloat lorange, gfloat hirange, - gfloat st_inc, gfloat pg_inc, gfloat pgsiz, - gpointer variablep, gchar *fmtvar, - gint left_a, gint right_a, gint top_a, gint bottom_a, - GtkCallback scale_cb, GtkCallback entry_cb) { - GtkWidget *label; - GtkWidget *hbox; - GtkWidget *scale; - GtkWidget *entry; - GtkObject *adjustment; - - label = gtk_label_new(name); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - - gtk_table_attach(GTK_TABLE(table), label, - left_a, right_a, top_a, bottom_a, - GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show(label); - - hbox = gtk_hbox_new(FALSE, 5); - gtk_table_attach(GTK_TABLE(table), hbox, - left_a+1, right_a+1, top_a, bottom_a, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - gtk_widget_show(hbox); - - adjustment = gtk_adjustment_new(defval, lorange, hirange, st_inc, - pg_inc, pgsiz); - gtk_signal_connect(GTK_OBJECT(adjustment), "value_changed", - (GtkSignalFunc) scale_cb, - variablep); - - scale = gtk_hscale_new(GTK_ADJUSTMENT(adjustment)); - gtk_widget_set_usize(GTK_WIDGET(scale), 140, 0); - gtk_scale_set_digits(GTK_SCALE(scale), 2); - gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE); - gtk_box_pack_start(GTK_BOX(hbox), scale, TRUE, TRUE, 0); - gtk_widget_show(scale); - - entry = gtk_entry_new(); - gtk_object_set_user_data(GTK_OBJECT(entry), adjustment); - gtk_object_set_user_data(adjustment, entry); - gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, TRUE, 0); - gtk_widget_set_usize(entry, 75, 0); - - gtk_entry_set_text(GTK_ENTRY(entry), fmtvar); - gtk_signal_connect(GTK_OBJECT(entry), "changed", - (GtkSignalFunc) entry_cb, - variablep); - gtk_widget_show(entry); - -} - - - -static void -ui_close_callback(GtkWidget *widget, gpointer data){ - gtk_main_quit(); -} - -static void -ui_ok_callback(GtkWidget *widget, gpointer data){ - gint *rp; - rp = gtk_object_get_data(GTK_OBJECT(data), "runp"); - *rp=1; - gtk_widget_destroy(GTK_WIDGET(data)); -} - -static void -ui_fscale_callback(GtkAdjustment *adj, gpointer data){ - GtkWidget *ent; - double *nval; - gchar buf[40]; - - nval = (double*)data; - - if (*nval != adj->value) { - *nval = adj->value; - ent = gtk_object_get_user_data(GTK_OBJECT(adj)); - sprintf(buf, "%0.2f", adj->value); - - gtk_signal_handler_block_by_data(GTK_OBJECT(ent), data); - gtk_entry_set_text(GTK_ENTRY(ent), buf); - gtk_signal_handler_unblock_by_data(GTK_OBJECT(ent), data); - - if (mw_update_cb) (*mw_update_cb)(data); - -#ifndef NO_PREVIEW - if (do_preview && mw_do_preview!=NULL) (*mw_do_preview)(NULL); -#endif - } -} - -static void -ui_fentry_callback(GtkWidget *widget, gpointer data){ - GtkAdjustment *adjustment; - double new_val; - double *val; - - val = (double*)data; - new_val = atof(gtk_entry_get_text(GTK_ENTRY(widget))); - - if (*val != new_val) { - adjustment = gtk_object_get_user_data(GTK_OBJECT(widget)); - - if ((new_val >= adjustment->lower) && - (new_val <= adjustment->upper)) { - *val = new_val; - adjustment->value = new_val; - gtk_signal_emit_by_name(GTK_OBJECT(adjustment), "value_changed"); - } - if (mw_update_cb) (*mw_update_cb)(data); -#ifndef NO_PREVIEW - if (do_preview && mw_do_preview!=NULL) (*mw_do_preview)(NULL); -#endif - } -} - -static void -ui_iscale_callback(GtkAdjustment *adj, gpointer data){ - GtkWidget *ent; - gint *nval; - gchar buf[40]; - - nval = (gint*)data; - - if (*nval != (gint)adj->value) { - *nval = (gint)adj->value; - ent = gtk_object_get_user_data(GTK_OBJECT(adj)); - sprintf(buf, "%d", (gint)adj->value); - gtk_entry_set_text(GTK_ENTRY(ent), buf); - if (mw_update_cb) (*mw_update_cb)(data); -#ifndef NO_PREVIEW - if (do_preview && mw_do_preview!=NULL) (*mw_do_preview)(NULL); -#endif - } -} - -static void -ui_ientry_callback(GtkWidget *widget, gpointer data){ - GtkAdjustment *adj; - gint new_val; - gint *val; - - val = (gint *)data; - new_val = strtol(gtk_entry_get_text(GTK_ENTRY(widget)), NULL, 0); - - if (*val != new_val) { - adj = gtk_object_get_user_data(GTK_OBJECT(widget)); - - if ((new_val >= adj->lower) && - (new_val <= adj->upper)) { - *val = new_val; - adj->value = new_val; - gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed"); - } - if (mw_update_cb) (*mw_update_cb)(data); -#ifndef NO_PREVIEW - if (do_preview && mw_do_preview!=NULL) (*mw_do_preview)(NULL); -#endif - } -} - - - -/* end of megawidget/megawidget.c */ - - diff --git a/plug-ins/flame/megawidget.h b/plug-ins/flame/megawidget.h deleted file mode 100644 index e7162dc93d..0000000000 --- a/plug-ins/flame/megawidget.h +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************** - * file: megawidget/megawidget.h - * - * Copyright (c) 1997 Eric L. Hernes (erich@rrnet.com) - * All rights reserved. - * - * !! - * !! This file has been hacked to work with the flame plug-in - * !! - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software withough specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Id$ - */ - -#ifndef MEGAWIDGET_H - -#define NO_PREVIEW 1 - -struct mwRadioGroup { - gchar *name; - gint var; -}; -struct mwValueRadioGroup { - gchar *name; - gint val; -}; - -struct mwPreview { - gint width; - gint height; - gint bpp; - gdouble scale; - guchar *bits; -}; - -struct mwColorSel { - gdouble *color; - gdouble savcolor[4]; - gint opacity; - guchar *name; - GtkWidget *window; - GtkWidget *preview; -}; - -#ifndef PREVIEW_SIZE -#define PREVIEW_SIZE 100 -#endif - -GtkWidget *mw_app_new(gchar *resname, gchar *appname, gint *runpp); -void mw_fscale_entry_new(GtkWidget *table, char *name, - gfloat lorange, gfloat hirange, - gfloat st_inc, gfloat pg_inc, gfloat pgsiz, - gint left_a, gint right_a, gint top_a, - gint bottom_a, gdouble *var); -void mw_iscale_entry_new(GtkWidget *table, char *name, - gint lorange, gint hirange, - gint st_inc, gint pg_inc, gint pgsiz, - gint left_a, gint right_a, gint top_a, - gint bottom_a, gint *var); - -GSList *mw_radio_new(GSList *gsl, GtkWidget *parent, gchar *name, - gint *varp, gint init); -GSList *mw_radio_group_new(GtkWidget *parent, gchar *name, - struct mwRadioGroup *rg); -gint mw_radio_result(struct mwRadioGroup *rg); -GSList * mw_value_radio_group_new(GtkWidget *parent, gchar *name, - struct mwValueRadioGroup *rg, gint *var); - -GtkWidget *mw_toggle_button_new(GtkWidget *parent, gchar *fname, - gchar *label, gint *varp); -GtkWidget *mw_ientry_button_new(GtkWidget *parent, gchar *fname, - gchar *name, gint *varp); -GtkWidget *mw_fentry_button_new(GtkWidget *parent, gchar *fname, - gchar *name, gdouble *varp); -struct mwColorSel *mw_color_select_button_create(GtkWidget *parent, - gchar *name, - gdouble *color, - gint opacity); - -void mw_ientry_new(GtkWidget *parent, gchar *fname, - gchar *name, gint *varp); -void mw_fentry_new(GtkWidget *parent, gchar *fname, - gchar *name, gdouble *varp); - -typedef void mw_preview_t (GtkWidget *pvw); - -GtkWidget *mw_preview_new(GtkWidget *parent, struct mwPreview *mwp, - mw_preview_t *fcn); - -struct mwPreview *mw_preview_build(GDrawable *drw); -struct mwPreview *mw_preview_build_virgin(GDrawable *drw); - -typedef void (*mw_callback) (gpointer); -mw_callback mw_update_cb; - - -#endif /* MEGAWIDGET_H */ -/* end of megawidget/megawidget.h */