libgimpwidgets/gimpwidgets.c Modify random seed widget to allow the user

2004-02-01  Dave Neary  <bolsh@gimp.org>

        * libgimpwidgets/gimpwidgets.c
        * libgimpwidgets/gimpwidgets.h: Modify random seed widget to
        allow the user to specify that a seed should be chosen
        randomly for them (useful to allow re-running random plug-ins
        several times to get several different results).

        * plug-ins/common/blur.c
        * plug-ins/common/plasma.c
        * plug-ins/common/randomize.c
        * plug-ins/common/sinus.c
        * plug-ins/common/snoise.c
        * plug-ins/gflare/gflare.c
        * plug-ins/maze/algorithms.c
        * plug-ins/maze/maze.c
        * plug-ins/maze/maze.h
        * plug-ins/maze/maze_face.c: Changed appropriately.

        This fixes bug #129529.
This commit is contained in:
Dave Neary 2004-01-31 23:34:56 +00:00 committed by David Neary
parent 736fd660b9
commit 95ed7031f4
13 changed files with 119 additions and 29 deletions

View File

@ -1,3 +1,24 @@
2004-02-01 Dave Neary <bolsh@gimp.org>
* libgimpwidgets/gimpwidgets.c
* libgimpwidgets/gimpwidgets.h: Modify random seed widget to
allow the user to specify that a seed should be chosen
randomly for them (useful to allow re-running random plug-ins
several times to get several different results).
* plug-ins/common/blur.c
* plug-ins/common/plasma.c
* plug-ins/common/randomize.c
* plug-ins/common/sinus.c
* plug-ins/common/snoise.c
* plug-ins/gflare/gflare.c
* plug-ins/maze/algorithms.c
* plug-ins/maze/maze.c
* plug-ins/maze/maze.h
* plug-ins/maze/maze_face.c: Changed appropriately.
This fixes bug #129529.
2004-01-31 Raphaël Quinet <quinet@gamers.org>
* plug-ins/common/tiff.c (tiff_warning, tiff_error): Do not

View File

@ -1236,16 +1236,20 @@ GtkWidget *
gimp_random_seed_new (guint *seed, gboolean *random_seed)
{
GtkWidget *hbox;
GtkWidget *toggle;
GtkWidget *spinbutton;
GtkObject *adj;
GtkWidget *button;
hbox = gtk_hbox_new (FALSE, 4);
/* If we're being asked to generate a random seed, generate one. */
/* I'm not sure this should be here
if (*random_seed)
{
*seed = g_random_int ();
}
*/
spinbutton = gimp_spin_button_new (&adj, *seed,
0, (guint32) -1 , 1, 10, 0, 1, 0);
@ -1260,22 +1264,41 @@ gimp_random_seed_new (guint *seed, gboolean *random_seed)
"seed - this allows you to repeat a "
"given \"random\" operation"), NULL);
button = gtk_button_new_with_mnemonic (_("_Randomize"));
button = gtk_button_new_with_mnemonic (_("_New seed"));
gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
/* Send spinbutton as data so that we can change the value in
* gimp_random_seed_update() */
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_random_seed_update),
spinbutton);
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gimp_help_set_help_data (button,
_("Seed random number generator with a generated random number"),
NULL);
toggle = gtk_check_button_new_with_label (_("Randomize"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), *random_seed);
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
random_seed);
g_object_set_data (G_OBJECT (hbox), "spinbutton", spinbutton);
g_object_set_data (G_OBJECT (hbox), "button", button);
g_object_set_data (G_OBJECT (hbox), "toggle", toggle);
/* Set sensitivity data for the toggle, this stuff makes
* gimp_toggle_button_sensitive_update work */
g_object_set_data (G_OBJECT (toggle), "inverse_sensitive", spinbutton);
g_object_set_data (G_OBJECT (spinbutton), "inverse_sensitive", button);
// g_object_set_data (G_OBJECT (button), "inverse_sensitive", adj);
/* Initialise sensitivity */
gimp_toggle_button_update (toggle, random_seed);
return hbox;
}

View File

@ -237,6 +237,8 @@ void gimp_scale_entry_set_sensitive (GtkObject *adjustment,
#define GIMP_RANDOM_SEED_SPINBUTTON_ADJ(hbox) \
gtk_spin_button_get_adjustment \
(GTK_SPIN_BUTTON (g_object_get_data (G_OBJECT (hbox), "spinbutton")))
#define GIMP_RANDOM_SEED_TOGGLE(hbox) \
(g_object_get_data (G_OBJECT(hbox), "toggle"))
GtkWidget * gimp_random_seed_new (guint32 *seed,
gboolean *random_seed);

View File

@ -313,6 +313,7 @@ run (const gchar *name,
/*
* Initialize the rand() function seed
*/
if (pivals.blur_randomize)
g_random_set_seed (pivals.blur_seed);
blur (drawable);

View File

@ -79,6 +79,7 @@ typedef struct
{
guint32 seed;
gdouble turbulence;
gboolean random_seed;
} PlasmaValues;
@ -143,6 +144,7 @@ static PlasmaValues pvals =
{
0, /* seed */
1.0, /* turbulence */
FALSE, /* Use random seed */
};
/*
@ -246,6 +248,8 @@ run (const gchar *name,
case GIMP_RUN_WITH_LAST_VALS:
/* Possibly retrieve data */
gimp_get_data ("plug_in_plasma", &pvals);
if (pvals.random_seed)
pvals.seed = g_random_int ();
break;
default:
@ -294,7 +298,6 @@ plasma_dialog (GimpDrawable *drawable,
GtkWidget *seed;
GtkObject *adj;
gboolean run;
gboolean randomize = FALSE;
gimp_ui_init ("plasma", TRUE);
@ -316,7 +319,7 @@ plasma_dialog (GimpDrawable *drawable,
preview = gimp_old_preview_new2 (drawable_type, TRUE);
gtk_box_pack_start (GTK_BOX (main_vbox), preview->frame, FALSE, FALSE, 0);
plasma (drawable, TRUE); /* preview image */
plasma_seed_changed_callback (drawable, NULL); /* preview image */
gtk_widget_show (preview->widget);
@ -332,7 +335,7 @@ plasma_dialog (GimpDrawable *drawable,
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
seed = gimp_random_seed_new (&pvals.seed, &randomize);
seed = gimp_random_seed_new (&pvals.seed, &pvals.random_seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Random _Seed:"), 1.0, 0.5,
seed, 1, TRUE);
@ -344,6 +347,11 @@ plasma_dialog (GimpDrawable *drawable,
G_CALLBACK (plasma_seed_changed_callback),
drawable);
g_signal_connect_swapped (GIMP_RANDOM_SEED_TOGGLE (seed),
"toggled",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("T_urbulence:"), SCALE_WIDTH, 0,
pvals.turbulence,
@ -370,6 +378,9 @@ static void
plasma_seed_changed_callback (GimpDrawable *drawable,
gpointer data)
{
if (pvals.random_seed)
pvals.seed = g_random_int ();
plasma (drawable, TRUE);
}

View File

@ -387,6 +387,7 @@ run (const gchar *name,
/*
* Initialize the g_rand() function seed
*/
if (!pivals.randomize)
g_rand_set_seed (gr, pivals.seed);
randomize (drawable, gr);

View File

@ -72,6 +72,7 @@ typedef struct
glong colors;
GimpRGB col1;
GimpRGB col2;
gboolean random_seed;
} SinusVals;
static SinusVals svals =
@ -312,6 +313,7 @@ prepare_coef (params *p)
gr = g_rand_new ();
if (!svals.random_seed)
g_rand_set_seed (gr, svals.seed);
switch (svals.colorization)
@ -633,7 +635,6 @@ sinus_dialog (void)
GtkWidget *push_col2 = NULL;
GtkObject *adj;
gboolean run;
gboolean randomize;
gimp_ui_init ("sinus", TRUE);
@ -726,7 +727,7 @@ sinus_dialog (void)
table = gtk_table_new(3, 1, FALSE);
gtk_table_set_col_spacings(GTK_TABLE(table), 4);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
hbox = gimp_random_seed_new (&svals.seed, &randomize);
hbox = gimp_random_seed_new (&svals.seed, &svals.random_seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("R_andom Seed:"), 1.0, 0.5,
hbox, 1, TRUE);

View File

@ -92,6 +92,7 @@ typedef struct
gint detail;
gdouble xsize;
gdouble ysize;
gboolean random_seed;
} SolidNoiseValues;
@ -133,6 +134,7 @@ static SolidNoiseValues snvals =
1, /* detail */
4.0, /* xsize */
4.0, /* ysize */
FALSE,
};
static gint xclip, yclip;
@ -356,6 +358,8 @@ solid_noise_init (void)
GRand *gr;
gr = g_rand_new ();
if (!snvals.random_seed)
g_rand_set_seed (gr, snvals.seed);
/* Force sane parameters */
snvals.detail = CLAMP (snvals.detail, 0, 15);
@ -487,7 +491,6 @@ solid_noise_dialog (void)
GtkWidget *spinbutton;
GtkObject *adj;
gboolean run;
gboolean randomize = FALSE;
gimp_ui_init ("snoise", FALSE);
@ -515,7 +518,7 @@ solid_noise_dialog (void)
gtk_widget_show (table);
/* Random Seed */
seed_hbox = gimp_random_seed_new (&snvals.seed, &randomize);
seed_hbox = gimp_random_seed_new (&snvals.seed, &snvals.random_seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
seed_hbox, 1, TRUE);

View File

@ -167,6 +167,7 @@ typedef struct
GFlareShape sflare_shape;
gint sflare_nverts;
guint32 sflare_seed;
gboolean random_seed;
} GFlare;
typedef struct
@ -538,6 +539,7 @@ GFlare default_gflare =
GF_CIRCLE, /* sflare_shape */
6, /* sflare_nverts */
0, /* sflare_seed */
TRUE, /* random_seed */
};
/* These are keywords to be written to disk files specifying flares. */
@ -1881,6 +1883,7 @@ calc_place_sflare (void)
prob[i] = sum2 / sum;
}
if (!gflare->random_seed)
g_rand_set_seed (gr, gflare->sflare_seed);
for (n = 0; n < SFLARE_NUM; n++)
@ -3849,7 +3852,7 @@ ed_make_page_sflare (GFlareEditor *ed,
gtk_box_pack_start (GTK_BOX (seed_hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
seed = gimp_random_seed_new (&gflare->sflare_seed, &randomize);
seed = gimp_random_seed_new (&gflare->sflare_seed, &gflare->random_seed);
entry = GTK_WIDGET (GIMP_RANDOM_SEED_SPINBUTTON (seed));

View File

@ -280,7 +280,14 @@ prim(gint pos, gchar *maz, guint x, guint y)
guint progress=0, max_progress;
char d, i;
guint c=0;
gint rnd = mvals.seed;
gint rnd;
if (mvals.random_seed)
rnd = g_random_int ();
else
rnd = mvals.seed;
g_rand_set_seed (gr, rnd);
gimp_progress_init (_("Constructing maze using Prim's Algorithm..."));
@ -454,7 +461,14 @@ prim_tileable(gchar *maz, guint x, guint y)
guint progress=0, max_progress;
char d, i;
guint c=0;
gint rnd = mvals.seed;
gint rnd;
if (mvals.random_seed)
rnd = g_random_int ();
else
rnd = mvals.seed;
g_rand_set_seed (gr, rnd);
gimp_progress_init (_("Constructing tileable maze using Prim's Algorithm..."));
@ -463,7 +477,6 @@ prim_tileable(gchar *maz, guint x, guint y)
max_progress=x*y/4;
/* Pick someplace to start. */
g_rand_set_seed (gr, rnd);
pos = x * 2 * g_rand_int_range (gr, 0, y/2) + 2 * g_rand_int_range(gr, 0, x/2);

View File

@ -124,6 +124,7 @@ MazeValues mvals =
57, /* multiple * These two had "Experiment with this?" comments */
1, /* offset * in the maz.c source, so, lets expiriment. :) */
DEPTH_FIRST, /* Algorithm */
TRUE, /* random_seed */
};
GRand *gr;
@ -366,6 +367,9 @@ maze (GimpDrawable * drawable)
switch (mvals.algorithm)
{
case DEPTH_FIRST:
if (mvals.random_seed)
mazegen_tileable (0, maz, mw, mh, g_random_int ());
else
mazegen_tileable (0, maz, mw, mh, mvals.seed);
break;
@ -396,6 +400,9 @@ maze (GimpDrawable * drawable)
switch (mvals.algorithm)
{
case DEPTH_FIRST:
if (mvals.random_seed)
mazegen (maz_yy+maz_xx, maz, mw, mh, g_random_int());
else
mazegen (maz_yy+maz_xx, maz, mw, mh, mvals.seed);
break;
@ -418,6 +425,9 @@ maze (GimpDrawable * drawable)
switch (mvals.algorithm)
{
case DEPTH_FIRST:
if (mvals.random_seed)
mazegen (pos, maz, mw, mh, g_random_int ());
else
mazegen (pos, maz, mw, mh, mvals.seed);
break;

View File

@ -32,6 +32,7 @@ typedef struct {
gint multiple;
gint offset;
MazeAlgoType algorithm;
gboolean random_seed;
/* Interface options. */
} MazeValues;

View File

@ -288,7 +288,7 @@ maze_dialog (void)
&mvals.tile);
/* Seed input box */
seed_hbox = gimp_random_seed_new (&mvals.seed, &randomize);
seed_hbox = gimp_random_seed_new (&mvals.seed, &mvals.random_seed);
gimp_table_attach_aligned (GTK_TABLE (table), 0, trow,
_("Seed:"), 1.0, 0.5,
seed_hbox, 1, TRUE);