[gs-commits] mupdf 1.16.0.10 gl: Make usage display a proper dialog bo

[email protected] (Tor Andersson)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
commit 6a0d0f1e0f7f2569d9409569ff01fe030e382a0c
Author: Tor Andersson <[email protected]>
Date:   Wed Jul 31 13:28:44 2019 +0200

    gl: Make usage display a proper dialog box with scrollable text label.

diff --git a/platform/gl/gl-app.h b/platform/gl/gl-app.h
index 19f0020..7f91484 100644
--- a/platform/gl/gl-app.h
+++ b/platform/gl/gl-app.h
@@ -177,6 +177,7 @@ void ui_panel_end(void);
 void ui_spacer(void);
 void ui_splitter(int *x, int min, int max, enum side side);
 void ui_label(const char *fmt, ...);
+void ui_label_with_scrollbar(char *text, int width, int height, int *scroll);
 int ui_button(const char *label);
 int ui_checkbox(const char *label, int *value);
 int ui_slider(int *value, int min, int max, int width);
diff --git a/platform/gl/gl-main.c b/platform/gl/gl-main.c
index d867795..332974f 100644
--- a/platform/gl/gl-main.c
+++ b/platform/gl/gl-main.c
@@ -173,7 +173,6 @@ static int showoutline = 0;
 static int showlinks = 0;
 static int showsearch = 0;
 static int showinfo = 0;
-static int showhelp = 0;
 int showannotate = 0;
 int showform = 0;
 
@@ -400,6 +399,79 @@ static int search_hit_page = -1;
 static int search_hit_count = 0;
 static fz_quad search_hit_quads[5000];
 
+static char *help_dialog_text =
+	"The middle mouse button (scroll wheel button) pans the document view. "
+	"The right mouse button selects a region and copies the marked text to the clipboard."
+	"\n"
+	"\n"
+	"F1 - show this message\n"
+	"i - show document information\n"
+	"o - show document outline\n"
+	"a - show annotation editor\n"
+	"L - highlight links\n"
+	"F - highlight form fields\n"
+	"r - reload file\n"
+	"S - save file (only for PDF)\n"
+	"q - quit\n"
+	"\n"
+	"< - decrease E-book font size\n"
+	"> - increase E-book font size\n"
+	"A - toggle anti-aliasing\n"
+	"I - toggle inverted color mode\n"
+	"C - toggle tinted color mode\n"
+	"E - toggle ICC color management\n"
+	"e - toggle spot color emulation\n"
+	"\n"
+	"f - fullscreen window\n"
+	"w - shrink wrap window\n"
+	"W - fit to width\n"
+	"H - fit to height\n"
+	"Z - fit to page\n"
+	"z - reset zoom\n"
+	"[number] z - set zoom resolution in DPI\n"
+	"plus - zoom in\n"
+	"minus - zoom out\n"
+	"[ - rotate counter-clockwise\n"
+	"] - rotate clockwise\n"
+	"arrow keys - scroll in small increments\n"
+	"h, j, k, l - scroll in small increments\n"
+	"\n"
+	"b - smart move backward\n"
+	"space - smart move forward\n"
+	"comma or page up - go backward\n"
+	"period or page down - go forward\n"
+	"g - go to first page\n"
+	"G - go to last page\n"
+	"[number] g - go to page number\n"
+	"\n"
+	"m - save current location in history\n"
+	"t - go backward in history\n"
+	"T - go forward in history\n"
+	"[number] m - save current location in numbered bookmark\n"
+	"[number] t - go to numbered bookmark\n"
+	"\n"
+	"/ - search for text forward\n"
+	"? - search for text backward\n"
+	"n - repeat search\n"
+	"N - repeat search in reverse direction"
+	;
+
+static void help_dialog(void)
+{
+	static int scroll;
+	ui_dialog_begin(500, 1000);
+	ui_layout(T, X, W, 2, 2);
+	ui_label("MuPDF %s", FZ_VERSION);
+	ui_spacer();
+	ui_layout(B, NONE, S, 2, 2);
+	if (ui_button("Okay") || ui.key == KEY_ENTER || ui.key == KEY_ESCAPE)
+		ui.dialog = NULL;
+	ui_spacer();
+	ui_layout(ALL, BOTH, CENTER, 2, 2);
+	ui_label_with_scrollbar(help_dialog_text, 0, 0, &scroll);
+	ui_dialog_end();
+}
+
 static char error_message[256];
 static void error_dialog(void)
 {
@@ -1110,14 +1182,14 @@ static void do_app(void)
 		glutLeaveMainLoop();
 
 	if (ui.down || ui.middle || ui.right || ui.key)
-		showinfo = showhelp = 0;
+		showinfo = 0;
 
 	if (!ui.focus && ui.key && ui.plain)
 	{
 		switch (ui.key)
 		{
 		case KEY_ESCAPE: clear_search(); selected_annot = NULL; break;
-		case KEY_F1: showhelp = !showhelp; break;
+		case KEY_F1: ui.dialog = help_dialog; break;
 		case 'a': toggle_annotate(); break;
 		case 'o': toggle_outline(); break;
 		case 'L': showlinks = !showlinks; break;
@@ -1304,77 +1376,6 @@ static void do_info(void)
 	ui_dialog_end();
 }
 
-static void do_help_line(char *label, char *text)
-{
-	ui_panel_begin(0, ui.lineheight, 0, 0, 0);
-	{
-		ui_layout(L, NONE, W, 0, 0);
-		ui_panel_begin(150, ui.lineheight, 0, 0, 0);
-		ui_layout(R, NONE, W, 20, 0);
-		ui_label("%s", label);
-		ui_panel_end();
-
-		ui_layout(ALL, X, W, 0, 0);
-		ui_panel_begin(0, ui.lineheight, 0, 0, 0);
-		ui_label("%s", text);
-		ui_panel_end();
-	}
-	ui_panel_end();
-}
-
-static void do_help(void)
-{
-	ui_dialog_begin(500, 41 * ui.lineheight);
-	ui_layout(T, X, W, 0, 0);
-
-	do_help_line("MuPDF", FZ_VERSION);
-	ui_spacer();
-	do_help_line("F1", "show this message");
-	do_help_line("i", "show document information");
-	do_help_line("o", "show/hide outline");
-	do_help_line("a", "show/hide annotation editor");
-	do_help_line("L", "show/hide links");
-	do_help_line("F", "show/hide form fields");
-	do_help_line("r", "reload file");
-	do_help_line("S", "save PDF file");
-	do_help_line("q", "quit");
-	ui_spacer();
-	do_help_line("<", "decrease E-book font size");
-	do_help_line(">", "increase E-book font size");
-	do_help_line("I", "toggle inverted color mode");
-	do_help_line("C", "toggle tinted color mode");
-	do_help_line("e", "toggle spot color emulation");
-	do_help_line("E", "toggle ICC color management");
-	do_help_line("A", "toggle anti-aliasing");
-	ui_spacer();
-	do_help_line("f", "fullscreen window");
-	do_help_line("w", "shrink wrap window");
-	do_help_line("W or H", "fit to width or height");
-	do_help_line("Z", "fit to page");
-	do_help_line("z", "reset zoom");
-	do_help_line("N z", "set zoom to N");
-	do_help_line("+ or -", "zoom in or out");
-	do_help_line("[ or ]", "rotate left or right");
-	do_help_line("arrow keys", "pan in small increments");
-	ui_spacer();
-	do_help_line("b", "smart move backward");
-	do_help_line("Space", "smart move forward");
-	do_help_line(", or PgUp", "go backward");
-	do_help_line(". or PgDn", "go forward");
-	do_help_line("N g", "go to page N");
-	do_help_line("G", "go to last page");
-	ui_spacer();
-	do_help_line("t", "go backward in history");
-	do_help_line("T", "go forward in history");
-	do_help_line("N m", "save location in bookmark N");
-	do_help_line("N t", "go to bookmark N");
-	ui_spacer();
-	do_help_line("/ or ?", "search for text");
-	do_help_line("n or N", "repeat search");
-
-	ui_dialog_end();
-}
-
 static void do_canvas(void)
 {
 	static int saved_scroll_x = 0;
@@ -1588,8 +1589,6 @@ void do_main(void)
 
 	if (showinfo)
 		do_info();
-	else if (showhelp)
-		do_help();
 }
 
 void run_main_loop(void)
diff --git a/platform/gl/gl-ui.c b/platform/gl/gl-ui.c
index 04c7e17..9da029a 100644
--- a/platform/gl/gl-ui.c
+++ b/platform/gl/gl-ui.c
@@ -1070,6 +1070,30 @@ void ui_list_end(struct list *list)
 	ui_tree_end(list);
 }
 
+void ui_label_with_scrollbar(char *text, int width, int height, int *scroll)
+{
+	struct line lines[500];
+	fz_irect area;
+	int n;
+
+	area = ui_pack(width, height);
+	n = ui_break_lines(text, lines, nelem(lines), area.x1-area.x0 - 16, NULL);
+	if (n > (area.y1-area.y0) / ui.lineheight)
+	{
+		if (ui_mouse_inside(area))
+			*scroll -= ui.scroll_y * ui.lineheight * 3;
+		ui_scrollbar(area.x1-16, area.y0, area.x1, area.y1, scroll, area.y1-area.y0, n * ui.lineheight);
+	}
+	else
+		*scroll = 0;
+
+	glScissor(area.x0, ui.window_h-area.y1, area.x1-area.x0-16, area.y1-area.y0);
+	glEnable(GL_SCISSOR_TEST);
+	glColorHex(UI_COLOR_TEXT_FG);
+	ui_draw_lines(area.x0, area.y0 - *scroll, lines, n);
+	glDisable(GL_SCISSOR_TEST);
+}
+
 int ui_popup(const void *id, const char *label, int is_button, int count)
 {
 	int width = ui_measure_string(label);

http://git.ghostscript.com/?p=mupdf.git;a=commit;h=6a0d0f1e0f7f2569d9409569ff01fe030e382a0c

--
MuPDF library
Artifex Software, Inc.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.