added transform and untransform methods.

2007-01-11  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimppreview.[ch]: added transform and 
untransform
	methods.

	* libgimp/gimpzoompreview.c: more cleanups. Override the new
	GimpPreview methods.

	* plug-ins/common/nova.c: use the new transform functions.

	* libgimpwidgets/gimpwidgets.def: updated.


svn path=/trunk/; revision=21689
This commit is contained in:
Sven Neumann 2007-01-11 23:41:45 +00:00 committed by Sven Neumann
parent bc8948eec8
commit 511a488aa2
9 changed files with 266 additions and 94 deletions

View File

@ -1,3 +1,15 @@
2007-01-11 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimppreview.[ch]: added transform and untransform
methods.
* libgimp/gimpzoompreview.c: more cleanups. Override the new
GimpPreview methods.
* plug-ins/common/nova.c: use the new transform functions.
* libgimpwidgets/gimpwidgets.def: updated.
2007-01-11 Sven Neumann <sven@gimp.org>
* libgimp/gimpzoompreview.c: code cleanup. Added missing sanity

View File

@ -1,3 +1,9 @@
2007-01-12 Sven Neumann <sven@gimp.org>
* libgimpwidgets/libgimpwidgets-sections.txt: added new symbols.
* libgimpwidgets/tmpl/gimppreview.sgm: regenerated.
2007-01-03 Sven Neumann <sven@gimp.org>
* libgimpwidgets/images/gimp-ratio-entry.png: added screenshot.

View File

@ -1033,6 +1033,8 @@ gimp_preview_set_update
gimp_preview_set_bounds
gimp_preview_get_size
gimp_preview_get_position
gimp_preview_transform
gimp_preview_untransform
gimp_preview_get_area
gimp_preview_draw
gimp_preview_draw_buffer

View File

@ -90,6 +90,30 @@ A widget providing a #GimpPreviewArea plus framework to update the preview.
@y:
<!-- ##### FUNCTION gimp_preview_transform ##### -->
<para>
</para>
@preview:
@src_x:
@src_y:
@dest_x:
@dest_y:
<!-- ##### FUNCTION gimp_preview_untransform ##### -->
<para>
</para>
@preview:
@src_x:
@src_y:
@dest_x:
@dest_y:
<!-- ##### FUNCTION gimp_preview_get_area ##### -->
<para>

View File

@ -86,6 +86,16 @@ static void gimp_zoom_preview_draw_thumb (GimpPreview *preview,
gint width,
gint height);
static void gimp_zoom_preview_set_cursor (GimpPreview *preview);
static void gimp_zoom_preview_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
static void gimp_zoom_preview_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
static void gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable);
@ -122,6 +132,8 @@ gimp_zoom_preview_class_init (GimpZoomPreviewClass *klass)
preview_class->draw_buffer = gimp_zoom_preview_draw_buffer;
preview_class->draw_thumb = gimp_zoom_preview_draw_thumb;
preview_class->set_cursor = gimp_zoom_preview_set_cursor;
preview_class->transform = gimp_zoom_preview_transform;
preview_class->untransform = gimp_zoom_preview_untransform;
g_type_class_add_private (object_class, sizeof (GimpZoomPreviewPrivate));
@ -410,10 +422,6 @@ gimp_zoom_preview_draw (GimpPreview *preview)
gint width;
gint height;
gint bpp;
gint src_x;
gint src_y;
gint src_width;
gint src_height;
if (! priv->model)
return;
@ -422,16 +430,9 @@ gimp_zoom_preview_draw (GimpPreview *preview)
if (! drawable)
return;
width = preview->width;
height = preview->height;
gimp_zoom_preview_get_source_area (preview,
&src_x, &src_y, &src_width, &src_height);
data = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
src_x, src_y,
src_width, src_height,
data = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
&width, &height, &bpp);
if (data)
{
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
@ -473,21 +474,15 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
gint src_y;
gint src_width;
gint src_height;
gdouble zoom;
zoom = gimp_zoom_model_get_factor (priv->model);
selection_id = gimp_image_get_selection (image_id);
width = preview->width;
height = preview->height;
src_x = (priv->extents.x +
preview->xoff * priv->extents.width / width / zoom);
src_y = (priv->extents.y +
preview->yoff * priv->extents.height / height / zoom);
src_width = priv->extents.width / zoom;
src_height = priv->extents.height / zoom;
gimp_zoom_preview_get_source_area (preview,
&src_x, &src_y,
&src_width, &src_height);
src = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
src_x, src_y,
@ -541,6 +536,44 @@ gimp_zoom_preview_set_cursor (GimpPreview *preview)
}
}
static void
gimp_zoom_preview_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
*dest_x = ((gdouble) (src_x - priv->extents.x) *
preview->width / priv->extents.width * zoom) - preview->xoff;
*dest_y = ((gdouble) (src_y - priv->extents.y) *
preview->height / priv->extents.height * zoom) - preview->yoff;
}
static void
gimp_zoom_preview_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gdouble zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
*dest_x = (priv->extents.x +
((gdouble) (src_x + preview->xoff) *
priv->extents.width / preview->width / zoom));
*dest_y = (priv->extents.y +
((gdouble) (src_y + preview->yoff) *
priv->extents.height / preview->height / zoom));
}
static void
gimp_zoom_preview_set_drawable (GimpZoomPreview *preview,
GimpDrawable *drawable)
@ -642,14 +675,9 @@ gimp_zoom_preview_get_source_area (GimpPreview *preview,
gint *h)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gdouble zoom;
gdouble zoom = gimp_zoom_model_get_factor (priv->model);
zoom = gimp_zoom_model_get_factor (priv->model);
*x = (priv->extents.x +
preview->xoff * priv->extents.width / preview->width / zoom);
*y = (priv->extents.y +
preview->yoff * priv->extents.height / preview->height / zoom);
gimp_zoom_preview_untransform (preview, 0, 0, x, y);
*w = priv->extents.width / zoom;
*h = priv->extents.height / zoom;
@ -796,14 +824,16 @@ gimp_zoom_preview_get_source (GimpZoomPreview *preview,
if (drawable)
{
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
gint src_x;
gint src_y;
gint src_width;
gint src_height;
gimp_preview_get_size (GIMP_PREVIEW (preview), width, height);
*width = gimp_preview->width;
*height = gimp_preview->height;
gimp_zoom_preview_get_source_area (GIMP_PREVIEW (preview),
gimp_zoom_preview_get_source_area (gimp_preview,
&src_x, &src_y,
&src_width, &src_height);

View File

@ -91,6 +91,16 @@ static void gimp_preview_notify_checks (GimpPreview *preview);
static gboolean gimp_preview_invalidate_now (GimpPreview *preview);
static void gimp_preview_real_set_cursor (GimpPreview *preview);
static void gimp_preview_real_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
static void gimp_preview_real_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
static guint preview_signals[LAST_SIGNAL] = { 0 };
@ -155,6 +165,8 @@ gimp_preview_class_init (GimpPreviewClass *klass)
klass->draw_thumb = NULL;
klass->draw_buffer = NULL;
klass->set_cursor = gimp_preview_real_set_cursor;
klass->transform = gimp_preview_real_transform;
klass->untransform = gimp_preview_real_untransform;
g_type_class_add_private (object_class, sizeof (GimpPreviewPrivate));
@ -488,8 +500,29 @@ static void
gimp_preview_real_set_cursor (GimpPreview *preview)
{
if (GTK_WIDGET_REALIZED (preview->area))
gdk_window_set_cursor (preview->area->window,
preview->default_cursor);
gdk_window_set_cursor (preview->area->window, preview->default_cursor);
}
static void
gimp_preview_real_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
*dest_x = src_x - preview->xoff - preview->xmin;
*dest_y = src_y - preview->yoff - preview->ymin;
}
static void
gimp_preview_real_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
*dest_x = src_x + preview->xoff + preview->xmin;
*dest_y = src_y + preview->yoff + preview->ymin;
}
/**
@ -608,6 +641,58 @@ gimp_preview_get_position (GimpPreview *preview,
*y = preview->yoff + preview->ymin;
}
/**
* gimp_preview_transform:
* @preview: a #GimpPreview widget
* @src_x: horizontal position on the previewed image
* @src_y: vertical position on the previewed image
* @dest_x: returns the transformed horizontal position
* @dest_y: returns the transformed vertical position
*
* Transforms from image to widget coordinates.
*
* Since: GIMP 2.4
**/
void
gimp_preview_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
g_return_if_fail (GIMP_IS_PREVIEW (preview));
g_return_if_fail (dest_x != NULL && dest_y != NULL);
GIMP_PREVIEW_GET_CLASS (preview)->transform (preview,
src_x, src_y, dest_x, dest_y);
}
/**
* gimp_preview_untransform:
* @preview: a #GimpPreview widget
* @src_x: horizontal position relative to the preview area's origin
* @src_y: vertical position relative to preview area's origin
* @dest_x: returns the untransformed horizontal position
* @dest_y: returns the untransformed vertical position
*
* Transforms from widget to image coordinates.
*
* Since: GIMP 2.4
**/
void
gimp_preview_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y)
{
g_return_if_fail (GIMP_IS_PREVIEW (preview));
g_return_if_fail (dest_x != NULL && dest_y != NULL);
GIMP_PREVIEW_GET_CLASS (preview)->untransform (preview,
src_x, src_y, dest_x, dest_y);
}
/**
* gimp_preview_get_area:
* @preview: a #GimpPreview widget

View File

@ -66,7 +66,7 @@ struct _GimpPreviewClass
{
GtkVBoxClass parent_class;
/* virtuals */
/* virtual methods */
void (* draw) (GimpPreview *preview);
void (* draw_thumb) (GimpPreview *preview,
GimpPreviewArea *area,
@ -80,9 +80,19 @@ struct _GimpPreviewClass
/* signal */
void (* invalidated) (GimpPreview *preview);
/* virtual methods */
void (* transform) (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
void (* untransform) (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
/* Padding for future expansion */
void (* _gimp_reserved1) (void);
void (* _gimp_reserved2) (void);
void (* _gimp_reserved3) (void);
void (* _gimp_reserved4) (void);
};
@ -107,6 +117,17 @@ void gimp_preview_get_size (GimpPreview *preview,
gint *width,
gint *height);
void gimp_preview_transform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
void gimp_preview_untransform (GimpPreview *preview,
gint src_x,
gint src_y,
gint *dest_x,
gint *dest_y);
GtkWidget * gimp_preview_get_area (GimpPreview *preview);
void gimp_preview_draw (GimpPreview *preview);

View File

@ -228,6 +228,8 @@ EXPORTS
gimp_preview_set_bounds
gimp_preview_set_default_cursor
gimp_preview_set_update
gimp_preview_transform
gimp_preview_untransform
gimp_prop_boolean_combo_box_new
gimp_prop_boolean_radio_frame_new
gimp_prop_check_button_new

View File

@ -574,27 +574,14 @@ nova_center_coords_update (GimpSizeEntry *coords,
/*
* Update the cross cursor's coordinates accoding to pvals.[xy]center
* but not redraw it
* but do not redraw it.
*/
static void
nova_center_cursor_update (NovaCenter *center)
{
gint width, height;
gdouble xoff, yoff;
gdouble zoom;
gimp_preview_get_size (center->preview, &width, &height);
xoff = center->preview->xoff;
yoff = center->preview->yoff;
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (center->preview));
center->curx = pvals.xcenter * width / center->drawable->width * zoom -
xoff;
center->cury = pvals.ycenter * height / center->drawable->height * zoom -
yoff;
center->curx = CLAMP (center->curx, 0, width - 1);
center->cury = CLAMP (center->cury, 0, height - 1);
gimp_preview_transform (center->preview,
pvals.xcenter, pvals.ycenter,
&center->curx, &center->cury);
}
/*
@ -633,19 +620,13 @@ nova_center_preview_expose (GtkWidget *widget,
static gboolean
nova_center_update (GtkWidget *widget,
NovaCenter *center)
NovaCenter *center,
gint x,
gint y)
{
gint width, height;
gint curx, cury;
gdouble zoom;
gint tx, ty;
gimp_preview_get_size (center->preview, &width, &height);
gtk_widget_get_pointer (widget, &curx, &cury);
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (center->preview));
center->curx = (curx + center->preview->xoff) / zoom;
center->cury = (cury + center->preview->yoff) / zoom;
gimp_preview_untransform (center->preview, x, y, &tx, &ty);
nova_center_cursor_draw (center);
@ -653,12 +634,8 @@ nova_center_update (GtkWidget *widget,
nova_center_coords_update,
center);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 0,
center->curx * center->drawable->width /
width);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 1,
center->cury * center->drawable->height /
height);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 0, tx);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (center->coords), 1, ty);
g_signal_handlers_unblock_by_func (center->coords,
nova_center_coords_update,
@ -677,13 +654,21 @@ nova_center_preview_events (GtkWidget *widget,
switch (event->type)
{
case GDK_MOTION_NOTIFY:
if (((GdkEventMotion *) event)->state & GDK_BUTTON2_MASK)
return nova_center_update (widget, center);
{
GdkEventMotion *mevent = (GdkEventMotion *) event;
if (mevent->state & GDK_BUTTON2_MASK)
return nova_center_update (widget, center, mevent->x, mevent->y);
}
break;
case GDK_BUTTON_PRESS:
if (((GdkEventButton *) event)->button == 2)
return nova_center_update (widget, center);
{
GdkEventButton *bevent = (GdkEventButton *) event;
if (bevent->button == 2)
return nova_center_update (widget, center, bevent->x, bevent->y);
}
break;
default:
@ -708,7 +693,7 @@ gauss (GRand *gr)
gint i;
for (i = 0; i < 6; i++)
sum += (gdouble) g_rand_double (gr);
sum += g_rand_double (gr);
return sum / 6.0;
}
@ -759,6 +744,7 @@ nova (GimpDrawable *drawable,
hsv.h += ((gdouble) pvals.randomhue / 360.0) *
g_rand_double_range (gr, -0.5, 0.5);
if (hsv.h < 0)
hsv.h += 1.0;
else if (hsv.h >= 1.0)
@ -771,13 +757,14 @@ nova (GimpDrawable *drawable,
{
cache = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview),
&width, &height, &bpp);
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
xc = (gdouble) pvals.xcenter * width / drawable->width * zoom -
preview->xoff;
yc = (gdouble) pvals.ycenter * height / drawable->height * zoom -
preview->yoff;
x1 = y1 = 0;
zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview));
gimp_preview_transform (preview,
pvals.xcenter, pvals.ycenter, &xc, &yc);
x1 = 0;
y1 = 0;
x2 = width;
y2 = height;
}
@ -814,13 +801,14 @@ nova (GimpDrawable *drawable,
for (col = 0, x = 0; col < x2; col++, x++)
{
u = (gdouble) (x - xc) /
u = ((gdouble) (x - xc) /
((gdouble) pvals.radius * width /
drawable->width * zoom);
v = (gdouble) (y - yc) /
drawable->width * zoom));
v = ((gdouble) (y - yc) /
((gdouble) pvals.radius * height /
drawable->height * zoom);
l = sqrt (u * u + v * v);
drawable->height * zoom));
l = sqrt (SQR (u) + SQR (v));
/* This algorithm is still under construction. */
t = (atan2 (u, v) / (2 * G_PI) + .51) * pvals.nspoke;
@ -964,6 +952,7 @@ nova (GimpDrawable *drawable,
color.r += c;
dest[0] = CLAMP (color.r*255.0, 0, 255);
break;
case 3:
case 4:
/* red */
@ -1005,6 +994,7 @@ nova (GimpDrawable *drawable,
src += src_rgn.bpp;
dest += dest_rgn.bpp;
}
src_row += src_rgn.rowstride;
dest_row += dest_rgn.rowstride;
}