From 8f1c17018f8c1141089300762619b9f04d855c83 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 24 Feb 2015 12:05:10 +0100 Subject: glut: Show page number and file name in window title bar. --- platform/glut/glut-main.c | 57 ++++++++++++++++++++++++++++++++++------------- 1 file 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); -- cgit v1.2.3