From 28e36b31363f0a0ab1b68a902838cf12e133b587 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 20 Sep 2016 18:36:03 +0300 Subject: [PATCH] Add full compass coordinate mode for screen readers --- doc/Guidebook.mn | 1 + doc/Guidebook.tex | 1 + include/flag.h | 1 + src/do_name.c | 19 +++++++++++++------ src/options.c | 8 +++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index eef8ccc6a..7e9340869 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -2698,6 +2698,7 @@ The possible settings are: .sd .si .CC c "compass ('east' or '3s' or '2n,4w');" +.CC f "full compass ('east' or '3south' or '2north,4west');" .CC m "map (map column x=0 is not used);" .CC s "screen [row,column] (row is offset to match tty usage);" .CC n "none (no coordinates shown) [default]." diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index 98218165e..272e9e758 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -3230,6 +3230,7 @@ The possible settings are: %.sd %.si {\tt c} --- \verb#compass ('east' or '3s' or '2n,4w')#;\\ +{\tt f} --- \verb#full compass ('east' or '3south' or '2north,4west')#;\\ {\tt m} --- \verb#map (map column x=0 is not used)#;\\ {\tt s} --- \verb#screen [row,column] (row is offset to match tty usage)#;\\ {\tt n} --- \verb#none (no coordinates shown) [default]#. diff --git a/include/flag.h b/include/flag.h index 1f79f07dd..47139d355 100644 --- a/include/flag.h +++ b/include/flag.h @@ -173,6 +173,7 @@ struct sysflag { #define GPCOORDS_NONE 'n' #define GPCOORDS_MAP 'm' #define GPCOORDS_COMPASS 'c' +#define GPCOORDS_COMFULL 'f' #define GPCOORDS_SCREEN 's' struct instance_flags { diff --git a/src/do_name.c b/src/do_name.c index 594cab44d..11d9127c2 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -232,11 +232,11 @@ int gloc; } char * -dxdy_to_dist_descr(dx, dy) +dxdy_to_dist_descr(dx, dy, fulldir) int dx, dy; +boolean fulldir; { - /* [12] suffices, but guard against long translation for direction-name */ - static char buf[20]; + static char buf[30]; int dst; if (!dx && !dy) { @@ -245,18 +245,23 @@ int dx, dy; /* explicit direction; 'one step' is implicit */ Sprintf(buf, "%s", directionname(dst)); } else { + const char *dirnames[4][2] = { + { "n", "north" }, + { "s", "south" }, + { "w", "west" }, + { "e", "east" } }; buf[0] = '\0'; /* 9999: protect buf[] against overflow caused by invalid values */ if (dy) { if (abs(dy) > 9999) dy = sgn(dy) * 9999; - Sprintf(eos(buf), "%d%c%s", abs(dy), (dy > 0) ? 's' : 'n', + Sprintf(eos(buf), "%d%s%s", abs(dy), dirnames[(dy > 0)][fulldir], dx ? "," : ""); } if (dx) { if (abs(dx) > 9999) dx = sgn(dx) * 9999; - Sprintf(eos(buf), "%d%c", abs(dx), (dx > 0) ? 'e' : 'w'); + Sprintf(eos(buf), "%d%s", abs(dx), dirnames[2 + (dx > 0)][fulldir]); } } return buf; @@ -275,11 +280,13 @@ char *outbuf, cmode; switch (cmode) { default: break; + case GPCOORDS_COMFULL: case GPCOORDS_COMPASS: /* "east", "3s", "2n,4w" */ dx = x - u.ux; dy = y - u.uy; - Sprintf(outbuf, "(%s)", dxdy_to_dist_descr(dx, dy)); + Sprintf(outbuf, "(%s)", + dxdy_to_dist_descr(dx, dy, cmode == GPCOORDS_COMFULL)); break; case GPCOORDS_MAP: /* x,y */ /* upper left corner of map is <1,0>; diff --git a/src/options.c b/src/options.c index 225c4aa85..6a0a0d10c 100644 --- a/src/options.c +++ b/src/options.c @@ -2362,7 +2362,8 @@ boolean tinitial, tfrom_file; return; } else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) { static char gpcoords[] = { GPCOORDS_NONE, GPCOORDS_COMPASS, - GPCOORDS_MAP, GPCOORDS_SCREEN, '\0' }; + GPCOORDS_COMFULL, GPCOORDS_MAP, + GPCOORDS_SCREEN, '\0' }; char c = lowc(*op); if (c && index(gpcoords, c)) @@ -4104,6 +4105,10 @@ boolean setinitial, setfromfile; add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_COMPASS, 0, ATR_NONE, "compass ('east' or '3s' or '2n,4w')", (gp == GPCOORDS_COMPASS) ? MENU_SELECTED : MENU_UNSELECTED); + any.a_char = GPCOORDS_COMFULL; + add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_COMFULL, + 0, ATR_NONE, "full compass ('east' or '3south' or '2north,4west')", + (gp == GPCOORDS_COMFULL) ? MENU_SELECTED : MENU_UNSELECTED); any.a_char = GPCOORDS_MAP; add_menu(tmpwin, NO_GLYPH, &any, GPCOORDS_MAP, 0, ATR_NONE, "map ", @@ -4917,6 +4922,7 @@ char *buf; Sprintf(buf, "%s", (iflags.getpos_coords == GPCOORDS_MAP) ? "map" : (iflags.getpos_coords == GPCOORDS_COMPASS) ? "compass" + : (iflags.getpos_coords == GPCOORDS_COMFULL) ? "full compass" : (iflags.getpos_coords == GPCOORDS_SCREEN) ? "screen" : "none"); } else if (!strcmp(optname, "scores")) { -- 2.40.0