diff options
author | Thomas White <taw@physics.org> | 2021-03-01 09:47:57 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-03-01 09:47:57 +0100 |
commit | 85bf423b8ec734cee29863b7a411cdb7e5ce0399 (patch) | |
tree | ac71550a6241f288fcc6c736a274560657d425c3 /src | |
parent | 1584bced3ecc9fe699bd972a66741968a838398a (diff) |
GUI: Add history list for random image selection
Diffstat (limited to 'src')
-rw-r--r-- | src/crystfel_gui.c | 41 | ||||
-rw-r--r-- | src/gui_project.c | 2 | ||||
-rw-r--r-- | src/gui_project.h | 5 |
3 files changed, 45 insertions, 3 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index e2be0841..cd69f494 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -277,6 +277,32 @@ void update_imageview(struct crystfelproject *proj) } +static void push_random_frame(struct crystfelproject *proj, int fr) +{ + memmove(&proj->random_history[1], + &proj->random_history[0], + (N_RANDOM_HISTORY-1)*sizeof(int)); + proj->random_history[0] = fr; + proj->n_random_history++; + if ( proj->n_random_history > N_RANDOM_HISTORY ) { + proj->n_random_history = N_RANDOM_HISTORY; + } +} + + +static int pop_random_frame(struct crystfelproject *proj) +{ + int fr; + assert(proj->n_random_history > 0); + fr = proj->random_history[0]; + memmove(&proj->random_history[0], + &proj->random_history[1], + (N_RANDOM_HISTORY-1)*sizeof(int)); + proj->n_random_history--; + return fr; +} + + /* File->Quit */ static gint quit_sig(GtkWidget *widget, struct crystfelproject *proj) { @@ -344,10 +370,19 @@ static gint prev_frame_sig(GtkWidget *widget, static gint random_frame_sig(GtkWidget *widget, + GdkEventButton *event, struct crystfelproject *proj) { - proj->cur_frame = random()*proj->n_frames / RAND_MAX; - update_imageview(proj); + if ( event->state & GDK_SHIFT_MASK ) { + if ( proj->n_random_history > 0 ) { + proj->cur_frame = pop_random_frame(proj); + update_imageview(proj); + } + } else { + push_random_frame(proj, proj->cur_frame); + proj->cur_frame = random()*proj->n_frames / RAND_MAX; + update_imageview(proj); + } return FALSE; } @@ -720,7 +755,7 @@ int main(int argc, char *argv[]) button = gtk_button_new_from_icon_name("media-playlist-shuffle", GTK_ICON_SIZE_LARGE_TOOLBAR); gtk_box_pack_start(GTK_BOX(toolbar), button, FALSE, FALSE, 2.0); - g_signal_connect(G_OBJECT(button), "clicked", + g_signal_connect(G_OBJECT(button), "button-press-event", G_CALLBACK(random_frame_sig), &proj); /* Next */ diff --git a/src/gui_project.c b/src/gui_project.c index 12377d83..752cbc20 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -1060,6 +1060,8 @@ void default_project(struct crystfelproject *proj) proj->geom_filename = NULL; proj->n_frames = 0; proj->max_frames = 0; + proj->n_random_history = 0; + memset(proj->random_history, 0, N_RANDOM_HISTORY*sizeof(int)); proj->filenames = NULL; proj->events = NULL; proj->peak_params = NULL; diff --git a/src/gui_project.h b/src/gui_project.h index e08e20a7..e0717007 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -241,6 +241,9 @@ struct gui_task void *job_priv; }; + +#define N_RANDOM_HISTORY (16) + struct crystfelproject { GtkWidget *window; @@ -262,6 +265,8 @@ struct crystfelproject { int cur_frame; struct image *cur_image; + int random_history[N_RANDOM_HISTORY]; + int n_random_history; char *geom_filename; char *stream_filename; |