aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-02-23 16:02:34 +0100
committerThomas White <taw@physics.org>2021-02-23 16:02:34 +0100
commit8d0b642f67a2068ca9caad99b78dbd28950f33f6 (patch)
treeab9919d3b16d9c9e76400bf08d12457d933deac7 /src
parentba297b8c672e9058cc727ed2c81679760aad98b5 (diff)
Centre image at start (or on zoom reset)
This just sets the scroll bars to the middle position, which is not necessarily the middle of the detector. Still, it's better than starting at the edge every time.
Diffstat (limited to 'src')
-rw-r--r--src/crystfel_gui.c1
-rw-r--r--src/crystfelimageview.c16
-rw-r--r--src/crystfelimageview.h1
3 files changed, 18 insertions, 0 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index 5d71172e..daac90ab 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -1022,6 +1022,7 @@ int main(int argc, char *argv[])
proj.cur_frame = 0;
update_imageview(&proj);
+ crystfel_image_view_reset_zoom(CRYSTFEL_IMAGE_VIEW(proj.imageview));
toolbar = gtk_hbox_new(FALSE, 0.0);
diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c
index 795d628c..96f49803 100644
--- a/src/crystfelimageview.c
+++ b/src/crystfelimageview.c
@@ -739,6 +739,7 @@ GtkWidget *crystfel_image_view_new()
iv->refl_box_size = 1.0;
iv->label_refls = 1;
iv->need_rerender = 0;
+ iv->need_recentre = 0;
g_signal_connect(G_OBJECT(iv), "destroy",
G_CALLBACK(destroy_sig), iv);
@@ -911,6 +912,15 @@ static double auto_scale_top(const struct image *image)
}
+static void center_adjustment(GtkAdjustment *adj)
+{
+ double min = gtk_adjustment_get_lower(adj);
+ double max = gtk_adjustment_get_upper(adj);
+ double page = gtk_adjustment_get_page_size(adj);
+ gtk_adjustment_set_value(adj, min+(max-min-page)/2.0);
+}
+
+
static int rerender_image(CrystFELImageView *iv)
{
int i;
@@ -956,6 +966,11 @@ static int rerender_image(CrystFELImageView *iv)
iv->zoom = 1.0/iv->image->detgeom->panels[0].pixel_pitch;
}
configure_scroll_adjustments(iv);
+ if ( iv->need_recentre ) {
+ center_adjustment(iv->hadj);
+ center_adjustment(iv->vadj);
+ iv->need_recentre = 0;
+ }
iv->need_rerender = 0;
redraw(iv);
@@ -980,6 +995,7 @@ void crystfel_image_view_reset_zoom(CrystFELImageView *iv)
iv->detector_w = 1.0;
iv->detector_h = 1.0;
iv->zoom = -1.0;
+ iv->need_recentre = 1;
iv->need_rerender = 1;
redraw(iv);
}
diff --git a/src/crystfelimageview.h b/src/crystfelimageview.h
index 9e1bf4a1..8d51a48b 100644
--- a/src/crystfelimageview.h
+++ b/src/crystfelimageview.h
@@ -68,6 +68,7 @@ struct _crystfelimageview
/* Redraw/scroll stuff */
int need_rerender;
+ int need_recentre;
GtkScrollablePolicy hpol;
GtkScrollablePolicy vpol;
GtkAdjustment *hadj;