diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-08-26 14:15:58 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-10-06 11:21:23 +0200 |
commit | d23c0cde6c61f4c43a43973f26bf0110234be43c (patch) | |
tree | ea70901958370f1845ece19b30aa7b5074a0a8c5 | |
parent | cc0bbd1aae18dc2b96b86729983931c83ce84c5b (diff) | |
download | mupdf-d23c0cde6c61f4c43a43973f26bf0110234be43c.tar.xz |
glut: Scroll zoomed in page view with arrow keys.
-rw-r--r-- | platform/glut/glut-main.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/platform/glut/glut-main.c b/platform/glut/glut-main.c index f37d5b0b..0f64a8da 100644 --- a/platform/glut/glut-main.c +++ b/platform/glut/glut-main.c @@ -152,6 +152,7 @@ static fz_link *links = NULL; static unsigned int page_tex = 0; static int page_x, page_y, page_w, page_h; +static int offset_x = 0, offset_y = 0; void render_page(int pagenumber, float zoom, float rotate) { @@ -322,6 +323,7 @@ static void draw_outline(fz_outline *node, int w) static int y = 0; int h; + w -= 15; h = measure_outline_height(outline); ui_scrollbar(w, 0, w+15, screen_h, &y, screen_h, h); @@ -450,6 +452,7 @@ static void display(void) fz_rect r; float x, y; int canvas_x, canvas_w; + int canvas_y, canvas_h; glViewport(0, 0, screen_w, screen_h); glClearColor(0.3, 0.3, 0.4, 1.0); @@ -491,8 +494,34 @@ static void display(void) canvas_w = screen_w; } - x = canvas_x + (canvas_w - page_w) / 2; - y = (screen_h - page_h) / 2; + canvas_y = 0; + canvas_h = screen_h; + + if (page_w <= canvas_w) + { + x = canvas_x + (canvas_w - page_w) / 2; + } + else + { + if (offset_x > 0) + offset_x = 0; + if (offset_x + page_w < canvas_w) + offset_x = canvas_w - page_w; + x = canvas_x + offset_x; + } + + if (page_h <= canvas_h) + { + y = canvas_y + (canvas_h - page_h) / 2; + } + else + { + if (offset_y > 0) + offset_y = 0; + if (offset_y + page_h < canvas_h) + offset_y = canvas_h - page_h; + y = canvas_y + offset_y; + } r.x0 = x; r.y0 = y; @@ -558,8 +587,19 @@ static void keyboard(unsigned char key, int x, int y) static void special(int key, int x, int y) { int mod = glutGetModifiers(); + if (key == GLUT_KEY_F4 && mod == GLUT_ACTIVE_ALT) exit(0); + + switch (key) + { + case GLUT_KEY_UP: offset_y += 10; break; + case GLUT_KEY_DOWN: offset_y -= 10; break; + case GLUT_KEY_LEFT: offset_x += 10; break; + case GLUT_KEY_RIGHT: offset_x -= 10; break; + } + + glutPostRedisplay(); } static void mouse(int button, int state, int x, int y) |