Commit 3155d682 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimp/gimpdrawablepreview.[ch] always show the "Preview" check button.

2004-09-01  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpdrawablepreview.[ch]
	* libgimpwidgets/gimppreview.[ch]: always show the "Preview" check
	button. Simplified the preview APIs, moved the "size" style
	property to the GimpPreview class.

	* etc/gtkrc: changed the example accordingly.

	* plug-ins/common/despeckle.c
	* plug-ins/common/gauss.c
	* plug-ins/common/neon.c
	* plug-ins/common/sobel.c
	* plug-ins/common/softglow.c
	* plug-ins/common/spread.c
	* plug-ins/common/unsharp.c: follow change in GimpDrawablePreview API.
parent aeb28886
2004-09-01 Sven Neumann <sven@gimp.org>
* libgimp/gimpdrawablepreview.[ch]
* libgimpwidgets/gimppreview.[ch]: always show the "Preview" check
button. Simplified the preview APIs, moved the "size" style
property to the GimpPreview class.
* etc/gtkrc: changed the example accordingly.
* plug-ins/common/despeckle.c
* plug-ins/common/gauss.c
* plug-ins/common/neon.c
* plug-ins/common/sobel.c
* plug-ins/common/softglow.c
* plug-ins/common/spread.c
* plug-ins/common/unsharp.c: follow change in GimpDrawablePreview API.
2004-09-01 Michael Natterer <mitch@gimp.org>
* plug-ins/script-fu/script-fu-types.h (struct SFOptions): changed
......
2004-09-01 Sven Neumann <sven@gimp.org>
* libgimp/tmpl/gimpprogressbar.sgml
* libgimp/libgimp-docs.sgml
* libgimp/libgimp-sections.txt
* libgimp/libgimp.types
* libgimp/tmpl/gimpdrawablepreview.sgml
* libgimpwidgets/libgimpwidgets-sections.txt
* libgimpwidgets/tmpl/gimppreview.sgml: updated for GimpProgressBar
and GimpPreview API changes.
2004-08-31 Sven Neumann <sven@gimp.org>
* libgimp/Makefile.am
......
......@@ -83,6 +83,7 @@
<xi:include href="xml/gimpdrawablecombobox.xml" />
<xi:include href="xml/gimpimagecombobox.xml" />
<xi:include href="xml/gimppixbuf.xml" />
<xi:include href="xml/gimpprogressbar.xml" />
<xi:include href="xml/gimpmenu.xml" />
<xi:include href="xml/gimpbrushmenu.xml" />
<xi:include href="xml/gimpfontmenu.xml" />
......
......@@ -687,7 +687,6 @@ gimp_drawable_get_thumbnail
<TITLE>GimpDrawablePreview</TITLE>
GimpDrawablePreview
gimp_drawable_preview_new
gimp_drawable_preview_new_with_toggle
gimp_drawable_preview_draw
<SUBSECTION Standard>
GimpDrawablePreviewClass
......@@ -714,6 +713,22 @@ GimpImageConstraintFunc
gimp_image_combo_box_new
</SECTION>
<SECTION>
<FILE>gimpprogressbar</FILE>
<TITLE>GimpProgressBar</TITLE>
GimpProgressBar
gimp_progress_bar_new
<SUBSECTION Standard>
GimpProgressBarClass
GIMP_PROGRESS_BAR
GIMP_IS_PROGRESS_BAR
GIMP_TYPE_PROGRESS_BAR
gimp_progress_bar_get_type
GIMP_PROGRESS_BAR_CLASS
GIMP_IS_PROGRESS_BAR_CLASS
GIMP_PROGRESS_BAR_GET_CLASS
</SECTION>
<SECTION>
<FILE>gimpmenu</FILE>
GimpConstraintFunc
......
......@@ -3,3 +3,4 @@
#include <libgimp/gimpui.h>
gimp_drawable_preview_get_type
gimp_progress_bar_get_type
......@@ -25,15 +25,6 @@ GimpDrawablePreview
</para>
@drawable:
@Returns:
<!-- ##### FUNCTION gimp_drawable_preview_new_with_toggle ##### -->
<para>
</para>
@drawable:
@toggle:
@Returns:
......
<!-- ##### SECTION Title ##### -->
GimpProgressBar
<!-- ##### SECTION Short_Description ##### -->
<!-- ##### SECTION Long_Description ##### -->
<para>
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### STRUCT GimpProgressBar ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_progress_bar_new ##### -->
<para>
</para>
@Returns:
......@@ -798,9 +798,10 @@ GIMP_PREVIEW_AREA_GET_CLASS
<FILE>gimppreview</FILE>
<TITLE>GimpPreview</TITLE>
GimpPreview
gimp_preview_get_update
gimp_preview_set_update
gimp_preview_get_size
gimp_preview_get_position
gimp_preview_show_update_toggle
gimp_preview_invalidate
<SUBSECTION Standard>
GimpPreviewClass
......
......@@ -27,43 +27,52 @@ GimpPreview
@gimppreview: the object which received the signal.
<!-- ##### ARG GimpPreview:show-update-toggle ##### -->
<!-- ##### ARG GimpPreview:update ##### -->
<para>
</para>
<!-- ##### ARG GimpPreview:update ##### -->
<!-- ##### ARG GimpPreview:size ##### -->
<para>
</para>
<!-- ##### FUNCTION gimp_preview_get_size ##### -->
<!-- ##### FUNCTION gimp_preview_get_update ##### -->
<para>
</para>
@preview:
@width:
@height:
@Returns:
<!-- ##### FUNCTION gimp_preview_get_position ##### -->
<!-- ##### FUNCTION gimp_preview_set_update ##### -->
<para>
</para>
@preview:
@x:
@y:
@update:
<!-- ##### FUNCTION gimp_preview_show_update_toggle ##### -->
<!-- ##### FUNCTION gimp_preview_get_size ##### -->
<para>
</para>
@preview:
@show_update:
@width:
@height:
<!-- ##### FUNCTION gimp_preview_get_position ##### -->
<para>
</para>
@preview:
@x:
@y:
<!-- ##### FUNCTION gimp_preview_invalidate ##### -->
......
......@@ -30,14 +30,14 @@ binding "gimp-help-binding"
#
# Adjust the size of drawable previews in plug-in dialogs:
# Adjust the size of previews in plug-in dialogs:
#
style "gimp-large-preview"
{
GimpDrawablePreview::size = 256
GimpPreview::size = 256
}
# class "GimpDrawablePreview" style "gimp-large-preview"
# class "GimpPreview" style "gimp-large-preview"
#
......
......@@ -32,7 +32,6 @@
#include "gimpdrawablepreview.h"
#define DEFAULT_SIZE 150
#define SELECTION_BORDER 2
......@@ -85,13 +84,6 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass)
widget_class->style_set = gimp_drawable_preview_style_set;
preview_class->draw = gimp_drawable_preview_draw_original;
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("size",
NULL, NULL,
1, 1024,
DEFAULT_SIZE,
G_PARAM_READABLE));
}
static void
......@@ -173,18 +165,34 @@ gimp_drawable_preview_set_drawable (GimpDrawablePreview *drawable_preview,
preview->ymax = MIN (y2 + SELECTION_BORDER, height);
}
static void
gimp_drawable_preview_notify_update (GimpPreview *preview,
GParamSpec *pspec,
gboolean *toggle)
{
*toggle = gimp_preview_get_update (preview);
}
/**
* gimp_drawable_preview_new:
* @drawable: a #GimpDrawable
* @toggle: pointer to a #gboolean variable to sync with the "Preview"
* check-button or %NULL
*
* Creates a new #GimpDrawablePreview widget for @drawable.
* Creates a new #GimpDrawablePreview widget for @drawable. If
* updating the preview takes considerable time, you will want to
* store the state of the "Preview" check-button in the plug-in
* data. For convenience you can pass a pointer to the #gboolean as
* @toggle.
*
* Returns: A pointer to the new #GimpDrawablePreview widget.
*
* Since: GIMP 2.2
**/
GtkWidget *
gimp_drawable_preview_new (GimpDrawable *drawable)
gimp_drawable_preview_new (GimpDrawable *drawable,
gboolean *toggle)
{
GimpDrawablePreview *preview;
......@@ -192,35 +200,14 @@ gimp_drawable_preview_new (GimpDrawable *drawable)
preview = g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW, NULL);
gimp_drawable_preview_set_drawable (preview, drawable);
return GTK_WIDGET (preview);
}
/**
* gimp_drawable_preview_new_with_toggle:
* @drawable: a #GimpDrawable
* @toggle:
*
* Creates a new #GimpDrawablePreview widget for @drawable.
*
* Returns: A pointer to the new #GimpDrawablePreview widget.
*
* Since: GIMP 2.2
**/
GtkWidget *
gimp_drawable_preview_new_with_toggle (GimpDrawable *drawable,
gboolean *toggle)
{
GimpDrawablePreview *preview;
g_return_val_if_fail (drawable != NULL, NULL);
g_return_val_if_fail (toggle != NULL, NULL);
if (toggle)
{
gimp_preview_set_update (GIMP_PREVIEW (preview), *toggle);
preview = g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW,
"show_update_toggle", TRUE,
"update", *toggle,
NULL);
g_signal_connect (preview, "notify::update",
G_CALLBACK (gimp_drawable_preview_notify_update),
toggle);
}
gimp_drawable_preview_set_drawable (preview, drawable);
......
......@@ -53,14 +53,13 @@ struct _GimpDrawablePreviewClass
};
GType gimp_drawable_preview_get_type (void) G_GNUC_CONST;
GType gimp_drawable_preview_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_drawable_preview_new (GimpDrawable *drawable);
GtkWidget * gimp_drawable_preview_new_with_toggle (GimpDrawable *drawable,
gboolean *toggle);
GtkWidget * gimp_drawable_preview_new (GimpDrawable *drawable,
gboolean *toggle);
void gimp_drawable_preview_draw (GimpDrawablePreview *preview,
guchar *buf);
void gimp_drawable_preview_draw (GimpDrawablePreview *preview,
guchar *buf);
G_END_DECLS
......
......@@ -30,6 +30,7 @@
#include "libgimp/libgimp-intl.h"
#define DEFAULT_SIZE 150
#define PREVIEW_TIMEOUT 200
......@@ -42,8 +43,7 @@ enum
enum
{
PROP_0,
PROP_UPDATE,
PROP_SHOW_UPDATE_TOGGLE
PROP_UPDATE
};
......@@ -115,7 +115,8 @@ gimp_preview_get_type (void)
static void
gimp_preview_class_init (GimpPreviewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......@@ -140,16 +141,14 @@ gimp_preview_class_init (GimpPreviewClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class,
PROP_SHOW_UPDATE_TOGGLE,
g_param_spec_boolean ("show_update_toggle",
NULL, NULL,
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
klass->draw = NULL;
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("size",
NULL, NULL,
1, 1024,
DEFAULT_SIZE,
G_PARAM_READABLE));
}
static void
......@@ -157,6 +156,7 @@ gimp_preview_init (GimpPreview *preview)
{
GtkTable *table = GTK_TABLE (preview);
GtkWidget *frame;
GtkObject *adj;
gtk_table_resize (table, 3, 2);
gtk_table_set_homogeneous (table, FALSE);
......@@ -172,27 +172,27 @@ gimp_preview_init (GimpPreview *preview)
preview->width = preview->xmax - preview->xmin;
preview->height = preview->ymax - preview->ymin;
preview->hadj = gtk_adjustment_new (0, 0, preview->width - 1, 1.0,
preview->width, preview->width);
adj = gtk_adjustment_new (0, 0, preview->width - 1, 1.0,
preview->width, preview->width);
g_signal_connect (preview->hadj, "value_changed",
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_preview_h_scroll),
preview);
preview->hscr = gtk_hscrollbar_new (GTK_ADJUSTMENT (preview->hadj));
preview->hscr = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->hscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (table, preview->hscr, 0,1, 1,2,
GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
preview->vadj = gtk_adjustment_new (0, 0, preview->height - 1, 1.0,
preview->height, preview->height);
adj = gtk_adjustment_new (0, 0, preview->height - 1, 1.0,
preview->height, preview->height);
g_signal_connect (preview->vadj, "value_changed",
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_preview_v_scroll),
preview);
preview->vscr = gtk_vscrollbar_new (GTK_ADJUSTMENT (preview->vadj));
preview->vscr = gtk_vscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->vscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (table, preview->vscr, 1,2, 0,1,
......@@ -231,15 +231,16 @@ gimp_preview_init (GimpPreview *preview)
/* a toggle button to (des)activate the instant preview */
preview->toggle_update = gtk_check_button_new_with_mnemonic (_("_Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle_update),
preview->toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle),
preview->update_preview);
gtk_table_set_row_spacing (GTK_TABLE (preview), 1, 6);
gtk_table_attach (table, preview->toggle_update,
gtk_table_attach (table, preview->toggle,
0, 2, 2, 3, GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (preview->toggle);
g_signal_connect (preview->toggle_update, "toggled",
g_signal_connect (preview->toggle, "toggled",
G_CALLBACK (gimp_preview_toggle_callback),
preview);
}
......@@ -272,10 +273,6 @@ gimp_preview_get_property (GObject *object,
g_value_set_boolean (value, preview->update_preview);
break;
case PROP_SHOW_UPDATE_TOGGLE:
g_value_set_boolean (value, GTK_WIDGET_VISIBLE (preview->toggle_update));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -293,17 +290,10 @@ gimp_preview_set_property (GObject *object,
switch (property_id)
{
case PROP_UPDATE:
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle_update),
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle),
g_value_get_boolean (value));
break;
case PROP_SHOW_UPDATE_TOGGLE:
if (g_value_get_boolean (value))
gtk_widget_show (preview->toggle_update);
else
gtk_widget_hide (preview->toggle_update);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -467,8 +457,8 @@ gimp_preview_area_event (GtkWidget *area,
if (preview->xoff != xoff || preview->yoff != yoff)
{
gtk_adjustment_set_value (GTK_ADJUSTMENT (preview->hadj), xoff);
gtk_adjustment_set_value (GTK_ADJUSTMENT (preview->vadj), yoff);
gtk_range_set_value (GTK_RANGE (preview->hscr), xoff);
gtk_range_set_value (GTK_RANGE (preview->vscr), yoff);
gimp_preview_draw (preview);
gimp_preview_invalidate (preview);
......@@ -569,6 +559,40 @@ gimp_preview_invalidate_now (GimpPreview *preview)
return FALSE;
}
/**
* gimp_preview_set_update:
* @preview: a #GimpPreview widget
* @update:
*
* Since: GIMP 2.2
**/
void
gimp_preview_set_update (GimpPreview *preview,
gboolean update)
{
g_return_if_fail (GIMP_IS_PREVIEW (preview));
g_object_set (preview,
"update", update,
NULL);
}
/**
* gimp_preview_get_update:
* @preview: a #GimpPreview widget
*
* Return value: the state of the "Preview" check button.
*
* Since: GIMP 2.2
**/
gboolean
gimp_preview_get_update (GimpPreview *preview)
{
g_return_val_if_fail (GIMP_IS_PREVIEW (preview), FALSE);
return preview->update_preview;
}
/**
* gimp_preview_get_size:
* @preview: a #GimpPreview widget
......@@ -613,24 +637,6 @@ gimp_preview_get_position (GimpPreview *preview,
*y = preview->yoff + preview->ymin;
}
/**
* gimp_preview_show_update_toggle:
* @preview: a #GimpPreview widget
* @show_update: whether to show the "Update Preview" toggle button
*
* Since: GIMP 2.2
**/
void
gimp_preview_show_update_toggle (GimpPreview *preview,
gboolean show_update)
{
g_return_if_fail (GIMP_IS_PREVIEW (preview));
g_object_set (preview,
"show_update_toggle", show_update,
NULL);
}
/*
* gimp_preview_invalidate:
* @preview: a #GimpPreview widget
......
......@@ -44,23 +44,26 @@ struct _GimpPreview
{
GtkTable parent_instance;
gboolean update_preview;
/*< protected >*/
GtkWidget *area;
GtkWidget *hscr;
GtkWidget *vscr;
GtkWidget *toggle;
GdkCursor *cursor_move;
GdkCursor *cursor_busy;
/*< private >*/
gint xoff, yoff;
gint xmin, xmax, ymin, ymax;
gint drag_x, drag_y;
gint drag_xoff, drag_yoff;
gint width, height;
GtkObject *hadj, *vadj;
GtkWidget *hscr, *vscr;
gboolean in_drag;
GtkWidget *area;
GtkWidget *toggle_update;
gboolean update_preview;
guint timeout_id;
GdkCursor *cursor_move;
GdkCursor *cursor_busy;
};
struct _GimpPreviewClass
{
GtkTableClass parent_class;
......@@ -73,20 +76,21 @@ struct _GimpPreviewClass
};
GType gimp_preview_get_type (void) G_GNUC_CONST;
GType gimp_preview_get_type (void) G_GNUC_CONST;
void gimp_preview_get_size (GimpPreview *preview,
gint *width,
gint *height);
void gimp_preview_set_update (GimpPreview *preview,
gboolean update);
gboolean gimp_preview_get_update (GimpPreview *preview);
void gimp_preview_get_position (GimpPreview *preview,
gint *x,
gint *y);
void gimp_preview_get_size (GimpPreview *preview,
gint *width,
gint *height);
void gimp_preview_get_position (GimpPreview *preview,
gint *x,
gint *y);
void gimp_preview_show_update_toggle (GimpPreview *preview,
gboolean show_update);
void gimp_preview_invalidate (GimpPreview *preview);
void gimp_preview_invalidate (GimpPreview *preview);
G_END_DECLS
......
......@@ -267,7 +267,7 @@ run (const gchar *name,
INIT_I18N();
gimp_get_data (PLUG_IN_NAME, despeckle_vals);
break;
default:
status = GIMP_PDB_CALLING_ERROR;
break;
......@@ -597,8 +597,8 @@ despeckle_dialog (void)
hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_drawable_preview_new (drawable);
preview = gimp_drawable_preview_new (drawable, NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
g_signal_connect (preview, "invalidated",
......
......@@ -476,7 +476,7 @@ gauss_dialog (gint32 image_ID,
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_drawable_preview_new (drawable);
preview = gimp_drawable_preview_new (drawable, NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
......
......@@ -703,12 +703,12 @@ neon_dialog (GimpDrawable *drawable)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_drawable_preview_new (drawable);
preview = gimp_drawable_preview_new (drawable, NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
g_signal_connect (preview, "invalidated",
G_CALLBACK (neon_preview_update), NULL);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
......
......@@ -245,7 +245,7 @@ sobel_dialog (GimpDrawable *drawable)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_drawable_preview_new (drawable);
preview = gimp_drawable_preview_new (drawable, NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
g_signal_connect (preview, "invalidated",
......
......@@ -442,8 +442,8 @@ softglow (GimpDrawable *drawable,
pr = gimp_pixel_rgns_process (pr))
{
guchar *src_ptr = src_rgn.data;
guchar *dest_ptr = preview_buffer +
bytes *
guchar *dest_ptr = preview_buffer +
bytes *
((src_rgn.y - y1) * width + (src_rgn.x - x1));
guchar *blur_ptr = dest + (src_rgn.y - y1) * width + (src_rgn.x - x1);
......@@ -471,7 +471,8 @@ softglow (GimpDrawable *drawable,
}
else
{
gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, width, height, TRUE, TRUE);
gimp_pixel_rgn_init (&dest_rgn,
drawable, x1, y1, width, height, TRUE, TRUE);
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
......@@ -674,7 +675,7 @@ softglow_dialog (GimpDrawable *drawable)
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
preview = gimp_drawable_preview_new (drawable);
preview = gimp_drawable_preview_new (drawable, NULL);
gtk_box_pack_start (GTK_BOX (hbox), preview, FALSE, FALSE, 0);
gtk_widget_show (preview);
g_signal_connect_swapped (preview, "invalidated",
......
......@@ -230,10 +230,10 @@ typedef struct {
*/
static void
spread_func (gint x,
gint y,
guchar *dest,
gint bpp,
spread_func (gint x,
gint y,
guchar *dest,
gint bpp,
gpointer data)
{
SpreadParam_t *param = (SpreadParam_t*) data;
......@@ -242,11 +242,11 @@ spread_func (gint x,
gint xi, yi;
/* get random angle, x distance, and y distance */
xdist = (param->x_amount > 0
? g_rand_int_range (param->gr, -param->x_amount, param->x_amount)
xdist = (param->x_amount > 0
? g_rand_int_range (param->gr, -param->x_amount, param->x_amount)
: 0);
ydist = (param->y_amount > 0