Commit 8f9e5109 authored by David Odin's avatar David Odin
Browse files

converted to GimpPreviewArea. Also added scrollbars to move around. The

* plug-ins/common/noisify.c: converted to GimpPreviewArea.  Also added
  scrollbars to move around.  The preview was rather useless without them.
parent 502f9b71
2004-08-11 DindinX <david@dindinx.org>
* plug-ins/common/noisify.c: converted to GimpPreviewArea. Also added
scrollbars to move around. The preview was rather useless without
them.
2004-08-11 Michael Natterer <mitch@gimp.org>
* app/core/gimpdrawable-blend.c
......
......@@ -79,6 +79,7 @@ static gint noisify_dialog (GimpDrawable *drawable,
gint channels);
static void noisify_double_adjustment_update (GtkAdjustment *adjustment,
gpointer data);
static void preview_scroll_callback (GimpDrawable *drawable);
GimpPlugInInfo PLUG_IN_INFO =
{
......@@ -101,7 +102,15 @@ static NoisifyInterface noise_int =
};
static GimpRunMode run_mode;
static GimpOldPreview *preview;
/* All the Preview stuff... */
#define PREVIEW_SIZE 128
static GtkWidget *preview;
static GtkObject *hscroll_data, *vscroll_data;
static gint preview_width, preview_height, preview_bpp;
static gint preview_x1, preview_x2, preview_y1, preview_y2;
static gint sel_width, sel_height;
static gint sel_x1, sel_x2, sel_y1, sel_y2;
MAIN ()
......@@ -160,6 +169,12 @@ run (const gchar *name,
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
gimp_drawable_mask_bounds (drawable->drawable_id,
&sel_x1, &sel_y1, &sel_x2, &sel_y2);
sel_width = sel_x2 - sel_x1;
sel_height = sel_y2 - sel_y1;
if (gimp_drawable_is_gray (drawable->drawable_id))
nvals.noise[1] = 0.;
......@@ -269,13 +284,54 @@ noisify (GimpDrawable *drawable,
GRand *gr = g_rand_new ();
if (preview_mode)
gimp_old_preview_update (preview, noisify_func, gr);
{
guchar *preview_src, *preview_dst;
GimpPixelRgn src_rgn;
gint i;
preview_src = g_new (guchar, preview_width * preview_height * preview_bpp);
preview_dst = g_new (guchar, preview_width * preview_height * preview_bpp);
gimp_pixel_rgn_init (&src_rgn, drawable,
preview_x1, preview_y1,
preview_width, preview_height,
FALSE, FALSE);
gimp_pixel_rgn_get_rect (&src_rgn, preview_src,
preview_x1, preview_y1,
preview_width, preview_height);
for (i=0 ; i<preview_width * preview_height ; i++)
noisify_func (preview_src + i * preview_bpp,
preview_dst + i * preview_bpp,
preview_bpp,
gr);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, preview_width, preview_height,
gimp_drawable_type (drawable->drawable_id),
preview_dst,
preview_width * preview_bpp);
g_free (preview_src);
g_free (preview_dst);
}
else
gimp_rgn_iterate2 (drawable, run_mode, noisify_func, gr);
g_rand_free (gr);
}
static void
preview_scroll_callback (GimpDrawable *drawable)
{
preview_x1 = sel_x1 + GTK_ADJUSTMENT (hscroll_data)->value;
preview_y1 = sel_y1 + GTK_ADJUSTMENT (vscroll_data)->value;
preview_x2 = preview_x1 + MIN (preview_width, sel_width);
preview_y2 = preview_y1 + MIN (preview_height, sel_height);
noisify (drawable, TRUE);
}
static void
noisify_add_channel (GtkWidget *table, gint channel, gchar *name,
GimpDrawable *drawable)
......@@ -324,7 +380,10 @@ noisify_dialog (GimpDrawable *drawable,
{
GtkWidget *dlg;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *alignment;
GtkWidget *ptable;
GtkWidget *frame;
GtkWidget *scrollbar;
GtkWidget *toggle;
GtkWidget *table;
gboolean run;
......@@ -344,18 +403,62 @@ noisify_dialog (GimpDrawable *drawable,
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* preview */
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_old_preview_new (NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview->frame, FALSE, FALSE, 0);
gtk_widget_show (preview->frame);
gimp_old_preview_fill (preview, drawable);
noisify (drawable, TRUE); /* preview noisify */
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);
gtk_widget_show (alignment);
ptable = gtk_table_new (2, 2, FALSE);
gtk_container_add (GTK_CONTAINER (alignment), ptable);
gtk_widget_show (ptable);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE (ptable), frame, 0, 1, 0, 1, 0, 0, 0, 0);
gtk_widget_show (frame);
preview_width = MIN (sel_width, PREVIEW_SIZE);
preview_height = MIN (sel_height, PREVIEW_SIZE);
preview_bpp = drawable->bpp;
preview_x1 = sel_x1;
preview_y1 = sel_y1;
preview_x2 = preview_x1 + preview_width;
preview_y2 = preview_y1 + preview_height;
preview = gimp_preview_area_new ();
gtk_widget_set_size_request (preview, preview_width, preview_height);
gtk_container_add (GTK_CONTAINER (frame), preview);
gtk_widget_show (preview);
hscroll_data = gtk_adjustment_new (0, 0, sel_width - 1, 1.0,
MIN (preview_width, sel_width),
MIN (preview_width, sel_width));
g_signal_connect_swapped (hscroll_data, "value_changed",
G_CALLBACK (preview_scroll_callback),
drawable);
scrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (hscroll_data));
gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (ptable), scrollbar, 0, 1, 1, 2,
GTK_FILL, 0, 0, 0);
gtk_widget_show (scrollbar);
vscroll_data = gtk_adjustment_new (0, 0, sel_height - 1, 1.0,
MIN (preview_height, sel_height),
MIN (preview_height, sel_height));
g_signal_connect_swapped (vscroll_data, "value_changed",
G_CALLBACK (preview_scroll_callback),
drawable);
scrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (vscroll_data));
gtk_range_set_update_policy (GTK_RANGE (scrollbar), GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (ptable), scrollbar, 1, 2, 0, 1,
0, GTK_FILL, 0, 0);
gtk_widget_show (scrollbar);
if (gimp_drawable_is_rgb (drawable->drawable_id))
{
......@@ -419,6 +522,8 @@ noisify_dialog (GimpDrawable *drawable,
gtk_widget_show (dlg);
noisify (drawable, TRUE); /* preview noisify */
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dlg);
......
Supports Markdown
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