Commit 3ac4aab0 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

zoom on Ctrl-Scroll events.

2005-11-22  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpzoompreview.c: zoom on Ctrl-Scroll events.

	* libgimpwidgets/gimpscrolledpreview.c
	(gimp_scrolled_preview_area_event): correctly clamp adjustment
	value on scroll events. Ignore scroll events when Ctrl is pressed.
parent 795e2a8b
2005-11-22 Sven Neumann <sven@gimp.org>
* libgimp/gimpzoompreview.c: zoom on Ctrl-Scroll events.
* libgimpwidgets/gimpscrolledpreview.c
(gimp_scrolled_preview_area_event): correctly clamp adjustment
value on scroll events. Ignore scroll events when Ctrl is pressed.
2005-11-21 Sven Neumann <sven@gimp.org> 2005-11-21 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpscrolledpreview.c * libgimpwidgets/gimpscrolledpreview.c
......
...@@ -34,8 +34,10 @@ ...@@ -34,8 +34,10 @@
#include "gimpzoompreview.h" #include "gimpzoompreview.h"
#define SELECTION_BORDER 2 #define SELECTION_BORDER 2
typedef struct _GimpZoomPreviewPrivate GimpZoomPreviewPrivate; typedef struct _GimpZoomPreviewPrivate GimpZoomPreviewPrivate;
struct _GimpZoomPreviewPrivate struct _GimpZoomPreviewPrivate
...@@ -55,6 +57,9 @@ static void gimp_zoom_preview_size_allocate (GtkWidget *widget, ...@@ -55,6 +57,9 @@ static void gimp_zoom_preview_size_allocate (GtkWidget *widget,
GimpZoomPreview *preview); GimpZoomPreview *preview);
static void gimp_zoom_preview_style_set (GtkWidget *widget, static void gimp_zoom_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style); GtkStyle *prev_style);
static gboolean gimp_zoom_preview_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
GimpZoomPreview *preview);
static void gimp_zoom_preview_draw (GimpPreview *preview); static void gimp_zoom_preview_draw (GimpPreview *preview);
static void gimp_zoom_preview_draw_buffer (GimpPreview *preview, static void gimp_zoom_preview_draw_buffer (GimpPreview *preview,
const guchar *buffer, const guchar *buffer,
...@@ -125,6 +130,9 @@ gimp_zoom_preview_init (GimpZoomPreview *preview) ...@@ -125,6 +130,9 @@ gimp_zoom_preview_init (GimpZoomPreview *preview)
g_signal_connect (GIMP_PREVIEW (preview)->area, "size-allocate", g_signal_connect (GIMP_PREVIEW (preview)->area, "size-allocate",
G_CALLBACK (gimp_zoom_preview_size_allocate), G_CALLBACK (gimp_zoom_preview_size_allocate),
preview); preview);
g_signal_connect (GIMP_PREVIEW (preview)->area, "scroll-event",
G_CALLBACK (gimp_zoom_preview_scroll_event),
preview);
g_object_set (GIMP_PREVIEW (preview)->area, g_object_set (GIMP_PREVIEW (preview)->area,
"check-size", gimp_check_size (), "check-size", gimp_check_size (),
...@@ -148,6 +156,7 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview, ...@@ -148,6 +156,7 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
width = GIMP_PREVIEW (preview)->width; width = GIMP_PREVIEW (preview)->width;
height = GIMP_PREVIEW (preview)->height; height = GIMP_PREVIEW (preview)->height;
ratio = new_factor / old_factor; ratio = new_factor / old_factor;
adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->hscr)); adj = gtk_range_get_adjustment (GTK_RANGE (scrolled_preview->hscr));
...@@ -156,9 +165,9 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview, ...@@ -156,9 +165,9 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
adj->upper = width * new_factor; adj->upper = width * new_factor;
adj->step_increment = new_factor; adj->step_increment = new_factor;
adj->page_increment = MAX (width / 2.0, adj->step_increment); adj->page_increment = MAX (width / 2.0, adj->step_increment);
adj->value = CLAMP ((adj->value + width / 2.0) * ratio - width / 2.0, adj->value = CLAMP ((adj->value + width / 2.0) * ratio
adj->lower, - width / 2.0,
adj->upper - width); adj->lower, adj->upper - width);
gtk_adjustment_changed (adj); gtk_adjustment_changed (adj);
gtk_adjustment_value_changed (adj); gtk_adjustment_value_changed (adj);
...@@ -168,9 +177,9 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview, ...@@ -168,9 +177,9 @@ gimp_zoom_preview_set_adjustments (GimpZoomPreview *preview,
adj->upper = height * new_factor; adj->upper = height * new_factor;
adj->step_increment = new_factor; adj->step_increment = new_factor;
adj->page_increment = MAX (height / 2.0, adj->step_increment); adj->page_increment = MAX (height / 2.0, adj->step_increment);
adj->value = CLAMP ((adj->value + height / 2.0) *ratio - height / 2.0, adj->value = CLAMP ((adj->value + height / 2.0) * ratio
adj->lower, - height / 2.0,
adj->upper - height); adj->lower, adj->upper - height);
gtk_adjustment_changed (adj); gtk_adjustment_changed (adj);
gtk_adjustment_value_changed (adj); gtk_adjustment_value_changed (adj);
...@@ -184,6 +193,7 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget, ...@@ -184,6 +193,7 @@ gimp_zoom_preview_size_allocate (GtkWidget *widget,
{ {
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview); GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gdouble zoom_factor; gdouble zoom_factor;
gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin; gint width = GIMP_PREVIEW (preview)->xmax - GIMP_PREVIEW (preview)->xmin;
gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin; gint height = GIMP_PREVIEW (preview)->ymax - GIMP_PREVIEW (preview)->ymin;
...@@ -199,7 +209,7 @@ gimp_zoom_preview_style_set (GtkWidget *widget, ...@@ -199,7 +209,7 @@ gimp_zoom_preview_style_set (GtkWidget *widget,
GtkStyle *prev_style) GtkStyle *prev_style)
{ {
GimpPreview *preview = GIMP_PREVIEW (widget); GimpPreview *preview = GIMP_PREVIEW (widget);
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview); GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
GimpDrawable *drawable = priv->drawable; GimpDrawable *drawable = priv->drawable;
gint size; gint size;
gint width, height; gint width, height;
...@@ -209,9 +219,8 @@ gimp_zoom_preview_style_set (GtkWidget *widget, ...@@ -209,9 +219,8 @@ gimp_zoom_preview_style_set (GtkWidget *widget,
if (GTK_WIDGET_CLASS (parent_class)->style_set) if (GTK_WIDGET_CLASS (parent_class)->style_set)
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style); GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
gtk_widget_style_get (widget, gtk_widget_style_get (widget, "size", &size, NULL);
"size", &size,
NULL);
if (gimp_zoom_preview_get_bounds (drawable, &x1, &y1, &x2, &y2)) if (gimp_zoom_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
{ {
width = x2 - x1; width = x2 - x1;
...@@ -238,43 +247,38 @@ gimp_zoom_preview_style_set (GtkWidget *widget, ...@@ -238,43 +247,38 @@ gimp_zoom_preview_style_set (GtkWidget *widget,
preview->width, preview->height); preview->width, preview->height);
} }
guchar * static gboolean
gimp_zoom_preview_get_source (GimpZoomPreview *preview, gimp_zoom_preview_scroll_event (GtkWidget *widget,
gint *width, GdkEventScroll *event,
gint *height, GimpZoomPreview *preview)
gint *bpp)
{ {
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview); if (event->state & GDK_CONTROL_MASK)
guchar *data; {
GimpDrawable *drawable = priv->drawable; GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
gint src_x;
gint src_y;
gint src_width;
gint src_height;
gdouble zoom_factor;
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
zoom_factor = gimp_zoom_model_get_factor (priv->model); switch (event->direction)
*width = gimp_preview->width; {
*height = gimp_preview->height; case GDK_SCROLL_UP:
gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_IN, 0.0);
break;
src_x = priv->extents.x + case GDK_SCROLL_DOWN:
gimp_preview->xoff * priv->extents.width / *width / zoom_factor; gimp_zoom_model_zoom (priv->model, GIMP_ZOOM_OUT, 0.0);
src_y = priv->extents.y + break;
gimp_preview->yoff * priv->extents.height / *height / zoom_factor;
src_width = priv->extents.width / zoom_factor;
src_height = priv->extents.height / zoom_factor;
data = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id, default:
src_x, src_y, break;
src_width, src_height, }
width, height, bpp); }
return data;
return FALSE;
} }
static void static void
gimp_zoom_preview_draw (GimpPreview *preview) gimp_zoom_preview_draw (GimpPreview *preview)
{ {
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
GimpDrawable *drawable;
guchar *data; guchar *data;
gint width; gint width;
gint height; gint height;
...@@ -283,15 +287,14 @@ gimp_zoom_preview_draw (GimpPreview *preview) ...@@ -283,15 +287,14 @@ gimp_zoom_preview_draw (GimpPreview *preview)
gint src_y; gint src_y;
gint src_width; gint src_width;
gint src_height; gint src_height;
GimpDrawable *drawable;
gdouble zoom_factor; gdouble zoom_factor;
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
g_return_if_fail (GIMP_IS_ZOOM_PREVIEW (preview)); g_return_if_fail (GIMP_IS_ZOOM_PREVIEW (preview));
drawable = priv->drawable; drawable = priv->drawable;
if (!drawable) if (!drawable)
return; return;
zoom_factor = gimp_zoom_model_get_factor (priv->model); zoom_factor = gimp_zoom_model_get_factor (priv->model);
width = preview->width; width = preview->width;
...@@ -319,23 +322,21 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview, ...@@ -319,23 +322,21 @@ gimp_zoom_preview_draw_buffer (GimpPreview *preview,
const guchar *buffer, const guchar *buffer,
gint rowstride) gint rowstride)
{ {
gint32 image_id;
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview); GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
GimpDrawable *drawable = priv->drawable; GimpDrawable *drawable = priv->drawable;
gint32 image_id;
image_id = gimp_drawable_get_image (drawable->drawable_id); image_id = gimp_drawable_get_image (drawable->drawable_id);
if (gimp_selection_is_empty (image_id)) if (gimp_selection_is_empty (image_id))
{ {
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area), gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview->area),
0, 0, 0, 0,
preview->width, preview->height, preview->width, preview->height,
gimp_drawable_type (drawable->drawable_id), gimp_drawable_type (drawable->drawable_id),
buffer, buffer,
rowstride); rowstride);
} }
else else
{ {
...@@ -428,7 +429,8 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview, ...@@ -428,7 +429,8 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview,
{ {
buffer = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id, buffer = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
x1, y1, x2 - x1, y2 - y1, x1, y1, x2 - x1, y2 - y1,
&nav_width, &nav_height, &bpp); &nav_width, &nav_height,
&bpp);
} }
else else
{ {
...@@ -454,6 +456,7 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview, ...@@ -454,6 +456,7 @@ gimp_zoom_preview_draw_thumb (GimpPreview *preview,
g_free (buffer); g_free (buffer);
return; return;
} }
gimp_preview_area_draw (area, gimp_preview_area_draw (area,
0, 0, nav_width, nav_height, 0, 0, nav_width, nav_height,
type, buffer, bpp * nav_width); type, buffer, bpp * nav_width);
...@@ -472,13 +475,13 @@ gimp_zoom_preview_get_bounds (GimpDrawable *drawable, ...@@ -472,13 +475,13 @@ gimp_zoom_preview_get_bounds (GimpDrawable *drawable,
gint *xmax, gint *xmax,
gint *ymax) gint *ymax)
{ {
gboolean retval;
gint width; gint width;
gint height; gint height;
gint offset_x; gint offset_x;
gint offset_y; gint offset_y;
gint x1, y1; gint x1, y1;
gint x2, y2; gint x2, y2;
gboolean retval;
width = gimp_drawable_width (drawable->drawable_id); width = gimp_drawable_width (drawable->drawable_id);
height = gimp_drawable_height (drawable->drawable_id); height = gimp_drawable_height (drawable->drawable_id);
...@@ -508,9 +511,9 @@ GtkWidget * ...@@ -508,9 +511,9 @@ GtkWidget *
gimp_zoom_preview_new (GimpDrawable *drawable) gimp_zoom_preview_new (GimpDrawable *drawable)
{ {
GimpZoomPreview *preview; GimpZoomPreview *preview;
GimpZoomPreviewPrivate *priv;
gint width, height; gint width, height;
gint max_width, max_height; gint max_width, max_height;
GimpZoomPreviewPrivate *priv;
gint x1, y1; gint x1, y1;
gint x2, y2; gint x2, y2;
...@@ -536,8 +539,10 @@ gimp_zoom_preview_new (GimpDrawable *drawable) ...@@ -536,8 +539,10 @@ gimp_zoom_preview_new (GimpDrawable *drawable)
priv->extents.x = 0; priv->extents.x = 0;
priv->extents.y = 0; priv->extents.y = 0;
} }
priv->extents.width = width; priv->extents.width = width;
priv->extents.height = height; priv->extents.height = height;
if (width > height) if (width > height)
{ {
max_width = MIN (width, 512); max_width = MIN (width, 512);
...@@ -548,6 +553,7 @@ gimp_zoom_preview_new (GimpDrawable *drawable) ...@@ -548,6 +553,7 @@ gimp_zoom_preview_new (GimpDrawable *drawable)
max_height = MIN (height, 512); max_height = MIN (height, 512);
max_width = (width * max_height) / height; max_width = (width * max_height) / height;
} }
gimp_preview_set_bounds (GIMP_PREVIEW (preview), gimp_preview_set_bounds (GIMP_PREVIEW (preview),
0, 0, max_width, max_height); 0, 0, max_width, max_height);
...@@ -591,3 +597,51 @@ gimp_zoom_preview_get_factor (GimpZoomPreview *preview) ...@@ -591,3 +597,51 @@ gimp_zoom_preview_get_factor (GimpZoomPreview *preview)
return gimp_zoom_model_get_factor (priv->model); return gimp_zoom_model_get_factor (priv->model);
} }
/**
* gimp_zoom_preview_get_source:
* @preview:
* @width:
* @height:
* @bpp:
*
*
* Return Value:
*
* Since: GIMP 2.4
*/
guchar *
gimp_zoom_preview_get_source (GimpZoomPreview *preview,
gint *width,
gint *height,
gint *bpp)
{
GimpZoomPreviewPrivate *priv = GIMP_ZOOM_PREVIEW_GET_PRIVATE (preview);
GimpPreview *gimp_preview = GIMP_PREVIEW (preview);
GimpDrawable *drawable = priv->drawable;
guchar *data;
gint src_x;
gint src_y;
gint src_width;
gint src_height;
gdouble zoom_factor;
zoom_factor = gimp_zoom_model_get_factor (priv->model);
*width = gimp_preview->width;
*height = gimp_preview->height;
src_x = priv->extents.x +
gimp_preview->xoff * priv->extents.width / *width / zoom_factor;
src_y = priv->extents.y +
gimp_preview->yoff * priv->extents.height / *height / zoom_factor;
src_width = priv->extents.width / zoom_factor;
src_height = priv->extents.height / zoom_factor;
data = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
src_x, src_y,
src_width, src_height,
width, height, bpp);
return data;
}
...@@ -436,6 +436,10 @@ gimp_scrolled_preview_area_event (GtkWidget *area, ...@@ -436,6 +436,10 @@ gimp_scrolled_preview_area_event (GtkWidget *area,
GtkAdjustment *adj; GtkAdjustment *adj;
gfloat value; gfloat value;
/* Ctrl-Scroll is reserved for zooming */
if (sevent->state & GDK_CONTROL_MASK)
return FALSE;
if (sevent->state & GDK_SHIFT_MASK) if (sevent->state & GDK_SHIFT_MASK)
switch (direction) switch (direction)
{ {
...@@ -474,7 +478,9 @@ gimp_scrolled_preview_area_event (GtkWidget *area, ...@@ -474,7 +478,9 @@ gimp_scrolled_preview_area_event (GtkWidget *area,
break; break;
} }
gtk_adjustment_set_value (adj, value); gtk_adjustment_set_value (adj, CLAMP (value,
adj->lower,
adj->upper - adj->page_size));
} }
break; break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment