diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-02-24 12:03:56 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-10-06 11:21:23 +0200 |
commit | 6bf830926c2f15b40404080ceef034b5cbce0f33 (patch) | |
tree | ecf74c1a46d1210b1053da503b4dac3ad9d82e54 /platform | |
parent | 7bf832f17d73ca5336c6fe621b9ff2138c8b43cc (diff) | |
download | mupdf-6bf830926c2f15b40404080ceef034b5cbce0f33.tar.xz |
glut: Add forward history navigation key, and improve history behavior.
Jumping to a page will put the destination page in the history,
so that after reading a few pages, 't' will return to the point
where the original jump landed.
The forward key ('T', or shift-T) key will return to the page
before 't' was pressed.
Conflicts:
platform/glut/glut-main.c
Diffstat (limited to 'platform')
-rw-r--r-- | platform/glut/glut-main.c | 77 |
1 files changed, 63 insertions, 14 deletions
diff --git a/platform/glut/glut-main.c b/platform/glut/glut-main.c index 92d56cd0..49c1a6e6 100644 --- a/platform/glut/glut-main.c +++ b/platform/glut/glut-main.c @@ -205,6 +205,8 @@ static int showlinks = 0; static int history_count = 0; static int history[256]; +static int future_count = 0; +static int future[256]; static int marks[10]; static void push_history(void) @@ -220,6 +222,50 @@ static void push_history(void) } } +static void push_future(void) +{ + if (future_count + 1 >= nelem(future)) + { + memmove(future, future + 1, sizeof *future * (nelem(future) - 1)); + future[future_count] = currentpage; + } + else + { + future[future_count++] = currentpage; + } +} + +static void clear_future(void) +{ + future_count = 0; +} + +static void jump_to_page(int newpage) +{ + newpage = fz_clampi(newpage, 0, fz_count_pages(ctx, doc) - 1); + clear_future(); + push_history(); + currentpage = newpage; + push_history(); +} + +static void pop_history(void) +{ + int here = currentpage; + push_future(); + while (history_count > 0 && currentpage == here) + currentpage = history[--history_count]; +} + +static void pop_future(void) +{ + int here = currentpage; + push_history(); + while (future_count > 0 && currentpage == here) + currentpage = future[--future_count]; + push_history(); +} + static void draw_string(float x, float y, const char *s) { int c; @@ -304,8 +350,7 @@ static int draw_outline_imp(fz_outline *node, int end, int x0, int x1, int x, in if (!ui.active && ui.down) { ui.active = node; - push_history(); - currentpage = p; + jump_to_page(p); glutPostRedisplay(); /* we changed the current page, so force a redraw */ } } @@ -401,14 +446,9 @@ static void draw_links(fz_link *link, int xofs, int yofs, float zoom, float rota if (ui.hot == link) { if (link->dest.kind == FZ_LINK_GOTO) - { - push_history(); - currentpage = link->dest.ld.gotor.page; - } + jump_to_page(link->dest.ld.gotor.page); else if (link->dest.kind == FZ_LINK_URI) - { open_browser(link->dest.ld.uri.uri); - } } glutPostRedisplay(); } @@ -652,12 +692,21 @@ static void keyboard(unsigned char key, int x, int y) marks[number] = currentpage; break; case 't': - if (number == 0 && history_count > 0) - currentpage = history[--history_count]; + if (number == 0) + { + if (history_count > 0) + pop_history(); + } else if (number > 0 && number < nelem(marks)) { - push_history(); - currentpage = marks[number]; + jump_to_page(marks[number]); + } + break; + case 'T': + if (number == 0) + { + if (future_count > 0) + pop_future(); } break; case 'f': toggle_fullscreen(); break; @@ -671,8 +720,8 @@ static void keyboard(unsigned char key, int x, int y) case '.': currentpage += fz_maxi(number, 1); break; case 'b': number = fz_maxi(number, 1); while (number--) smart_move_backward(); break; case ' ': number = fz_maxi(number, 1); while (number--) smart_move_forward(); break; - case 'g': push_history(); currentpage = number - 1; break; - case 'G': push_history(); currentpage = fz_count_pages(ctx, doc) - 1; break; + case 'g': jump_to_page(number - 1); break; + case 'G': jump_to_page(fz_count_pages(ctx, doc) - 1); break; case '+': currentzoom = zoom_in(currentzoom); break; case '-': currentzoom = zoom_out(currentzoom); break; case '[': currentrotate += 90; break; |