aboutsummaryrefslogtreecommitdiff
path: root/src/crystfelimageview.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-02-10 12:10:24 +0100
committerThomas White <taw@physics.org>2022-02-10 12:28:05 +0100
commit4c898a1f455d07ca002725775e61068388025407 (patch)
tree02ca492020d14842d255107690e8350e542e6209 /src/crystfelimageview.c
parent7840ff8f9885278566f414e5b5f9ea6039c12071 (diff)
CrystFELImageView: Handle smooth scrolling events
Fixes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/58
Diffstat (limited to 'src/crystfelimageview.c')
-rw-r--r--src/crystfelimageview.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c
index 05e4f7c8..74d8cca5 100644
--- a/src/crystfelimageview.c
+++ b/src/crystfelimageview.c
@@ -127,33 +127,20 @@ static void configure_scroll_adjustments(CrystFELImageView *iv)
}
-static gint scroll_sig(GtkWidget *window, GdkEventScroll *event,
- CrystFELImageView *iv)
+static void handle_scroll_click(double zoom_scale,
+ CrystFELImageView *iv,
+ GdkEventScroll *event)
{
- double zoom_scale, ratio;
- int claim = FALSE;
+ double ratio;
int zoom_allowed = 1;
- if ( iv->image == NULL ) return FALSE;
-
- if ( event->direction == GDK_SCROLL_UP ) {
- zoom_scale = 1.1;
- claim = TRUE;
- }
- if ( event->direction == GDK_SCROLL_DOWN ) {
- zoom_scale = 0.9;
- claim = TRUE;
- }
- if ( event->direction == GDK_SCROLL_LEFT ) return TRUE;
- if ( event->direction == GDK_SCROLL_RIGHT ) return TRUE;
-
/* Size of a detector pixel in screen pixels */
ratio = iv->zoom * iv->image->detgeom->panels[0].pixel_pitch;
if ( (ratio < 0.05) && (zoom_scale < 1.0) ) zoom_allowed = 0;
if ( (ratio > 100.0) && (zoom_scale > 1.0) ) zoom_allowed = 0;
- if ( claim && zoom_allowed ) {
+ if ( zoom_allowed ) {
double shift_x, shift_y;
double scr_x, scr_y;
@@ -173,8 +160,42 @@ static gint scroll_sig(GtkWidget *window, GdkEventScroll *event,
redraw(iv);
}
+}
+
+
+static gint scroll_sig(GtkWidget *window, GdkEventScroll *event,
+ CrystFELImageView *iv)
+{
+ double xs, ys;
+
+ if ( iv->image == NULL ) return FALSE;
+
+ switch ( event->direction ) {
+
+ case GDK_SCROLL_SMOOTH:
+ if ( gdk_event_get_scroll_deltas((GdkEvent *)event, &xs, &ys) ) {
+ handle_scroll_click(1.0-ys*0.1, iv, event);
+ }
+ return TRUE;
+
+ case GDK_SCROLL_UP:
+ handle_scroll_click(1.1, iv, event);
+ return TRUE;
+
+ case GDK_SCROLL_DOWN:
+ handle_scroll_click(0.9, iv, event);
+ return TRUE;
- return claim;
+ case GDK_SCROLL_LEFT:
+ return TRUE; /* Do not propagate further */
+
+ case GDK_SCROLL_RIGHT:
+ return TRUE; /* Do not propagate further */
+
+ default:
+ printf("Unhandled scroll direction %i\n", event->direction);
+ return FALSE;
+ }
}
@@ -848,7 +869,7 @@ GtkWidget *crystfel_image_view_new()
| GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
| GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK
- | GDK_SCROLL_MASK);
+ | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK);
gtk_widget_grab_focus(GTK_WIDGET(iv));