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:
+6
-4
@@ -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 */
|
/* Copyright (c) Dean Luick, 1992 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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;
|
E int click_x, click_y, click_button, updated_inventory;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Boolean slow;
|
Boolean slow; /* issue prompts between map and message wins */
|
||||||
Boolean autofocus;
|
Boolean autofocus; /* grab pointer focus for popup windows */
|
||||||
Boolean message_line;
|
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 */
|
Boolean double_tile_size; /* double tile size */
|
||||||
String tile_file; /* name of file to open for tiles */
|
String tile_file; /* name of file to open for tiles */
|
||||||
String icon; /* name of desired icon */
|
String icon; /* name of desired icon */
|
||||||
@@ -290,6 +291,7 @@ E Boolean FDECL(nhApproxColor, (Screen *, Colormap, char *, XColor *));
|
|||||||
E Dimension FDECL(nhFontHeight, (Widget));
|
E Dimension FDECL(nhFontHeight, (Widget));
|
||||||
E char FDECL(key_event_to_char, (XKeyEvent *));
|
E char FDECL(key_event_to_char, (XKeyEvent *));
|
||||||
E void FDECL(msgkey, (Widget, XtPointer, XEvent *));
|
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_XtPopup, (Widget, int, Widget));
|
||||||
E void FDECL(nh_XtPopdown, (Widget));
|
E void FDECL(nh_XtPopdown, (Widget));
|
||||||
E void FDECL(win_X11_init, (int));
|
E void FDECL(win_X11_init, (int));
|
||||||
|
|||||||
+8
-1
@@ -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
|
! 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.
|
! 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.
|
! questions is _not_ used.
|
||||||
NetHack*slow: True
|
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.
|
! The number of lines the message window will show without scrolling.
|
||||||
!NetHack*message_lines: 12
|
!NetHack*message_lines: 12
|
||||||
!
|
!
|
||||||
|
|||||||
+44
-6
@@ -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 */
|
/* Copyright (c) Dean Luick, 1992 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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,
|
* can find the template file for NetHack.ad in the current directory,
|
||||||
* load its contents into memory so that the application startup call
|
* load its contents into memory so that the application startup call
|
||||||
* in X11_init_nhwindows() can use them as fallback resources.
|
* 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");
|
fp = fopen("./NetHack.ad", "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
@@ -1048,6 +1050,9 @@ static XtResource resources[] = {
|
|||||||
{ nhStr("message_line"), nhStr("Message_line"), XtRBoolean,
|
{ nhStr("message_line"), nhStr("Message_line"), XtRBoolean,
|
||||||
sizeof(Boolean), XtOffset(AppResources *, message_line), XtRString,
|
sizeof(Boolean), XtOffset(AppResources *, message_line), XtRString,
|
||||||
nhStr("False") },
|
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,
|
{ nhStr("double_tile_size"), nhStr("Double_tile_size"), XtRBoolean,
|
||||||
sizeof(Boolean), XtOffset(AppResources *, double_tile_size), XtRString,
|
sizeof(Boolean), XtOffset(AppResources *, double_tile_size), XtRString,
|
||||||
nhStr("False") },
|
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).
|
* handler and reset its label to be the prompt text (below).
|
||||||
*/
|
*/
|
||||||
input_func = yn_key;
|
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) {
|
} else if (!yn_label) {
|
||||||
/*
|
/*
|
||||||
* Not 'slow'; create a persistent widget that will be popped up
|
* 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;
|
num_args = 0;
|
||||||
XtSetArg(args[num_args], XtNlabel, " "); num_args++;
|
XtSetArg(args[num_args], XtNlabel, " "); num_args++;
|
||||||
XtSetValues(yn_label, args, 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 {
|
} else {
|
||||||
nh_XtPopdown(yn_popup); /* this removes the event grab */
|
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
|
* Set up the playing console. This has three major parts: the
|
||||||
* message window, the map, and the status window.
|
* 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(XtNresizable), True); num_args++;
|
||||||
XtSetArg(args[num_args], nhStr(XtNlabel), " "); num_args++;
|
XtSetArg(args[num_args], nhStr(XtNlabel), " "); num_args++;
|
||||||
XtSetValues(yn_label, args, 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 */
|
/* attempt to catch fatal X11 errors before the program quits */
|
||||||
(void) XtAppSetErrorHandler(app_context, (XtErrorHandler) hangup);
|
(void) XtAppSetErrorHandler(app_context, (XtErrorHandler) hangup);
|
||||||
|
|
||||||
|
highlight_yn(TRUE); /* switch foreground and background */
|
||||||
|
|
||||||
/* We can now print to the message window. */
|
/* We can now print to the message window. */
|
||||||
iflags.window_inited = 1;
|
iflags.window_inited = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -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 */
|
/* Copyright (c) Dean Luick, 1992 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -883,6 +883,7 @@ struct xwindow *wp;
|
|||||||
XClearWindow(XtDisplay(wp->w), XtWindow(wp->w));
|
XClearWindow(XtDisplay(wp->w), XtWindow(wp->w));
|
||||||
set_map_size(wp, COLNO, ROWNO);
|
set_map_size(wp, COLNO, ROWNO);
|
||||||
check_cursor_visibility(wp);
|
check_cursor_visibility(wp);
|
||||||
|
highlight_yn(TRUE); /* change fg/bg to match map */
|
||||||
} else if (wp->prevx != wp->cursx || wp->prevy != wp->cursy) {
|
} else if (wp->prevx != wp->cursx || wp->prevy != wp->cursy) {
|
||||||
register unsigned int x = wp->prevx, y = wp->prevy;
|
register unsigned int x = wp->prevx, y = wp->prevy;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user