revise X11 highlight yn prompting

The three line change I made previously to implement highlighting for
prompts that ask for single-character input was easy and worked well
for a tiles map, but it didn't look very good for a text map.  This
handles both text map and tile map and also adds a configurable
'highlight_prompt' X resource to let the user enable or disable the
feature.  The resource template file (win/X11/NetHack.ad, copied to
$HACKDIR during install) now has it enabled by default.

The highlighting--more specifically, the "lowlighting" when no prompt
is active--still looks bad if the map window has a vertical scrollbar
on left edge.  I don't have any inspiration about how to fix that up.
This commit is contained in:
PatR
2016-02-08 16:32:07 -08:00
parent 518e067e82
commit c8aa84337b
4 changed files with 60 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winX.h $NHDT-Date: 1454455159 2016/02/02 23:19:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.21 $ */
/* NetHack 3.6 winX.h $NHDT-Date: 1454977916 2016/02/09 00:31:56 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.22 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -244,9 +244,10 @@ E boolean exit_x_event; /* exit condition for event loop */
E int click_x, click_y, click_button, updated_inventory;
typedef struct {
Boolean slow;
Boolean autofocus;
Boolean message_line;
Boolean slow; /* issue prompts between map and message wins */
Boolean autofocus; /* grab pointer focus for popup windows */
Boolean message_line; /* separate current turn mesgs from prev ones */
Boolean highlight_prompt; /* if 'slow', highlight yn prompts */
Boolean double_tile_size; /* double tile size */
String tile_file; /* name of file to open for tiles */
String icon; /* name of desired icon */
@@ -290,6 +291,7 @@ E Boolean FDECL(nhApproxColor, (Screen *, Colormap, char *, XColor *));
E Dimension FDECL(nhFontHeight, (Widget));
E char FDECL(key_event_to_char, (XKeyEvent *));
E void FDECL(msgkey, (Widget, XtPointer, XEvent *));
E void FDECL(highlight_yn, (BOOLEAN_P));
E void FDECL(nh_XtPopup, (Widget, int, Widget));
E void FDECL(nh_XtPopdown, (Widget));
E void FDECL(win_X11_init, (int));

View File

@@ -1,4 +1,4 @@
! $NHDT-Date: 1452920161 2016/01/16 04:56:01 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.9 $
! $NHDT-Date: 1454977917 2016/02/09 00:31:57 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.10 $
! The display_file, tombstone, and menu windows are all formatted assuming
! a fixed width font. Text windows may or may not be formatted as above.
@@ -68,6 +68,13 @@ NetHack*message*translations: <KeyPress>: input()
! questions is _not_ used.
NetHack*slow: True
! If 'slow' is True, setting 'highlight_prompt' to True will cause the line
! between map and message display that's used for prompting to be "hidden"
! as part of the map when no prompt is active, then invert foreground and
! background to stand out when a prompt is issued and waiting for a response.
! If 'slow' is False, 'highlight_prompt' will have no effect.
NetHack*highlight_prompt: True
! The number of lines the message window will show without scrolling.
!NetHack*message_lines: 12
!

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winX.c $NHDT-Date: 1454834200 2016/02/07 08:36:40 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.38 $ */
/* NetHack 3.6 winX.c $NHDT-Date: 1454977918 2016/02/09 00:31:58 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.39 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -501,6 +501,8 @@ load_default_resources()
* can find the template file for NetHack.ad in the current directory,
* load its contents into memory so that the application startup call
* in X11_init_nhwindows() can use them as fallback resources.
*
* No attempt to support the 'include' directive has been made.
*/
fp = fopen("./NetHack.ad", "r");
if (!fp)
@@ -1048,6 +1050,9 @@ static XtResource resources[] = {
{ nhStr("message_line"), nhStr("Message_line"), XtRBoolean,
sizeof(Boolean), XtOffset(AppResources *, message_line), XtRString,
nhStr("False") },
{ nhStr("highlight_prompt"), nhStr("Highlight_prompt"), XtRBoolean,
sizeof(Boolean), XtOffset(AppResources *, highlight_prompt), XtRString,
nhStr("True") },
{ nhStr("double_tile_size"), nhStr("Double_tile_size"), XtRBoolean,
sizeof(Boolean), XtOffset(AppResources *, double_tile_size), XtRString,
nhStr("False") },
@@ -1906,7 +1911,7 @@ char def; /* default response if user hits <space> or <return> */
* handler and reset its label to be the prompt text (below).
*/
input_func = yn_key;
swap_fg_bg(yn_label); /* highlight the prompt line */
highlight_yn(FALSE); /* expose yn_label as separate from map */
} else if (!yn_label) {
/*
* Not 'slow'; create a persistent widget that will be popped up
@@ -1958,7 +1963,7 @@ char def; /* default response if user hits <space> or <return> */
num_args = 0;
XtSetArg(args[num_args], XtNlabel, " "); num_args++;
XtSetValues(yn_label, args, num_args);
swap_fg_bg(yn_label); /* un-highlight the prompt line */
highlight_yn(FALSE); /* disguise yn_label as part of map */
} else {
nh_XtPopdown(yn_popup); /* this removes the event grab */
}
@@ -2036,6 +2041,40 @@ Boolean *flag; /* continue_to_dispatch flag not used */
}
}
/* if 'slow' and 'highlight_prompt', set the yn_label widget to look like
part of the map when idle or to invert background and foreground when
a prompt is active */
void
highlight_yn(init)
boolean init;
{
struct xwindow *xmap;
if (!appResources.slow || !appResources.highlight_prompt)
return;
/* first time through, WIN_MAP isn't fully initiialized yet */
xmap = ((map_win != WIN_ERR) ? &window_list[map_win]
: (WIN_MAP != WIN_ERR) ? &window_list[WIN_MAP] : 0);
if (init && xmap) {
Arg args[2];
XGCValues vals;
unsigned long fg_bg = (GCForeground | GCBackground);
GC gc = (xmap->map_information->is_tile
? xmap->map_information->tile_map.white_gc
: xmap->map_information->text_map.copy_gc);
(void) memset((genericptr_t) &vals, 0, sizeof vals);
if (XGetGCValues(XtDisplay(xmap->w), gc, fg_bg, &vals)) {
XtSetArg(args[0], XtNforeground, vals.foreground);
XtSetArg(args[1], XtNbackground, vals.background);
XtSetValues(yn_label, args, TWO);
}
} else
swap_fg_bg(yn_label);
}
/*
* Set up the playing console. This has three major parts: the
* message window, the map, and the status window.
@@ -2098,9 +2137,6 @@ init_standard_windows()
XtSetArg(args[num_args], nhStr(XtNresizable), True); num_args++;
XtSetArg(args[num_args], nhStr(XtNlabel), " "); num_args++;
XtSetValues(yn_label, args, num_args);
/* switch foreground and background so that the prompt line looks
like part of the map */
swap_fg_bg(yn_label);
}
/*
@@ -2241,6 +2277,8 @@ init_standard_windows()
/* attempt to catch fatal X11 errors before the program quits */
(void) XtAppSetErrorHandler(app_context, (XtErrorHandler) hangup);
highlight_yn(TRUE); /* switch foreground and background */
/* We can now print to the message window. */
iflags.window_inited = 1;
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winmap.c $NHDT-Date: 1454455161 2016/02/02 23:19:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.26 $ */
/* NetHack 3.6 winmap.c $NHDT-Date: 1454977918 2016/02/09 00:31:58 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.27 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -883,6 +883,7 @@ struct xwindow *wp;
XClearWindow(XtDisplay(wp->w), XtWindow(wp->w));
set_map_size(wp, COLNO, ROWNO);
check_cursor_visibility(wp);
highlight_yn(TRUE); /* change fg/bg to match map */
} else if (wp->prevx != wp->cursx || wp->prevy != wp->cursy) {
register unsigned int x = wp->prevx, y = wp->prevy;