diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-02-24 12:05:10 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-10-06 11:21:23 +0200 |
commit | 8f1c17018f8c1141089300762619b9f04d855c83 (patch) | |
tree | c39f477056e4629f28676c889732d02ab2601954 | |
parent | a60628470e5ec33d2a3a31f3fc5d2bea8f0ef853 (diff) | |
download | mupdf-8f1c17018f8c1141089300762619b9f04d855c83.tar.xz |
glut: Show page number and file name in window title bar.
-rw-r--r-- | platform/glut/glut-main.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/platform/glut/glut-main.c b/platform/glut/glut-main.c index 01c9a884..b646d919 100644 --- a/platform/glut/glut-main.c +++ b/platform/glut/glut-main.c @@ -138,6 +138,8 @@ static int zoom_out(int oldres) #define MAXRES (zoom_list[nelem(zoom_list)-1]) #define DEFRES 96 +static const char *filename = ""; +static const char *title = "MuPDF/GL"; static fz_context *ctx = NULL; static fz_document *doc = NULL; static fz_outline *outline = NULL; @@ -151,6 +153,33 @@ static int scroll_x = 0, scroll_y = 0; static int canvas_x = 0, canvas_w = 100; static int canvas_y = 0, canvas_h = 100; +static int screen_w = 1, screen_h = 1; + +static int oldpage = 0, currentpage = 0; +static float oldzoom = DEFRES, currentzoom = DEFRES; +static float oldrotate = 0, currentrotate = 0; + +static int showoutline = 0; +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 update_title(void) +{ + static char buf[256]; + int n = strlen(title); + if (n > 50) + sprintf(buf, "...%s - %d / %d", title + n - 50, currentpage + 1, fz_count_pages(ctx, doc)); + else + sprintf(buf, "%s - %d / %d", title, currentpage + 1, fz_count_pages(ctx, doc)); + glutSetWindowTitle(buf); + glutSetIconTitle(buf); +} + void render_page(int pagenumber, float zoom, float rotate) { fz_page *page; @@ -194,21 +223,6 @@ void render_page(int pagenumber, float zoom, float rotate) fz_drop_page(ctx, page); } -static int screen_w = 1, screen_h = 1; - -static int oldpage = 0, currentpage = 0; -static float oldzoom = DEFRES, currentzoom = DEFRES; -static float oldrotate = 0, currentrotate = 0; - -static int showoutline = 0; -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) { if (history_count + 1 >= nelem(history)) @@ -642,6 +656,7 @@ static void display(void) if (oldpage != currentpage || oldzoom != currentzoom || oldrotate != currentrotate) { render_page(currentpage, currentzoom, currentrotate); + update_title(); oldpage = currentpage; oldzoom = currentzoom; oldrotate = currentrotate; @@ -848,9 +863,18 @@ int main(int argc, char **argv) exit(1); } + filename = argv[1]; + title = strrchr(filename, '/'); + if (!title) + title = strrchr(filename, '\\'); + if (title) + ++title; + else + title = filename; + memset(&ui, 0, sizeof ui); - glutCreateWindow("MuPDF/GL"); + glutCreateWindow(filename); ctx = fz_new_context(NULL, NULL, 0); fz_register_document_handlers(ctx); @@ -858,6 +882,7 @@ int main(int argc, char **argv) doc = fz_open_document(ctx, argv[1]); render_page(currentpage, currentzoom, currentrotate); + update_title(); glutReshapeFunc(reshape); glutDisplayFunc(display); |