Commit ba9c7fe9 authored by Dave Neary's avatar Dave Neary Committed by David Neary
Browse files

libgimpwidgets/gimpwidgets.c libgimpwidgets/gimpwidgets.h



2002-11-24  Dave Neary  <bolsh@gimp.org>

        * libgimpwidgets/gimpwidgets.c
        * libgimpwidgets/gimpwidgets.h
        * 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 the gimp random seed
        widget's behaviour and made associated changes in
        plug-ins that use it.
parent 5f28cddf
......@@ -918,44 +918,28 @@ gimp_scale_entry_set_sensitive (GtkObject *adjustment,
}
static void
gimp_random_seed_toggle_update (GtkWidget *widget,
gpointer data)
gimp_random_seed_update (GtkWidget *widget,
gpointer data)
{
gint *toggle_val;
toggle_val = (gint *) data;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
*toggle_val = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
"time_true"));
else
*toggle_val = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
"time_false"));
GtkWidget *w = data;
gimp_toggle_button_sensitive_update (GTK_TOGGLE_BUTTON (widget));
gtk_spin_button_set_value (GTK_SPIN_BUTTON (w),
(guint) g_random_int ());
}
/**
* gimp_random_seed_new:
* @seed: A pointer to the variable which stores the random seed.
* @use_time: A pointer to the variable which stores the @use_time
* toggle boolean.
* @time_true: The value to write to @use_time if the toggle button is checked.
* @time_false: The value to write to @use_time if the toggle button is
* unchecked.
*
* Note that this widget automatically sets tooltips with
* gimp_help_set_help_data(), so you'll have to initialize GIMP's help
* system with gimp_help_init() before using it.
*
* Returns: A #GtkHBox containing a #GtkSpinButton for the random seed and
* a #GtkToggleButton for toggling the @use_time behaviour.
* Returns: A #GtkHBox containing a #GtkSpinButton for the seed and
* a #GtkButton for setting a random seed.
**/
GtkWidget *
gimp_random_seed_new (gint *seed,
gint *use_time,
gint time_true,
gint time_false)
gimp_random_seed_new (guint *seed)
{
GtkWidget *hbox;
GtkWidget *spinbutton;
......@@ -968,42 +952,31 @@ gimp_random_seed_new (gint *seed,
0, (guint32) -1 , 1, 10, 0, 1, 0);
gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (adj), "value_changed",
G_CALLBACK (gimp_int_adjustment_update),
G_CALLBACK (gimp_uint_adjustment_update),
seed);
gtk_widget_show (spinbutton);
gimp_help_set_help_data (spinbutton,
_("If the \"Time\" button is not pressed, "
"use this value for random number generator "
_("Use this value for random number generator "
"seed - this allows you to repeat a "
"given \"random\" operation"), NULL);
button = gtk_toggle_button_new_with_mnemonic (_("_Time"));
button = gtk_button_new_with_mnemonic (_("_Randomize"));
gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
g_signal_connect (G_OBJECT (button), "toggled",
G_CALLBACK (gimp_random_seed_toggle_update),
use_time);
/* Send spinbutton as data so that we can change the value in
* gimp_random_seed_update() */
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (gimp_random_seed_update),
spinbutton);
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
gimp_help_set_help_data (button,
_("Seed random number generator from the current "
"time - this guarantees a reasonable "
"randomization"), NULL);
g_object_set_data (G_OBJECT (button), "time_true",
GINT_TO_POINTER (time_true));
g_object_set_data (G_OBJECT (button), "time_false",
GINT_TO_POINTER (time_false));
g_object_set_data (G_OBJECT (button), "inverse_sensitive",
spinbutton);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
*use_time == time_true);
_("Seed random number generator with a generated random number"),
NULL);
g_object_set_data (G_OBJECT (hbox), "spinbutton", spinbutton);
g_object_set_data (G_OBJECT (hbox), "togglebutton", button);
g_object_set_data (G_OBJECT (hbox), "button", button);
return hbox;
}
......
......@@ -197,13 +197,7 @@ void gimp_scale_entry_set_sensitive (GtkObject *adjustment,
gtk_spin_button_get_adjustment \
(GTK_SPIN_BUTTON (g_object_get_data (G_OBJECT (hbox), "spinbutton")))
#define GIMP_RANDOM_SEED_TOGGLEBUTTON(hbox) \
(g_object_get_data (G_OBJECT (hbox), "togglebutton"))
GtkWidget * gimp_random_seed_new (gint *seed,
gint *use_time,
gint time_true,
gint time_false);
GtkWidget * gimp_random_seed_new (guint32 *seed);
#define GIMP_COORDINATES_CHAINBUTTON(sizeentry) \
(g_object_get_data (G_OBJECT (sizeentry), "chainbutton"))
......
......@@ -96,7 +96,6 @@ typedef struct
{
gdouble blur_pct; /* likelihood of randomization (as %age) */
gdouble blur_rcount; /* repeat count */
gint seed_type; /* seed init. type - default or user value */
gint blur_seed; /* seed value for g_random_set_seed() function */
} BlurVals;
......@@ -104,7 +103,6 @@ static BlurVals pivals =
{
100.0,
1.0,
SEED_DEFAULT,
0,
};
......@@ -118,7 +116,6 @@ static BlurInterface blur_int =
FALSE /* have we run? */
};
/*********************************
*
* LOCAL FUNCTIONS
......@@ -181,7 +178,6 @@ query (void)
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_FLOAT, "blur_pct", "Randomization percentage (1 - 100)" },
{ GIMP_PDB_FLOAT, "blur_rcount", "Repeat count(1 - 100)" },
{ GIMP_PDB_INT32, "seed_type", "Seed type (10 = current time, 11 = seed value)" },
{ GIMP_PDB_INT32, "blur_seed", "Seed value (used only if seed type is 11)" }
};
......@@ -249,6 +245,7 @@ run (gchar *name,
values[0].data.d_status = status;
*nreturn_vals = 1;
*return_vals = values;
/*
* Make sure the drawable type is appropriate.
*/
......@@ -282,9 +279,6 @@ run (gchar *name,
pivals.blur_rcount = (gdouble) param[4].data.d_float;
pivals.blur_rcount = (gdouble) MIN (100.0,pivals.blur_rcount);
pivals.blur_rcount = (gdouble) MAX (1.0, pivals.blur_rcount);
pivals.seed_type = (gint) param[5].data.d_int32;
pivals.seed_type = (gint) MIN (SEED_USER, param[5].data.d_int32);
pivals.seed_type = (gint) MAX (SEED_DEFAULT, param[5].data.d_int32);
pivals.blur_seed = (gint) param[6].data.d_int32;
}
else if ((strcmp (name, PLUG_IN_NAME) == 0) &&
......@@ -292,8 +286,7 @@ run (gchar *name,
{
pivals.blur_pct = (gdouble) 100.0;
pivals.blur_rcount = (gdouble) 1.0;
pivals.seed_type = SEED_DEFAULT;
pivals.blur_seed = 0;
pivals.blur_seed = g_random_int ();
}
else
{
......@@ -325,8 +318,7 @@ run (gchar *name,
/*
* Initialize the rand() function seed
*/
if (pivals.seed_type == SEED_USER)
g_random_set_seed (pivals.blur_seed);
g_random_set_seed (pivals.blur_seed);
blur (drawable);
/*
......@@ -359,6 +351,7 @@ run (gchar *name,
*/
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
/*********************************
......@@ -473,7 +466,7 @@ blur (GimpDrawable *drawable)
ind = 0;
for (col = 0; col < (x2 - x1) * bytes; col++)
{
if (g_random_int_range(0, 100) <= (gint) pivals.blur_pct)
if (g_random_int_range (0, 100) <= (gint) pivals.blur_pct)
{
ind++;
if (ind == bytes || !has_alpha)
......@@ -628,9 +621,7 @@ blur_dialog (void)
gtk_widget_show (table);
/* Random Seed */
seed_hbox = gimp_random_seed_new (&pivals.blur_seed,
&pivals.seed_type,
SEED_DEFAULT, SEED_USER);
seed_hbox = gimp_random_seed_new (&pivals.blur_seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
seed_hbox, 1, TRUE);
......
......@@ -83,10 +83,8 @@
typedef struct
{
gint seed;
guint32 seed;
gdouble turbulence;
/* Interface only */
gboolean timeseed;
} PlasmaValues;
typedef struct
......@@ -111,7 +109,7 @@ static gint plasma_dialog (GimpDrawable *drawable,
static void plasma_ok_callback (GtkWidget *widget,
gpointer data);
static void plasma_seed_changed_callback (GimpDrawable *drawable,
gboolean preview_mode);
gpointer data);
static void plasma (GimpDrawable *drawable,
gboolean preview_mode);
......@@ -163,7 +161,6 @@ static PlasmaValues pvals =
{
0, /* seed */
1.0, /* turbulence */
TRUE /* Time seed? */
};
static PlasmaInterface pint =
......@@ -254,9 +251,8 @@ run (gchar *name,
}
else
{
pvals.seed = (gint) param[3].data.d_int32;
pvals.seed = (guint32) param[3].data.d_int32;
pvals.turbulence = (gdouble) param[4].data.d_float;
pvals.timeseed = FALSE;
if (pvals.turbulence <= 0)
status = GIMP_PDB_CALLING_ERROR;
......@@ -267,7 +263,6 @@ run (gchar *name,
INIT_I18N();
/* Possibly retrieve data */
gimp_get_data ("plug_in_plasma", &pvals);
/* If we're using a time seed, set it at the start */
break;
default:
......@@ -290,7 +285,7 @@ run (gchar *name,
/* Store data */
if (run_mode == GIMP_RUN_INTERACTIVE ||
(pvals.timeseed && run_mode == GIMP_RUN_WITH_LAST_VALS))
(run_mode == GIMP_RUN_WITH_LAST_VALS))
gimp_set_data ("plug_in_plasma", &pvals, sizeof (PlasmaValues));
}
else
......@@ -375,9 +370,7 @@ plasma_dialog (GimpDrawable *drawable, GimpImageType drawable_type)
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
seed = gimp_random_seed_new (&pvals.seed,
&pvals.timeseed,
TRUE, FALSE);
seed = gimp_random_seed_new (&pvals.seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
seed, 1, TRUE);
......@@ -388,10 +381,6 @@ plasma_dialog (GimpDrawable *drawable, GimpImageType drawable_type)
"value_changed",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
g_signal_connect_swapped (G_OBJECT (GIMP_RANDOM_SEED_TOGGLEBUTTON (seed)),
"toggled",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("T_urbulence:"), SCALE_WIDTH, 0,
......@@ -404,7 +393,7 @@ plasma_dialog (GimpDrawable *drawable, GimpImageType drawable_type)
&pvals.turbulence);
g_signal_connect_swapped (G_OBJECT (adj), "value_changed",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
NULL);
gtk_widget_show (dlg);
......@@ -426,9 +415,9 @@ plasma_ok_callback (GtkWidget *widget,
static void
plasma_seed_changed_callback (GimpDrawable *drawable,
gboolean preview_mode)
gpointer data)
{
plasma(drawable, preview_mode);
plasma(drawable, TRUE);
}
#define AVE(n, v1, v2) n[0] = ((gint)v1[0] + (gint)v2[0]) / 2;\
......@@ -460,7 +449,7 @@ plasma (GimpDrawable *drawable,
GRand *gr;
gr = g_rand_new ();
init_plasma (drawable, preview_mode, gr);
/*
......@@ -488,8 +477,7 @@ init_plasma (GimpDrawable *drawable,
GRand *gr)
{
if (!pvals.timeseed)
g_rand_set_seed (gr, pvals.seed);
g_rand_set_seed (gr, pvals.seed);
turbulence = pvals.turbulence;
......@@ -668,7 +656,7 @@ add_random (GRand *gr,
{
amnt = 1;
}
tmp = amnt/2 - g_rand_int_range(gr, 0, amnt);
tmp = g_rand_int_range(gr, -amnt/2, amnt/2);
if ((gint)d[i] + tmp < 0)
{
......
......@@ -130,7 +130,6 @@ typedef struct
{
gdouble rndm_pct; /* likelihood of randomization (as %age) */
gdouble rndm_rcount; /* repeat count */
gint seed_type; /* seed init. type - current time or user value */
gint rndm_seed; /* seed value for g_rand_set_seed() function */
} RandomizeVals;
......@@ -209,7 +208,6 @@ query (void)
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_FLOAT, "rndm_pct", "Randomization percentage (1.0 - 100.0)" },
{ GIMP_PDB_FLOAT, "rndm_rcount", "Repeat count (1.0 - 100.0)" },
{ GIMP_PDB_INT32, "seed_type", "Seed type (10 = current time, 11 = seed value)" },
{ GIMP_PDB_INT32, "rndm_seed", "Seed value (used only if seed type is 11)" }
};
......@@ -346,7 +344,6 @@ run (gchar *name,
{
pivals.rndm_pct = (gdouble) param[3].data.d_float;
pivals.rndm_rcount = (gdouble) param[4].data.d_float;
pivals.seed_type = (gint) param[5].data.d_int32;
pivals.rndm_seed = (gint) param[6].data.d_int32;
if ((rndm_type != RNDM_PICK &&
......@@ -389,9 +386,8 @@ run (gchar *name,
/*
* Initialize the g_rand() function seed
*/
if (pivals.seed_type != SEED_DEFAULT)
g_rand_set_seed (gr, pivals.rndm_seed);
g_rand_set_seed (gr, pivals.rndm_seed);
randomize (drawable, gr);
/*
* If we ran interactively (even repeating) update the display.
......@@ -737,9 +733,7 @@ randomize_dialog (void)
gtk_widget_show(table);
/* Random Seed */
seed_hbox = gimp_random_seed_new (&pivals.rndm_seed,
&pivals.seed_type,
SEED_DEFAULT, SEED_USER);
seed_hbox = gimp_random_seed_new (&pivals.rndm_seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
seed_hbox, 1, TRUE);
......
......@@ -1031,14 +1031,13 @@ typedef struct
gdouble scaley;
gdouble cmplx;
gdouble blend_power;
gint seed;
guint32 seed;
gint tiling;
glong perturbation;
glong colorization;
glong colors;
GimpRGB col1;
GimpRGB col2;
gint seed_is_default;
} SinusVals;
static SinusVals svals =
......@@ -1148,7 +1147,6 @@ query (void)
{ GIMP_PDB_FLOAT, "alpha2", "alpha for the second color (used if the drawable has an alpha chanel)" },
{ GIMP_PDB_INT32, "blend", "0= linear, 1= bilinear, 2= sinusoidal" },
{ GIMP_PDB_FLOAT, "blend_power", "Power used to strech the blend" },
{ GIMP_PDB_INT32, "seed_is_default", "If set, random number generator is seeded with random seed" }
};
INIT_I18N ();
......@@ -1227,7 +1225,6 @@ run (gchar *name,
gimp_rgb_set_alpha (&svals.col2, param[13].data.d_float);
svals.colorization = param[14].data.d_int32;
svals.blend_power = param[15].data.d_float;
svals.seed_is_default = param[16].data.d_int32;
}
break;
......@@ -1283,8 +1280,8 @@ prepare_coef (params *p)
GRand *gr;
gr = g_rand_new ();
if(!svals.seed_is_default)
g_rand_set_seed (gr, svals.seed);
g_rand_set_seed (gr, svals.seed);
switch (svals.colorization)
{
......@@ -1658,11 +1655,8 @@ sinus_double_adjustment_update (GtkAdjustment *adjustment,
static void
sinus_random_update (GObject *unused,
GtkWidget *random)
gpointer data)
{
if (random)
gtk_spin_button_set_value(GIMP_RANDOM_SEED_SPINBUTTON(random),
(double) svals.seed);
if (do_preview)
sinus_do_preview (NULL);
......@@ -1812,8 +1806,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, &svals.seed_is_default,
TRUE, FALSE);
hbox = gimp_random_seed_new (&svals.seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
hbox, 1, TRUE);
......@@ -1822,8 +1815,6 @@ sinus_dialog (void)
g_signal_connect(G_OBJECT (GIMP_RANDOM_SEED_SPINBUTTON_ADJ (hbox)),
"value_changed", G_CALLBACK (sinus_random_update), NULL);
g_signal_connect(G_OBJECT (GIMP_RANDOM_SEED_TOGGLEBUTTON (hbox)),
"toggled", G_CALLBACK (sinus_random_update), hbox);
gtk_widget_show(table);
toggle = gtk_check_button_new_with_mnemonic (_("_Force Tiling?"));
......
......@@ -92,8 +92,6 @@ typedef struct
gint detail;
gdouble xsize;
gdouble ysize;
/* Interface only */
gint defaultseed;
} SolidNoiseValues;
typedef struct
......@@ -138,11 +136,10 @@ static SolidNoiseValues snvals =
{
0, /* tilable */
0, /* turbulent */
1, /* seed */
0, /* seed */
1, /* detail */
4.0, /* xsize */
4.0, /* ysize */
0 /* use default seed */
};
static SolidNoiseInterface snint =
......@@ -375,10 +372,6 @@ solid_noise_init (void)
if (snvals.seed < 0)
snvals.seed = 0;
/* Define the pseudo-random number generator seed */
if (!snvals.defaultseed)
g_rand_set_seed (gr, snvals.seed);
/* Set scaling factors */
if (snvals.tilable)
{
......@@ -538,9 +531,7 @@ solid_noise_dialog (void)
gtk_container_add (GTK_CONTAINER (frame), table);
/* Random Seed */
seed_hbox = gimp_random_seed_new (&snvals.seed,
&snvals.defaultseed,
TRUE, FALSE);
seed_hbox = gimp_random_seed_new (&snvals.seed);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("_Random Seed:"), 1.0, 0.5,
seed_hbox, 1, TRUE);
......
......@@ -169,8 +169,7 @@ typedef struct
gdouble sflare_hue;
GFlareShape sflare_shape;
gint sflare_nverts;
gint sflare_seed;
gint sflare_seed_default;
guint32 sflare_seed;
} GFlare;
typedef struct
......@@ -564,8 +563,7 @@ GFlare default_gflare =
0.0, /* sflare_hue */
GF_CIRCLE, /* sflare_shape */
6, /* sflare_nverts */
1, /* sflare_seed */
FALSE, /* sflare_seed_default */
0, /* sflare_seed */
};
/* These are keywords to be written to disk files specifying flares. */
......@@ -1462,15 +1460,8 @@ gflare_load (const gchar *filename, const gchar *name)
gflare_read_int (&gflare->sflare_nverts, gf);
gflare_read_int (&gflare->sflare_seed, gf);
if (gflare->sflare_seed == -1)
{
gflare->sflare_seed = 1;
gflare->sflare_seed_default = TRUE;
}
else
{
gflare->sflare_seed_default = FALSE;
}
if (gflare->sflare_seed == 0)
gflare->sflare_seed = g_random_int();
fclose (gf->fp);
......@@ -1663,7 +1654,7 @@ gflare_save (GFlare *gflare)
g_ascii_formatd (buf[1], G_ASCII_DTOSTR_BUF_SIZE, "%f", gflare->sflare_rotation);
g_ascii_formatd (buf[2], G_ASCII_DTOSTR_BUF_SIZE, "%f", gflare->sflare_hue);
fprintf (fp, "%s %s %s\n", buf[0], buf[1], buf[2]);
fprintf (fp, "%s %d %d\n", gflare_shapes[gflare->sflare_shape], gflare->sflare_nverts, gflare->sflare_seed_default ? -1 : gflare->sflare_seed);
fprintf (fp, "%s %d %d\n", gflare_shapes[gflare->sflare_shape], gflare->sflare_nverts, gflare->sflare_seed);
fclose (fp);
DEBUG_PRINT (("Saved %s\n", gflare->filename));
......@@ -2092,8 +2083,7 @@ calc_place_sflare ()
prob[i] = sum2 / sum;
}
if (!gflare->sflare_seed_default)
g_rand_set_seed (gr, gflare->sflare_seed);
g_rand_set_seed (gr, gflare->sflare_seed);
for (n = 0; n < SFLARE_NUM; n++)
{
......@@ -4186,12 +4176,9 @@ 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,
&gflare->sflare_seed_default,
TRUE, FALSE);
seed = gimp_random_seed_new (&gflare->sflare_seed);
entry = GTK_WIDGET (GIMP_RANDOM_SEED_SPINBUTTON (seed));
toggle = GTK_WIDGET (GIMP_RANDOM_SEED_TOGGLEBUTTON (seed));
gtk_box_pack_start (GTK_BOX (seed_hbox), seed, FALSE, TRUE, 0);
gtk_widget_show (seed);
......@@ -4200,9 +4187,6 @@ ed_make_page_sflare (GFlareEditor *ed,
"value_changed",
G_CALLBACK (ed_preview_update),
NULL);
g_signal_connect (G_OBJECT (toggle), "toggled",
G_CALLBACK (ed_preview_update),
NULL);
/*
* Create Pages
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment