]> granicus.if.org Git - nethack/commitdiff
revise X11 highlight yn prompting
authorPatR <rankin@nethack.org>
Tue, 9 Feb 2016 00:32:07 +0000 (16:32 -0800)
committerPatR <rankin@nethack.org>
Tue, 9 Feb 2016 00:32:07 +0000 (16:32 -0800)
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.

include/winX.h
win/X11/NetHack.ad
win/X11/winX.c
win/X11/winmap.c

index 536ec84d0b67dae7da12605a00bd2412d2e998a6..78648c8b4f89e60f8bbdabc7c5298a3e1372c7a4 100644 (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));
index 8958b31ec4bb686135bcfd013df3b8f09c66aacd..89a29fd5899d9c0e8ba5c881fa59774a51a5b8f1 100644 (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
 !
index b0714ab5b05bb324126f7770c172707a53fa897b..2633b45cd854fd25dde8c1531d51e0cd0bf3d3bf 100644 (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;
 }
index d2b79cf73ea303c9a5dfb86907b4c827a8855823..93f5dd6c3710d3e0fd6925e28f3660fa3ade3795 100644 (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;