libgimpwidgets/gimppreview.c split this widget into itself (more abstract

* libgimpwidgets/gimppreview.c
* libgimpwidgets/gimppreview.h: split this widget into itself (more
  abstract now) and ...

* libgimpwidgets/gimpscrolledpreview.c
* libgimpwidgets/gimpscrolledpreview.h: this widget which also have
  some scrollbars and a nagivation preview.

* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.

* libgimp/gimpaspectpreview.c
* libgimp/gimpaspectpreview.h: Added this widget, derived from
  GimpPreview, which has always the same ratio has the given drawable.
  This widget has almost the same api as GimpDrawablePreview, and is
  useful for plug-ins that show the whole (scaled) drawable in their
  preview.

* libgimp/gimpdrawablepreview.c
* libgimp/gimpdrawablepreview.h: GimpDrawablePreview is now derived
  from GimpScrolledPreview.

* libgimp/Makefile.am
* libgimp/gimpui.h
* libgimp/gimpuitypes.h: changed accordingly.

* plug-ins/common/plasma.c: use a GimpAspectPreview.

* plug-ins/common/bumpmap.c
* plug-ins/common/cartoon.c
* plug-ins/common/deinterlace.c
* plug-ins/common/despeckle.c
* plug-ins/common/dog.c
* plug-ins/common/edge.c
* plug-ins/common/engrave.c
* plug-ins/common/exchange.c
* plug-ins/common/gauss.c
* plug-ins/common/grid.c
* plug-ins/common/mblur.c
* plug-ins/common/neon.c
* plug-ins/common/noisify.c
* plug-ins/common/oilify.c
* plug-ins/common/photocopy.c
* plug-ins/common/sel_gauss.c
* plug-ins/common/sharpen.c
* plug-ins/common/shift.c
* plug-ins/common/sobel.c
* plug-ins/common/softglow.c
* plug-ins/common/spread.c
* plug-ins/common/struc.c
* plug-ins/common/unsharp.c
* plug-ins/common/wind.c: use gimp_scrolled_preview_get_position
  instead of gimp_preview_get_position.
This commit is contained in:
David Odin 2004-09-28 23:23:09 +00:00
parent a8f621fe9e
commit a001920ead
39 changed files with 1196 additions and 599 deletions

View File

@ -1,3 +1,59 @@
2004-09-29 DindinX <dindinx@gimp.org>
* libgimpwidgets/gimppreview.c
* libgimpwidgets/gimppreview.h: split this widget into itself (more
abstract now) and ...
* libgimpwidgets/gimpscrolledpreview.c
* libgimpwidgets/gimpscrolledpreview.h: this widget which also have
some scrollbars and a nagivation preview.
* libgimpwidgets/Makefile.am
* libgimpwidgets/gimpwidgetstypes.h: changed accordingly.
* libgimp/gimpaspectpreview.c
* libgimp/gimpaspectpreview.h: Added this widget, derived from
GimpPreview, which has always the same ratio has the given drawable.
This widget has almost the same api as GimpDrawablePreview, and is
useful for plug-ins that show the whole (scaled) drawable in their
preview.
* libgimp/gimpdrawablepreview.c
* libgimp/gimpdrawablepreview.h: GimpDrawablePreview is now derived
from GimpScrolledPreview.
* libgimp/Makefile.am
* libgimp/gimpui.h
* libgimp/gimpuitypes.h: changed accordingly.
* plug-ins/common/plasma.c: use a GimpAspectPreview.
* plug-ins/common/bumpmap.c
* plug-ins/common/cartoon.c
* plug-ins/common/deinterlace.c
* plug-ins/common/despeckle.c
* plug-ins/common/dog.c
* plug-ins/common/edge.c
* plug-ins/common/engrave.c
* plug-ins/common/exchange.c
* plug-ins/common/gauss.c
* plug-ins/common/grid.c
* plug-ins/common/mblur.c
* plug-ins/common/neon.c
* plug-ins/common/noisify.c
* plug-ins/common/oilify.c
* plug-ins/common/photocopy.c
* plug-ins/common/sel_gauss.c
* plug-ins/common/sharpen.c
* plug-ins/common/shift.c
* plug-ins/common/sobel.c
* plug-ins/common/softglow.c
* plug-ins/common/spread.c
* plug-ins/common/struc.c
* plug-ins/common/unsharp.c
* plug-ins/common/wind.c: use gimp_scrolled_preview_get_position
instead of gimp_preview_get_position.
2004-09-29 Michael Natterer <mitch@gimp.org>
* libgimp/gimpregioniterator.[ch]: renamed the "run_mode"

View File

@ -224,6 +224,8 @@ libgimpui_2_0_la_SOURCES = \
gimpuitypes.h \
gimpmenu.c \
gimpmenu.h \
gimpaspectpreview.c \
gimpaspectpreview.h \
gimpbrushmenu.c \
gimpbrushmenu.h \
gimpdrawablepreview.c \
@ -279,6 +281,7 @@ gimpinclude_HEADERS = \
gimpui.h \
gimpuitypes.h \
gimpmenu.h \
gimpaspectpreview.h \
gimpbrushmenu.h \
gimpdrawablepreview.h \
gimpfontmenu.h \

185
libgimp/gimpaspectpreview.c Normal file
View File

@ -0,0 +1,185 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpaspectpreview.c
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "gimpuitypes.h"
#include "gimp.h"
#include "libgimp-intl.h"
#include "gimpaspectpreview.h"
static void gimp_aspect_preview_class_init (GimpAspectPreviewClass *klass);
static void gimp_aspect_preview_init (GimpAspectPreview *preview);
static void gimp_aspect_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_aspect_preview_draw (GimpPreview *preview);
static GimpPreviewClass *parent_class = NULL;
GType
gimp_aspect_preview_get_type (void)
{
static GType preview_type = 0;
if (! preview_type)
{
static const GTypeInfo preview_info =
{
sizeof (GimpAspectPreviewClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_aspect_preview_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpAspectPreview),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_aspect_preview_init,
};
preview_type = g_type_register_static (GIMP_TYPE_PREVIEW,
"GimpAspectPreview",
&preview_info, 0);
}
return preview_type;
}
static void
gimp_aspect_preview_class_init (GimpAspectPreviewClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
widget_class->style_set = gimp_aspect_preview_style_set;
preview_class->draw = gimp_aspect_preview_draw;
}
static void
gimp_aspect_preview_init (GimpAspectPreview *preview)
{
g_object_set (GIMP_PREVIEW (preview)->area,
"check-size", gimp_check_size (),
"check-type", gimp_check_type (),
NULL);
}
static void
gimp_aspect_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style)
{
GimpAspectPreview *preview = GIMP_ASPECT_PREVIEW (widget);
gint size;
gint width, height;
if (GTK_WIDGET_CLASS (parent_class)->style_set)
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
gtk_widget_style_get (widget,
"size", &size,
NULL);
width = gimp_drawable_width (preview->drawable->drawable_id);
height = gimp_drawable_height (preview->drawable->drawable_id);
if (width > height)
{
GIMP_PREVIEW (preview)->width = MIN (width, size);
GIMP_PREVIEW (preview)->height = (height * GIMP_PREVIEW (preview)->width) / width;
}
else
{
GIMP_PREVIEW (preview)->height = MIN (height, size);
GIMP_PREVIEW (preview)->width = (width * GIMP_PREVIEW (preview)->height) / height;
}
gtk_widget_set_size_request (GIMP_PREVIEW (preview)->area,
GIMP_PREVIEW (preview)->width,
GIMP_PREVIEW (preview)->height);
}
GtkWidget *
gimp_aspect_preview_new (GimpDrawable *drawable,
gboolean *toggle)
{
GimpAspectPreview *preview;
gint width, height;
preview = g_object_new (GIMP_TYPE_ASPECT_PREVIEW, NULL);
preview->drawable = drawable;
width = gimp_drawable_width (drawable->drawable_id);
height = gimp_drawable_height (drawable->drawable_id);
gimp_preview_set_bounds (GIMP_PREVIEW (preview), 0, 0, width, height);
g_object_set (GIMP_PREVIEW (preview)->frame,
"ratio", (gdouble)width / (gdouble)height,
NULL);
return GTK_WIDGET (preview);
}
static void
gimp_aspect_preview_draw (GimpPreview *preview)
{
g_return_if_fail (GIMP_IS_ASPECT_PREVIEW (preview));
gimp_preview_area_fill (GIMP_PREVIEW_AREA (preview->area),
0, 0,
preview->width,
preview->height,
0, 0, 0);
}
/**
* gimp_aspect_preview_draw_buffer:
* @preview: a #GimpAspectPreview widget
* @buffer:
* @rowstride:
*
* Since: GIMP 2.2
**/
void
gimp_aspect_preview_draw_buffer (GimpAspectPreview *preview,
const guchar *buffer,
gint rowstride)
{
g_return_if_fail (GIMP_IS_ASPECT_PREVIEW (preview));
g_return_if_fail (buffer != NULL);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (GIMP_PREVIEW (preview)->area),
0, 0,
GIMP_PREVIEW (preview)->width,
GIMP_PREVIEW (preview)->height,
gimp_drawable_type (preview->drawable->drawable_id),
buffer,
rowstride);
}

View File

@ -0,0 +1,67 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpaspectpreview.h
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_ASPECT_PREVIEW_H__
#define __GIMP_ASPECT_PREVIEW_H__
#include <libgimpwidgets/gimppreview.h>
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_ASPECT_PREVIEW (gimp_aspect_preview_get_type ())
#define GIMP_ASPECT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ASPECT_PREVIEW, GimpAspectPreview))
#define GIMP_ASPECT_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ASPECT_PREVIEW, GimpAspectPreviewClass))
#define GIMP_IS_ASPECT_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ASPECT_PREVIEW))
#define GIMP_IS_ASPECT_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ASPECT_PREVIEW))
#define GIMP_ASPECT_PREVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ASPECT_PREVIEW, GimpAspectPreviewClass))
typedef struct _GimpAspectPreviewClass GimpAspectPreviewClass;
struct _GimpAspectPreview
{
GimpPreview parent_instance;
/*< private >*/
GimpDrawable *drawable;
};
struct _GimpAspectPreviewClass
{
GimpPreviewClass parent_class;
};
GType gimp_aspect_preview_get_type (void) G_GNUC_CONST;
GtkWidget *gimp_aspect_preview_new (GimpDrawable *drawable,
gboolean *toggle);
void gimp_aspect_preview_draw_buffer (GimpAspectPreview *preview,
const guchar *buffer,
gint rowstride);
G_END_DECLS
#endif /* __GIMP_ASPECT_PREVIEW_H__ */

View File

@ -42,14 +42,12 @@ static void gimp_drawable_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_drawable_preview_draw_original (GimpPreview *preview);
static void gimp_drawable_preview_draw_thumb (GimpPreview *preview,
static void gimp_drawable_preview_draw_thumb (GimpScrolledPreview *preview,
GimpPreviewArea *area,
gint width,
gint height);
static GimpPreviewClass *parent_class = NULL;
static GimpScrolledPreviewClass *parent_class = NULL;
GType
gimp_drawable_preview_get_type (void)
@ -71,7 +69,7 @@ gimp_drawable_preview_get_type (void)
(GInstanceInitFunc) gimp_drawable_preview_init
};
preview_type = g_type_register_static (GIMP_TYPE_PREVIEW,
preview_type = g_type_register_static (GIMP_TYPE_SCROLLED_PREVIEW,
"GimpDrawablePreview",
&drawable_preview_info, 0);
}
@ -84,13 +82,14 @@ gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
GimpScrolledPreviewClass *scrolled_preview_class = GIMP_SCROLLED_PREVIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
widget_class->style_set = gimp_drawable_preview_style_set;
widget_class->style_set = gimp_drawable_preview_style_set;
preview_class->draw = gimp_drawable_preview_draw_original;
preview_class->draw_thumb = gimp_drawable_preview_draw_thumb;
preview_class->draw = gimp_drawable_preview_draw_original;
scrolled_preview_class->draw_thumb = gimp_drawable_preview_draw_thumb;
}
static void
@ -126,6 +125,7 @@ static void
gimp_drawable_preview_draw_original (GimpPreview *preview)
{
GimpDrawablePreview *drawable_preview = GIMP_DRAWABLE_PREVIEW (preview);
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
GimpDrawable *drawable = drawable_preview->drawable;
guchar *buffer;
GimpPixelRgn srcPR;
@ -137,20 +137,20 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
rowstride = preview->width * drawable->bpp;
buffer = g_new (guchar, rowstride * preview->height);
preview->xoff = CLAMP (preview->xoff,
0, preview->xmax - preview->xmin - preview->width);
preview->yoff = CLAMP (preview->yoff,
0, preview->ymax - preview->ymin - preview->height);
scrolled_preview->xoff = CLAMP (scrolled_preview->xoff,
0, preview->xmax - preview->xmin - preview->width);
scrolled_preview->yoff = CLAMP (scrolled_preview->yoff,
0, preview->ymax - preview->ymin - preview->height);
gimp_pixel_rgn_init (&srcPR, drawable,
preview->xoff + preview->xmin,
preview->yoff + preview->ymin,
scrolled_preview->xoff + preview->xmin,
scrolled_preview->yoff + preview->ymin,
preview->width, preview->height,
FALSE, FALSE);
gimp_pixel_rgn_get_rect (&srcPR, buffer,
preview->xoff + preview->xmin,
preview->yoff + preview->ymin,
scrolled_preview->xoff + preview->xmin,
scrolled_preview->yoff + preview->ymin,
preview->width, preview->height);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
@ -162,10 +162,10 @@ gimp_drawable_preview_draw_original (GimpPreview *preview)
}
static void
gimp_drawable_preview_draw_thumb (GimpPreview *preview,
GimpPreviewArea *area,
gint width,
gint height)
gimp_drawable_preview_draw_thumb (GimpScrolledPreview *preview,
GimpPreviewArea *area,
gint width,
gint height)
{
GimpDrawablePreview *drawable_preview = GIMP_DRAWABLE_PREVIEW (preview);
GimpDrawable *drawable = drawable_preview->drawable;
@ -214,17 +214,18 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
const guchar *buf,
gint rowstride)
{
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
GimpDrawable *drawable = preview->drawable;
gint32 image_id;
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
GimpScrolledPreview *scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
GimpDrawable *drawable = preview->drawable;
gint32 image_id;
image_id = gimp_drawable_get_image (drawable->drawable_id);
if (gimp_selection_is_empty (image_id))
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (gimp_preview->area),
x - gimp_preview->xoff - gimp_preview->xmin,
y - gimp_preview->yoff - gimp_preview->ymin,
x - scrolled_preview->xoff - gimp_preview->xmin,
y - scrolled_preview->yoff - gimp_preview->ymin,
width,
height,
gimp_drawable_type (drawable->drawable_id),
@ -254,8 +255,8 @@ gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
gimp_pixel_rgn_get_rect (&selection_rgn, sel, x, y, width, height);
gimp_preview_area_mask (GIMP_PREVIEW_AREA (gimp_preview->area),
x - gimp_preview->xoff - gimp_preview->xmin,
y - gimp_preview->yoff - gimp_preview->ymin,
x - scrolled_preview->xoff - gimp_preview->xmin,
y - scrolled_preview->yoff - gimp_preview->ymin,
width,
height,
gimp_drawable_type (drawable->drawable_id),
@ -380,17 +381,19 @@ gimp_drawable_preview_draw_buffer (GimpDrawablePreview *preview,
const guchar *buffer,
gint rowstride)
{
GimpPreview *gimp_preview;
GimpPreview *gimp_preview;
GimpScrolledPreview *scrolled_preview;
g_return_if_fail (GIMP_IS_DRAWABLE_PREVIEW (preview));
g_return_if_fail (preview->drawable != NULL);
g_return_if_fail (buffer != NULL);
gimp_preview = GIMP_PREVIEW (preview);
gimp_preview = GIMP_PREVIEW (preview);
scrolled_preview = GIMP_SCROLLED_PREVIEW (preview);
gimp_drawable_preview_draw_area (preview,
gimp_preview->xmin + gimp_preview->xoff,
gimp_preview->ymin + gimp_preview->yoff,
gimp_preview->xmin + scrolled_preview->xoff,
gimp_preview->ymin + scrolled_preview->yoff,
gimp_preview->width,
gimp_preview->height,
buffer, rowstride);

View File

@ -22,7 +22,7 @@
#ifndef __GIMP_DRAWABLE_PREVIEW_H__
#define __GIMP_DRAWABLE_PREVIEW_H__
#include <libgimpwidgets/gimppreview.h>
#include <libgimpwidgets/gimpscrolledpreview.h>
G_BEGIN_DECLS
@ -42,14 +42,14 @@ typedef struct _GimpDrawablePreviewClass GimpDrawablePreviewClass;
struct _GimpDrawablePreview
{
GimpPreview parent_instance;
GimpScrolledPreview parent_instance;
GimpDrawable *drawable;
GimpDrawable *drawable;
};
struct _GimpDrawablePreviewClass
{
GimpPreviewClass parent_class;
GimpScrolledPreviewClass parent_class;
};

View File

@ -28,6 +28,7 @@
#include <libgimp/gimpexport.h>
#include <libgimp/gimpmenu.h>
#include <libgimp/gimpaspectpreview.h>
#include <libgimp/gimpbrushmenu.h>
#include <libgimp/gimpdrawablepreview.h>
#include <libgimp/gimpfontmenu.h>
@ -46,7 +47,7 @@ G_BEGIN_DECLS
void gimp_ui_init (const gchar *prog_name,
gboolean preview);
gboolean preview);
G_END_DECLS

View File

@ -29,6 +29,7 @@ G_BEGIN_DECLS
/* For information look into the html documentation */
typedef struct _GimpAspectPreview GimpAspectPreview;
typedef struct _GimpDrawablePreview GimpDrawablePreview;
typedef struct _GimpProgressBar GimpProgressBar;

View File

@ -124,6 +124,8 @@ libgimpwidgets_2_0_la_sources = \
gimppreviewarea.h \
gimpquerybox.c \
gimpquerybox.h \
gimpscrolledpreview.c \
gimpscrolledpreview.h \
gimpsizeentry.c \
gimpsizeentry.h \
gimpstock.c \
@ -182,6 +184,7 @@ libgimpwidgetsinclude_HEADERS = \
gimppreview.h \
gimppreviewarea.h \
gimpquerybox.h \
gimpscrolledpreview.h \
gimpsizeentry.h \
gimpstock.h \
gimpunitmenu.h

View File

@ -33,8 +33,6 @@
#define DEFAULT_SIZE 150
#define POPUP_SIZE 100
#define PEN_WIDTH 3
#define PREVIEW_TIMEOUT 200
@ -78,32 +76,13 @@ static gboolean gimp_preview_area_event (GtkWidget *area,
GdkEvent *event,
GimpPreview *preview);
static void gimp_preview_h_scroll (GtkAdjustment *hadj,
GimpPreview *preview);
static void gimp_preview_v_scroll (GtkAdjustment *vadj,
GimpPreview *preview);
static gboolean gimp_preview_nav_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpPreview *preview);
static void gimp_preview_nav_popup_realize (GtkWidget *widget,
GimpPreview *preview);
static void gimp_preview_nav_popup_unrealize (GtkWidget *widget,
GimpPreview *preview);
static gboolean gimp_preview_nav_popup_event (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview);
static gboolean gimp_preview_nav_popup_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpPreview *preview);
static void gimp_preview_toggle_callback (GtkWidget *toggle,
GimpPreview *preview);
static void gimp_preview_notify_checks (GimpPreview *preview);
static gboolean gimp_preview_invalidate_now (GimpPreview *preview);
static void gimp_preview_set_cursor (GimpPreview *preview);
static guint preview_signals[LAST_SIGNAL] = { 0 };
@ -165,7 +144,7 @@ gimp_preview_class_init (GimpPreviewClass *klass)
widget_class->popup_menu = gimp_preview_popup_menu;
klass->draw = NULL;
klass->draw_thumb = NULL;
klass->set_cursor = gimp_preview_set_cursor;
g_object_class_install_property (object_class,
PROP_UPDATE,
@ -186,10 +165,7 @@ gimp_preview_class_init (GimpPreviewClass *klass)
static void
gimp_preview_init (GimpPreview *preview)
{
GtkWidget *table;
GtkWidget *frame;
GtkWidget *image;
GtkObject *adj;
gdouble xalign = 0.0;
gtk_box_set_homogeneous (GTK_BOX (preview), FALSE);
@ -203,13 +179,10 @@ gimp_preview_init (GimpPreview *preview)
gtk_box_pack_start (GTK_BOX (preview), preview->frame, TRUE, TRUE, 0);
gtk_widget_show (preview->frame);
table = gtk_table_new (3, 2, FALSE);
gtk_container_add (GTK_CONTAINER (preview->frame), table);
gtk_widget_show (table);
preview->table = gtk_table_new (3, 2, FALSE);
gtk_container_add (GTK_CONTAINER (preview->frame), preview->table);
gtk_widget_show (preview->table);
preview->xoff = 0;
preview->yoff = 0;
preview->in_drag = FALSE;
preview->timeout_id = 0;
preview->xmin = preview->ymin = 0;
@ -217,39 +190,10 @@ gimp_preview_init (GimpPreview *preview)
preview->width = preview->xmax - preview->xmin;
preview->height = preview->ymax - preview->ymin;
preview->nav_popup = NULL;
/* scrollbars */
adj = gtk_adjustment_new (0, 0, preview->width - 1, 1.0,
preview->width, preview->width);
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_preview_h_scroll),
preview);
preview->hscr = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->hscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (table), preview->hscr, 0,1, 1,2,
GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
adj = gtk_adjustment_new (0, 0, preview->height - 1, 1.0,
preview->height, preview->height);
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_preview_v_scroll),
preview);
preview->vscr = gtk_vscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->vscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (table), preview->vscr, 1,2, 0,1,
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
/* preview area */
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE (table), frame, 0,1, 0,1,
gtk_table_attach (GTK_TABLE (preview->table), frame, 0,1, 0,1,
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
gtk_widget_show (frame);
@ -285,19 +229,6 @@ gimp_preview_init (GimpPreview *preview)
G_CALLBACK (gimp_preview_area_size_allocate),
preview);
/* navigation icon */
preview->nav_icon = gtk_event_box_new ();
gtk_table_attach (GTK_TABLE (table), preview->nav_icon, 1,2, 1,2,
GTK_SHRINK, GTK_SHRINK, 0, 0);
image = gtk_image_new_from_stock (GIMP_STOCK_NAVIGATION, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (preview->nav_icon), image);
gtk_widget_show (image);
g_signal_connect (preview->nav_icon, "button_press_event",
G_CALLBACK (gimp_preview_nav_button_press),
preview);
/* toggle button to (des)activate the instant preview */
preview->toggle = gtk_check_button_new_with_mnemonic (_("_Preview"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (preview->toggle),
@ -321,12 +252,6 @@ gimp_preview_dispose (GObject *object)
preview->timeout_id = 0;
}
if (preview->nav_popup)
{
gtk_widget_destroy (preview->nav_popup);
preview->nav_popup = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
@ -401,32 +326,16 @@ gimp_preview_area_realize (GtkWidget *widget,
{
GdkDisplay *display = gtk_widget_get_display (widget);
g_return_if_fail (preview->cursor_move == NULL);
g_return_if_fail (preview->cursor_busy == NULL);
preview->cursor_move = gdk_cursor_new_for_display (display, GDK_FLEUR);
preview->cursor_busy = gdk_cursor_new_for_display (display, GDK_WATCH);
if (preview->xmax - preview->xmin > preview->width ||
preview->ymax - preview->ymin > preview->height)
{
gdk_window_set_cursor (widget->window, preview->cursor_move);
}
else
{
gdk_window_set_cursor (widget->window, NULL);
}
}
static void
gimp_preview_area_unrealize (GtkWidget *widget,
GimpPreview *preview)
{
if (preview->cursor_move)
{
gdk_cursor_unref (preview->cursor_move);
preview->cursor_move = NULL;
}
if (preview->cursor_busy)
{
gdk_cursor_unref (preview->cursor_busy);
@ -439,69 +348,12 @@ gimp_preview_area_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpPreview *preview)
{
GdkCursor *cursor = NULL;
gint width = preview->xmax - preview->xmin;
gint height = preview->ymax - preview->ymin;
gint width = preview->xmax - preview->xmin;
gint height = preview->ymax - preview->ymin;
preview->width = MIN (width, allocation->width);
preview->height = MIN (height, allocation->height);
if (width > preview->width)
{
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
adj->lower = 0;
adj->upper = width;
adj->page_size = preview->width;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
gtk_adjustment_changed (adj);
gtk_widget_show (preview->hscr);
cursor = preview->cursor_move;
}
else
{
gtk_widget_hide (preview->hscr);
}
if (height > preview->height)
{
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->vscr));
adj->lower = 0;
adj->upper = height;
adj->page_size = preview->height;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
gtk_adjustment_changed (adj);
gtk_widget_show (preview->vscr);
cursor = preview->cursor_move;
}
else
{
gtk_widget_hide (preview->vscr);
}
if (GTK_WIDGET_VISIBLE (preview->vscr) &&
GTK_WIDGET_VISIBLE (preview->hscr) &&
GIMP_PREVIEW_GET_CLASS (preview)->draw_thumb)
{
gtk_widget_show (preview->nav_icon);
}
else
{
gtk_widget_hide (preview->nav_icon);
}
if (GTK_WIDGET_REALIZED (widget))
gdk_window_set_cursor (widget->window, cursor);
gimp_preview_draw (preview);
gimp_preview_invalidate (preview);
}
@ -519,61 +371,12 @@ gimp_preview_area_event (GtkWidget *area,
case GDK_BUTTON_PRESS:
switch (button_event->button)
{
case 1:
gtk_widget_get_pointer (area, &preview->drag_x, &preview->drag_y);
preview->drag_xoff = preview->xoff;
preview->drag_yoff = preview->yoff;
preview->in_drag = TRUE;
gtk_grab_add (area);
break;
case 2:
break;
case 3:
gimp_preview_area_menu_popup (GIMP_PREVIEW_AREA (area), button_event);
return TRUE;
}
break;
case GDK_BUTTON_RELEASE:
if (preview->in_drag && button_event->button == 1)
{
gtk_grab_remove (area);
preview->in_drag = FALSE;
}
break;
case GDK_MOTION_NOTIFY:
if (preview->in_drag)
{
gint x, y;
gint dx, dy;
gint xoff, yoff;
gtk_widget_get_pointer (area, &x, &y);
dx = x - preview->drag_x;
dy = y - preview->drag_y;
xoff = CLAMP (preview->drag_xoff - dx,
0, preview->xmax - preview->xmin - preview->width);
yoff = CLAMP (preview->drag_yoff - dy,
0, preview->ymax - preview->ymin - preview->height);
if (preview->xoff != xoff || preview->yoff != 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);
}
}
break;
default:
break;
}
@ -581,238 +384,6 @@ gimp_preview_area_event (GtkWidget *area,
return FALSE;
}
static void
gimp_preview_h_scroll (GtkAdjustment *hadj,
GimpPreview *preview)
{
preview->xoff = hadj->value;
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
preview->xoff, preview->yoff);
if (! preview->in_drag)
{
gimp_preview_draw (preview);
gimp_preview_invalidate (preview);
}
}
static void
gimp_preview_v_scroll (GtkAdjustment *vadj,
GimpPreview *preview)
{
preview->yoff = vadj->value;
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (preview->area),
preview->xoff, preview->yoff);
if (! preview->in_drag)
{
gimp_preview_draw (preview);
gimp_preview_invalidate (preview);
}
}
static gboolean
gimp_preview_nav_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpPreview *preview)
{
if (preview->nav_popup)
return TRUE;
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
{
GtkWidget *outer;
GtkWidget *inner;
GtkWidget *area;
GdkCursor *cursor;
gint x, y;
gdouble h, v;
preview->nav_popup = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_screen (GTK_WINDOW (preview->nav_popup),
gtk_widget_get_screen (widget));
outer = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (outer), GTK_SHADOW_OUT);
gtk_container_add (GTK_CONTAINER (preview->nav_popup), outer);
gtk_widget_show (outer);
inner = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (inner), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (outer), inner);
gtk_widget_show (inner);
area = gimp_preview_area_new ();
gtk_container_add (GTK_CONTAINER (inner), area);
g_signal_connect (area, "realize",
G_CALLBACK (gimp_preview_nav_popup_realize),
preview);
g_signal_connect (area, "unrealize",
G_CALLBACK (gimp_preview_nav_popup_unrealize),
preview);
g_signal_connect (area, "event",
G_CALLBACK (gimp_preview_nav_popup_event),
preview);
g_signal_connect_after (area, "expose_event",
G_CALLBACK (gimp_preview_nav_popup_expose),
preview);
GIMP_PREVIEW_GET_CLASS (preview)->draw_thumb (preview,
GIMP_PREVIEW_AREA (area),
POPUP_SIZE, POPUP_SIZE);
gtk_widget_realize (area);
gtk_widget_show (area);
gdk_window_get_origin (widget->window, &x, &y);
h = ((gdouble) (preview->xoff + preview->width / 2) /
(gdouble) (preview->xmax - preview->xmin));
v = ((gdouble) (preview->yoff + preview->height / 2) /
(gdouble) (preview->ymax - preview->ymin));
x += event->x - h * (gdouble) GIMP_PREVIEW_AREA (area)->width;
y += event->y - v * (gdouble) GIMP_PREVIEW_AREA (area)->height;
gtk_window_move (GTK_WINDOW (preview->nav_popup),
x - 2 * widget->style->xthickness,
y - 2 * widget->style->ythickness);
gtk_widget_show (preview->nav_popup);
gtk_grab_add (area);
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
GDK_FLEUR);
gdk_pointer_grab (area->window, TRUE,
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
area->window, cursor,
event->time);
gdk_cursor_unref (cursor);
}
return TRUE;
}
static void
gimp_preview_nav_popup_realize (GtkWidget *widget,
GimpPreview *preview)
{
if (! preview->nav_gc)
{
preview->nav_gc = gdk_gc_new (widget->window);
gdk_gc_set_function (preview->nav_gc, GDK_INVERT);
gdk_gc_set_line_attributes (preview->nav_gc,
PEN_WIDTH,
GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
}
}
static void
gimp_preview_nav_popup_unrealize (GtkWidget *widget,
GimpPreview *preview)
{
if (preview->nav_gc)
{
g_object_unref (preview->nav_gc);
preview->nav_gc = NULL;
}
}
static gboolean
gimp_preview_nav_popup_event (GtkWidget *widget,
GdkEvent *event,
GimpPreview *preview)
{
switch (event->type)
{
case GDK_BUTTON_RELEASE:
{
GdkEventButton *button_event = (GdkEventButton *) event;
if (button_event->button == 1)
{
gtk_grab_remove (widget);
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
button_event->time);
gtk_widget_destroy (preview->nav_popup);
preview->nav_popup = NULL;
}
}
break;
case GDK_MOTION_NOTIFY:
{
GdkEventMotion *motion_event = (GdkEventMotion *) event;
GtkAdjustment *hadj;
GtkAdjustment *vadj;
gdouble x, y;
hadj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
vadj = gtk_range_get_adjustment (GTK_RANGE (preview->vscr));
x = (motion_event->x *
(hadj->upper - hadj->lower) / widget->allocation.width);
y = (motion_event->y *
(vadj->upper - vadj->lower) / widget->allocation.height);
x += hadj->lower - hadj->page_size / 2;
y += vadj->lower - vadj->page_size / 2;
gtk_adjustment_set_value (hadj, CLAMP (x,
hadj->lower,
hadj->upper - hadj->page_size));
gtk_adjustment_set_value (vadj, CLAMP (y,
vadj->lower,
vadj->upper - vadj->page_size));
gtk_widget_queue_draw (widget);
}
break;
default:
break;
}
return FALSE;
}
static gboolean
gimp_preview_nav_popup_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpPreview *preview)
{
gdouble x, y;
gdouble w, h;
x = (gdouble) preview->xoff / (gdouble) (preview->xmax - preview->xmin);
y = (gdouble) preview->yoff / (gdouble) (preview->ymax - preview->ymin);
w = (gdouble) preview->width / (gdouble) (preview->xmax - preview->xmin);
h = (gdouble) preview->height / (gdouble) (preview->ymax - preview->ymin);
gdk_gc_set_clip_rectangle (preview->nav_gc, &event->area);
gdk_draw_rectangle (widget->window, preview->nav_gc,
FALSE,
x * (gdouble) widget->allocation.width + PEN_WIDTH / 2,
y * (gdouble) widget->allocation.height + PEN_WIDTH / 2,
MAX (1,
ceil (w * widget->allocation.width) - PEN_WIDTH),
MAX (1,
ceil (h * widget->allocation.height) - PEN_WIDTH));
return FALSE;
}
static void
gimp_preview_toggle_callback (GtkWidget *toggle,
GimpPreview *preview)
@ -847,6 +418,10 @@ static gboolean
gimp_preview_invalidate_now (GimpPreview *preview)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (preview));
GimpPreviewClass *class = GIMP_PREVIEW_GET_CLASS (preview);
if (class->draw)
class->draw (preview);
preview->timeout_id = 0;
@ -859,16 +434,7 @@ gimp_preview_invalidate_now (GimpPreview *preview)
g_signal_emit (preview, preview_signals[INVALIDATED], 0);
if (preview->xmax - preview->xmin > preview->width ||
preview->ymax - preview->ymin > preview->height)
{
gdk_window_set_cursor (preview->area->window, preview->cursor_move);
}
else
{
gdk_window_set_cursor (preview->area->window, NULL);
}
class->set_cursor (preview);
gdk_window_set_cursor (toplevel->window, NULL);
}
else
@ -879,6 +445,12 @@ gimp_preview_invalidate_now (GimpPreview *preview)
return FALSE;
}
static void
gimp_preview_set_cursor (GimpPreview *preview)
{
gdk_window_set_cursor (preview->area->window, NULL);
}
/**
* gimp_preview_set_update:
* @preview: a #GimpPreview widget
@ -973,28 +545,6 @@ gimp_preview_get_size (GimpPreview *preview,
*height = preview->height;
}
/**
* gimp_preview_get_position:
* @preview: a #GimpPreview widget
* @x: return location for the horizontal offset
* @y: return location for the vertical offset
*
* Since: GIMP 2.2
**/
void
gimp_preview_get_position (GimpPreview *preview,
gint *x,
gint *y)
{
g_return_if_fail (GIMP_IS_PREVIEW (preview));
if (x)
*x = preview->xoff + preview->xmin;
if (y)
*y = preview->yoff + preview->ymin;
}
/*
* gimp_preview_draw:
* @preview: a #GimpPreview widget

View File

@ -48,36 +48,25 @@ struct _GimpPreview
/*< protected >*/
GtkWidget *area;
GtkWidget *table;
GtkWidget *frame;
GtkWidget *hscr;
GtkWidget *vscr;
GtkWidget *nav_icon;
GtkWidget *nav_popup;
GtkWidget *toggle;
GdkCursor *cursor_move;
GdkCursor *cursor_busy;
GdkGC *nav_gc;
/*< private >*/
gint xoff, yoff;
gint xmin, xmax, ymin, ymax;
gint drag_x, drag_y;
gint drag_xoff, drag_yoff;
gint width, height;
gboolean in_drag;
guint timeout_id;
};
struct _GimpPreviewClass
{
GtkVBoxClass parent_class;
/* virtuals */
void (* draw) (GimpPreview *preview);
void (* draw_thumb) (GimpPreview *preview,
GimpPreviewArea *area,
gint width,
gint height);
void (* set_cursor) (GimpPreview *preview);
/* signal */
void (* invalidated) (GimpPreview *preview);
@ -99,9 +88,6 @@ void gimp_preview_set_bounds (GimpPreview *preview,
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_draw (GimpPreview *preview);
void gimp_preview_invalidate (GimpPreview *preview);

View File

@ -0,0 +1,642 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimppreview.c
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpmath/gimpmath.h"
#include "gimpwidgets.h"
#include "gimpscrolledpreview.h"
#include "libgimp/libgimp-intl.h"
#define POPUP_SIZE 100
#define PEN_WIDTH 3
static void gimp_scrolled_preview_class_init (GimpScrolledPreviewClass *klass);
static void gimp_scrolled_preview_init (GimpScrolledPreview *preview);
static void gimp_scrolled_preview_dispose (GObject *object);
static void gimp_scrolled_preview_area_realize (GtkWidget *widget,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_area_unrealize (GtkWidget *widget,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_area_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpScrolledPreview *preview);
static gboolean gimp_scrolled_preview_area_event (GtkWidget *area,
GdkEvent *event,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_h_scroll (GtkAdjustment *hadj,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_v_scroll (GtkAdjustment *vadj,
GimpScrolledPreview *preview);
static gboolean gimp_scrolled_preview_nav_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_nav_popup_realize (GtkWidget *widget,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_nav_popup_unrealize (GtkWidget *widget,
GimpScrolledPreview *preview);
static gboolean gimp_scrolled_preview_nav_popup_event (GtkWidget *widget,
GdkEvent *event,
GimpScrolledPreview *preview);
static gboolean gimp_scrolled_preview_nav_popup_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpScrolledPreview *preview);
static void gimp_scrolled_preview_set_cursor (GimpPreview *preview);
static GimpPreviewClass *parent_class = NULL;
GType
gimp_scrolled_preview_get_type (void)
{
static GType preview_type = 0;
if (! preview_type)
{
static const GTypeInfo preview_info =
{
sizeof (GimpScrolledPreviewClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_scrolled_preview_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpScrolledPreview),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_scrolled_preview_init,
};
preview_type = g_type_register_static (GIMP_TYPE_PREVIEW,
"GimpScrolledPreview",
&preview_info,
G_TYPE_FLAG_ABSTRACT);
}
return preview_type;
}
static void
gimp_scrolled_preview_class_init (GimpScrolledPreviewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->dispose = gimp_scrolled_preview_dispose;
klass->draw_thumb = NULL;
preview_class->set_cursor = gimp_scrolled_preview_set_cursor;
}
static void
gimp_scrolled_preview_init (GimpScrolledPreview *preview)
{
GtkWidget *image;
GtkObject *adj;
preview->xoff = 0;
preview->yoff = 0;
preview->in_drag = FALSE;
preview->nav_popup = NULL;
/* scrollbars */
adj = gtk_adjustment_new (0, 0, GIMP_PREVIEW (preview)->width - 1, 1.0,
GIMP_PREVIEW (preview)->width,
GIMP_PREVIEW (preview)->width);
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_scrolled_preview_h_scroll),
preview);
preview->hscr = gtk_hscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->hscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (GIMP_PREVIEW (preview)->table),
preview->hscr, 0,1, 1,2,
GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
adj = gtk_adjustment_new (0, 0, GIMP_PREVIEW (preview)->height - 1, 1.0,
GIMP_PREVIEW (preview)->height,
GIMP_PREVIEW (preview)->height);
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_scrolled_preview_v_scroll),
preview);
preview->vscr = gtk_vscrollbar_new (GTK_ADJUSTMENT (adj));
gtk_range_set_update_policy (GTK_RANGE (preview->vscr),
GTK_UPDATE_CONTINUOUS);
gtk_table_attach (GTK_TABLE (GIMP_PREVIEW (preview)->table),
preview->vscr, 1,2, 0,1,
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
g_signal_connect (GIMP_PREVIEW (preview)->area, "event",
G_CALLBACK (gimp_scrolled_preview_area_event),
preview);
g_signal_connect (GIMP_PREVIEW (preview)->area, "realize",
G_CALLBACK (gimp_scrolled_preview_area_realize),
preview);
g_signal_connect (GIMP_PREVIEW (preview)->area, "unrealize",
G_CALLBACK (gimp_scrolled_preview_area_unrealize),
preview);
g_signal_connect (GIMP_PREVIEW (preview)->area, "size_allocate",
G_CALLBACK (gimp_scrolled_preview_area_size_allocate),
preview);
/* navigation icon */
preview->nav_icon = gtk_event_box_new ();
gtk_table_attach (GTK_TABLE (GIMP_PREVIEW(preview)->table),
preview->nav_icon, 1,2, 1,2,
GTK_SHRINK, GTK_SHRINK, 0, 0);
image = gtk_image_new_from_stock (GIMP_STOCK_NAVIGATION, GTK_ICON_SIZE_MENU);
gtk_container_add (GTK_CONTAINER (preview->nav_icon), image);
gtk_widget_show (image);
g_signal_connect (preview->nav_icon, "button_press_event",
G_CALLBACK (gimp_scrolled_preview_nav_button_press),
preview);
}
static void
gimp_scrolled_preview_dispose (GObject *object)
{
GimpScrolledPreview *preview = GIMP_SCROLLED_PREVIEW (object);
if (preview->nav_popup)
{
gtk_widget_destroy (preview->nav_popup);
preview->nav_popup = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_scrolled_preview_area_realize (GtkWidget *widget,
GimpScrolledPreview *preview)
{
GdkDisplay *display = gtk_widget_get_display (widget);
g_return_if_fail (preview->cursor_move == NULL);
preview->cursor_move = gdk_cursor_new_for_display (display, GDK_FLEUR);
gimp_scrolled_preview_set_cursor (GIMP_PREVIEW (preview));
}
static void
gimp_scrolled_preview_area_unrealize (GtkWidget *widget,
GimpScrolledPreview *preview)
{
if (preview->cursor_move)
{
gdk_cursor_unref (preview->cursor_move);
preview->cursor_move = NULL;
}
}
static void
gimp_scrolled_preview_area_size_allocate (GtkWidget *widget,
GtkAllocation *allocation,
GimpScrolledPreview *preview)
{
GdkCursor *cursor = NULL;
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
GIMP_PREVIEW (preview)->width = MIN (width, allocation->width);
GIMP_PREVIEW (preview)->height = MIN (height, allocation->height);
if (width > GIMP_PREVIEW (preview)->width)
{
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
adj->lower = 0;
adj->upper = width;
adj->page_size = GIMP_PREVIEW (preview)->width;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
gtk_adjustment_changed (adj);
gtk_widget_show (preview->hscr);
cursor = preview->cursor_move;
}
else
{
gtk_widget_hide (preview->hscr);
}
if (height > GIMP_PREVIEW (preview)->height)
{
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (preview->vscr));
adj->lower = 0;
adj->upper = height;
adj->page_size = GIMP_PREVIEW (preview)->height;
adj->step_increment = 1.0;
adj->page_increment = MAX (adj->page_size / 2.0, adj->step_increment);
gtk_adjustment_changed (adj);
gtk_widget_show (preview->vscr);
cursor = preview->cursor_move;
}
else
{
gtk_widget_hide (preview->vscr);
}
if (GTK_WIDGET_VISIBLE (preview->vscr) &&
GTK_WIDGET_VISIBLE (preview->hscr) &&
GIMP_SCROLLED_PREVIEW_GET_CLASS (preview)->draw_thumb)
{
gtk_widget_show (preview->nav_icon);
}
else
{
gtk_widget_hide (preview->nav_icon);
}
if (GTK_WIDGET_REALIZED (widget))
gdk_window_set_cursor (widget->window, cursor);
gimp_preview_draw (GIMP_PREVIEW (preview));
gimp_preview_invalidate (GIMP_PREVIEW (preview));
}
static gboolean
gimp_scrolled_preview_area_event (GtkWidget *area,
GdkEvent *event,
GimpScrolledPreview *preview)
{
GdkEventButton *button_event = (GdkEventButton *) event;
switch (event->type)
{
case GDK_BUTTON_PRESS:
switch (button_event->button)
{
case 1:
gtk_widget_get_pointer (area, &preview->drag_x, &preview->drag_y);
preview->drag_xoff = preview->xoff;
preview->drag_yoff = preview->yoff;
preview->in_drag = TRUE;
gtk_grab_add (area);
break;
case 2:
break;
case 3:
return TRUE;
}
break;
case GDK_BUTTON_RELEASE:
if (preview->in_drag && button_event->button == 1)
{
gtk_grab_remove (area);
preview->in_drag = FALSE;
}
break;
case GDK_MOTION_NOTIFY:
if (preview->in_drag)
{
gint x, y;
gint dx, dy;
gint xoff, yoff;
gtk_widget_get_pointer (area, &x, &y);
dx = x - preview->drag_x;
dy = y - preview->drag_y;
xoff = CLAMP (preview->drag_xoff - dx,
0, GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin - GIMP_PREVIEW (preview)->width);
yoff = CLAMP (preview->drag_yoff - dy,
0, GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin - GIMP_PREVIEW (preview)->height);
if (preview->xoff != xoff || preview->yoff != yoff)
{
gtk_range_set_value (GTK_RANGE (preview->hscr), xoff);
gtk_range_set_value (GTK_RANGE (preview->vscr), yoff);
gimp_preview_draw (GIMP_PREVIEW (preview));
gimp_preview_invalidate (GIMP_PREVIEW (preview));
}
}
break;
default:
break;
}
return FALSE;
}
static void
gimp_scrolled_preview_h_scroll (GtkAdjustment *hadj,
GimpScrolledPreview *preview)
{
preview->xoff = hadj->value;
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (GIMP_PREVIEW (preview)->area),
preview->xoff, preview->yoff);
if (! preview->in_drag)
{
gimp_preview_draw (GIMP_PREVIEW (preview));
gimp_preview_invalidate (GIMP_PREVIEW (preview));
}
}
static void
gimp_scrolled_preview_v_scroll (GtkAdjustment *vadj,
GimpScrolledPreview *preview)
{
preview->yoff = vadj->value;
gimp_preview_area_set_offsets (GIMP_PREVIEW_AREA (GIMP_PREVIEW (preview)->area),
preview->xoff, preview->yoff);
if (! preview->in_drag)
{
gimp_preview_draw (GIMP_PREVIEW (preview));
gimp_preview_invalidate (GIMP_PREVIEW (preview));
}
}
static gboolean
gimp_scrolled_preview_nav_button_press (GtkWidget *widget,
GdkEventButton *event,
GimpScrolledPreview *preview)
{
if (preview->nav_popup)
return TRUE;
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
{
GtkWidget *outer;
GtkWidget *inner;
GtkWidget *area;
GdkCursor *cursor;
gint x, y;
gdouble h, v;
preview->nav_popup = gtk_window_new (GTK_WINDOW_POPUP);
gtk_window_set_screen (GTK_WINDOW (preview->nav_popup),
gtk_widget_get_screen (widget));
outer = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (outer), GTK_SHADOW_OUT);
gtk_container_add (GTK_CONTAINER (preview->nav_popup), outer);
gtk_widget_show (outer);
inner = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (inner), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (outer), inner);
gtk_widget_show (inner);
area = gimp_preview_area_new ();
gtk_container_add (GTK_CONTAINER (inner), area);
g_signal_connect (area, "realize",
G_CALLBACK (gimp_scrolled_preview_nav_popup_realize),
preview);
g_signal_connect (area, "unrealize",
G_CALLBACK (gimp_scrolled_preview_nav_popup_unrealize),
preview);
g_signal_connect (area, "event",
G_CALLBACK (gimp_scrolled_preview_nav_popup_event),
preview);
g_signal_connect_after (area, "expose_event",
G_CALLBACK (gimp_scrolled_preview_nav_popup_expose),
preview);
GIMP_SCROLLED_PREVIEW_GET_CLASS (preview)->draw_thumb (preview,
GIMP_PREVIEW_AREA (area),
POPUP_SIZE, POPUP_SIZE);
gtk_widget_realize (area);
gtk_widget_show (area);
gdk_window_get_origin (widget->window, &x, &y);
h = ((gdouble) (preview->xoff + GIMP_PREVIEW (preview)->width / 2) /
(gdouble) (GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin));
v = ((gdouble) (preview->yoff + GIMP_PREVIEW (preview)->height / 2) /
(gdouble) (GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin));
x += event->x - h * (gdouble) GIMP_PREVIEW_AREA (area)->width;
y += event->y - v * (gdouble) GIMP_PREVIEW_AREA (area)->height;
gtk_window_move (GTK_WINDOW (preview->nav_popup),
x - 2 * widget->style->xthickness,
y - 2 * widget->style->ythickness);
gtk_widget_show (preview->nav_popup);
gtk_grab_add (area);
cursor = gdk_cursor_new_for_display (gtk_widget_get_display (widget),
GDK_FLEUR);
gdk_pointer_grab (area->window, TRUE,
GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
area->window, cursor,
event->time);
gdk_cursor_unref (cursor);
}
return TRUE;
}
static void
gimp_scrolled_preview_nav_popup_realize (GtkWidget *widget,
GimpScrolledPreview *preview)
{
if (! preview->nav_gc)
{
preview->nav_gc = gdk_gc_new (widget->window);
gdk_gc_set_function (preview->nav_gc, GDK_INVERT);
gdk_gc_set_line_attributes (preview->nav_gc,
PEN_WIDTH,
GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_ROUND);
}
}
static void
gimp_scrolled_preview_nav_popup_unrealize (GtkWidget *widget,
GimpScrolledPreview *preview)
{
if (preview->nav_gc)
{
g_object_unref (preview->nav_gc);
preview->nav_gc = NULL;
}
}
static gboolean
gimp_scrolled_preview_nav_popup_event (GtkWidget *widget,
GdkEvent *event,
GimpScrolledPreview *preview)
{
switch (event->type)
{
case GDK_BUTTON_RELEASE:
{
GdkEventButton *button_event = (GdkEventButton *) event;
if (button_event->button == 1)
{
gtk_grab_remove (widget);
gdk_display_pointer_ungrab (gtk_widget_get_display (widget),
button_event->time);
gtk_widget_destroy (preview->nav_popup);
preview->nav_popup = NULL;
}
}
break;
case GDK_MOTION_NOTIFY:
{
GdkEventMotion *motion_event = (GdkEventMotion *) event;
GtkAdjustment *hadj;
GtkAdjustment *vadj;
gdouble x, y;
hadj = gtk_range_get_adjustment (GTK_RANGE (preview->hscr));
vadj = gtk_range_get_adjustment (GTK_RANGE (preview->vscr));
x = (motion_event->x *
(hadj->upper - hadj->lower) / widget->allocation.width);
y = (motion_event->y *
(vadj->upper - vadj->lower) / widget->allocation.height);
x += hadj->lower - hadj->page_size / 2;
y += vadj->lower - vadj->page_size / 2;
gtk_adjustment_set_value (hadj, CLAMP (x,
hadj->lower,
hadj->upper - hadj->page_size));
gtk_adjustment_set_value (vadj, CLAMP (y,
vadj->lower,
vadj->upper - vadj->page_size));
gtk_widget_queue_draw (widget);
}
break;
default:
break;
}
return FALSE;
}
static gboolean
gimp_scrolled_preview_nav_popup_expose (GtkWidget *widget,
GdkEventExpose *event,
GimpScrolledPreview *preview)
{
gdouble x, y;
gdouble w, h;
x = (gdouble) preview->xoff / (gdouble) (GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin);
y = (gdouble) preview->yoff / (gdouble) (GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin);
w = (gdouble) GIMP_PREVIEW (preview)->width / (gdouble) (GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin);
h = (gdouble) GIMP_PREVIEW (preview)->height / (gdouble) (GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin);
gdk_gc_set_clip_rectangle (preview->nav_gc, &event->area);
gdk_draw_rectangle (widget->window, preview->nav_gc,
FALSE,
x * (gdouble) widget->allocation.width + PEN_WIDTH / 2,
y * (gdouble) widget->allocation.height + PEN_WIDTH / 2,
MAX (1,
ceil (w * widget->allocation.width) - PEN_WIDTH),
MAX (1,
ceil (h * widget->allocation.height) - PEN_WIDTH));
return FALSE;
}
static void
gimp_scrolled_preview_set_cursor (GimpPreview *preview)
{
if (preview->xmax - preview->xmin > preview->width ||
preview->ymax - preview->ymin > preview->height)
{
gdk_window_set_cursor (preview->area->window,
GIMP_SCROLLED_PREVIEW (preview)->cursor_move);
}
else
{
gdk_window_set_cursor (preview->area->window, NULL);
}
}
/**
* gimp_preview_get_position:
* @preview: a #GimpPreview widget
* @x: return location for the horizontal offset
* @y: return location for the vertical offset
*
* Since: GIMP 2.2
**/
void
gimp_scrolled_preview_get_position (GimpScrolledPreview *preview,
gint *x,
gint *y)
{
g_return_if_fail (GIMP_IS_SCROLLED_PREVIEW (preview));
if (x)
*x = preview->xoff + GIMP_PREVIEW (preview)->xmin;
if (y)
*y = preview->yoff + GIMP_PREVIEW (preview)->ymin;
}

View File

@ -0,0 +1,83 @@
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpscrolledpreview.h
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_SCROLLED_PREVIEW_H__
#define __GIMP_SCROLLED_PREVIEW_H__
#include "gimppreview.h"
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
#define GIMP_TYPE_SCROLLED_PREVIEW (gimp_scrolled_preview_get_type ())
#define GIMP_SCROLLED_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SCROLLED_PREVIEW, GimpScrolledPreview))
#define GIMP_SCROLLED_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_SCROLLED_PREVIEW, GimpScrolledPreviewClass))
#define GIMP_IS_SCROLLED_PREVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SCROLLED_PREVIEW))
#define GIMP_IS_SCROLLED_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_SCROLLED_PREVIEW))
#define GIMP_SCROLLED_PREVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_SCROLLED_PREVIEW, GimpScrolledPreviewClass))
typedef struct _GimpScrolledPreviewClass GimpScrolledPreviewClass;
struct _GimpScrolledPreview
{
GimpPreview parent_instance;
/*< protected >*/
GtkWidget *hscr;
GtkWidget *vscr;
GtkWidget *nav_icon;
GtkWidget *nav_popup;
GdkCursor *cursor_move;
GdkGC *nav_gc;
/*< private >*/
gint xoff, yoff;
gint drag_x, drag_y;
gint drag_xoff, drag_yoff;
gboolean in_drag;
};
struct _GimpScrolledPreviewClass
{
GimpPreviewClass parent_class;
/* virtuals */
void (* draw_thumb) (GimpScrolledPreview *preview,
GimpPreviewArea *area,
gint width,
gint height);
};
GType gimp_scrolled_preview_get_type (void) G_GNUC_CONST;
void gimp_scrolled_preview_get_position (GimpScrolledPreview *preview,
gint *x,
gint *y);
G_END_DECLS
#endif /* __GIMP_SCROLLED_PREVIEW_H__ */

View File

@ -83,6 +83,7 @@ typedef struct _GimpPickButton GimpPickButton;
typedef struct _GimpPreview GimpPreview;
typedef struct _GimpPreviewArea GimpPreviewArea;
typedef struct _GimpPixmap GimpPixmap;
typedef struct _GimpScrolledPreview GimpScrolledPreview;
typedef struct _GimpSizeEntry GimpSizeEntry;
typedef struct _GimpUnitMenu GimpUnitMenu;

View File

@ -1229,7 +1229,8 @@ dialog_update_preview (GimpPreview *preview)
gint width, height;
gint bytes;
gimp_preview_get_position (preview, &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (preview, &width, &height);
bytes =drawable->bpp;

View File

@ -289,7 +289,8 @@ cartoon (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
}
else

View File

@ -199,7 +199,8 @@ deinterlace (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
dest_buffer = dest = g_new (guchar, width * height * bytes);
}

View File

@ -724,7 +724,8 @@ preview_update (GtkWidget *widget)
/*
* Setup for filter...
*/
gimp_preview_get_position (preview, &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_pixel_rgn_init (&src_rgn, drawable,
x1, y1, preview->width, preview->height,

View File

@ -923,7 +923,8 @@ preview_update_preview (GimpDrawablePreview *preview,
bpp = gimp_drawable_bpp (drawable->drawable_id);
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
buffer = g_new (guchar, width * height * bpp);

View File

@ -800,7 +800,8 @@ edge_preview_update (GimpDrawablePreview *preview)
/*
* Setup for filter...
*/
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview),
&width, &height);

View File

@ -434,7 +434,8 @@ engrave_small (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;

View File

@ -661,7 +661,8 @@ exchange (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;

View File

@ -654,7 +654,8 @@ gauss (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
}

View File

@ -384,7 +384,8 @@ grid (gint32 image_ID,
if (preview)
{
gimp_preview_get_position (preview, &sx1, &sy1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&sx1, &sy1);
gimp_preview_get_size (preview, &sx2, &sy2);
buffer = g_new (guchar, bytes * sx2 * sy2);

View File

@ -779,7 +779,8 @@ mblur (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (preview, &x, &y);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x, &y);
gimp_preview_get_size (preview, &width, &height);
}
else

View File

@ -261,7 +261,8 @@ neon (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;

View File

@ -282,7 +282,8 @@ noisify (GimpDrawablePreview *preview)
gint bpp;
GRand *gr = g_rand_new ();
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
bpp = preview->drawable->bpp;

View File

@ -235,7 +235,8 @@ oilify_rgb (GimpDrawable *drawable,
/* get the selection bounds */
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;
@ -356,7 +357,8 @@ oilify_intensity (GimpDrawable *drawable,
/* get the selection bounds */
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;

View File

@ -304,7 +304,8 @@ photocopy (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
}
else

View File

@ -79,6 +79,7 @@ typedef struct
guint32 seed;
gdouble turbulence;
gboolean random_seed;
gboolean preview;
} PlasmaValues;
@ -143,19 +144,19 @@ static PlasmaValues pvals =
0, /* seed */
1.0, /* turbulence */
FALSE, /* Use random seed */
TRUE /* preview */
};
/*
* Some globals to save passing too many paramaters that don't change.
*/
#define PREVIEW_SIZE 128
static GtkWidget *preview;
static guchar preview_buffer[PREVIEW_SIZE * PREVIEW_SIZE * 4];
static guchar *preview_buffer;
static gint preview_width, preview_height;
static gint ix1, iy1, ix2, iy2; /* Selected image size. */
static gint bpp, alpha;
static gboolean has_alpha;
static gdouble turbulence;
static glong max_progress, progress;
/***** Functions *****/
@ -291,10 +292,8 @@ run (const gchar *name,
static gboolean
plasma_dialog (GimpDrawable *drawable)
{
GtkWidget *dlg;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *frame;
GtkWidget *dialog;
GtkWidget *main_vbox;
GtkWidget *label;
GtkWidget *table;
GtkWidget *seed;
@ -303,38 +302,31 @@ plasma_dialog (GimpDrawable *drawable)
gimp_ui_init ("plasma", TRUE);
dlg = gimp_dialog_new (_("Plasma"), "plasma",
NULL, 0,
gimp_standard_help_func, "plug-in-plasma",
dialog = gimp_dialog_new (_("Plasma"), "plasma",
NULL, 0,
gimp_standard_help_func, "plug-in-plasma",
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
NULL);
vbox = gtk_vbox_new (FALSE, 12);
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);
main_vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), main_vbox);
gtk_widget_show (main_vbox);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
preview = gimp_preview_area_new ();
gtk_widget_set_size_request (preview, PREVIEW_SIZE, PREVIEW_SIZE);
gtk_container_add (GTK_CONTAINER (frame), preview);
preview = gimp_aspect_preview_new (drawable, &pvals.preview);
gtk_box_pack_start_defaults (GTK_BOX (main_vbox), preview);
gtk_widget_show (preview);
g_signal_connect_swapped (preview, "invalidated",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
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);
gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
seed = gimp_random_seed_new (&pvals.seed, &pvals.random_seed);
@ -346,8 +338,8 @@ plasma_dialog (GimpDrawable *drawable)
g_signal_connect_swapped (GIMP_RANDOM_SEED_SPINBUTTON_ADJ (seed),
"value_changed",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
G_CALLBACK (gimp_preview_invalidate),
preview);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("T_urbulence:"), SCALE_WIDTH, 0,
@ -359,16 +351,14 @@ plasma_dialog (GimpDrawable *drawable)
G_CALLBACK (gimp_double_adjustment_update),
&pvals.turbulence);
g_signal_connect_swapped (adj, "value_changed",
G_CALLBACK (plasma_seed_changed_callback),
drawable);
G_CALLBACK (gimp_preview_invalidate),
preview);
gtk_widget_show (dlg);
gtk_widget_show (dialog);
plasma_seed_changed_callback (drawable, NULL); /* preview image */
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dlg);
gtk_widget_destroy (dialog);
return run;
}
@ -425,13 +415,14 @@ init_plasma (GimpDrawable *drawable,
g_rand_set_seed (gr, pvals.seed);
turbulence = pvals.turbulence;
if (preview_mode)
{
ix1 = iy1 = 0;
ix2 = PREVIEW_SIZE;
iy2 = PREVIEW_SIZE;
gimp_preview_get_size (GIMP_PREVIEW (preview),
&preview_width, &preview_height);
ix2 = preview_width;
iy2 = preview_height;
preview_buffer = g_new (guchar, ix2 * iy2 * drawable->bpp);
pft = NULL;
}
@ -469,11 +460,10 @@ end_plasma (GimpDrawable *drawable,
}
else
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
gimp_drawable_type (drawable->drawable_id),
preview_buffer,
PREVIEW_SIZE * bpp);
gimp_aspect_preview_draw_buffer (GIMP_ASPECT_PREVIEW (preview),
preview_buffer,
preview_width * bpp);
g_free (preview_buffer);
}
g_rand_free (gr);
@ -491,7 +481,7 @@ get_pixel (GimpPixelFetcher *pft,
}
else
{
memcpy (pixel, preview_buffer + (y * PREVIEW_SIZE + x) * bpp, bpp);
memcpy (pixel, preview_buffer + (y * preview_width + x) * bpp, bpp);
}
}
@ -508,7 +498,7 @@ put_pixel (GimpPixelFetcher *pft,
}
else
{
memcpy (preview_buffer + (y * PREVIEW_SIZE + x) * bpp, pixel, bpp);
memcpy (preview_buffer + (y * preview_width + x) * bpp, pixel, bpp);
}
}
@ -618,7 +608,7 @@ do_plasma (GimpPixelFetcher *pft,
get_pixel (pft, x2, y1, tr);
get_pixel (pft, x2, y2, br);
ran = (gint) ((256.0 / (2.0 * scale_depth)) * turbulence);
ran = (gint) ((256.0 / (2.0 * scale_depth)) * pvals.turbulence);
xave = (x1 + x2) / 2;
yave = (y1 + y2) / 2;

View File

@ -471,7 +471,8 @@ preview_update (GimpDrawablePreview *preview)
/*
* Setup for filter...
*/
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
/* initialize pixel regions */

View File

@ -556,7 +556,8 @@ preview_update (GimpDrawablePreview *preview)
/*
* Setup for filter...
*/
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview),
&preview_width, &preview_height);
img_bpp = gimp_drawable_bpp (preview->drawable->drawable_id);

View File

@ -241,7 +241,8 @@ shift (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
}
else

View File

@ -348,7 +348,8 @@ sobel (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (preview, &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (preview, &width, &height);
x2 = x1 + width;
y2 = y1 + height;

View File

@ -256,7 +256,8 @@ softglow (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (preview, &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (preview, &width, &height);
x2 = x1 + width;
y2 = y1 + height;

View File

@ -308,7 +308,8 @@ spread_preview_update (GimpPreview *preview,
bpp = drawable_preview->drawable->bpp;
dest = buffer = g_new (guchar, width * height * bpp);
gimp_preview_get_position (preview, &x_off, &y_off);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x_off, &y_off);
for (y = 0 ; y < height ; y++)
for (x = 0 ; x < width ; x++)

View File

@ -1353,7 +1353,8 @@ strucpi (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;

View File

@ -771,7 +771,8 @@ preview_update (GimpPreview *preview)
/*
* Setup for filter...
*/
gimp_preview_get_position (preview, &preview_x1, &preview_y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&preview_x1, &preview_y1);
gimp_preview_get_size (preview, &preview_x2, &preview_y2);
preview_x2 += preview_x1;
preview_y2 += preview_y1;

View File

@ -303,7 +303,8 @@ render_blast (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;
y2 = y1 + height;
@ -426,7 +427,8 @@ render_wind (GimpDrawable *drawable,
if (preview)
{
gimp_preview_get_position (GIMP_PREVIEW (preview), &x1, &y1);
gimp_scrolled_preview_get_position (GIMP_SCROLLED_PREVIEW (preview),
&x1, &y1);
gimp_preview_get_size (GIMP_PREVIEW (preview), &width, &height);
x2 = x1 + width;
y2 = y1 + height;